We have around 100 database migration files. Many of them make schema changes which are irreversible. There are also later migrations which change or remove tables which were created in earlier migrations.
我们有大约100个数据库迁移文件。他们中的许多人进行了不可逆转的架构更改。稍后还有一些迁移可以更改或删除在早期迁移中创建的表。
We are creating new databases straight from the schema.rb file, so we were wondering if there is any reason to keep the full set of migrations?
我们是直接从schema.rb文件创建新数据库,所以我们想知道是否有任何理由保留完整的迁移集?
We would create a new migration which is based on our existing schema.rb.
我们将创建一个基于现有schema.rb的新迁移。
2 个解决方案
#1
7
Yes, what you're proposing is considered a best practice.
是的,您提出的建议被视为最佳做法。
I've done this with my old apps several times. You'll want to back your migrations up somewhere until you're satisfied all is well, of course, this is an important part of application maintenance - if you have a lot of old migrations, it can take forever to do a db:reset
or to get a new development environment running.
我已经使用我的旧应用程序多次这样做了。您希望将迁移备份到某个地方,直到您对一切都很满意为止,当然,这是应用程序维护的一个重要部分 - 如果您有大量旧迁移,则可能需要永远执行db:reset或者让新的开发环境运行。
#2
4
I use rake db:setup
and rake db:reset
exclusively (never rake db:migrate
) to install a new database, on a production server or on a new development machine. Those commands already use the schema.rb
or structure.sql
to recreate the database.
我使用rake db:setup和rake db:reset(从不rake db:migrate)来在生产服务器或新开发机器上安装新数据库。这些命令已使用schema.rb或structure.sql重新创建数据库。
That said, it is really easy to make a copy of schema.rb
, use that as a new starting-point and delete all the old migrations.
也就是说,制作schema.rb的副本非常容易,将其用作新的起点并删除所有旧的迁移。
I prefer to keep my migrations for historic purposes, but that is a matter of taste.
我更喜欢将我的迁移用于历史目的,但这是一个品味问题。
#1
7
Yes, what you're proposing is considered a best practice.
是的,您提出的建议被视为最佳做法。
I've done this with my old apps several times. You'll want to back your migrations up somewhere until you're satisfied all is well, of course, this is an important part of application maintenance - if you have a lot of old migrations, it can take forever to do a db:reset
or to get a new development environment running.
我已经使用我的旧应用程序多次这样做了。您希望将迁移备份到某个地方,直到您对一切都很满意为止,当然,这是应用程序维护的一个重要部分 - 如果您有大量旧迁移,则可能需要永远执行db:reset或者让新的开发环境运行。
#2
4
I use rake db:setup
and rake db:reset
exclusively (never rake db:migrate
) to install a new database, on a production server or on a new development machine. Those commands already use the schema.rb
or structure.sql
to recreate the database.
我使用rake db:setup和rake db:reset(从不rake db:migrate)来在生产服务器或新开发机器上安装新数据库。这些命令已使用schema.rb或structure.sql重新创建数据库。
That said, it is really easy to make a copy of schema.rb
, use that as a new starting-point and delete all the old migrations.
也就是说,制作schema.rb的副本非常容易,将其用作新的起点并删除所有旧的迁移。
I prefer to keep my migrations for historic purposes, but that is a matter of taste.
我更喜欢将我的迁移用于历史目的,但这是一个品味问题。