@pgpmjs/export 1.4.0 → 1.5.0

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.
@@ -130,8 +130,9 @@ export const exportTableData = async (db, spec, options = {}) => {
130
130
  const excluded = new Set(options.excludeColumns ?? []);
131
131
  const allColumns = await getDataExportColumns(db, spec.schema, spec.table);
132
132
  const columns = allColumns.filter(c => !excluded.has(c.name) && !isVolatileTimestampColumn(c));
133
+ const targetSchema = spec.targetSchema ?? spec.schema;
133
134
  const base = {
134
- schema: spec.schema,
135
+ schema: targetSchema,
135
136
  table: spec.table,
136
137
  columns,
137
138
  rowCount: 0,
@@ -165,7 +166,7 @@ export const exportTableData = async (db, spec, options = {}) => {
165
166
  if (rowsRes.rows.length === 0)
166
167
  return base;
167
168
  const insertQb = new QueryBuilder()
168
- .schema(spec.schema)
169
+ .schema(targetSchema)
169
170
  .table(spec.table)
170
171
  .insert(rowsRes.rows.map((row) => Object.fromEntries(columns.map(c => [c.name, cast(lit(row[c.name]), c.type)]))));
171
172
  if (options.conflictDoNothing) {
package/export-data.d.ts CHANGED
@@ -69,6 +69,7 @@ export interface MetadataExportColumn {
69
69
  */
70
70
  export declare const getMetadataExportColumns: (db: Queryable, columns: MetadataExportColumn[]) => Promise<DataExportColumn[]>;
71
71
  export interface DataExportTableSpec {
72
+ /** Physical schema the rows are read from. */
72
73
  schema: string;
73
74
  table: string;
74
75
  /** Optional equality filter, e.g. { column: 'database_id', value: id }. */
@@ -76,6 +77,13 @@ export interface DataExportTableSpec {
76
77
  column: string;
77
78
  value: string;
78
79
  };
80
+ /**
81
+ * Schema the emitted INSERT/DELETE/verify statements target when it
82
+ * differs from the physical source schema (e.g. rows read from a
83
+ * prefixed staging schema but replayed into its published logical name).
84
+ * Defaults to `schema`.
85
+ */
86
+ targetSchema?: string;
79
87
  }
80
88
  export interface ExportTableDataOptions {
81
89
  /**
@@ -88,6 +96,7 @@ export interface ExportTableDataOptions {
88
96
  conflictDoNothing?: boolean;
89
97
  }
90
98
  export interface TableDataExport {
99
+ /** Schema the emitted statements target (targetSchema when supplied). */
91
100
  schema: string;
92
101
  table: string;
93
102
  /** Columns included in the INSERT, in table order. */
package/export-data.js CHANGED
@@ -136,8 +136,9 @@ const exportTableData = async (db, spec, options = {}) => {
136
136
  const excluded = new Set(options.excludeColumns ?? []);
137
137
  const allColumns = await (0, exports.getDataExportColumns)(db, spec.schema, spec.table);
138
138
  const columns = allColumns.filter(c => !excluded.has(c.name) && !(0, exports.isVolatileTimestampColumn)(c));
139
+ const targetSchema = spec.targetSchema ?? spec.schema;
139
140
  const base = {
140
- schema: spec.schema,
141
+ schema: targetSchema,
141
142
  table: spec.table,
142
143
  columns,
143
144
  rowCount: 0,
@@ -171,7 +172,7 @@ const exportTableData = async (db, spec, options = {}) => {
171
172
  if (rowsRes.rows.length === 0)
172
173
  return base;
173
174
  const insertQb = new query_builder_1.QueryBuilder()
174
- .schema(spec.schema)
175
+ .schema(targetSchema)
175
176
  .table(spec.table)
176
177
  .insert(rowsRes.rows.map((row) => Object.fromEntries(columns.map(c => [c.name, (0, query_builder_1.cast)((0, query_builder_1.lit)(row[c.name]), c.type)]))));
177
178
  if (options.conflictDoNothing) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pgpmjs/export",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
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",
@@ -46,7 +46,7 @@
46
46
  "dependencies": {
47
47
  "@constructive-io/query-builder": "^3.1.2",
48
48
  "@pgpmjs/core": "^7.4.2",
49
- "@pgpmjs/migrate-client": "^1.1.3",
49
+ "@pgpmjs/migrate-client": "^1.2.0",
50
50
  "@pgpmjs/types": "^2.37.2",
51
51
  "csv-to-pg": "^4.1.2",
52
52
  "glob": "^13.0.6",
@@ -56,5 +56,5 @@
56
56
  "pg-cache": "^3.16.2",
57
57
  "pg-env": "^1.19.2"
58
58
  },
59
- "gitHead": "0e3ee42c44c9b35ffac4bf1faa6775eb69311ec4"
59
+ "gitHead": "518e7ab2270661c64875258436d90fdf76b4b336"
60
60
  }