如何使用rake db:dump:schema转储多个postgres模式

Joh*_*gle 5 postgresql ruby-on-rails ruby-on-rails-3

我们的postgres数据库有两个模式:公共模式和元数据模式.我在测试数据库中需要两个模式,但rake db:schema:dump只转储公共模式.如果我添加 schema_search_path: "public, metadata"到我的database.yml文件,它会转储两个模式,但架构信息不存在.

我如何转储两个模式,db/schema.rb以便我可以加载它们rake db:test:prepare

Joh*_*gle 2

在我看来,答案是使用结构文件而不是模式文件。

将其添加到 application.rb

# use a .sql structure instead of a schema.rb for the schema
config.active_record.schema_format = :sql
Run Code Online (Sandbox Code Playgroud)

删除您的 schema.rb 文件

现在,这将使用结构(sql)而不是模式(rb)转储您的数据库,并且它可以更具表现力。但是,它现在与您的数据库供应商绑定在一起(对我们来说没什么大不了的)。

bundle exec rake db:test:prepare
Run Code Online (Sandbox Code Playgroud)