Let's say I'm working in git
on my Rails
app, and I have two branches, each with their own migration.
1) branch001
creates a table called tableA
via migration 20160101000000_create_table_A
2) branch002
creates a table called tableB
via migration 20160101000001_create_table_B
Clearly the timestamp for the 2nd migration was created after the first.
But let's say I merge branch002
to master
first because it's ready first. My schema file becomes -
ActiveRecord::Schema.define(version: 20160101000001) do .... end
The schema version tells activerecord it's already patched to a level/version greater than my first branch.
What will happen when I finally get around to merging my first branch?
20160101000000
?Thanks!
EDIT -
Really wondering what I should do to resolve the merge conflict when I merge the 2nd branch into master
. Should I leave it as the later timestamp or regress it to the earlier timestamp?
<<<<<<< HEAD (master) ActiveRecord::Schema.define(version: 20160101000001) do ======= ActiveRecord::Schema.define(version: 20160101000000) do >>>>>>> 282cda7... Adding Table B
To check for status, run rails db:migrate:status . Then you'll have a good view of the migrations you want to remove. Then, run rails db:rollback to revert the changes one by one. After doing so, you can check the status again to be fully confident.
It will run these migrations in order based on the date of the migration. Note that running the db:migrate also invokes the db:schema:dump task, which will update your db/schema. rb file to match the structure of your database.
【Ruby on Rails】 When you want to delete a migration file you made, you can choose version and delete it. You don't need to execute rails db:rollback many times!
Unlike rake db:migrate that runs migrations that have not run yet, rake db:schema:load loads the schema that is already generated in db/schema. rb into the database. Always use this command when: You run the application for the first time.
In case of conflict you should select the higher number of the two. But whatever you choose it has no impact on actual migrations.
If you choose the lower number then next time you run rake db:migrate
it will change this number (to the higher one) and you will have a change in your schema.rb
and no migration. It's not a problem - only your commit will be a bit strange.
Rails rake task runs all migrations that it finds and that don't have a value in schema_migrations
table. And then it takes the highest migration timestamp and puts this timestamp into the schema.rb
. The whole migration idea is not based on some "most recent timestamp" (schema version) but it's based on the content of schema_migrations
table that contains all migration timestamps that it has already run. So through this table it guarantees that no migration is skipped.
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