PostgreSQL adapter schema_search_path trong database.yml không giải quyết được sự cố của bạn?
development:
adapter: postgresql
encoding: utf-8
database: solidus
host: 127.0.0.1
port: 5432
username: postgres
password: postgres
schema_search_path: "discogs,public"
Hoặc, bạn có thể chỉ định các kết nối khác nhau cho mỗi schema:
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"
Sau mỗi lần kết nối được xác định, tạo ra hai mô hình:
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
Và, tất cả các mô hình của bạn được thừa hưởng từ lược đồ tương ứng:
class MyModelFromPublic < PublicSchema
set_table_name :my_table_name
end
class MyOtherModelFromDiscoGs < DiscoGsSchema
set_table_name :disco
end
Tôi hy vọng nó sẽ giúp.
Làm cách nào để tạo lược đồ không công khai khi thiết lập cơ sở dữ liệu thông qua lệnh db: tạo rake? Việc thêm lược đồ vào cơ sở dữ liệu template1 là một khả năng. Nhưng có cách nào để làm điều đó như là một phần của quá trình phát triển rails thông thường? – TsenYing
@TsenYing [Có pg_power gem] (http://stackoverflow.com/a/18227887/673826) cho rằng đó là một tùy chọn. [Nhà của nó ở đây] (https://github.com/TMXCredit/pg_power). Nó đã không được cập nhật trong 2 năm mặc dù. Một tùy chọn khác có thể là viết tác vụ * create * rake trong không gian tên * db * và thêm nội dung của bạn vào đó. – mlt