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
Sync parallel test DBs to schema using SHA #36873
Conversation
def self.create_and_load_schema(i, env_name:) | ||
old, ENV["VERBOSE"] = ENV["VERBOSE"], "false" | ||
|
||
ActiveRecord::Base.configurations.configs_for(env_name: env_name).each do |db_config| | ||
db_config.config["database"] += "-#{i}" | ||
ActiveRecord::Tasks::DatabaseTasks.create(db_config.config) |
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.
Where'd this go? Nothing in reset_to_schema
sounds obviously likely to do the create if needed (and from its name, I don't think I'd expect it to anyway)
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.
purge
does (re)create the database. I was thinking reset in the "rake db:reset
" sense, which recreates the database, but reading it again I agree that might be confusing
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.
I don't feel strongly about avoiding 'reset' -- that parallel makes sense too.
.. but where does the create actually happen now?
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.
Ack! You're right. This does not work when there is no DB 😳 I thought purge
would create. I'll fix this and improve the naming.
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.
I went with reconstruct_from_schema
, which I like (I didn't want recreate because create doesn't imply loading the schema, but reconstruct does sound like it loads the DB's structure).
I've made sure this now also creates DBs.
Previously, every time we ran tests in parallel we would load the schema for all N DBs. Now that we have the ability to sync DBs with the schema file exactly using metadata and a SHA, we can instead only load the schemas when they change.
75ab5fd
to
d8b8171
Compare
Sync parallel test DBs to schema using SHA
😍⭐️ |
I think this should be applied to 6-0-stable as well, so it'll be part of 6.0 final. |
Thanks @jhawthorn, works great 😄 |
Previously, every time we ran tests in parallel we would load the schema for all N databases, and then drop them at the end of testing.
Now that we have the ability to sync DBs with the schema file exactly using metadata and a SHA, we can instead only load the schemas when they change. In order for this to work we no longer drop the databases at the end of the tests. If the schema is in sync, we truncate the tables to ensure we start with an empty DB.
I believe this will make setup fast enough to close #36807
Builds on #36870, obsoletes #36826