I have an issue when defining views with joins between two postgres schemas (e.g. public and client_a).
Suppose we have this view definition:
CREATE VIEW my_view AS SELECT plans.name, clients.id
FROM clients
JOIN public.plans ON plans.id = clients.plan_id
Then then the following SQL is stored in db/schema.rb (notice missing public prefix for plans):
SELECT plans.name, clients.id
FROM clients
JOIN plans ON plans.id = clients.plan_id
I'm using this in combination with the apartment gem which loads schema.rb file for every tenant it creates. It also creates all tables for every schema/tenant, even if they are only used in the public schema.
The query to get the views:
|
SELECT pg_get_viewdef(oid) |
|
FROM pg_class |
|
WHERE relkind = 'v' |
|
AND relname = '#{view_name}' |
Not sure how to proceed yet. The views generated by migrations are correct.
Basically I want the "exluded model tables" from apartment to be prefixed with public in the db/schema.rb while the others use search_path.
I have an issue when defining views with joins between two postgres schemas (e.g.
publicandclient_a).Suppose we have this view definition:
Then then the following SQL is stored in
db/schema.rb(notice missingpublicprefix forplans):I'm using this in combination with the apartment gem which loads
schema.rbfile for every tenant it creates. It also creates all tables for every schema/tenant, even if they are only used in the public schema.The query to get the views:
schema_plus_views/lib/schema_plus/views/active_record/connection_adapters/postgresql_adapter.rb
Lines 19 to 22 in 1d04d8e
Not sure how to proceed yet. The views generated by migrations are correct.
Basically I want the "exluded model tables" from apartment to be prefixed with
publicin the db/schema.rb while the others usesearch_path.