Rails:在早期开发阶段改变迁移 [英] Rails: Alter migrations during early development phases
本文介绍了Rails:在早期开发阶段改变迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Rails 应用程序开发的早期阶段,我更喜欢直接修改迁移文件以将新列(字段)添加到我的表(模型)中,而不是堆积迁移来更改字段和/或进行细微更改.
During the very early phases of development in a Rails app, I prefer to modify the migrations files directly to add new columns (fields) to my tables (models) instead of piling up migrations to alter fields and/or do minor changes.
这在 Rails 中可行吗?
Is that possible in Rails?
推荐答案
最干净的解决方案,来自 Vijay Dev 的解决方案是创建一个 rake 任务:
Cleanest solution, driven from Vijay Dev's solution is to create a rake task:
namespace :db do
desc "Drops, recreates and seeds the database."
task :reload => [:drop, :create, :migrate, :seed] do
Rake::Task['db:drop'].invoke
Rake::Task['db:create'].invoke
Rake::Task['db:migrate'].invoke
Rake::Task['db:seed'].invoke
end
end
这篇关于Rails:在早期开发阶段改变迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文