Skip to content

Conversation

@pyramation
Copy link
Contributor

Summary

This PR fixes a bug in the export pipeline where the sql_actions query had no WHERE clause, causing it to export actions from ALL databases instead of just the target database. This could cause cross-database pollution in persistent database environments.

Additionally, adds a new skipSchemaRenaming option to support self-referential introspection scenarios where infrastructure schema names (like metaschema_public, services_public) should be preserved rather than renamed.

Key changes:

  • Add WHERE database_id = $1 filter to the sql_actions query
  • Add skipSchemaRenaming option to both ExportMigrationsToDiskOptions and ExportOptions interfaces
  • Thread the option through exportMigrations and exportMigrationsToDisk functions

Review & Testing Checklist for Human

  • Verify db_migrate.sql_actions table has a database_id column - the query assumes this column exists but it wasn't verified in the codebase
  • Test export workflow end-to-end - run pnpm generate:rls or equivalent export command to verify the database_id filter doesn't break existing functionality
  • Verify no regressions in exported output - compare exported migrations before/after this change to ensure the filter produces correct results

Recommended test plan:

  1. Run the introspection/export workflow against a test database
  2. Verify the exported sql_actions only contain entries for the target database_id
  3. Confirm the generated pgpm modules are valid and deployable

Notes

This is Phase 1 of a larger plan to enable metaschema self-referential introspection for RLS policy generation. The skipSchemaRenaming option is added but not yet used by any callers - that will come in subsequent phases.

Link to Devin run: https://app.devin.ai/sessions/23949faa112a4110a435a82d88fb47c1
Requested by: Dan Lynch (@pyramation)

…pSchemaRenaming option

- Add WHERE database_id = $1 filter to sql_actions query to prevent cross-database pollution
- Add skipSchemaRenaming option to preserve infrastructure schema names during export
- Thread skipSchemaRenaming through exportMigrations and exportMigrationsToDisk functions

This fixes a bug where all sql_actions from all databases were exported instead of
just the actions for the target database_id. The skipSchemaRenaming option enables
self-referential introspection where you want to apply RLS policies to real
infrastructure schemas (metaschema_public, services_public, etc.) without renaming them.
@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 4e27e2d into main Jan 5, 2026
36 checks passed
@pyramation pyramation deleted the devin/1767602506-fix-export-database-id-filter branch January 5, 2026 08:49
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.

2 participants