Permalink
Browse files

Merge pull request #121 from ppworks/support-postgresql10

Support PostgreSQL 10
  • Loading branch information...
aserafin committed Nov 24, 2017
2 parents 9d393b2 + 66ad1f8 commit 52072e7e74db592008e8a222c75695877b70caea
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 52072e7

Please sign in to comment.