database.yml의 PostgreSQL 어댑터 schema_search_path가 문제를 해결합니까? 정의 된 각 연결 후
public_schema:
adapter: postgresql
encoding: utf-8
database: solidus
host: 127.0.0.1
port: 5432
username: postgres
password: postgres
schema_search_path: "public"
discogs_schema:
adapter: postgresql
encoding: utf-8
database: solidus
host: 127.0.0.1
port: 5432
username: postgres
password: postgres
schema_search_path: "discogs"
두 가지 모델 생성 :
development:
adapter: postgresql
encoding: utf-8
database: solidus
host: 127.0.0.1
port: 5432
username: postgres
password: postgres
schema_search_path: "discogs,public"
또는 당신이 할 수있는 각 스키마에 대해 서로 다른 연결을 지정합니다
class PublicSchema < ActiveRecord::Base
self.abstract_class = true
establish_connection :public_schema
end
class DiscoGsSchema < ActiveRecord::Base
self.abstract_class = true
establish_connection :discogs_schema
end
을 그리고, 모든 모델은 상속 해당 스키마 :
class MyModelFromPublic < PublicSchema
set_table_name :my_table_name
end
class MyOtherModelFromDiscoGs < DiscoGsSchema
set_table_name :disco
end
도움이되기를 바랍니다.
db : create rake 작업을 통해 데이터베이스를 설정할 때 비공개 스키마를 만드는 방법은 무엇입니까? template1 데이터베이스에 스키마를 추가하는 것도 가능합니다. 하지만 일반적인 레일/레이크 개발 프로세스의 일부로이 작업을 수행 할 수있는 방법이 있습니까? – TsenYing
@TsenYing [There is pg_power gem] (http://stackoverflow.com/a/18227887/673826)은 하나의 옵션입니다. 그것의 [home is here] (https://github.com/TMXCredit/pg_power). 그것은 비록 2 년 동안 업데이 트되지 않았습니다. 또 다른 옵션은 * db * 네임 스페이스에 * create * rake 태스크를 작성하고 거기에 물건을 추가하는 것입니다. – mlt