什么是清理Rails中的迁移的好方法?

时间:2021-08-14 23:31:10

So I've been working on this web app for a year now and I would like to compile to schema into ONE migration, that way my text editor loads faster, git working directory isn't so cluttered.

所以我已经在这个网络应用程序上工作了一年,我想编译成一个移植模式,这样我的文本编辑器加载速度更快,git工作目录不是那么混乱。

Search find will be faster.

搜索查找会更快。

Any my config/db won't be 4000px long.

任何我的配置/数据库都不会是4000px长。

4 个解决方案

#1


3  

One way to go is to take a blank database and run all the migrations. Now you've got all the template data which you can save to a yaml. The yaml plus the schema should be enough to bring the DB back without running any of your previously existing migrations.

一种方法是采用空白数据库并运行所有迁移。现在您已经获得了可以保存为yaml的所有模板数据。 yaml加上模式应足以使数据库恢复运行而不运行任何先前存在的迁移。

However, other answers should mention an existing tool or gem for doing this.

但是,其他答案应该提到现有的工具或宝石。

#2


10  

Remove the migration files once you've migrated your servers. If you ever want to start with a fresh deployment, run rake db:schema:load or rake db:setup. You shouldn't be re-running all your migrations as explained here.

迁移服务器后删除迁移文件。如果您想要从全新部署开始,请运行rake db:schema:load或rake db:setup。您不应该按照此处的说明重新运行所有迁移。

#3


7  

You don't need to keep your migrations around forever, you are free to delete them as soon as you're sure you don't need them anymore. Just go into your db/migrate/ directory and delete the migrations that are older than, say, a couple months.

您无需永久保留迁移,只要您确定不再需要迁移,就可以*删除它们。只需进入db / migrate /目录并删除比几个月更早的迁移。

As long as all the migrations that you want to delete have been applied everywhere (i.e. development and production) then you don't need them anymore (unless you want to go backwards). Really, migrations aren't meant to be permanent files, they're just around to get you from A to B and then they're just baggage.

只要您要删除的所有迁移都已应用于任何地方(即开发和生产),那么您不再需要它们(除非您想要倒退)。真的,迁移并不是永久性文件,它们只是让你从A到B,然后它们只是行李。

#4


2  

Given that none of the answers mention it, this is the gem that does the job: https://github.com/jalkoby/squasher

鉴于没有一个答案提到它,这是完成这项工作的宝石:https://github.com/jalkoby/squasher

It basically reruns the migrations from scratch until the date you specify, and then loads the resulting db/schema.rb into an initial migration that replaces the old ones. It can also cleanup the schema_migrations table so you don't get those

它基本上从头开始重新运行迁移,直到您指定的日期,然后将生成的db / schema.rb加载到替换旧的迁移的初始迁移中。它还可以清理schema_migrations表,因此您无法获取它们

up     <timestamp>  ********** NO FILE **********

entries when running rake db:migrate:status.

运行rake db:migrate:status时的条目。

#1


3  

One way to go is to take a blank database and run all the migrations. Now you've got all the template data which you can save to a yaml. The yaml plus the schema should be enough to bring the DB back without running any of your previously existing migrations.

一种方法是采用空白数据库并运行所有迁移。现在您已经获得了可以保存为yaml的所有模板数据。 yaml加上模式应足以使数据库恢复运行而不运行任何先前存在的迁移。

However, other answers should mention an existing tool or gem for doing this.

但是,其他答案应该提到现有的工具或宝石。

#2


10  

Remove the migration files once you've migrated your servers. If you ever want to start with a fresh deployment, run rake db:schema:load or rake db:setup. You shouldn't be re-running all your migrations as explained here.

迁移服务器后删除迁移文件。如果您想要从全新部署开始,请运行rake db:schema:load或rake db:setup。您不应该按照此处的说明重新运行所有迁移。

#3


7  

You don't need to keep your migrations around forever, you are free to delete them as soon as you're sure you don't need them anymore. Just go into your db/migrate/ directory and delete the migrations that are older than, say, a couple months.

您无需永久保留迁移,只要您确定不再需要迁移,就可以*删除它们。只需进入db / migrate /目录并删除比几个月更早的迁移。

As long as all the migrations that you want to delete have been applied everywhere (i.e. development and production) then you don't need them anymore (unless you want to go backwards). Really, migrations aren't meant to be permanent files, they're just around to get you from A to B and then they're just baggage.

只要您要删除的所有迁移都已应用于任何地方(即开发和生产),那么您不再需要它们(除非您想要倒退)。真的,迁移并不是永久性文件,它们只是让你从A到B,然后它们只是行李。

#4


2  

Given that none of the answers mention it, this is the gem that does the job: https://github.com/jalkoby/squasher

鉴于没有一个答案提到它,这是完成这项工作的宝石:https://github.com/jalkoby/squasher

It basically reruns the migrations from scratch until the date you specify, and then loads the resulting db/schema.rb into an initial migration that replaces the old ones. It can also cleanup the schema_migrations table so you don't get those

它基本上从头开始重新运行迁移,直到您指定的日期,然后将生成的db / schema.rb加载到替换旧的迁移的初始迁移中。它还可以清理schema_migrations表,因此您无法获取它们

up     <timestamp>  ********** NO FILE **********

entries when running rake db:migrate:status.

运行rake db:migrate:status时的条目。