Ruby-on-rails rake db:schema:dump 是否从迁移或数据库本身重新创建 schema.rb?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3815447/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:17:02  来源:igfitidea点击:

Does rake db:schema:dump recreate schema.rb from migrations or the database itself?

ruby-on-railsschemamigrationrake

提问by pingu

Does

rake db:schema:dump

recreate schema.rbfrom migrations or the database itself?

schema.rb从迁移或数据库本身重新创建?

回答by Radek Paviensky

The answer is simple: from the database.

答案很简单:来自数据库。

By the way - when you take a look into the source code of db:* tasksyou can see that migration tasks calls schema:dump after the run

顺便说一句 - 当您查看 db:* tasks 的源代码时,您可以看到迁移任务在运行后调用了 schema:dump

desc "Migrate the database (options: VERSION=x, VERBOSE=false)."
task :migrate => :environment do
  ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
  ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
  Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
end

So the migration works in the way that it change the database and thengenerate schema.rb file.

因此,迁移的工作方式是更改数据库,然后生成 schema.rb 文件。