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

Raise an error if sequence is defined for attribute with auto-incrementing sequence in the DB #1585

Open
owst opened this issue Jul 1, 2023 · 0 comments
Labels

Comments

@owst
Copy link

owst commented Jul 1, 2023

This feature request came from rubocop/rubocop-factory_bot#52 which has an example reproduction of the problem.

Problem this feature will solve

E.g. with a simple factory:

  factory :post do
    sequence :id
  end

where the post table's id is backed by a DB sequence, it is quite easy for the FactoryBot sequence to get out of sync with the DB sequence and cause duplicate errors, for example with:

FactoryBot.create(:post)
Post.create!
FactoryBot.create(:post)

the second FactoryBot.create will error due to a duplicate id value in the DB.

Desired solution

Disallow defining a sequence for an attribute that is backed by an auto-incrementing sequence in the database.

Alternatives considered

Perhaps the RuboCop check is sufficient, and implementing the check/error in FactoryBot is not possible or deemed worth the effort?

@owst owst added the feature label Jul 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant