Permalink
Browse files

Support PostgreSQL 10

  • Loading branch information...
ppworks committed Oct 25, 2017
1 parent 9d393b2 commit 66ad1f8de7838a4b9733159ba0815826626a0951
Showing with 11 additions and 3 deletions.
  1. +11 −3 lib/seed-fu/seeder.rb
@@ -91,9 +91,17 @@ def update_id_sequence
quoted_id = @model_class.connection.quote_column_name(@model_class.primary_key)
sequence = @model_class.sequence_name

@model_class.connection.execute <<-EOS
SELECT setval('#{sequence}', (SELECT GREATEST(MAX(#{quoted_id})+(SELECT increment_by FROM #{sequence}), (SELECT min_value FROM #{sequence})) FROM #{@model_class.quoted_table_name}), false)
EOS
if @model_class.connection.postgresql_version >= 100000
sql =<<-EOS
SELECT setval('#{sequence}', (SELECT GREATEST(MAX(#{quoted_id})+(SELECT seqincrement FROM pg_sequence WHERE seqrelid = '#{sequence}'::regclass), (SELECT seqmin FROM pg_sequence WHERE seqrelid = '#{sequence}'::regclass)) FROM #{@model_class.quoted_table_name}), false)
EOS
else
sql =<<-EOS
SELECT setval('#{sequence}', (SELECT GREATEST(MAX(#{quoted_id})+(SELECT increment_by FROM #{sequence}), (SELECT min_value FROM #{sequence})) FROM #{@model_class.quoted_table_name}), false)
EOS
end

@model_class.connection.execute sql
end
end
end

0 comments on commit 66ad1f8

Please sign in to comment.