Can I delete all migration files and start from scratch?

耗尽温柔 提交于 2019-12-20 04:32:12

问题


I have a Rails-API app that I'm going to re-deploy after a long time. The app is non-production, but I am ready to deploy the production version. I want to basically delete all the migration files and start from scratch using the schema, is there any problem with this approach? Assuming I can do this, what do I need to alter the schema.rb to? Is this a common practice? Seems reasonable to me.

# what do I change the version param value to?
ActiveRecord::Schema.define(version: 20171129023538)  

回答1:


Migrations are used to update your database or to rollback to previous versions. Once migrations have been run in all environments, they're never looked at again (unless you're manually messing around with the schema_migrations table of course). Once all your migrations have been run, the current state of the database is in db/schema.rb (or db/structure.sql) so schema.rb is all you need to start with a fresh database.

I tend to clear out old migrations every couple months just to cut down on clutter.

As far as the version goes, you can leave it alone. As long as it represent a time in the past (such as 2017-11-29 02:35:38) and it is lower than any migrations that need to be run (which doesn't apply as you're deleting them all) then it doesn't matter what it is.

Go ahead and clear out all the migrations, they're already reflected in schema.rb and you can always dig them out of revision control if you really need them.



来源:https://stackoverflow.com/questions/47639801/can-i-delete-all-migration-files-and-start-from-scratch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!