-
Notifications
You must be signed in to change notification settings - Fork 18
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
AlecK/APPEALS-35707 Replace database_cleaner
with database_cleaner-active_record
#20779
base: main
Are you sure you want to change the base?
Conversation
database_cleaner
with database_cleaner-active_record
Code Climate has analyzed commit f52a7b3 and detected 0 issues on this pull request. View more on Code Climate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple minor changes I'd like to see (mostly clean up).
Also, since locking the gem to 2.0.0
is more of a temporary workaround, I would like to see if we can implement a permanent solution similar to the one you alluded to in the PR description (here)...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⭐ Looks great!
…ction. DBCleanerAR locked to 2.0.0
Remove old commented gem Co-authored-by: Jeremy Croteau <[email protected]>
Forgot about byebug, removed Co-authored-by: Jeremy Croteau <[email protected]>
dd0e79c
to
f52a7b3
Compare
Resolves APPEALS-35707
Description
With Rails 6.1 the
database_cleaner
gem is no longer compatible, and needs to be replaced withdatabase_cleaner-active_record
instead. As part of the update, the API has changed and we no longer useDatabaseCleaner[:active_record, { connection: whatever }]
. Instead we should now being usingDatabaseCleaner[:active_record, { db: whatever }]
Note: There is currently an issue with
database_cleaner-active_record
v2.0.1+ that results in a foreign key constrain error when attempting to truncate. The gem is locked at 2.0.0 until this is resolved. Relevant issueAttempted Solutions Beyond Locking to 2.0.0
As locking the gem to 2.0.0 is not preferred, I looked for an alternative solution this issue. Below are a list of the proposed solutions I found from various resources:
Turning off foreign key checks temporarily by:
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 1')
ActiveRecord::Base.connection.disable_referential_integrity
ActiveRecord::Base.connection.enable_referential_integrity
Resetting PK sequence by looping through the tables
ActiveRecord::Base.connection.reset_pk_sequence!(tables)
Various DBCleaner options
DatabaseCleaner.clean_with(:truncation, {cascade: true})
DatabaseCleaner.clean_with(:deletion)
:only
,:except
,:pre_count
, and:cache_tables
. I've tried a few other options that were recommended for this issue, but don't seem to be with this version of db cleaner.:only
option as a way to truncate the tables in order. The first table would be deleted, which resulted in the relation between the two tables vanishing, causing an unidentified table error upon reaching the next table.Testing Plan
make reset
locally and ensure the databases are re-seeded correctly. Test Story