@pgpmjs/export 0.21.3 → 0.21.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57,6 +57,15 @@ const buildDynamicFieldsFromGraphQL = async (client, tableConfig) => {
57
57
  }
58
58
  }
59
59
  }
60
+ // Omit columns that are marked as columnDefaults — their DDL DEFAULT (e.g.
61
+ // current_database()) will supply the correct value at deploy time, so the
62
+ // exported INSERT must not hardcode an environment-specific literal.
63
+ if (tableConfig.columnDefaults) {
64
+ for (const colName of Object.keys(tableConfig.columnDefaults)) {
65
+ delete dynamicFields[colName];
66
+ enumFields.delete(colName);
67
+ }
68
+ }
60
69
  return { fields: dynamicFields, enumFields };
61
70
  }
62
71
  catch (err) {
@@ -139,6 +148,16 @@ export const exportGraphQLMeta = async ({ client, database_id }) => {
139
148
  }
140
149
  if (Object.keys(dynamicFields).length === 0)
141
150
  return;
151
+ // Omit columnDefaults columns from row data so the Parser never sees them.
152
+ // configFields already excludes them (via buildDynamicFieldsFromGraphQL),
153
+ // so dynamicFields won't contain them either — but the pgRow data still does.
154
+ if (tableConfig.columnDefaults) {
155
+ for (const colName of Object.keys(tableConfig.columnDefaults)) {
156
+ for (const row of pgRows) {
157
+ delete row[colName];
158
+ }
159
+ }
160
+ }
142
161
  const parser = new Parser({
143
162
  schema: tableConfig.schema,
144
163
  table: tableConfig.table,
@@ -43,6 +43,14 @@ const buildDynamicFields = async (pool, tableConfig) => {
43
43
  }
44
44
  }
45
45
  }
46
+ // Omit columns that are marked as columnDefaults — their DDL DEFAULT (e.g.
47
+ // current_database()) will supply the correct value at deploy time, so the
48
+ // exported INSERT must not hardcode an environment-specific literal.
49
+ if (tableConfig.columnDefaults) {
50
+ for (const colName of Object.keys(tableConfig.columnDefaults)) {
51
+ delete dynamicFields[colName];
52
+ }
53
+ }
46
54
  return dynamicFields;
47
55
  };
48
56
  export const exportMeta = async ({ opts, dbname, database_id }) => {
@@ -104,6 +112,17 @@ export const exportMeta = async ({ opts, dbname, database_id }) => {
104
112
  }
105
113
  }
106
114
  }
115
+ // Omit columnDefaults columns from row data so the Parser never sees them.
116
+ // The Parser's field config already excludes them (via buildDynamicFields),
117
+ // so they would be ignored anyway, but removing them from the data is cleaner.
118
+ const tblCfg = META_TABLE_CONFIG[key];
119
+ if (tblCfg?.columnDefaults) {
120
+ for (const colName of Object.keys(tblCfg.columnDefaults)) {
121
+ for (const row of result.rows) {
122
+ delete row[colName];
123
+ }
124
+ }
125
+ }
107
126
  const parsed = await parser.parse(result.rows);
108
127
  if (parsed) {
109
128
  sql[key] = parsed;
@@ -282,11 +282,17 @@ export const META_TABLE_CONFIG = {
282
282
  favicon: 'upload',
283
283
  apple_touch_icon: 'image',
284
284
  logo: 'image'
285
+ },
286
+ columnDefaults: {
287
+ dbname: 'current_database()'
285
288
  }
286
289
  },
287
290
  apis: {
288
291
  schema: 'services_public',
289
- table: 'apis'
292
+ table: 'apis',
293
+ columnDefaults: {
294
+ dbname: 'current_database()'
295
+ }
290
296
  },
291
297
  apps: {
292
298
  schema: 'services_public',
@@ -60,6 +60,15 @@ const buildDynamicFieldsFromGraphQL = async (client, tableConfig) => {
60
60
  }
61
61
  }
62
62
  }
63
+ // Omit columns that are marked as columnDefaults — their DDL DEFAULT (e.g.
64
+ // current_database()) will supply the correct value at deploy time, so the
65
+ // exported INSERT must not hardcode an environment-specific literal.
66
+ if (tableConfig.columnDefaults) {
67
+ for (const colName of Object.keys(tableConfig.columnDefaults)) {
68
+ delete dynamicFields[colName];
69
+ enumFields.delete(colName);
70
+ }
71
+ }
63
72
  return { fields: dynamicFields, enumFields };
64
73
  }
