@pgpmjs/export 0.32.7 → 1.0.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.
- package/esm/export-graphql.js +12 -3
- package/esm/export-migrations.js +14 -8
- package/export-graphql.d.ts +7 -1
- package/export-graphql.js +12 -3
- package/export-migrations.d.ts +7 -1
- package/export-migrations.js +14 -8
- package/package.json +7 -7
package/esm/export-graphql.js
CHANGED
|
@@ -4,7 +4,7 @@ import { GraphQLClient } from './graphql-client';
|
|
|
4
4
|
import { exportGraphQLMeta } from './export-graphql-meta';
|
|
5
5
|
import { graphqlRowToPostgresRow } from './graphql-naming';
|
|
6
6
|
import { DB_REQUIRED_EXTENSIONS, SERVICE_REQUIRED_EXTENSIONS, META_COMMON_HEADER, META_COMMON_FOOTER, META_TABLE_ORDER, detectMissingModules, installMissingModules, makeReplacer, preparePackage, normalizeOutdir } from './export-utils';
|
|
7
|
-
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 }) => {
|
|
7
|
+
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, excludeCategories }) => {
|
|
8
8
|
const normalizedOutdir = normalizeOutdir(outdir);
|
|
9
9
|
const svcOutdir = normalizeOutdir(serviceOutdir || outdir);
|
|
10
10
|
const name = extensionName;
|
|
@@ -49,10 +49,19 @@ export const exportGraphQL = async ({ project, metaEndpoint, migrateEndpoint, to
|
|
|
49
49
|
actionName: true,
|
|
50
50
|
actionId: true,
|
|
51
51
|
actorId: true,
|
|
52
|
-
payload: true
|
|
52
|
+
payload: true,
|
|
53
|
+
category: true
|
|
53
54
|
},
|
|
54
55
|
where: {
|
|
55
|
-
databaseId: { equalTo: databaseId }
|
|
56
|
+
databaseId: { equalTo: databaseId },
|
|
57
|
+
...(excludeCategories && excludeCategories.length > 0
|
|
58
|
+
? {
|
|
59
|
+
or: [
|
|
60
|
+
{ category: { isNull: true } },
|
|
61
|
+
{ category: { notIn: excludeCategories } }
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
: {})
|
|
56
65
|
},
|
|
57
66
|
orderBy: ['ID_ASC'],
|
|
58
67
|
first: PAGE_SIZE,
|
package/esm/export-migrations.js
CHANGED
|
@@ -2,7 +2,7 @@ import { getPgPool } from 'pg-cache';
|
|
|
2
2
|
import { writePgpmFiles, writePgpmPlan } from '@pgpmjs/core';
|
|
3
3
|
import { exportMeta } from './export-meta';
|
|
4
4
|
import { DB_REQUIRED_EXTENSIONS, SERVICE_REQUIRED_EXTENSIONS, META_COMMON_HEADER, META_COMMON_FOOTER, META_TABLE_ORDER, detectMissingModules, installMissingModules, makeReplacer, preparePackage, normalizeOutdir } from './export-utils';
|
|
5
|
-
const exportMigrationsToDisk = async ({ project, options, database, databaseId, databaseName, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, argv, repoName, username, serviceOutdir, skipSchemaRenaming = false }) => {
|
|
5
|
+
const exportMigrationsToDisk = async ({ project, options, database, databaseId, databaseName, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, argv, repoName, username, serviceOutdir, skipSchemaRenaming = false, excludeCategories }) => {
|
|
6
6
|
const normalizedOutdir = normalizeOutdir(outdir);
|
|
7
7
|
// Use serviceOutdir for service module, defaulting to outdir if not provided
|
|
8
8
|
const svcOutdir = normalizeOutdir(serviceOutdir || outdir);
|
|
@@ -31,10 +31,16 @@ const exportMigrationsToDisk = async ({ project, options, database, databaseId,
|
|
|
31
31
|
schemas: schemasForReplacement,
|
|
32
32
|
name
|
|
33
33
|
});
|
|
34
|
-
// Filter sql_actions by database_id to avoid cross-database pollution
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
|
|
34
|
+
// Filter sql_actions by database_id to avoid cross-database pollution.
|
|
35
|
+
// Category exclusion is applied here explicitly rather than via the
|
|
36
|
+
// export.exclude_categories session GUC, which only affects the session
|
|
37
|
+
// it was set on and therefore cannot be relied upon across connections.
|
|
38
|
+
const results = excludeCategories && excludeCategories.length > 0
|
|
39
|
+
? await pgPool.query(`select * from db_migrate.sql_actions
|
|
40
|
+
where database_id = $1
|
|
41
|
+
and (category is null or category != ALL($2::text[]))
|
|
42
|
+
order by id`, [databaseId, excludeCategories])
|
|
43
|
+
: await pgPool.query(`select * from db_migrate.sql_actions where database_id = $1 order by id`, [databaseId]);
|
|
38
44
|
const opts = {
|
|
39
45
|
name,
|
|
40
46
|
replacer,
|
|
@@ -142,9 +148,8 @@ ${META_COMMON_FOOTER}
|
|
|
142
148
|
opts.outdir = svcOutdir;
|
|
143
149
|
writePgpmPlan(metaPackage, opts);
|
|
144
150
|
writePgpmFiles(metaPackage, opts);
|
|
145
|
-
pgPool.end();
|
|
146
151
|
};
|
|
147
|
-
export const exportMigrations = async ({ project, options, dbInfo, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, argv, repoName, username, serviceOutdir, skipSchemaRenaming }) => {
|
|
152
|
+
export const exportMigrations = async ({ project, options, dbInfo, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, argv, repoName, username, serviceOutdir, skipSchemaRenaming, excludeCategories }) => {
|
|
148
153
|
for (let v = 0; v < dbInfo.database_ids.length; v++) {
|
|
149
154
|
const databaseId = dbInfo.database_ids[v];
|
|
150
155
|
await exportMigrationsToDisk({
|
|
@@ -165,7 +170,8 @@ export const exportMigrations = async ({ project, options, dbInfo, author, outdi
|
|
|
165
170
|
repoName,
|
|
166
171
|
username,
|
|
167
172
|
serviceOutdir,
|
|
168
|
-
skipSchemaRenaming
|
|
173
|
+
skipSchemaRenaming,
|
|
174
|
+
excludeCategories
|
|
169
175
|
});
|
|
170
176
|
}
|
|
171
177
|
};
|
package/export-graphql.d.ts
CHANGED
|
@@ -48,5 +48,11 @@ export interface ExportGraphQLOptions {
|
|
|
48
48
|
username?: string;
|
|
49
49
|
serviceOutdir?: string;
|
|
50
50
|
skipSchemaRenaming?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* sql_actions categories to exclude from the export (e.g. ['security',
|
|
53
|
+
* 'permissions']). Rows whose category matches are omitted; rows with a
|
|
54
|
+
* null category are always kept.
|
|
55
|
+
*/
|
|
56
|
+
excludeCategories?: string[];
|
|
51
57
|
}
|
|
52
|
-
export declare const exportGraphQL: ({ project, metaEndpoint, migrateEndpoint, token, headers, migrateHeaders, databaseId, databaseName, schema_names, schemas, author, outdir, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, argv, repoName, username, serviceOutdir, skipSchemaRenaming }: ExportGraphQLOptions) => Promise<void>;
|
|
58
|
+
export declare const exportGraphQL: ({ project, metaEndpoint, migrateEndpoint, token, headers, migrateHeaders, databaseId, databaseName, schema_names, schemas, author, outdir, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, argv, repoName, username, serviceOutdir, skipSchemaRenaming, excludeCategories }: ExportGraphQLOptions) => Promise<void>;
|
package/export-graphql.js
CHANGED
|
@@ -7,7 +7,7 @@ const graphql_client_1 = require("./graphql-client");
|
|
|
7
7
|
const export_graphql_meta_1 = require("./export-graphql-meta");
|
|
8
8
|
const graphql_naming_1 = require("./graphql-naming");
|
|
9
9
|
const export_utils_1 = require("./export-utils");
|
|
10
|
-
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 }) => {
|
|
10
|
+
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, excludeCategories }) => {
|
|
11
11
|
const normalizedOutdir = (0, export_utils_1.normalizeOutdir)(outdir);
|
|
12
12
|
const svcOutdir = (0, export_utils_1.normalizeOutdir)(serviceOutdir || outdir);
|
|
13
13
|
const name = extensionName;
|
|
@@ -52,10 +52,19 @@ const exportGraphQL = async ({ project, metaEndpoint, migrateEndpoint, token, he
|
|
|
52
52
|
actionName: true,
|
|
53
53
|
actionId: true,
|
|
54
54
|
actorId: true,
|
|
55
|
-
payload: true
|
|
55
|
+
payload: true,
|
|
56
|
+
category: true
|
|
56
57
|
},
|
|
57
58
|
where: {
|
|
58
|
-
databaseId: { equalTo: databaseId }
|
|
59
|
+
databaseId: { equalTo: databaseId },
|
|
60
|
+
...(excludeCategories && excludeCategories.length > 0
|
|
61
|
+
? {
|
|
62
|
+
or: [
|
|
63
|
+
{ category: { isNull: true } },
|
|
64
|
+
{ category: { notIn: excludeCategories } }
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
: {})
|
|
59
68
|
},
|
|
60
69
|
orderBy: ['ID_ASC'],
|
|
61
70
|
first: PAGE_SIZE,
|
package/export-migrations.d.ts
CHANGED
|
@@ -30,6 +30,12 @@ interface ExportOptions {
|
|
|
30
30
|
* Useful for self-referential introspection where you want to apply policies to real schemas.
|
|
31
31
|
*/
|
|
32
32
|
skipSchemaRenaming?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Action categories to exclude from the export (e.g. ['security', 'permissions']).
|
|
35
|
+
* Rows in db_migrate.sql_actions whose category matches are omitted from the
|
|
36
|
+
* generated pgpm plan and SQL files. Rows with a NULL category are always kept.
|
|
37
|
+
*/
|
|
38
|
+
excludeCategories?: string[];
|
|
33
39
|
}
|
|
34
|
-
export declare const exportMigrations: ({ project, options, dbInfo, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, argv, repoName, username, serviceOutdir, skipSchemaRenaming }: ExportOptions) => Promise<void>;
|
|
40
|
+
export declare const exportMigrations: ({ project, options, dbInfo, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, argv, repoName, username, serviceOutdir, skipSchemaRenaming, excludeCategories }: ExportOptions) => Promise<void>;
|
|
35
41
|
export {};
|
package/export-migrations.js
CHANGED
|
@@ -5,7 +5,7 @@ const pg_cache_1 = require("pg-cache");
|
|
|
5
5
|
const core_1 = require("@pgpmjs/core");
|
|
6
6
|
const export_meta_1 = require("./export-meta");
|
|
7
7
|
const export_utils_1 = require("./export-utils");
|
|
8
|
-
const exportMigrationsToDisk = async ({ project, options, database, databaseId, databaseName, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, argv, repoName, username, serviceOutdir, skipSchemaRenaming = false }) => {
|
|
8
|
+
const exportMigrationsToDisk = async ({ project, options, database, databaseId, databaseName, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, argv, repoName, username, serviceOutdir, skipSchemaRenaming = false, excludeCategories }) => {
|
|
9
9
|
const normalizedOutdir = (0, export_utils_1.normalizeOutdir)(outdir);
|
|
10
10
|
// Use serviceOutdir for service module, defaulting to outdir if not provided
|
|
11
11
|
const svcOutdir = (0, export_utils_1.normalizeOutdir)(serviceOutdir || outdir);
|
|
@@ -34,10 +34,16 @@ const exportMigrationsToDisk = async ({ project, options, database, databaseId,
|
|
|
34
34
|
schemas: schemasForReplacement,
|
|
35
35
|
name
|
|
36
36
|
});
|
|
37
|
-
// Filter sql_actions by database_id to avoid cross-database pollution
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
|
|
37
|
+
// Filter sql_actions by database_id to avoid cross-database pollution.
|
|
38
|
+
// Category exclusion is applied here explicitly rather than via the
|
|
39
|
+
// export.exclude_categories session GUC, which only affects the session
|
|
40
|
+
// it was set on and therefore cannot be relied upon across connections.
|
|
41
|
+
const results = excludeCategories && excludeCategories.length > 0
|
|
42
|
+
? await pgPool.query(`select * from db_migrate.sql_actions
|
|
43
|
+
where database_id = $1
|
|
44
|
+
and (category is null or category != ALL($2::text[]))
|
|
45
|
+
order by id`, [databaseId, excludeCategories])
|
|
46
|
+
: await pgPool.query(`select * from db_migrate.sql_actions where database_id = $1 order by id`, [databaseId]);
|
|
41
47
|
const opts = {
|
|
42
48
|
name,
|
|
43
49
|
replacer,
|
|
@@ -145,9 +151,8 @@ ${export_utils_1.META_COMMON_FOOTER}
|
|
|
145
151
|
opts.outdir = svcOutdir;
|
|
146
152
|
(0, core_1.writePgpmPlan)(metaPackage, opts);
|
|
147
153
|
(0, core_1.writePgpmFiles)(metaPackage, opts);
|
|
148
|
-
pgPool.end();
|
|
149
154
|
};
|
|
150
|
-
const exportMigrations = async ({ project, options, dbInfo, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, argv, repoName, username, serviceOutdir, skipSchemaRenaming }) => {
|
|
155
|
+
const exportMigrations = async ({ project, options, dbInfo, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, argv, repoName, username, serviceOutdir, skipSchemaRenaming, excludeCategories }) => {
|
|
151
156
|
for (let v = 0; v < dbInfo.database_ids.length; v++) {
|
|
152
157
|
const databaseId = dbInfo.database_ids[v];
|
|
153
158
|
await exportMigrationsToDisk({
|
|
@@ -168,7 +173,8 @@ const exportMigrations = async ({ project, options, dbInfo, author, outdir, sche
|
|
|
168
173
|
repoName,
|
|
169
174
|
username,
|
|
170
175
|
serviceOutdir,
|
|
171
|
-
skipSchemaRenaming
|
|
176
|
+
skipSchemaRenaming,
|
|
177
|
+
excludeCategories
|
|
172
178
|
});
|
|
173
179
|
}
|
|
174
180
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpmjs/export",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.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",
|
|
@@ -38,16 +38,16 @@
|
|
|
38
38
|
"graphql"
|
|
39
39
|
],
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@pgsql/types": "^
|
|
41
|
+
"@pgsql/types": "^18.0.0",
|
|
42
42
|
"@types/pg": "^8.20.0",
|
|
43
43
|
"makage": "^0.3.0",
|
|
44
|
-
"pgsql-test": "^
|
|
44
|
+
"pgsql-test": "^5.0.0"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@pgpmjs/core": "^
|
|
48
|
-
"@pgpmjs/migrate-client": "^0.
|
|
47
|
+
"@pgpmjs/core": "^7.0.0",
|
|
48
|
+
"@pgpmjs/migrate-client": "^1.0.0",
|
|
49
49
|
"@pgpmjs/types": "^2.35.1",
|
|
50
|
-
"csv-to-pg": "^
|
|
50
|
+
"csv-to-pg": "^4.0.0",
|
|
51
51
|
"glob": "^13.0.6",
|
|
52
52
|
"inflekt": "^0.7.1",
|
|
53
53
|
"inquirerer": "^4.9.1",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"pg-cache": "^3.15.2",
|
|
56
56
|
"pg-env": "^1.18.1"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "278757de075dcdaf3d7aca114644d64c10e49ba7"
|
|
59
59
|
}
|