6

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

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

4

1 回答 1

2

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

将此添加到 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
于 2013-09-27T16:24:14.907 回答