diff --git a/packages/function-resolution/__tests__/request-lane-reads.test.ts b/packages/function-resolution/__tests__/request-lane-reads.test.ts index 501476a5..45cd8566 100644 --- a/packages/function-resolution/__tests__/request-lane-reads.test.ts +++ b/packages/function-resolution/__tests__/request-lane-reads.test.ts @@ -100,14 +100,20 @@ describe('request-lane resolution reads', () => { VALUES ($1, $2, $3) RETURNING id`, [database, schema.id, table] )).id; + const routingPrivate = await pg.one( + `INSERT INTO metaschema_public.schema (database_id, name, schema_name) + VALUES ($1, $2, $3) RETURNING id`, + [database, `${name}_routing_private`, `${name}_routing_private`] + ); await pg.query( `INSERT INTO metaschema_modules_public.route_module (database_id, scope, schema_id, private_schema_id, resolver_function_name, routes_table_id, hostname_bindings_table_id, route_bindings_table_id, redirects_table_id) - VALUES ($1, 'database', $2, $2, 'resolve_route', $3, $4, $5, $6)`, + VALUES ($1, 'database', $2, $3, 'resolve_route', $4, $5, $6, $7)`, [ database, schema.id, + routingPrivate.id, await routingTable('routes'), await routingTable('hostname_bindings'), await routingTable('route_bindings'), @@ -218,9 +224,9 @@ describe('request-lane resolution reads', () => { it('lists every database-scope plane in resolution order for its grantee', async () => { const planes = await pg.any(`SELECT * FROM function_resolution.routing_planes()`); expect(planes).toEqual([ - { database_id: PLATFORM_DB, schema_name: 'platform_storage_public', resolver_schema_name: 'platform_storage_public', resolver_function_name: 'resolve_route' }, - { database_id: TENANT_DB, schema_name: 'tenant_storage_public', resolver_schema_name: 'tenant_storage_public', resolver_function_name: 'resolve_route' }, - { database_id: OTHER_DB, schema_name: 'other_storage_public', resolver_schema_name: 'other_storage_public', resolver_function_name: 'resolve_route' } + { database_id: PLATFORM_DB, schema_name: 'platform_storage_public', resolver_schema_name: 'platform_routing_private', resolver_function_name: 'resolve_route' }, + { database_id: TENANT_DB, schema_name: 'tenant_storage_public', resolver_schema_name: 'tenant_routing_private', resolver_function_name: 'resolve_route' }, + { database_id: OTHER_DB, schema_name: 'other_storage_public', resolver_schema_name: 'other_routing_private', resolver_function_name: 'resolve_route' } ]); }); }); diff --git a/packages/function-resolution/deploy/schemas/function_resolution/procedures/routing_planes.sql b/packages/function-resolution/deploy/schemas/function_resolution/procedures/routing_planes.sql index 6e138d3c..ee8cef28 100644 --- a/packages/function-resolution/deploy/schemas/function_resolution/procedures/routing_planes.sql +++ b/packages/function-resolution/deploy/schemas/function_resolution/procedures/routing_planes.sql @@ -13,11 +13,8 @@ BEGIN; -- It enumerates every tenant database, so it is granted to no request role: -- only the platform login (granted at provision) calls it, on its own -- connection with no role switch. schema_name is the plane's public schema --- (its tables); resolver_schema_name is the schema its resolver is generated --- into, so callers qualify the resolver from it rather than assuming. The --- readers are still generated into the public schema, so for now both columns --- carry the same value; resolver_schema_name changes to the plane's private --- schema when the readers move there. A plane whose route_module names no +-- (its tables); resolver_schema_name is the private schema its resolver is +-- generated into, which is on no API. A plane whose route_module names no -- schema or no resolver is returned as-is so the caller fails loudly on it. CREATE FUNCTION function_resolution.routing_planes() RETURNS TABLE ( @@ -29,10 +26,11 @@ RETURNS TABLE ( SELECT rm.database_id, s.schema_name::text, - s.schema_name::text, + ps.schema_name::text, rm.resolver_function_name FROM metaschema_modules_public.route_module AS rm LEFT JOIN metaschema_public.schema AS s ON s.id = rm.schema_id + LEFT JOIN metaschema_public.schema AS ps ON ps.id = rm.private_schema_id WHERE rm.scope = 'database' ORDER BY rm.database_id $$ LANGUAGE sql STABLE SECURITY DEFINER; diff --git a/packages/function-resolution/sql/pgpm-function-resolution--0.47.7.bundle.tar.gz b/packages/function-resolution/sql/pgpm-function-resolution--0.47.7.bundle.tar.gz index 9cbd3f18..e8966e6b 100644 Binary files a/packages/function-resolution/sql/pgpm-function-resolution--0.47.7.bundle.tar.gz and b/packages/function-resolution/sql/pgpm-function-resolution--0.47.7.bundle.tar.gz differ diff --git a/packages/function-resolution/sql/pgpm-function-resolution--0.47.7.sql b/packages/function-resolution/sql/pgpm-function-resolution--0.47.7.sql index 025d94ac..b0a19549 100644 --- a/packages/function-resolution/sql/pgpm-function-resolution--0.47.7.sql +++ b/packages/function-resolution/sql/pgpm-function-resolution--0.47.7.sql @@ -2414,10 +2414,11 @@ CREATE FUNCTION function_resolution.routing_planes() RETURNS TABLE ( SELECT rm.database_id, s.schema_name::text, - s.schema_name::text, + ps.schema_name::text, rm.resolver_function_name FROM metaschema_modules_public.route_module AS rm LEFT JOIN metaschema_public.schema AS s ON s.id = rm.schema_id + LEFT JOIN metaschema_public.schema AS ps ON ps.id = rm.private_schema_id WHERE rm.scope = 'database' ORDER BY rm.database_id $EOFCODE$ LANGUAGE sql STABLE SECURITY DEFINER;