In rails 3, how does the db:migrate
task determine which migrations to run?
Consider the following use case:
db:migrate
is run on the serverSince t1 is earlier, does developer A's migration get run or not?
I noticed the schema_migrations
table, and I'm wondering if any migration that has not run yet will be run.
Is there a good way to manage Migrations in a project with multiple branches? One way would be to merge, then delete all migration-files created while the branches were separate, and then create one new migration file that holds all changes from the time the branch was created until it was merged back in.
A Rails migration is a tool for changing an application's database schema. Instead of managing SQL scripts, you define database changes in a domain-specific language (DSL). The code is database-independent, so you can easily move your app to a new platform.
Every time a migration is generated using the rails g migration command, Rails generates the migration file with a unique timestamp. The timestamp is in the format YYYYMMDDHHMMSS . Whenever a migration is run, Rails inserts the migration timestamp into an internal table schema_migrations .
On databases that support transactions with statements that change the schema, migrations are wrapped in a transaction. If the database does not support this then when a migration fails the parts of it that succeeded will not be rolled back. You will have to rollback the changes that were made by hand.
Your hunch is correct - any migration not in schema_migrations
will be run, and they will be run in timestamp order ascending.
In this case, the next time db:migrate
is run after A merges, migration t1 will be run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With