如何配置额外/不同的迁移文件夹 [英] How to configure an extra/different migrations folder
问题描述
我和一位同事在共享一些模型的不同项目中工作.因此,我们通过 git 子模块共享模型.
A colleague and I are working in different projects that share some models. So, we are sharing the models through a git submodule.
此外,我们还希望能够共享迁移:
Additionally, we'd like to be able to also share migrations:
这样,我同事的迁移将在我项目的 db/migrate/other_db
文件夹中.
In this way, my colleague's migrations would be in the folder db/migrate/other_db
of my project.
如何配置 rails 迁移以在这个额外的文件夹中运行迁移?
How can I configure rails migrations to also run the migrations in this extra folder?
推荐答案
Rails 5/6 更新;
Update for Rails 5/6;
Rails 5 建议在 config/database.yml
文件中设置额外的迁移路径.很简单,看这个例子;
Rails 5 recommends setting additional migration paths in your config/database.yml
file. It's very easy, see this example;
development:
migrations_paths:
- "db/migrate/other_db"
- "db/migrate/something_else"
ActiveRecord::Migrator.migrations_path=
将在 Rails 6 中被弃用.
ActiveRecord::Migrator.migrations_path=
will be deprecated in Rails 6.
这篇关于如何配置额外/不同的迁移文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!