@pgpmjs/export 1.16.5 → 1.16.7
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.
- package/esm/export-graphql.js +3 -2
- package/esm/export-migrations.js +3 -2
- package/esm/export-utils.js +21 -0
- package/export-graphql.js +2 -1
- package/export-migrations.js +2 -1
- package/export-utils.d.ts +13 -0
- package/export-utils.js +23 -1
- package/package.json +6 -6
package/esm/export-graphql.js
CHANGED
|
@@ -11,7 +11,7 @@ import { writePgpmFiles, writePgpmPlan } from '@pgpmjs/core';
|
|
|
11
11
|
import { createClient } from '@pgpmjs/migrate-client';
|
|
12
12
|
import { partitionExportRows, restructureExportRows } from '@pgpmjs/transform';
|
|
13
13
|
import { exportGraphQLMeta } from './export-graphql-meta';
|
|
14
|
-
import { DB_REQUIRED_EXTENSIONS, detectMissingModules, installMissingModules, makeReplacer, META_COMMON_FOOTER, META_COMMON_HEADER, META_TABLE_ORDER, normalizeOutdir, preparePackage, SERVICE_REQUIRED_EXTENSIONS } from './export-utils';
|
|
14
|
+
import { buildMetaRevertScript, DB_REQUIRED_EXTENSIONS, detectMissingModules, installMissingModules, makeReplacer, META_COMMON_FOOTER, META_COMMON_HEADER, META_TABLE_CONFIG, META_TABLE_ORDER, normalizeOutdir, preparePackage, SERVICE_REQUIRED_EXTENSIONS } from './export-utils';
|
|
15
15
|
import { GraphQLClient } from './graphql-client';
|
|
16
16
|
import { graphqlRowToPostgresRow } from './graphql-naming';
|
|
17
17
|
export const exportGraphQL = async ({ project, metaEndpoint, migrateEndpoint, token, headers, migrateHeaders, databaseId, databaseName, schema_names, schemas, author, outdir, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, argv, repoName, username, serviceOutdir, skipSchemaRenaming = false, granularity, partition }) => {
|
|
@@ -202,7 +202,8 @@ export const exportGraphQL = async ({ project, metaEndpoint, migrateEndpoint, to
|
|
|
202
202
|
${replacedSql}
|
|
203
203
|
|
|
204
204
|
${META_COMMON_FOOTER}
|
|
205
|
-
|
|
205
|
+
`,
|
|
206
|
+
revert: buildMetaRevertScript(tableName, META_TABLE_CONFIG[tableName], databaseId)
|
|
206
207
|
});
|
|
207
208
|
tablesWithContent.push(tableName);
|
|
208
209
|
}
|
package/esm/export-migrations.js
CHANGED
|
@@ -2,7 +2,7 @@ import { writePgpmFiles, writePgpmPlan } from '@pgpmjs/core';
|
|
|
2
2
|
import { partitionExportRows, restructureExportRows } from '@pgpmjs/transform';
|
|
3
3
|
import { getPgPool } from 'pg-cache';
|
|
4
4
|
import { exportMeta } from './export-meta';
|
|
5
|
-
import { DB_REQUIRED_EXTENSIONS, detectMissingModules, installMissingModules, makeReplacer, META_COMMON_FOOTER, META_COMMON_HEADER, META_TABLE_ORDER, normalizeOutdir, preparePackage, SERVICE_REQUIRED_EXTENSIONS } from './export-utils';
|
|
5
|
+
import { buildMetaRevertScript, DB_REQUIRED_EXTENSIONS, detectMissingModules, installMissingModules, makeReplacer, META_COMMON_FOOTER, META_COMMON_HEADER, META_TABLE_CONFIG, META_TABLE_ORDER, normalizeOutdir, preparePackage, SERVICE_REQUIRED_EXTENSIONS } from './export-utils';
|
|
6
6
|
const exportMigrationsToDisk = async ({ project, options, database, databaseId, databaseName, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, argv, repoName, username, serviceOutdir, skipSchemaRenaming = false, excludeCategories, granularity, partition }) => {
|
|
7
7
|
const normalizedOutdir = normalizeOutdir(outdir);
|
|
8
8
|
// Use serviceOutdir for service module, defaulting to outdir if not provided
|
|
@@ -186,7 +186,8 @@ const exportMigrationsToDisk = async ({ project, options, database, databaseId,
|
|
|
186
186
|
${replacedSql}
|
|
187
187
|
|
|
188
188
|
${META_COMMON_FOOTER}
|
|
189
|
-
|
|
189
|
+
`,
|
|
190
|
+
revert: buildMetaRevertScript(tableName, META_TABLE_CONFIG[tableName], databaseId)
|
|
190
191
|
});
|
|
191
192
|
tablesWithContent.push(tableName);
|
|
192
193
|
}
|
package/esm/export-utils.js
CHANGED
|
@@ -114,6 +114,27 @@ $LQLMIGRATION$;`;
|
|
|
114
114
|
*/
|
|
115
115
|
export const META_COMMON_FOOTER = `
|
|
116
116
|
SET session_replication_role TO DEFAULT;`;
|
|
117
|
+
/**
|
|
118
|
+
* Revert body for a `migrate/<table>` metaschema snapshot change: delete the
|
|
119
|
+
* exported database's rows from that table.
|
|
120
|
+
*
|
|
121
|
+
* The snapshot INSERTs every row belonging to `database_id` (keyed by `id` for
|
|
122
|
+
* `metaschema_public.database` itself), so the inverse is a database-scoped
|
|
123
|
+
* DELETE. Without it the change reverts to a no-op and a redeploy fails on the
|
|
124
|
+
* snapshot's own primary keys.
|
|
125
|
+
*
|
|
126
|
+
* Runs with `session_replication_role = replica` like the deploy body: FKs are
|
|
127
|
+
* unenforced, so the plan's reverse order is sufficient and no cascade fires.
|
|
128
|
+
*/
|
|
129
|
+
export const buildMetaRevertScript = (key, tableConfig, database_id) => {
|
|
130
|
+
const column = key === 'database' ? 'id' : 'database_id';
|
|
131
|
+
return `SET session_replication_role TO replica;
|
|
132
|
+
|
|
133
|
+
DELETE FROM "${tableConfig.schema}"."${tableConfig.table}" WHERE "${column}" = '${database_id}';
|
|
134
|
+
|
|
135
|
+
SET session_replication_role TO DEFAULT;
|
|
136
|
+
`;
|
|
137
|
+
};
|
|
117
138
|
/**
|
|
118
139
|
* Hand-authored per-table overrides layered on top of the generated
|
|
119
140
|
* table manifest. Only exceptional exporter behavior lives here:
|
package/export-graphql.js
CHANGED
|
@@ -205,7 +205,8 @@ const exportGraphQL = async ({ project, metaEndpoint, migrateEndpoint, token, he
|
|
|
205
205
|
${replacedSql}
|
|
206
206
|
|
|
207
207
|
${export_utils_1.META_COMMON_FOOTER}
|
|
208
|
-
|
|
208
|
+
`,
|
|
209
|
+
revert: (0, export_utils_1.buildMetaRevertScript)(tableName, export_utils_1.META_TABLE_CONFIG[tableName], databaseId)
|
|
209
210
|
});
|
|
210
211
|
tablesWithContent.push(tableName);
|
|
211
212
|
}
|
package/export-migrations.js
CHANGED
|
@@ -189,7 +189,8 @@ const exportMigrationsToDisk = async ({ project, options, database, databaseId,
|
|
|
189
189
|
${replacedSql}
|
|
190
190
|
|
|
191
191
|
${export_utils_1.META_COMMON_FOOTER}
|
|
192
|
-
|
|
192
|
+
`,
|
|
193
|
+
revert: (0, export_utils_1.buildMetaRevertScript)(tableName, export_utils_1.META_TABLE_CONFIG[tableName], databaseId)
|
|
193
194
|
});
|
|
194
195
|
tablesWithContent.push(tableName);
|
|
195
196
|
}
|
package/export-utils.d.ts
CHANGED
|
@@ -42,6 +42,19 @@ export declare const META_COMMON_HEADER = "SET session_replication_role TO repli
|
|
|
42
42
|
* Common SQL footer for meta export files.
|
|
43
43
|
*/
|
|
44
44
|
export declare const META_COMMON_FOOTER = "\nSET session_replication_role TO DEFAULT;";
|
|
45
|
+
/**
|
|
46
|
+
* Revert body for a `migrate/<table>` metaschema snapshot change: delete the
|
|
47
|
+
* exported database's rows from that table.
|
|
48
|
+
*
|
|
49
|
+
* The snapshot INSERTs every row belonging to `database_id` (keyed by `id` for
|
|
50
|
+
* `metaschema_public.database` itself), so the inverse is a database-scoped
|
|
51
|
+
* DELETE. Without it the change reverts to a no-op and a redeploy fails on the
|
|
52
|
+
* snapshot's own primary keys.
|
|
53
|
+
*
|
|
54
|
+
* Runs with `session_replication_role = replica` like the deploy body: FKs are
|
|
55
|
+
* unenforced, so the plan's reverse order is sufficient and no cascade fires.
|
|
56
|
+
*/
|
|
57
|
+
export declare const buildMetaRevertScript: (key: string, tableConfig: Pick<TableConfig, "schema" | "table">, database_id: string) => string;
|
|
45
58
|
export type FieldType = 'uuid' | 'uuid[]' | 'text' | 'text[]' | 'boolean' | 'image' | 'upload' | 'url' | 'jsonb' | 'jsonb[]' | 'int' | 'interval' | 'timestamptz';
|
|
46
59
|
export interface TableConfig {
|
|
47
60
|
schema: string;
|
package/export-utils.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.normalizeOutdir = exports.preparePackage = exports.makeReplacer = exports.installMissingModules = exports.detectMissingModules = exports.getTimestampDefaultColumnsForTable = exports.META_TABLE_TIMESTAMP_DEFAULTS = exports.META_TABLE_CONFIG = exports.META_TABLE_ORDER = exports.META_TABLE_OVERRIDES = exports.META_COMMON_FOOTER = exports.META_COMMON_HEADER = exports.SERVICE_REQUIRED_EXTENSIONS = exports.isTimestampDefaultColumn = exports.getTableColumnsWithDefaults = exports.mapPgTypeToFieldType = exports.DB_REQUIRED_EXTENSIONS = void 0;
|
|
6
|
+
exports.normalizeOutdir = exports.preparePackage = exports.makeReplacer = exports.installMissingModules = exports.detectMissingModules = exports.getTimestampDefaultColumnsForTable = exports.META_TABLE_TIMESTAMP_DEFAULTS = exports.META_TABLE_CONFIG = exports.META_TABLE_ORDER = exports.META_TABLE_OVERRIDES = exports.buildMetaRevertScript = exports.META_COMMON_FOOTER = exports.META_COMMON_HEADER = exports.SERVICE_REQUIRED_EXTENSIONS = exports.isTimestampDefaultColumn = exports.getTableColumnsWithDefaults = exports.mapPgTypeToFieldType = exports.DB_REQUIRED_EXTENSIONS = void 0;
|
|
7
7
|
const core_1 = require("@pgpmjs/core");
|
|
8
8
|
const fs_1 = require("fs");
|
|
9
9
|
const glob_1 = require("glob");
|
|
@@ -123,6 +123,28 @@ $LQLMIGRATION$;`;
|
|
|
123
123
|
*/
|
|
124
124
|
exports.META_COMMON_FOOTER = `
|
|
125
125
|
SET session_replication_role TO DEFAULT;`;
|
|
126
|
+
/**
|
|
127
|
+
* Revert body for a `migrate/<table>` metaschema snapshot change: delete the
|
|
128
|
+
* exported database's rows from that table.
|
|
129
|
+
*
|
|
130
|
+
* The snapshot INSERTs every row belonging to `database_id` (keyed by `id` for
|
|
131
|
+
* `metaschema_public.database` itself), so the inverse is a database-scoped
|
|
132
|
+
* DELETE. Without it the change reverts to a no-op and a redeploy fails on the
|
|
133
|
+
* snapshot's own primary keys.
|
|
134
|
+
*
|
|
135
|
+
* Runs with `session_replication_role = replica` like the deploy body: FKs are
|
|
136
|
+
* unenforced, so the plan's reverse order is sufficient and no cascade fires.
|
|
137
|
+
*/
|
|
138
|
+
const buildMetaRevertScript = (key, tableConfig, database_id) => {
|
|
139
|
+
const column = key === 'database' ? 'id' : 'database_id';
|
|
140
|
+
return `SET session_replication_role TO replica;
|
|
141
|
+
|
|
142
|
+
DELETE FROM "${tableConfig.schema}"."${tableConfig.table}" WHERE "${column}" = '${database_id}';
|
|
143
|
+
|
|
144
|
+
SET session_replication_role TO DEFAULT;
|
|
145
|
+
`;
|
|
146
|
+
};
|
|
147
|
+
exports.buildMetaRevertScript = buildMetaRevertScript;
|
|
126
148
|
/**
|
|
127
149
|
* Hand-authored per-table overrides layered on top of the generated
|
|
128
150
|
* table manifest. Only exceptional exporter behavior lives here:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpmjs/export",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.7",
|
|
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",
|
|
@@ -41,22 +41,22 @@
|
|
|
41
41
|
"@pgsql/types": "^18.0.0",
|
|
42
42
|
"@types/pg": "^8.20.4",
|
|
43
43
|
"makage": "^0.3.0",
|
|
44
|
-
"pgsql-test": "^5.10.
|
|
44
|
+
"pgsql-test": "^5.10.6"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@constructive-io/query-builder": "^3.10.2",
|
|
48
|
-
"@pgpmjs/core": "^7.25.
|
|
49
|
-
"@pgpmjs/migrate-client": "^1.11.
|
|
48
|
+
"@pgpmjs/core": "^7.25.3",
|
|
49
|
+
"@pgpmjs/migrate-client": "^1.11.7",
|
|
50
50
|
"@pgpmjs/naming-spec": "^0.3.0",
|
|
51
51
|
"@pgpmjs/transform": "^0.23.3",
|
|
52
52
|
"@pgpmjs/types": "^2.50.3",
|
|
53
53
|
"csv-to-pg": "^4.10.3",
|
|
54
54
|
"glob": "^13.0.6",
|
|
55
|
-
"inflekt": "^0.8.
|
|
55
|
+
"inflekt": "^0.8.1",
|
|
56
56
|
"inquirerer": "^4.9.3",
|
|
57
57
|
"pg": "^8.21.0",
|
|
58
58
|
"pg-cache": "^3.25.4",
|
|
59
59
|
"pg-env": "^1.29.1"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "a7ba21122bd39663b40fb8fc3afe6eb9b69e0041"
|
|
62
62
|
}
|