fix: export metaschema_public.function in services migration + defensive null fallback#1131
Merged
pyramation merged 2 commits intomainfrom May 11, 2026
Merged
Conversation
…on names When metaschema_public.function rows are missing (e.g. the insert_rls_module trigger was skipped during migration), the RLS_SETTINGS_SQL LEFT JOINs resolve NULL for function names. toRlsModuleFromSettings was returning an RlsModule with null fields, preventing fallback to the working legacy api_modules lookup. Add a guard to return undefined when critical fields (authenticate, authenticate_schema) are null, allowing queryRlsModule to fall back to queryRlsModuleLegacy.
The export pipeline was not including metaschema_public.function in the constructive-services migration output. This table is referenced by rls_settings (6 FK columns) and pubkey_settings (4 FK columns). Since all constructive-services migrations deploy with session_replication_role=replica (disabling triggers), the insert_rls_module trigger never fires to create these function rows. The result is dangling UUID references in rls_settings, causing the GraphQL server to resolve NULL function names and skip authentication. Changes: - Add function to META_TABLE_CONFIG with schema/fields definition - Add function to META_TABLE_ORDER (after schema, before table) - Add queryAndParse for metaschema_public.function in export-meta.ts - Add queryAndParse for function in export-graphql-meta.ts After this fix, running generate:constructive will produce a new function.sql migration file in constructive-services containing the INSERT statements for all registered functions.
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two fixes for auth function discovery breaking in the GraphQL server:
1. Export pipeline: add
metaschema_public.functionto services migration exportrls_settings(6 FK columns) andpubkey_settings(4 FK columns) both referencemetaschema_public.function, but the@pgpmjs/exportpipeline was not including this table in theconstructive-servicesmigration output. Since all constructive-services migrations deploy withsession_replication_role=replica(disabling triggers), theinsert_rls_moduletrigger never fires to create the function rows. The result: dangling UUID references inrls_settings, theRLS_SETTINGS_SQLLEFT JOINs resolve NULL for every function name, the auth middleware seesauthenticate=none, skips authentication, and all RLS policies deny access.Changes in
pgpm/export/src/:export-utils.ts: AddfunctiontoMETA_TABLE_CONFIG(schema + fields) andMETA_TABLE_ORDER(placed afterschema, beforetableto satisfy FK deps)export-meta.ts: AddqueryAndParseformetaschema_public.functionexport-graphql-meta.ts: AddqueryAndParseforfunctionin the parallel batchAfter merging, re-running
pnpm run generate:constructivein constructive-db will produce afunction.sqlmigration inconstructive-services.2. Defensive fallback in
toRlsModuleFromSettingstoRlsModuleFromSettingswas returning a truthyRlsModuleobject with null fields when function rows were missing. This preventedqueryRlsModulefrom falling back to the working legacyapi_moduleslookup. Added a guard: ifauthenticateorauthenticate_schemaare null, returnundefinedto trigger the fallback.Review & Testing Checklist for Human
META_TABLE_ORDERplacesfunctionafterschema(FK dep) and beforerls_settings/pubkey_settings(FK refs)pnpm run generate:constructivein constructive-db and confirmservices/constructive-services/deploy/migrate/function.sqlis generated with the 6 auth function rowsSELECT count(*) FROM metaschema_public.functionshows the expected rowsRLS_SETTINGS_SQLNotes
database_extensionis also queried inexport-meta.tsbut not inMETA_TABLE_ORDER— this may be another gap worth investigating separately."Link to Devin session: https://app.devin.ai/sessions/45d6930943ec467496290581d22cb3a9
Requested by: @pyramation