@pgpmjs/core 7.13.0 → 7.15.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.
@@ -40,15 +40,12 @@ const types_1 = require("@pgpmjs/types");
40
40
  const path_1 = require("path");
41
41
  const path = __importStar(require("path"));
42
42
  const pg_cache_1 = require("pg-cache");
43
+ const materialize_1 = require("../apply/materialize");
44
+ const apply_spec_1 = require("../apply/apply-spec");
45
+ const deploy_bundled_1 = require("../bundle/deploy-bundled");
43
46
  const pgpm_1 = require("../core/class/pgpm");
44
47
  const client_1 = require("../migrate/client");
45
- const package_1 = require("../packaging/package");
46
- // Cache for fast deployment
47
- const deployFastCache = {};
48
- const getCacheKey = (pg, name, database) => {
49
- const { host, port, user } = pg ?? {};
50
- return `${host}:${port}:${user}:${database}:${name}`;
51
- };
48
+ const deps_1 = require("../resolution/deps");
52
49
  const log = new logger_1.Logger('deploy');
53
50
  const deployProject = async (opts, name, database, pkg, toChange) => {
54
51
  const mergedOpts = (0, env_1.getEnvOptions)(opts);
@@ -59,9 +56,12 @@ const deployProject = async (opts, name, database, pkg, toChange) => {
59
56
  throw types_1.errors.MODULE_NOT_FOUND({ name });
60
57
  }
61
58
  const modulePath = path.resolve(pkg.workspacePath, modules[name].path);
62
- const moduleProject = new pgpm_1.PgpmPackage(modulePath, { extensionsDir: pkg.extensionsDir });
63
59
  log.info(`đŸ“Ļ Resolving dependencies for ${name}...`);
64
- const extensions = moduleProject.getModuleExtensions();
60
+ // Proxy (apply-spec) modules have no pgpm.plan, so resolve straight off the
61
+ // workspace module map instead of instantiating a module-rooted package.
62
+ const extensions = (0, apply_spec_1.hasApplySpec)(modulePath)
63
+ ? (0, deps_1.resolveExtensionDependencies)(name, modules)
64
+ : new pgpm_1.PgpmPackage(modulePath, { extensionsDir: pkg.extensionsDir }).getModuleExtensions();
65
65
  const pgPool = (0, pg_cache_1.getPgPool)({ ...opts.pg, database });
66
66
  log.success(`🚀 Starting deployment to database ${database}...`);
67
67
  for (const extension of extensions.resolved) {
@@ -73,59 +73,32 @@ const deployProject = async (opts, name, database, pkg, toChange) => {
73
73
  await pgPool.query(msg);
74
74
  }
75
75
  else {
76
- const modulePath = (0, path_1.resolve)(pkg.workspacePath, modules[extension].path);
76
+ const sourcePath = (0, path_1.resolve)(pkg.workspacePath, modules[extension].path);
77
+ const modulePath = await (0, materialize_1.resolveEffectiveModulePath)(extension, sourcePath, modules, pkg.workspacePath);
77
78
  log.info(`📂 Deploying local module: ${extension}`);
78
79
  log.debug(`→ Path: ${modulePath}`);
79
- if (mergedOpts.deployment.fast) {
80
- // Use fast deployment strategy
81
- const localProject = new pgpm_1.PgpmPackage(modulePath, { extensionsDir: pkg.extensionsDir });
82
- const cacheKey = getCacheKey(mergedOpts.pg, extension, database);
83
- if (mergedOpts.deployment.cache && deployFastCache[cacheKey]) {
84
- log.warn(`⚡ Using cached package for ${extension}.`);
85
- await pgPool.query(deployFastCache[cacheKey].sql);
80
+ if (modulePath !== sourcePath) {
81
+ log.info(`🔁 Applying transpiled module (spec in ${sourcePath})`);
82
+ }
83
+ // The fast strategy is opt-in; everything else uses the per-change path.
84
+ if (mergedOpts.deployment.fast || mergedOpts.deployment.bundled) {
85
+ // Fast strategy: execute the module in one shot AND record the
86
+ // migration ledger, from the pre-built bundle artifact when one
87
+ // verifies and from `deploy/` otherwise. If the semantics cannot be
88
+ // honoured, fall through to the per-change migration path rather than
89
+ // deploying without a ledger.
90
+ const outcome = await (0, deploy_bundled_1.deployModuleFast)(modulePath, {
91
+ config: { ...mergedOpts.pg, database },
92
+ logOnly: mergedOpts.deployment.logOnly,
93
+ useTransaction: mergedOpts.deployment.useTx,
94
+ hashMethod: mergedOpts.deployment.hashMethod
95
+ });
96
+ if ((0, deploy_bundled_1.isBundledDeployResult)(outcome)) {
86
97
  continue;
87
98
  }
88
- let modulePackage;
89
- try {
90
- modulePackage = await (0, package_1.packageModule)(localProject.modulePath, {
91
- usePlan: mergedOpts.deployment.usePlan,
92
- extension: false
93
- });
94
- }
95
- catch (err) {
96
- // Build comprehensive error message
97
- const errorLines = [];
98
- errorLines.push(`❌ Failed to package module "${extension}" at path: ${modulePath}`);
99
- errorLines.push(` Module Path: ${modulePath}`);
100
- errorLines.push(` Workspace Path: ${pkg.workspacePath}`);
101
- errorLines.push(` Error Code: ${err.code || 'N/A'}`);
102
- errorLines.push(` Error Message: ${err.message || 'Unknown error'}`);
103
- // Provide debugging hints
104
- if (err.code === 'ENOENT') {
105
- errorLines.push('💡 Hint: File or directory not found. Check if the module path is correct.');
106
- }
107
- else if (err.code === 'EACCES') {
108
- errorLines.push('💡 Hint: Permission denied. Check file permissions.');
109
- }
110
- else if (err.message && err.message.includes('pgpm.plan')) {
111
- errorLines.push('💡 Hint: pgpm.plan file issue. Check if the plan file exists and is valid.');
112
- }
113
- // Log the consolidated error message
114
- log.error(errorLines.join('\n'));
115
- console.error(err); // Preserve full stack trace
116
- throw types_1.errors.DEPLOYMENT_FAILED({
117
- type: 'Deployment',
118
- module: extension
119
- });
120
- }
121
- log.debug(`→ Command: sqitch deploy db:pg:${database}`);
122
- log.debug(`> ${modulePackage.sql}`);
123
- await pgPool.query(modulePackage.sql);
124
- if (mergedOpts.deployment.cache) {
125
- deployFastCache[cacheKey] = modulePackage;
126
- }
99
+ log.info(`â†Šī¸ Fast deploy unavailable for ${extension} (${outcome}); using per-change path.`);
127
100
  }
128
- else {
101
+ {
129
102
  // Use new migration system
130
103
  log.debug(`→ Command: constructive migrate deploy db:pg:${database}`);
131
104
  try {
@@ -39,8 +39,11 @@ const types_1 = require("@pgpmjs/types");
39
39
  const path_1 = require("path");
40
40
  const path = __importStar(require("path"));
41
41
  const pg_cache_1 = require("pg-cache");
42
+ const materialize_1 = require("../apply/materialize");
43
+ const apply_spec_1 = require("../apply/apply-spec");
42
44
  const pgpm_1 = require("../core/class/pgpm");
43
45
  const client_1 = require("../migrate/client");
46
+ const deps_1 = require("../resolution/deps");
44
47
  const log = new logger_1.Logger('revert');
45
48
  const revertProject = async (opts, name, database, pkg, options) => {
46
49
  log.info(`🔍 Gathering modules from ${pkg.workspacePath}...`);
@@ -50,9 +53,12 @@ const revertProject = async (opts, name, database, pkg, options) => {
50
53
  throw types_1.errors.MODULE_NOT_FOUND({ name });
51
54
  }
52
55
  const modulePath = path.resolve(pkg.workspacePath, modules[name].path);
53
- const moduleProject = new pgpm_1.PgpmPackage(modulePath, { extensionsDir: pkg.extensionsDir });
54
56
  log.info(`đŸ“Ļ Resolving dependencies for ${name}...`);
55
- const extensions = moduleProject.getModuleExtensions();
57
+ // Proxy (apply-spec) modules have no pgpm.plan, so resolve straight off the
58
+ // workspace module map instead of instantiating a module-rooted package.
59
+ const extensions = (0, apply_spec_1.hasApplySpec)(modulePath)
60
+ ? (0, deps_1.resolveExtensionDependencies)(name, modules)
61
+ : new pgpm_1.PgpmPackage(modulePath, { extensionsDir: pkg.extensionsDir }).getModuleExtensions();
56
62
  const pgPool = (0, pg_cache_1.getPgPool)({
57
63
  ...opts.pg,
58
64
  database
@@ -78,7 +84,8 @@ const revertProject = async (opts, name, database, pkg, options) => {
78
84
  }
79
85
  }
80
86
  else {
81
- const modulePath = (0, path_1.resolve)(pkg.workspacePath, modules[extension].path);
87
+ const sourcePath = (0, path_1.resolve)(pkg.workspacePath, modules[extension].path);
88
+ const modulePath = await (0, materialize_1.resolveEffectiveModulePath)(extension, sourcePath, modules, pkg.workspacePath);
82
89
  log.info(`📂 Reverting local module: ${extension}`);
83
90
  log.debug(`→ Path: ${modulePath}`);
84
91
  // Use new migration system
@@ -39,8 +39,11 @@ const types_1 = require("@pgpmjs/types");
39
39
  const path_1 = require("path");
40
40
  const path = __importStar(require("path"));
41
41
  const pg_cache_1 = require("pg-cache");
42
+ const materialize_1 = require("../apply/materialize");
43
+ const apply_spec_1 = require("../apply/apply-spec");
42
44
  const pgpm_1 = require("../core/class/pgpm");
43
45
  const client_1 = require("../migrate/client");
46
+ const deps_1 = require("../resolution/deps");
44
47
  const log = new logger_1.Logger('verify');
45
48
  const verifyProject = async (opts, name, database, pkg, options) => {
46
49
  log.info(`🔍 Gathering modules from ${pkg.workspacePath}...`);
@@ -50,9 +53,12 @@ const verifyProject = async (opts, name, database, pkg, options) => {
50
53
  throw types_1.errors.MODULE_NOT_FOUND({ name });
51
54
  }
52
55
  const modulePath = path.resolve(pkg.workspacePath, modules[name].path);
53
- const moduleProject = new pgpm_1.PgpmPackage(modulePath, { extensionsDir: pkg.extensionsDir });
54
56
  log.info(`đŸ“Ļ Resolving dependencies for ${name}...`);
55
- const extensions = moduleProject.getModuleExtensions();
57
+ // Proxy (apply-spec) modules have no pgpm.plan, so resolve straight off the
58
+ // workspace module map instead of instantiating a module-rooted package.
59
+ const extensions = (0, apply_spec_1.hasApplySpec)(modulePath)
60
+ ? (0, deps_1.resolveExtensionDependencies)(name, modules)
61
+ : new pgpm_1.PgpmPackage(modulePath, { extensionsDir: pkg.extensionsDir }).getModuleExtensions();
56
62
  const pgPool = (0, pg_cache_1.getPgPool)({
57
63
  ...opts.pg,
58
64
  database
@@ -67,7 +73,8 @@ const verifyProject = async (opts, name, database, pkg, options) => {
67
73
  await pgPool.query(query, [extension]);
68
74
  }
69
75
  else {
70
- const modulePath = (0, path_1.resolve)(pkg.workspacePath, modules[extension].path);
76
+ const sourcePath = (0, path_1.resolve)(pkg.workspacePath, modules[extension].path);
77
+ const modulePath = await (0, materialize_1.resolveEffectiveModulePath)(extension, sourcePath, modules, pkg.workspacePath);
71
78
  log.info(`📂 Verifying local module: ${extension}`);
72
79
  log.debug(`→ Path: ${modulePath}`);
73
80
  log.debug(`→ Command: constructive migrate verify db:pg:${database}`);