I'm trying to manually create/update the db/structure.sql file for test purposes. I have "config.active_record.schema_format = :sql
" set in application.rb. I am wondering if there is a command equivalent to "ActiveRecord::SchemaDumper.dump
" that will create or update structure.sql. I've tried structure_dump, but the output is nil:
我正在尝试手动创建/更新db / structure.sql文件以进行测试。我在application.rb中设置了“config.active_record.schema_format =:sql”。我想知道是否有一个命令等效于“ActiveRecord :: SchemaDumper.dump”,它将创建或更新structure.sql。我已经尝试过structure_dump,但输出为nil:
> ActiveRecord::Base.connection.structure_dump
=> nil
I also tried passing a file to that method:
我也尝试将文件传递给该方法:
> File.open( File.join(Rails.root, 'db/structure.sql')) { |f| ActiveRecord::Base.connection.structure_dump() }
=> nil
So far, the only way I've been able to generate or update db/structure.sql is by running rake db:migrate. Any alternatives? Or am I missing something when trying to run ActiveRecord::Base.connection.structure_dump?
到目前为止,我能够生成或更新db / structure.sql的唯一方法是运行rake db:migrate。任何替代品?或者我在尝试运行ActiveRecord :: Base.connection.structure_dump时遗漏了什么?
1 个解决方案
#1
25
Try rake db:structure:dump
which will recreate the db/structure.sql
from the database.
尝试使用rake db:structure:dump,它将从数据库中重新创建db / structure.sql。
#1
25
Try rake db:structure:dump
which will recreate the db/structure.sql
from the database.
尝试使用rake db:structure:dump,它将从数据库中重新创建db / structure.sql。