Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: allow you to seed data that has an id < 1 #54

Merged
merged 5 commits into from
Jun 16, 2014

Conversation

SamSaffron
Copy link
Contributor

allow you to seed data that has an id < 1 in postgres

prior to this seed-fu attempts to repair the id sequence with an invalid id

"(SELECT MAX(#{quoted_id}) FROM #{@model_class.quoted_table_name}) + 1" +
");"
)
next_id = (@model_class.maximum(:id) || 0) + 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will introduce race condition errors. There can be an insert between this line and updating sequence so we will change sequence value to wrong one. I think we can achieve the same using

"SELECT pg_catalog.setval(" +
               "#{quoted_sequence}," +
               "(SLECT MAX(#{quoted_id}) FROM #{@model_class.quoted_table_name} where #{quoted_id} > 0) + 1" +
");"

@aserafin
Copy link
Collaborator

can you add tests for your pull requests?

@SamSaffron
Copy link
Contributor Author

@aserafin added spec and fixed specs in rails 4, its not a new concurrency concern, if you want absolute safety you would need a serialized transaction.

@aserafin aserafin merged commit f4ffaf3 into mbleigh:master Jun 16, 2014
aserafin added a commit that referenced this pull request Jun 16, 2014
* commit 'refs/pull/origin/54':
  Failing test in DB=postgresql
  fix specs in Rails 4
  use rspec
  add rake file
  BUGFIX: if you seed data that has an id < 1 seed-fu attempts to reset the id sequence to an invalid id

Conflicts:
	lib/seed-fu/seeder.rb
	spec/spec_helper.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants