@pgpmjs/core 4.7.2 → 4.8.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.
|
@@ -92,7 +92,7 @@ const installMissingModules = async (moduleDir, missingModules) => {
|
|
|
92
92
|
await moduleProject.installModules(...missingNames);
|
|
93
93
|
console.log('Modules installed successfully.');
|
|
94
94
|
};
|
|
95
|
-
const exportMigrationsToDisk = async ({ project, options, database, databaseId, databaseName, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, repoName, username, serviceOutdir }) => {
|
|
95
|
+
const exportMigrationsToDisk = async ({ project, options, database, databaseId, databaseName, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, repoName, username, serviceOutdir, skipSchemaRenaming = false }) => {
|
|
96
96
|
outdir = outdir + '/';
|
|
97
97
|
// Use serviceOutdir for service module, defaulting to outdir if not provided
|
|
98
98
|
const svcOutdir = (serviceOutdir || outdir.slice(0, -1)) + '/';
|
|
@@ -111,11 +111,20 @@ const exportMigrationsToDisk = async ({ project, options, database, databaseId,
|
|
|
111
111
|
return;
|
|
112
112
|
}
|
|
113
113
|
const name = extensionName || db.rows[0].name;
|
|
114
|
+
// When skipSchemaRenaming is true, pass empty schemas array to avoid renaming
|
|
115
|
+
// This is useful for self-referential introspection where you want to apply
|
|
116
|
+
// policies to real infrastructure schemas (metaschema_public, services_public, etc.)
|
|
117
|
+
const schemasForReplacement = skipSchemaRenaming
|
|
118
|
+
? []
|
|
119
|
+
: schemas.rows.filter((schema) => schema_names.includes(schema.schema_name));
|
|
114
120
|
const { replace, replacer } = makeReplacer({
|
|
115
|
-
schemas:
|
|
121
|
+
schemas: schemasForReplacement,
|
|
116
122
|
name
|
|
117
123
|
});
|
|
118
|
-
|
|
124
|
+
// Filter sql_actions by database_id to avoid cross-database pollution
|
|
125
|
+
// Previously this query had no WHERE clause, which could export actions
|
|
126
|
+
// from unrelated databases in a persistent database environment
|
|
127
|
+
const results = await pgPool.query(`select * from db_migrate.sql_actions where database_id = $1 order by id`, [databaseId]);
|
|
119
128
|
const opts = {
|
|
120
129
|
name,
|
|
121
130
|
replacer,
|
|
@@ -171,8 +180,12 @@ const exportMigrationsToDisk = async ({ project, options, database, databaseId,
|
|
|
171
180
|
if (svcMissingResult.shouldInstall) {
|
|
172
181
|
await installMissingModules(svcModuleDir, svcMissingResult.missingModules);
|
|
173
182
|
}
|
|
183
|
+
// Use same skipSchemaRenaming logic for meta replacer
|
|
184
|
+
const metaSchemasForReplacement = skipSchemaRenaming
|
|
185
|
+
? []
|
|
186
|
+
: schemas.rows.filter((schema) => schema_names.includes(schema.schema_name));
|
|
174
187
|
const metaReplacer = makeReplacer({
|
|
175
|
-
schemas:
|
|
188
|
+
schemas: metaSchemasForReplacement,
|
|
176
189
|
name: metaExtensionName
|
|
177
190
|
});
|
|
178
191
|
const metaPackage = [
|
|
@@ -219,7 +232,7 @@ SET session_replication_role TO DEFAULT;
|
|
|
219
232
|
}
|
|
220
233
|
pgPool.end();
|
|
221
234
|
};
|
|
222
|
-
export const exportMigrations = async ({ project, options, dbInfo, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, repoName, username, serviceOutdir }) => {
|
|
235
|
+
export const exportMigrations = async ({ project, options, dbInfo, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, repoName, username, serviceOutdir, skipSchemaRenaming }) => {
|
|
223
236
|
for (let v = 0; v < dbInfo.database_ids.length; v++) {
|
|
224
237
|
const databaseId = dbInfo.database_ids[v];
|
|
225
238
|
await exportMigrationsToDisk({
|
|
@@ -238,7 +251,8 @@ export const exportMigrations = async ({ project, options, dbInfo, author, outdi
|
|
|
238
251
|
prompter,
|
|
239
252
|
repoName,
|
|
240
253
|
username,
|
|
241
|
-
serviceOutdir
|
|
254
|
+
serviceOutdir,
|
|
255
|
+
skipSchemaRenaming
|
|
242
256
|
});
|
|
243
257
|
}
|
|
244
258
|
};
|
package/esm/modules/modules.js
CHANGED
|
@@ -8,8 +8,8 @@ import { errors } from '@pgpmjs/types';
|
|
|
8
8
|
export const PGPM_MODULE_MAP = {
|
|
9
9
|
'pgpm-base32': '@pgpm/base32',
|
|
10
10
|
'pgpm-database-jobs': '@pgpm/database-jobs',
|
|
11
|
-
'
|
|
12
|
-
'
|
|
11
|
+
'metaschema-modules': '@pgpm/metaschema-modules',
|
|
12
|
+
'metaschema-schema': '@pgpm/metaschema-schema',
|
|
13
13
|
'pgpm-inflection': '@pgpm/inflection',
|
|
14
14
|
'pgpm-jwt-claims': '@pgpm/jwt-claims',
|
|
15
15
|
'pgpm-stamps': '@pgpm/stamps',
|
|
@@ -29,6 +29,12 @@ interface ExportOptions {
|
|
|
29
29
|
username?: string;
|
|
30
30
|
/** Output directory for service/meta module. Defaults to outdir if not provided. */
|
|
31
31
|
serviceOutdir?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Skip schema name replacement for infrastructure schemas.
|
|
34
|
+
* When true, schema names like metaschema_public, services_public will not be renamed.
|
|
35
|
+
* Useful for self-referential introspection where you want to apply policies to real schemas.
|
|
36
|
+
*/
|
|
37
|
+
skipSchemaRenaming?: boolean;
|
|
32
38
|
}
|
|
33
|
-
export declare const exportMigrations: ({ project, options, dbInfo, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, repoName, username, serviceOutdir }: ExportOptions) => Promise<void>;
|
|
39
|
+
export declare const exportMigrations: ({ project, options, dbInfo, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, repoName, username, serviceOutdir, skipSchemaRenaming }: ExportOptions) => Promise<void>;
|
|
34
40
|
export {};
|
|
@@ -98,7 +98,7 @@ const installMissingModules = async (moduleDir, missingModules) => {
|
|
|
98
98
|
await moduleProject.installModules(...missingNames);
|
|
99
99
|
console.log('Modules installed successfully.');
|
|
100
100
|
};
|
|
101
|
-
const exportMigrationsToDisk = async ({ project, options, database, databaseId, databaseName, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, repoName, username, serviceOutdir }) => {
|
|
101
|
+
const exportMigrationsToDisk = async ({ project, options, database, databaseId, databaseName, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, repoName, username, serviceOutdir, skipSchemaRenaming = false }) => {
|
|
102
102
|
outdir = outdir + '/';
|
|
103
103
|
// Use serviceOutdir for service module, defaulting to outdir if not provided
|
|
104
104
|
const svcOutdir = (serviceOutdir || outdir.slice(0, -1)) + '/';
|
|
@@ -117,11 +117,20 @@ const exportMigrationsToDisk = async ({ project, options, database, databaseId,
|
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
119
|
const name = extensionName || db.rows[0].name;
|
|
120
|
+
// When skipSchemaRenaming is true, pass empty schemas array to avoid renaming
|
|
121
|
+
// This is useful for self-referential introspection where you want to apply
|
|
122
|
+
// policies to real infrastructure schemas (metaschema_public, services_public, etc.)
|
|
123
|
+
const schemasForReplacement = skipSchemaRenaming
|
|
124
|
+
? []
|
|
125
|
+
: schemas.rows.filter((schema) => schema_names.includes(schema.schema_name));
|
|
120
126
|
const { replace, replacer } = makeReplacer({
|
|
121
|
-
schemas:
|
|
127
|
+
schemas: schemasForReplacement,
|
|
122
128
|
name
|
|
123
129
|
});
|
|
124
|
-
|
|
130
|
+
// Filter sql_actions by database_id to avoid cross-database pollution
|
|
131
|
+
// Previously this query had no WHERE clause, which could export actions
|
|
132
|
+
// from unrelated databases in a persistent database environment
|
|
133
|
+
const results = await pgPool.query(`select * from db_migrate.sql_actions where database_id = $1 order by id`, [databaseId]);
|
|
125
134
|
const opts = {
|
|
126
135
|
name,
|
|
127
136
|
replacer,
|
|
@@ -177,8 +186,12 @@ const exportMigrationsToDisk = async ({ project, options, database, databaseId,
|
|
|
177
186
|
if (svcMissingResult.shouldInstall) {
|
|
178
187
|
await installMissingModules(svcModuleDir, svcMissingResult.missingModules);
|
|
179
188
|
}
|
|
189
|
+
// Use same skipSchemaRenaming logic for meta replacer
|
|
190
|
+
const metaSchemasForReplacement = skipSchemaRenaming
|
|
191
|
+
? []
|
|
192
|
+
: schemas.rows.filter((schema) => schema_names.includes(schema.schema_name));
|
|
180
193
|
const metaReplacer = makeReplacer({
|
|
181
|
-
schemas:
|
|
194
|
+
schemas: metaSchemasForReplacement,
|
|
182
195
|
name: metaExtensionName
|
|
183
196
|
});
|
|
184
197
|
const metaPackage = [
|
|
@@ -225,7 +238,7 @@ SET session_replication_role TO DEFAULT;
|
|
|
225
238
|
}
|
|
226
239
|
pgPool.end();
|
|
227
240
|
};
|
|
228
|
-
const exportMigrations = async ({ project, options, dbInfo, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, repoName, username, serviceOutdir }) => {
|
|
241
|
+
const exportMigrations = async ({ project, options, dbInfo, author, outdir, schema_names, extensionName, extensionDesc, metaExtensionName, metaExtensionDesc, prompter, repoName, username, serviceOutdir, skipSchemaRenaming }) => {
|
|
229
242
|
for (let v = 0; v < dbInfo.database_ids.length; v++) {
|
|
230
243
|
const databaseId = dbInfo.database_ids[v];
|
|
231
244
|
await exportMigrationsToDisk({
|
|
@@ -244,7 +257,8 @@ const exportMigrations = async ({ project, options, dbInfo, author, outdir, sche
|
|
|
244
257
|
prompter,
|
|
245
258
|
repoName,
|
|
246
259
|
username,
|
|
247
|
-
serviceOutdir
|
|
260
|
+
serviceOutdir,
|
|
261
|
+
skipSchemaRenaming
|
|
248
262
|
});
|
|
249
263
|
}
|
|
250
264
|
};
|
package/modules/modules.js
CHANGED
|
@@ -11,8 +11,8 @@ const types_1 = require("@pgpmjs/types");
|
|
|
11
11
|
exports.PGPM_MODULE_MAP = {
|
|
12
12
|
'pgpm-base32': '@pgpm/base32',
|
|
13
13
|
'pgpm-database-jobs': '@pgpm/database-jobs',
|
|
14
|
-
'
|
|
15
|
-
'
|
|
14
|
+
'metaschema-modules': '@pgpm/metaschema-modules',
|
|
15
|
+
'metaschema-schema': '@pgpm/metaschema-schema',
|
|
16
16
|
'pgpm-inflection': '@pgpm/inflection',
|
|
17
17
|
'pgpm-jwt-claims': '@pgpm/jwt-claims',
|
|
18
18
|
'pgpm-stamps': '@pgpm/stamps',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpmjs/core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.0",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "PGPM Package and Migration Tools",
|
|
6
6
|
"main": "index.js",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"pgsql-parser": "^17.9.9",
|
|
65
65
|
"yanse": "^0.1.11"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "97528ad4eb2f60c16785ffb84af7b61c52cb5ad8"
|
|
68
68
|
}
|