Skip to content

Commit

Permalink
Merge pull request #125 from mnaberez/postgresql_version
Browse files Browse the repository at this point in the history
Restore support for PostgreSQL with Rails versions before 5.0.0
  • Loading branch information
aserafin authored Apr 7, 2018
2 parents 9a5913f + 0ad8e46 commit ba11d38
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Version 2.3.8
-------------

Bug fixes:

* Restored support for PostgreSQL with Rails versions before 5.0.0 broken in Seed Fu 2.3.7.

Version 2.3.7
-------------

Expand Down
3 changes: 2 additions & 1 deletion lib/seed-fu/seeder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def update_id_sequence
quoted_id = @model_class.connection.quote_column_name(@model_class.primary_key)
sequence = @model_class.sequence_name

if @model_class.connection.postgresql_version >= 100000
# TODO postgresql_version was made public in Rails 5.0.0, remove #send when support for earlier versions are dropped
if @model_class.connection.send(: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
Expand Down

0 comments on commit ba11d38

Please sign in to comment.