简体   繁体   English

如何在Rails的子文件夹中组织迁移文件?

[英]How to organize migration files in subfolders in Rails?

Is there a way to organize migration files in the db/migrate folder? 有没有办法在db/migrate文件夹中组织迁移文件?

Because you quickly have tons of migration files in this folder and it would be great to have something like: 因为您很快就会在此文件夹中拥有大量的迁移文件,所以最好有以下内容:

  • db/migrate/user_migrations/
    • timestamp_create_users.rb
    • timestamp_create_addresses.rb

And so on... 等等...

Is there a simple way to do this? 有没有简单的方法可以做到这一点? Some kind of configuration? 某种配置? Is it a bad practice and should I absolutely not do this? 这是不好的做法吗,我绝对不应该这样做吗?

If anyone has any piece of information about that, I'll be glad to hear! 如果有人对此有任何了解,我将很高兴听到!

There is currently no way to do this and also no reason. 当前没有办法也没有理由。 There will be cased where a single migration touches several models and features, a model-based categorization is not very appropriate. 在单个迁移涉及多个模型和功能的情况下,基于模型的分类不太合适。

You can also delete very old migrations if you already applied them to all your systems or if they invalidate each other (such as the migration to create table A that is then subsequently removed). 如果已经将旧的迁移应用于所有系统或它们彼此无效(例如创建表A的迁移,随后又将其删除),则也可以删除它们。

Someone may argue that removing a migration may cause the system to not be bootstrapped from scratch. 有人可能会争辩说,删除迁移可能会导致系统无法从头启动。 However, migrations should not be used for this. 但是,不应为此使用迁移。 In fact, migrations are only used to alter the database. 实际上,迁移仅用于更改数据库。 To load the schema for an empty database you should use $ rake db:schema:load . 要为空数据库加载模式,应使用$ rake db:schema:load

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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