65
74
  catch (err) {
@@ -142,6 +151,16 @@ const exportGraphQLMeta = async ({ client, database_id }) => {
142
151
  }
143
152
  if (Object.keys(dynamicFields).length === 0)
144
153
  return;
154
+ // Omit columnDefaults columns from row data so the Parser never sees them.
155
+ // configFields already excludes them (via buildDynamicFieldsFromGraphQL),
156
+ // so dynamicFields won't contain them either — but the pgRow data still does.
157
+ if (tableConfig.columnDefaults) {
158
+ for (const colName of Object.keys(tableConfig.columnDefaults)) {
159
+ for (const row of pgRows) {
160
+ delete row[colName];
161
+ }
162
+ }
163
+ }
145
164
  const parser = new csv_to_pg_1.Parser({
146
165
  schema: tableConfig.schema,
147
166
  table: tableConfig.table,
package/export-meta.js CHANGED
@@ -46,6 +46,14 @@ const buildDynamicFields = async (pool, tableConfig) => {
46
46
  }
47
47
  }
48
48
  }
49
+ // Omit columns that are marked as columnDefaults — their DDL DEFAULT (e.g.
50
+ // current_database()) will supply the correct value at deploy time, so the
51
+ // exported INSERT must not hardcode an environment-specific literal.
52
+ if (tableConfig.columnDefaults) {
53
+ for (const colName of Object.keys(tableConfig.columnDefaults)) {
54
+ delete dynamicFields[colName];
55
+ }
56
+ }
49
57
  return dynamicFields;
50
58
  };
51
59
  const exportMeta = async ({ opts, dbname, database_id }) => {
@@ -107,6 +115,17 @@ const exportMeta = async ({ opts, dbname, database_id }) => {
107
115
  }
108
116
  }
109
117
  }
118
+ // Omit columnDefaults columns from row data so the Parser never sees them.
119
+ // The Parser's field config already excludes them (via buildDynamicFields),
120
+ // so they would be ignored anyway, but removing them from the data is cleaner.
121
+ const tblCfg = export_utils_1.META_TABLE_CONFIG[key];
122
+ if (tblCfg?.columnDefaults) {
123
+ for (const colName of Object.keys(tblCfg.columnDefaults)) {
124
+ for (const row of result.rows) {
125
+ delete row[colName];
126
+ }
127
+ }
128
+ }
110
129
  const parsed = await parser.parse(result.rows);
111
130
  if (parsed) {
112
131
  sql[key] = parsed;
package/export-utils.d.ts CHANGED
@@ -37,6 +37,12 @@ export interface TableConfig {
37
37
  conflictDoNothing?: boolean;
38
38
  typeOverrides?: Record<string, FieldType>;
39
39
  gqlTypeName?: string;
40
+ /** Columns whose values are environment-specific and should be excluded from the
41
+ * exported INSERT so that the column's DDL DEFAULT applies at deploy time.
42
+ * Key = column name, Value = the SQL expression the column defaults to (for documentation).
43
+ * E.g. { dbname: 'current_database()' } — the exporter omits `dbname` from the
44
+ * INSERT, and `DEFAULT current_database()` in the table definition supplies it. */
45
+ columnDefaults?: Record<string, string>;
40
46
  }
41
47
  /**
42
48
  * Shared metadata table configuration.
package/export-utils.js CHANGED
@@ -289,11 +289,17 @@ exports.META_TABLE_CONFIG = {
289
289
  favicon: 'upload',
290
290
  apple_touch_icon: 'image',
291
291
  logo: 'image'
292
+ },
293
+ columnDefaults: {
294
+ dbname: 'current_database()'
292
295
  }
293
296
  },
294
297
  apis: {
295
298
  schema: 'services_public',
296
- table: 'apis'
299
+ table: 'apis',
300
+ columnDefaults: {
301
+ dbname: 'current_database()'
302
+ }
297
303
  },
298
304
  apps: {
299
305
  schema: 'services_public',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pgpmjs/export",
3
- "version": "0.21.3",
3
+ "version": "0.21.5",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "PGPM export tools for SQL and GraphQL database migration extraction",
6
6
  "main": "index.js",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@pgpmjs/core": "^6.24.0",
48
- "@pgpmjs/migrate-client": "^0.15.5",
48
+ "@pgpmjs/migrate-client": "^0.15.6",
49
49
  "@pgpmjs/types": "^2.29.0",
50
50
  "csv-to-pg": "^3.18.0",
51
51
  "glob": "^13.0.6",
@@ -55,5 +55,5 @@
55
55
  "pg-cache": "^3.12.0",
56
56
  "pg-env": "^1.16.0"
57
57
  },
58
- "gitHead": "659c7776183c8dc497e640c384e8d1af45965065"
58
+ "gitHead": "2558a0cdb58c815933af8bfe6769cd59014c77cf"
59
59
  }