我们的 postgres 数据库有两个模式:公共(public)模式和元数据模式。我的测试数据库中需要这两个模式,但是 rake db:schema:dump
只转储公共(public)模式。如果我将 schema_search_path: "public, metadata"
添加到我的 database.yml 文件中,它会转储两个模式,但模式信息不存在。
如何将这两个模式转储到 db/schema.rb
以便我可以使用 rake db:test:prepare
加载它们?
最佳答案
在我看来答案是使用结构文件而不是模式文件。
将此添加到 application.rb
# use a .sql structure instead of a schema.rb for the schema
config.active_record.schema_format = :sql
删除您的 schema.rb 文件
现在这将使用结构 (sql) 而不是模式 (rb) 转储您的数据库,并且它可以更具表现力。但是,它现在与您的数据库供应商相关联(对我们来说不是什么大问题)。
bundle exec rake db:test:prepare
关于ruby-on-rails - 如何使用 rake db :dump:schema 转储多个 postgres 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19054541/