Skip to content

fix(export): use extensionName for services schema prefix instead of metaExtensionName#827

Merged
pyramation merged 1 commit intomainfrom
devin/1773640682-fix-export-schema-prefix
Mar 16, 2026
Merged

fix(export): use extensionName for services schema prefix instead of metaExtensionName#827
pyramation merged 1 commit intomainfrom
devin/1773640682-fix-export-schema-prefix

Conversation

@pyramation
Copy link
Contributor

fix(export): use extensionName for services schema prefix

Summary

Fixes a schema naming bug in exportMigrationsToDisk where the services/meta package replacer used metaExtensionName as the schema prefix instead of extensionName.

Before: Exporting an app named agent-db with services named agent-db-services produced incorrect schema references in the services SQL:

agent_db_services_auth_public   ← wrong
agent_db_services_auth_private  ← wrong

After: Services metadata correctly references schemas owned by the application package:

agent_db_auth_public   ← correct
agent_db_auth_private  ← correct

The fix adds an optional schemaPrefix parameter to makeReplacer. When provided, schema names use this prefix instead of name. The name parameter still controls the constructive-extension-name → extension name replacement (so the services package name is preserved correctly). This is fully backward compatible — callers that don't pass schemaPrefix behave identically to before.

Why constructive-db wasn't visibly affected: constructive-db's renameSchemas() pre-renames DB schemas to constructive_* before export, and extensionName is constructive. So the metaReplacer's replacement constructive_auth_publictoSnakeCase('constructive-services_auth_public') = constructive_services_auth_public does technically produce the wrong output — but this may have been masked by other factors (e.g., skipSchemaRenaming: true in the RLS path, or the services package not being re-exported recently).

Review & Testing Checklist for Human

  • Verify constructive-db export is unaffected: Run the constructive-db export/introspection pipeline (generate:constructive or equivalent) and confirm the services package still has constructive_auth_public (not constructive_services_auth_public). This is the highest-risk regression path.
  • Verify constructive-extension-name replacement still works: The name param (= metaExtensionName) is still used for the literal string replacement. Check that the services package's control file and metadata still reference the correct services extension name (not the app name).
  • Test agent-os export end-to-end: Run run-export.ts against a provisioned agent-os database with the updated @pgpmjs/core and confirm schema names in packages/agent-db-services/deploy/migrate/ use agent_db_auth_public (not agent_db_services_auth_public).

Notes

  • Link to Devin session
  • Requested by: @pyramation
  • The agent-os repo currently has a post-export workaround (sed-style replacement in run-export.ts) that can be removed once this fix is published

…metaExtensionName

The metaReplacer in exportMigrationsToDisk was using metaExtensionName
(e.g. 'agent-db-services') as the schema prefix for the services package,
producing incorrect schema names like 'agent_db_services_auth_public'.

The services metadata INSERT statements reference the actual deployed
schemas which are owned by the application package and use its prefix
(e.g. 'agent_db_auth_public'), not the services package prefix.

Fix: Add an optional 'schemaPrefix' parameter to makeReplacer. When
provided, schema names use this prefix instead of 'name'. The metaReplacer
now passes extensionName as schemaPrefix, so:
- Extension name replacement: 'constructive-extension-name' -> metaExtensionName (correct)
- Schema prefix replacement: uses extensionName (correct)

This is backward compatible - existing callers that don't pass schemaPrefix
work exactly as before. For constructive-db where schemas are already named
'constructive_*', the replacer produces the same output since
extensionName='constructive' matches the existing prefix.
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@pyramation pyramation merged commit ed46d54 into main Mar 16, 2026
43 checks passed
@pyramation pyramation deleted the devin/1773640682-fix-export-schema-prefix branch March 16, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant