一位同事和我正在分享一些模型的不同项目.所以,我们通过git子模块共享模型.
此外,我们也希望能够共享迁移:
这样,我的同事的迁移将在我的项目的db / migrate / other_db文件夹中.
如何将rails迁移配置为在另外的文件夹中运行迁移?
解决方法
在你的配置文件(config / application.rb的所有环境或配置/环境/ $(环境).rb只针对特定的环境)添加这一行:
config.paths['db/migrate'] += 'db/migrate/other_db'
如果要更改默认的“db / migrate”路径(config.paths [‘db / migrate’]是一个数组,默认情况下是一个字符串’db / migrate’),请执行以下操作:
config.paths['db/migrate'] = ['db/my_migrate']
这是默认的config.paths,我们也可以改变:
"app" => ["app"],"app/assets" => ["app/assets"],"app/controllers" => ["app/controllers"],"app/helpers" => ["app/helpers"],"app/models" => ["app/models"],"app/mailers" => ["app/mailers"],"app/views" => ["app/views"],"lib" => ["lib"],"lib/assets" => ["lib/assets"],"lib/tasks" => ["lib/tasks"],"config" => ["config"],"config/environments" => ["config/environments"],"config/initializers" => ["config/initializers"],"config/locales" => ["config/locales"],"config/routes" => ["config/routes.rb"],"db" => ["db"],"db/migrate" => ["db/migrate"],"db/seeds" => ["db/seeds.rb"],"vendor" => ["vendor"],"vendor/assets" => ["vendor/assets"],"vendor/plugins" => ["vendor/plugins"],"config/database" => ["config/database.yml"],"config/environment" => ["config/environment.rb"],"lib/templates" => ["lib/templates"],"log" => ["log/development.log"],"public" => ["public"],"public/javascripts" => ["public/javascripts"],"public/stylesheets" => ["public/stylesheets"],"tmp" => ["tmp"],