@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.
Files changed (45) hide show
  1. package/apply/apply-spec.js +84 -9
  2. package/apply/index.d.ts +1 -0
  3. package/apply/index.js +1 -0
  4. package/apply/materialize.js +15 -2
  5. package/apply/reuse.d.ts +52 -0
  6. package/apply/reuse.js +226 -0
  7. package/apply/types.d.ts +89 -0
  8. package/bundle/artifact.d.ts +35 -0
  9. package/bundle/artifact.js +96 -0
  10. package/bundle/deploy-bundled.d.ts +71 -0
  11. package/bundle/deploy-bundled.js +177 -0
  12. package/bundle/index.d.ts +2 -0
  13. package/bundle/index.js +4 -0
  14. package/core/class/pgpm.js +54 -57
  15. package/esm/apply/apply-spec.js +84 -9
  16. package/esm/apply/index.js +1 -0
  17. package/esm/apply/materialize.js +15 -2
  18. package/esm/apply/reuse.js +221 -0
  19. package/esm/bundle/artifact.js +89 -0
  20. package/esm/bundle/deploy-bundled.js +170 -0
  21. package/esm/bundle/index.js +4 -0
  22. package/esm/core/class/pgpm.js +54 -57
  23. package/esm/extensions/compile.js +109 -0
  24. package/esm/extensions/index.js +4 -0
  25. package/esm/extensions/manifest.js +139 -0
  26. package/esm/extensions/resolve-install.js +70 -0
  27. package/esm/index.js +1 -1
  28. package/esm/migrate/clean.js +1 -2
  29. package/esm/packaging/package.js +8 -1
  30. package/esm/projects/deploy.js +36 -58
  31. package/extensions/compile.d.ts +35 -0
  32. package/extensions/compile.js +113 -0
  33. package/extensions/index.d.ts +4 -0
  34. package/extensions/index.js +20 -0
  35. package/extensions/manifest.d.ts +78 -0
  36. package/extensions/manifest.js +144 -0
  37. package/extensions/resolve-install.d.ts +20 -0
  38. package/extensions/resolve-install.js +74 -0
  39. package/index.d.ts +1 -1
  40. package/index.js +1 -1
  41. package/migrate/clean.js +1 -2
  42. package/package.json +10 -10
  43. package/packaging/package.d.ts +7 -1
  44. package/packaging/package.js +8 -1
  45. package/projects/deploy.js +36 -58
@@ -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 msg = `CREATE EXTENSION IF NOT EXISTS "${extension}" CASCADE;`;
77
- log.info(`đŸ“Ĩ Installing external extension: ${extension}`);
78
- log.debug(`> ${msg}`);
79
- await pgPool.query(msg);
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
- if (mergedOpts.deployment.fast) {
90
- // Use fast deployment strategy
91
- const localProject = new pgpm_1.PgpmPackage(modulePath, { extensionsDir: pkg.extensionsDir });
92
- const cacheKey = getCacheKey(mergedOpts.pg, extension, database);
93
- if (mergedOpts.deployment.cache && deployFastCache[cacheKey]) {
94
- log.warn(`⚡ Using cached package for ${extension}.`);
95
- await pgPool.query(deployFastCache[cacheKey].sql);
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
- let modulePackage;
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
- else {
116
+ {
139
117
  // Use new migration system
140
118
  log.debug(`→ Command: constructive migrate deploy db:pg:${database}`);
141
119
  try {