How do I disable the migrations feature in a Rails app?

别说谁变了你拦得住时间么 提交于 2019-12-01 00:58:48

This came up again when testing finally came to the front. Thus, I took deeper look and came up with the following thanks, in part, to the comments left on the question. This removes all rake DB capabilities and tests still run fine. (In case anyone is wondering, we clone the test DB from elsewhere when we need to refresh it.)

Add this to the Rakefile:

# Disable DB migrations, DB test preparing, etc.
Rake::Task.tasks.each do |t|
    if t.name[0,3] == "db:"
        t.clear
        t.add_description("!!! Disabled in favor of enterprise design at Acme.")
    end
end

Comment out all the fixtures in test/test_helper.rb:

#fixtures :all

In juanitogan's answer, we disable all db tasks. In my case I still wanted to be able to run db:schema:load. Here the slightly modified code for the Rakefile:

# Disable migrations
Rake::Task.tasks.each do |t|
  if t.name.start_with?("db:migrate")
    t.clear
    t.add_description("Disabled; Load the data model via db:schema:load.")
    t.actions << proc { puts "Migrations ignored. That's ok. Please see README."}
  end
end

When creating models, you can append the --no-migration option like so: rails g model abc --no-migration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!