简体   繁体   中英

How does mysqldump and load affect rails schema and migrations?

I have a mariaDB database with a rails application.

I'm planning to setup the rails application normally first, then use its user interface to create the database data first, then export those data using mysqldump.

mysqldump -u username -p database_name > data-dump.sql

My question is, if I do migration later, can I still load the mysql dump without facing a problem?

For example, if my migration removes a column, should I create a new database backup using mysqldump again?

And is there anything I need to be careful about schema?

When you do a mysqldump, by default the table create statements are included. They are only excluded if you pass in the --no-create-info flag. Since your migrations are just alterations to the tables, you can be assured that when you load your data later, it will have all of your migrations applied to it up to the point in time your database was dumped.

Furthermore, when you run migrations, rails keeps track of which have been run in the schema_migrations table. So if you roll back to a point in time where you had more migrations afterwards, you can re-run rake db:migrate and only those new ones will run, since that data was all part of your backup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM