-
Notifications
You must be signed in to change notification settings - Fork 15
Description
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:
schema_plus_views/lib/schema_plus/views/active_record/connection_adapters/postgresql_adapter.rb
Lines 19 to 22 in 1d04d8e
| 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.