在rake db:schema:dump中包含多个postgres模式?

时间:2011-07-29 17:39:04

标签: ruby-on-rails database postgresql schema rake

在使用postgres架构(即schema_name.users)的应用程序上运行rake db:schema:dump时,看起来它只是在db用户的搜索路径中转储第一个架构的表。有没有办法从多个模式中包含表?

以不同方式陈述问题:

createdb myapp

psql myapp -U postgres -c "create table stuff" 
#=> creates table "stuff" in the public schema

psql myapp -U postgres -c "create schema specific_thing"

psql myapp -U postgres -c 'create table "specific_thing".users(id int)'

createuser -U postgres -S -D -R special_user

psql myapp -U postgres -c "grant all on schema specific_thing to special_user"

psql myapp -U postgres -c "ALTER USER special_user SET search_path TO specific_thing,public"

database.yml:

...

development:
  adapter: postgresql
  database: stuff
  username: special_user
  password:
  host: localhost

...

正在运行:rake db:schema:dump

仅从users架构转储specific_thing talbe并忽略公共架构中的所有内容。

1 个答案:

答案 0 :(得分:1)

所以这就是我找到的。我没有在我面前的代码所以我不能指出任何具体的东西,但PostgresAdapter中有一些代码可以识别适配器认为可用的“表”。适配器假设它总是处理'公共'模式(公共实际上是在获取表列表的查询中硬编码),因此我对问题的解决方案包括将PostgresAdapter子类化为具有不同概念的“表”是。这让我大部分都在那里。还有一些其他的障碍需要克服,但是在将这件作品融入拼图后,一切都更加清晰。肯定会花一些时间在Rails源代码中。

相关问题