@pgpmjs/core 7.14.0 â 7.16.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/apply/apply-spec.js +84 -9
- package/apply/index.d.ts +1 -0
- package/apply/index.js +1 -0
- package/apply/materialize.js +15 -2
- package/apply/reuse.d.ts +52 -0
- package/apply/reuse.js +226 -0
- package/apply/types.d.ts +89 -0
- package/bundle/artifact.d.ts +35 -0
- package/bundle/artifact.js +96 -0
- package/bundle/deploy-bundled.d.ts +71 -0
- package/bundle/deploy-bundled.js +177 -0
- package/bundle/index.d.ts +2 -0
- package/bundle/index.js +4 -0
- package/core/class/pgpm.js +54 -57
- package/esm/apply/apply-spec.js +84 -9
- package/esm/apply/index.js +1 -0
- package/esm/apply/materialize.js +15 -2
- package/esm/apply/reuse.js +221 -0
- package/esm/bundle/artifact.js +89 -0
- package/esm/bundle/deploy-bundled.js +170 -0
- package/esm/bundle/index.js +4 -0
- package/esm/core/class/pgpm.js +54 -57
- package/esm/extensions/compile.js +109 -0
- package/esm/extensions/index.js +4 -0
- package/esm/extensions/manifest.js +139 -0
- package/esm/extensions/resolve-install.js +70 -0
- package/esm/index.js +1 -1
- package/esm/migrate/clean.js +1 -2
- package/esm/packaging/package.js +8 -1
- package/esm/projects/deploy.js +36 -58
- package/extensions/compile.d.ts +35 -0
- package/extensions/compile.js +113 -0
- package/extensions/index.d.ts +4 -0
- package/extensions/index.js +20 -0
- package/extensions/manifest.d.ts +78 -0
- package/extensions/manifest.js +144 -0
- package/extensions/resolve-install.d.ts +20 -0
- package/extensions/resolve-install.js +74 -0
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/migrate/clean.js +1 -2
- package/package.json +10 -10
- package/packaging/package.d.ts +7 -1
- package/packaging/package.js +8 -1
- package/projects/deploy.js +36 -58
package/projects/deploy.js
CHANGED
|
@@ -42,16 +42,11 @@ const path = __importStar(require("path"));
|
|
|
42
42
|
const pg_cache_1 = require("pg-cache");
|
|
43
43
|
const materialize_1 = require("../apply/materialize");
|
|
44
44
|
const apply_spec_1 = require("../apply/apply-spec");
|
|
45
|
+
const deploy_bundled_1 = require("../bundle/deploy-bundled");
|
|
45
46
|
const pgpm_1 = require("../core/class/pgpm");
|
|
47
|
+
const extensions_1 = require("../extensions");
|
|
46
48
|
const client_1 = require("../migrate/client");
|
|
47
|
-
const package_1 = require("../packaging/package");
|
|
48
49
|
const deps_1 = require("../resolution/deps");
|
|
49
|
-
// Cache for fast deployment
|
|
50
|
-
const deployFastCache = {};
|
|
51
|
-
const getCacheKey = (pg, name, database) => {
|
|
52
|
-
const { host, port, user } = pg ?? {};
|
|
53
|
-
return `${host}:${port}:${user}:${database}:${name}`;
|
|
54
|
-
};
|
|
55
50
|
const log = new logger_1.Logger('deploy');
|
|
56
51
|
const deployProject = async (opts, name, database, pkg, toChange) => {
|
|
57
52
|
const mergedOpts = (0, env_1.getEnvOptions)(opts);
|
|
@@ -69,14 +64,28 @@ const deployProject = async (opts, name, database, pkg, toChange) => {
|
|
|
69
64
|
? (0, deps_1.resolveExtensionDependencies)(name, modules)
|
|
70
65
|
: new pgpm_1.PgpmPackage(modulePath, { extensionsDir: pkg.extensionsDir }).getModuleExtensions();
|
|
71
66
|
const pgPool = (0, pg_cache_1.getPgPool)({ ...opts.pg, database });
|
|
67
|
+
// Local modules (in resolve order) that may carry an `extensions.json`
|
|
68
|
+
// declaring how an external extension should be installed (schema + grants).
|
|
69
|
+
const localModules = extensions.resolved.filter((m) => !extensions.external.includes(m));
|
|
70
|
+
const roleMap = (0, extensions_1.roleMapFromRoles)(mergedOpts.db?.roles);
|
|
72
71
|
log.success(`đ Starting deployment to database ${database}...`);
|
|
73
72
|
for (const extension of extensions.resolved) {
|
|
74
73
|
try {
|
|
75
74
|
if (extensions.external.includes(extension)) {
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
const install = (0, extensions_1.findExtensionInstall)(extension, localModules, modules, pkg.workspacePath, { roleMap });
|
|
76
|
+
if (install) {
|
|
77
|
+
log.info(`đĨ Installing external extension (declarative): ${extension}`);
|
|
78
|
+
for (const stmt of install.deploy) {
|
|
79
|
+
log.debug(`> ${stmt}`);
|
|
80
|
+
await pgPool.query(stmt);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const msg = `CREATE EXTENSION IF NOT EXISTS "${extension}" CASCADE;`;
|
|
85
|
+
log.info(`đĨ Installing external extension: ${extension}`);
|
|
86
|
+
log.debug(`> ${msg}`);
|
|
87
|
+
await pgPool.query(msg);
|
|
88
|
+
}
|
|
80
89
|
}
|
|
81
90
|
else {
|
|
82
91
|
const sourcePath = (0, path_1.resolve)(pkg.workspacePath, modules[extension].path);
|
|
@@ -86,56 +95,25 @@ const deployProject = async (opts, name, database, pkg, toChange) => {
|
|
|
86
95
|
if (modulePath !== sourcePath) {
|
|
87
96
|
log.info(`đ Applying transpiled module (spec in ${sourcePath})`);
|
|
88
97
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
// The fast strategy is opt-in; everything else uses the per-change path.
|
|
99
|
+
if (mergedOpts.deployment.fast || mergedOpts.deployment.bundled) {
|
|
100
|
+
// Fast strategy: execute the module in one shot AND record the
|
|
101
|
+
// migration ledger, from the pre-built bundle artifact when one
|
|
102
|
+
// verifies and from `deploy/` otherwise. If the semantics cannot be
|
|
103
|
+
// honoured, fall through to the per-change migration path rather than
|
|
104
|
+
// deploying without a ledger.
|
|
105
|
+
const outcome = await (0, deploy_bundled_1.deployModuleFast)(modulePath, {
|
|
106
|
+
config: { ...mergedOpts.pg, database },
|
|
107
|
+
logOnly: mergedOpts.deployment.logOnly,
|
|
108
|
+
useTransaction: mergedOpts.deployment.useTx,
|
|
109
|
+
hashMethod: mergedOpts.deployment.hashMethod
|
|
110
|
+
});
|
|
111
|
+
if ((0, deploy_bundled_1.isBundledDeployResult)(outcome)) {
|
|
96
112
|
continue;
|
|
97
113
|
}
|
|
98
|
-
|
|
99
|
-
try {
|
|
100
|
-
modulePackage = await (0, package_1.packageModule)(localProject.modulePath, {
|
|
101
|
-
usePlan: mergedOpts.deployment.usePlan,
|
|
102
|
-
extension: false
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
catch (err) {
|
|
106
|
-
// Build comprehensive error message
|
|
107
|
-
const errorLines = [];
|
|
108
|
-
errorLines.push(`â Failed to package module "${extension}" at path: ${modulePath}`);
|
|
109
|
-
errorLines.push(` Module Path: ${modulePath}`);
|
|
110
|
-
errorLines.push(` Workspace Path: ${pkg.workspacePath}`);
|
|
111
|
-
errorLines.push(` Error Code: ${err.code || 'N/A'}`);
|
|
112
|
-
errorLines.push(` Error Message: ${err.message || 'Unknown error'}`);
|
|
113
|
-
// Provide debugging hints
|
|
114
|
-
if (err.code === 'ENOENT') {
|
|
115
|
-
errorLines.push('đĄ Hint: File or directory not found. Check if the module path is correct.');
|
|
116
|
-
}
|
|
117
|
-
else if (err.code === 'EACCES') {
|
|
118
|
-
errorLines.push('đĄ Hint: Permission denied. Check file permissions.');
|
|
119
|
-
}
|
|
120
|
-
else if (err.message && err.message.includes('pgpm.plan')) {
|
|
121
|
-
errorLines.push('đĄ Hint: pgpm.plan file issue. Check if the plan file exists and is valid.');
|
|
122
|
-
}
|
|
123
|
-
// Log the consolidated error message
|
|
124
|
-
log.error(errorLines.join('\n'));
|
|
125
|
-
console.error(err); // Preserve full stack trace
|
|
126
|
-
throw types_1.errors.DEPLOYMENT_FAILED({
|
|
127
|
-
type: 'Deployment',
|
|
128
|
-
module: extension
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
log.debug(`â Command: sqitch deploy db:pg:${database}`);
|
|
132
|
-
log.debug(`> ${modulePackage.sql}`);
|
|
133
|
-
await pgPool.query(modulePackage.sql);
|
|
134
|
-
if (mergedOpts.deployment.cache) {
|
|
135
|
-
deployFastCache[cacheKey] = modulePackage;
|
|
136
|
-
}
|
|
114
|
+
log.info(`âŠī¸ Fast deploy unavailable for ${extension} (${outcome}); using per-change path.`);
|
|
137
115
|
}
|
|
138
|
-
|
|
116
|
+
{
|
|
139
117
|
// Use new migration system
|
|
140
118
|
log.debug(`â Command: constructive migrate deploy db:pg:${database}`);
|
|
141
119
|
try {
|