feat(export): classify metadata-described columns for volatile defaults#1461
Merged
Conversation
Add getMetadataExportColumns to @pgpmjs/export: classify columns supplied as metadata (name/type/default expression) rather than a live physical table, running the exact same provolatile-based volatility classification as getDataExportColumns via an ephemeral temp table. Lets metadata-only planes reuse isVolatileTimestampColumn instead of pattern-matching default expression text.
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:
|
…eterministic Run getMetadataExportColumns inside a rolled-back transaction (or a savepoint when the caller is already in one): the temp table has a fixed name, is never committed, and cannot survive a failure. Add a failure-path test asserting no residue and a still-usable session.
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
@pgpmjs/exportcould only detect volatile-default columns for physically deployed tables:getDataExportColumnsreadspg_attrdef+pg_proc.provolatileoff a live relation. Callers with metadata-only planes (tables that exist as schema metadata but aren't physically deployed at export time) had no shared way to run the same classification, so they hand-rolled regexes over default-expression text.This adds a first-class metadata-table entry point that runs the exact same provolatile-based classification:
Implementation builds an ephemeral
CREATE TEMP TABLE pgpm_metadata_export_columns (c0 <type> [DEFAULT <expr>], ...)from the supplied descriptions, then callsgetDataExportColumnson it — one shared code path. Results preserve input order/names, so callers reuseisVolatileTimestampColumnunchanged:Transactional & deterministic — zero residue. The whole classification runs inside a transaction that is always rolled back (
BEGIN … ROLLBACK, orSAVEPOINT … ROLLBACK TOwhen the caller is already inside a transaction, e.g. pgsql-test). DDL is transactional in Postgres, so even a mid-flight failure erases the temp table — nothing is ever committed, the table name is a fixed deterministic identifier (no random suffix), and a failure cannot abort the caller's transaction.dbmust be a single session (client, not pool), as with any temp-table work.Synthetic
c0..cNcolumn identifiers keep the DDL immune to reserved words / duplicate names. Each column'stypemust resolve in the connected DB and each non-null default must be a valid default expression for that type.Notes
constructive-db'sgenerate_constructive.ts(scoped-plane meta-export), which is replacing its regex fallback with this API — see constructive-io/constructive-db#2490. That consumer needs this published (@pgpmjs/exportnext minor,^1.4.0) before it can adopt it.getMetadataExportColumnscoverage inpgpm/export/__tests__/export-data.test.tsasserting parity withgetDataExportColumnsover an equivalent physical table,isVolatileTimestampColumnselection, input-order preservation, rollback cleanup, and the failure path (no leftover temp table, session still usable). Full package suite green.Link to Devin session: https://app.devin.ai/sessions/b7e597395f8d4394a20a72f2473b6934
Requested by: @pyramation