grada-run 0.43.2 → 0.45.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/bin/cli.js CHANGED
@@ -131,7 +131,7 @@ function runCommand(promise) {
131
131
  // Help wins over every subcommand: no flow — destructive or otherwise —
132
132
  // may execute from a help invocation. `db` keeps its own usage path
133
133
  // inside runDb (db usage for `db --help` and every `db <leaf> --help`,
134
- // exit 0; bare `db` still reports its missing subcommand).
134
+ // exit 0; bare `db` prints usage the same untracked way).
135
135
  const wantsHelp = positionalArgs[0] === 'help' || rawArgs.includes('--help') || rawArgs.includes('-h');
136
136
  // Version wins over every subcommand like help does — but unlike help it
137
137
  // needs no `db` exemption: the version is global, identical everywhere.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grada-run",
3
- "version": "0.43.2",
3
+ "version": "0.45.0",
4
4
  "description": "Provision production-ready AWS infrastructure and CI/CD pipelines in seconds.",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -15,6 +15,12 @@ export const DEFAULT_BACKUP_POLL_INTERVAL_MS = 5000;
15
15
 
16
16
  const SNAPSHOT_NOT_FOUND_NAMES = new Set(['DBSnapshotNotFound', 'DBSnapshotNotFoundFault']);
17
17
  const CLUSTER_SNAPSHOT_NOT_FOUND_NAMES = new Set(['DBClusterSnapshotNotFound', 'DBClusterSnapshotNotFoundFault']);
18
+ const SNAPSHOT_ALREADY_EXISTS_NAMES = new Set([
19
+ 'DBSnapshotAlreadyExists',
20
+ 'DBSnapshotAlreadyExistsFault',
21
+ 'DBClusterSnapshotAlreadyExists',
22
+ 'DBClusterSnapshotAlreadyExistsFault',
23
+ ]);
18
24
  // Snapshot states that never become available: polling past them only
19
25
  // wastes the timeout and misreports.
20
26
  const TERMINAL_SNAPSHOT_STATUSES = new Set(['failed', 'deleted', 'deleting']);
@@ -142,25 +148,43 @@ async function runDbBackupMain(input = {}) {
142
148
  { Key: 'ManagedBy', Value: 'grada' },
143
149
  { Key: 'Project', Value: projectName },
144
150
  ];
145
- if (isCluster) {
146
- await rdsClient.send(new CreateDBClusterSnapshotCommand({
147
- DBClusterIdentifier: target.id,
148
- DBClusterSnapshotIdentifier: snapshotId,
149
- Tags: snapshotTags,
150
- }));
151
- } else {
152
- await rdsClient.send(new CreateDBSnapshotCommand({
153
- DBInstanceIdentifier: target.id,
154
- DBSnapshotIdentifier: snapshotId,
155
- Tags: snapshotTags,
156
- }));
151
+ // An existing id is success, not failure: CI retries and re-runs of
152
+ // the same migration must not fail just because the snapshot step
153
+ // already ran. The wait below then resolves its actual state
154
+ // (available, still creating, or failed) the same as a fresh create.
155
+ let reusedExisting = false;
156
+ try {
157
+ if (isCluster) {
158
+ await rdsClient.send(new CreateDBClusterSnapshotCommand({
159
+ DBClusterIdentifier: target.id,
160
+ DBClusterSnapshotIdentifier: snapshotId,
161
+ Tags: snapshotTags,
162
+ }));
163
+ } else {
164
+ await rdsClient.send(new CreateDBSnapshotCommand({
165
+ DBInstanceIdentifier: target.id,
166
+ DBSnapshotIdentifier: snapshotId,
167
+ Tags: snapshotTags,
168
+ }));
169
+ }
170
+ } catch (error) {
171
+ if (error && SNAPSHOT_ALREADY_EXISTS_NAMES.has(error.name)) {
172
+ reusedExisting = true;
173
+ } else {
174
+ throw error;
175
+ }
157
176
  }
158
177
 
159
178
  if (noWait) {
160
- s.stop(color.green('Snapshot creation started.'));
161
- console.log(`\n Snapshot ${color.cyan(snapshotId)} is being created (status: creating).`);
179
+ if (reusedExisting) {
180
+ s.stop(color.green('Snapshot already exists.'));
181
+ console.log(`\n Snapshot ${color.cyan(snapshotId)} already exists — reusing it.`);
182
+ } else {
183
+ s.stop(color.green('Snapshot creation started.'));
184
+ console.log(`\n Snapshot ${color.cyan(snapshotId)} is being created (status: creating).`);
185
+ }
162
186
  console.log(color.dim(` Restore it later with: npx grada-run db restore ${snapshotId}\n`));
163
- await trackSuccess('db_backup_run', { projectName, waited: false, db_kind: target.kind });
187
+ await trackSuccess('db_backup_run', { projectName, waited: false, db_kind: target.kind, reused_existing: reusedExisting });
164
188
  outro(color.green('Done.'));
165
189
  return { ok: true, snapshotId, status: 'creating' };
166
190
  }
@@ -243,7 +267,7 @@ async function runDbBackupMain(input = {}) {
243
267
  s.stop(color.green('Snapshot available.'));
244
268
  console.log(`\n Snapshot ${color.cyan(snapshotId)} is ready.`);
245
269
  console.log(color.dim(` Restore it with: npx grada-run db restore ${snapshotId}\n`));
246
- await trackSuccess('db_backup_run', { projectName, waited: true, db_kind: target.kind });
270
+ await trackSuccess('db_backup_run', { projectName, waited: true, db_kind: target.kind, reused_existing: reusedExisting });
247
271
  outro(color.green('Done.'));
248
272
  return { ok: true, snapshotId, status: 'available' };
249
273
  } catch (error) {
@@ -18,7 +18,7 @@ import {
18
18
  readFileSafe,
19
19
  readTerraformComputeTarget,
20
20
  } from '../../utils/resolvers.js';
21
- import { detectMigrationCommand, isNpmShimCommand, dockerfileStripsNpmShims } from '../../utils/detector.js';
21
+ import { detectMigrationCommand, isNpmShimCommand, dockerfileStripsNpmShims, ormMappedHintSegment } from '../../utils/detector.js';
22
22
  import { resolveContainer } from '../../utils/ecs.js';
23
23
  import { runEphemeralEcsTask } from '../../utils/ecs-runner.js';
24
24
  import { parseTimeoutSeconds } from '../../utils/system.js';
@@ -86,7 +86,7 @@ export function quoteShellArg(value) {
86
86
  return `'${String(value).replace(/'/g, `'\\''`)}'`;
87
87
  }
88
88
 
89
- function renderGateBlock({ includeSetupNode, stepName, runLine }) {
89
+ function renderGateBlock({ includeSetupNode, steps }) {
90
90
  const lines = [` ${GATE_START_MARKER}`];
91
91
  if (includeSetupNode) {
92
92
  lines.push(
@@ -97,16 +97,18 @@ function renderGateBlock({ includeSetupNode, stepName, runLine }) {
97
97
  ''
98
98
  );
99
99
  }
100
- lines.push(
101
- ` - name: ${stepName}`,
102
- // Gates run AWS calls: honor the credential-skip outcome like
103
- // every other post-assume step (BUG-138). Neutral on deploy
104
- // (a failed assume fails the run before any gate runs).
105
- ` if: steps.aws-creds.outcome == 'success'`,
106
- ' run: |',
107
- ` ${runLine}`,
108
- ` ${GATE_END_MARKER}`
109
- );
100
+ for (const { stepName, runLine } of steps) {
101
+ lines.push(
102
+ ` - name: ${stepName}`,
103
+ // Gates run AWS calls: honor the credential-skip outcome like
104
+ // every other post-assume step (BUG-138). Neutral on deploy
105
+ // (a failed assume fails the run before any gate runs).
106
+ ` if: steps.aws-creds.outcome == 'success'`,
107
+ ' run: |',
108
+ ` ${runLine}`
109
+ );
110
+ }
111
+ lines.push(` ${GATE_END_MARKER}`);
110
112
  return `${lines.join('\n')}\n`;
111
113
  }
112
114
 
@@ -132,10 +134,10 @@ export function buildRunnerInvocation(cliVersion) {
132
134
 
133
135
  // Shared injection core: strips any previous gate, renders the block, and
134
136
  // splices it before the anchor step. Returns null without the anchor.
135
- function injectGateBlock(content, { runLine, stepName, anchor }) {
137
+ function injectGateBlock(content, { steps, anchor }) {
136
138
  const base = stripPreviousGateBlock(String(content ?? ''));
137
139
  const includeSetupNode = !base.includes('actions/setup-node');
138
- const block = renderGateBlock({ includeSetupNode, stepName, runLine });
140
+ const block = renderGateBlock({ includeSetupNode, steps });
139
141
  const anchorIdx = base.indexOf(anchor);
140
142
  if (anchorIdx === -1) return null;
141
143
  const insertAt = base.lastIndexOf('\n', anchorIdx) + 1;
@@ -147,9 +149,18 @@ function injectGateBlock(content, { runLine, stepName, anchor }) {
147
149
  // anchor step is present. Pure and unit-tested.
148
150
  export function injectMigrationGate(workflowContent, { cmd, cliVersion } = {}) {
149
151
  const taskDefRef = '${{ steps.register-task-def.outputs.task-arn }}';
152
+ const runner = buildRunnerInvocation(cliVersion);
150
153
  return injectGateBlock(workflowContent, {
151
- stepName: 'Pre-Deploy Database Migration',
152
- runLine: `${buildRunnerInvocation(cliVersion)} db migrate --cmd ${quoteShellArg(cmd)} --task-def "${taskDefRef}" --headless`,
154
+ steps: [
155
+ {
156
+ stepName: 'Take pre-migration database snapshot',
157
+ runLine: `${runner} db backup --id "pre-deploy-\${{ github.sha }}" --headless`,
158
+ },
159
+ {
160
+ stepName: 'Pre-Deploy Database Migration',
161
+ runLine: `${runner} db migrate --cmd ${quoteShellArg(cmd)} --task-def "${taskDefRef}" --headless`,
162
+ },
163
+ ],
153
164
  anchor: '- name: Force ECS deployment',
154
165
  });
155
166
  }
@@ -160,8 +171,12 @@ export function injectMigrationGate(workflowContent, { cmd, cliVersion } = {}) {
160
171
  // service itself via --workspace. Returns null without the anchor.
161
172
  export function injectPreviewMigrationGate(workflowContent, { cmd, cliVersion } = {}) {
162
173
  return injectGateBlock(workflowContent, {
163
- stepName: 'Preview Database Migration',
164
- runLine: `${buildRunnerInvocation(cliVersion)} db migrate --cmd ${quoteShellArg(cmd)} --workspace "\${{ env.WORKSPACE }}" --headless`,
174
+ steps: [
175
+ {
176
+ stepName: 'Preview Database Migration',
177
+ runLine: `${buildRunnerInvocation(cliVersion)} db migrate --cmd ${quoteShellArg(cmd)} --workspace "\${{ env.WORKSPACE }}" --headless`,
178
+ },
179
+ ],
165
180
  anchor: '- name: Comment PR',
166
181
  });
167
182
  }
@@ -336,10 +351,11 @@ async function runDbMigrateMain(input = {}) {
336
351
  // headless; warn loudly (and proceed) interactively. Fail-open when
337
352
  // no Dockerfile is present — nothing to prove breakage against.
338
353
  if (isNpmShimCommand(resolvedCmd) && dockerfileStripsNpmShims(readFileSafe(path.join(cwd, 'Dockerfile')))) {
354
+ const ormHint = ormMappedHintSegment(cwd, '--cmd ');
339
355
  if (headless) {
340
356
  return failCommand({
341
357
  message: `\n✖ Refusing to run "${resolvedCmd}": your Dockerfile strips npm/npx from the runner image, so this command would fail with "command not found" inside the task.\n`,
342
- hint: ' Bundle a framework-compiled runner instead and re-run with an explicit node-based command, e.g. --cmd "node ./dist/migrate.cjs". Ensure your Dockerfile builds the bundle and copies it into the runner image.\n',
358
+ hint: ` Bundle a framework-compiled runner instead and re-run with an explicit node-based command, e.g. --cmd "node ./dist/migrate.cjs". Ensure your Dockerfile builds the bundle and copies it into the runner image${ormHint}.\n`,
343
359
  event: 'db_migrate_run',
344
360
  telemetry: { projectName, cmd_source: cmdSource, ci_setup: setupCi, error_code: 'NPM_CMD_STRIPPED_RUNNER' },
345
361
  errorCode: 'NPM_CMD_STRIPPED_RUNNER',
@@ -347,7 +363,7 @@ async function runDbMigrateMain(input = {}) {
347
363
  resultExtra: { cluster, service, region },
348
364
  });
349
365
  }
350
- console.log(color.yellow(`⚠️ "${resolvedCmd}" starts with npm/npx but your Dockerfile strips those binaries from the runner image — this will fail with "command not found" unless you switch to a node-based command (e.g. "node ./dist/migrate.cjs"). Ensure your Dockerfile builds the bundle and copies it into the runner image.`));
366
+ console.log(color.yellow(`⚠️ "${resolvedCmd}" starts with npm/npx but your Dockerfile strips those binaries from the runner image — this will fail with "command not found" unless you switch to a node-based command (e.g. "node ./dist/migrate.cjs"). Ensure your Dockerfile builds the bundle and copies it into the runner image.${ormHint}`));
351
367
  trackEvent('npm_cmd_stripped_runner', { projectName, cmd_source: cmdSource, ci_setup: setupCi });
352
368
  }
353
369
 
@@ -397,7 +413,7 @@ async function runDbMigrateMain(input = {}) {
397
413
  }
398
414
  await atomicWriteFile(workflowFile, updated, 'utf8');
399
415
  console.log(color.green('\n✅ Pre-deploy migration gate installed in .github/workflows/deploy.yml.'));
400
- console.log(color.dim(' Migrations now run against the new image revision before the ECS service updates.\n'));
416
+ console.log(color.dim(' Each deploy now snapshots the database, then runs migrations against the new image revision before the ECS service updates.\n'));
401
417
  if (readTerraformComputeTarget(cwd) === 'ecs') {
402
418
  const previewFile = path.join(cwd, '.github', 'workflows', 'preview.yml');
403
419
  let previewContent = null;
@@ -114,13 +114,20 @@ async function runDbMain(argv = [], extraOptions = {}) {
114
114
  return runDbImport({ ...parseDbImportArgs(argv), ...extra });
115
115
  }
116
116
 
117
+ if (subcommand === undefined) {
118
+ // Bare invocation is help-seeking, not an error: usage + exit
119
+ // 0, untracked like --help (keeps probe noise out of error
120
+ // telemetry).
121
+ console.log(color.yellow('\n⚠ Missing db subcommand.'));
122
+ console.log('');
123
+ printDbUsage();
124
+ console.log('');
125
+ return { ok: true };
126
+ }
127
+
117
128
  return failCommand({
118
129
  print: () => {
119
- if (subcommand === undefined) {
120
- console.log(color.yellow('\n⚠ Missing db subcommand.'));
121
- } else {
122
- console.log(color.red(`\n✖ Unknown db subcommand "${subcommand}".`));
123
- }
130
+ console.log(color.red(`\n✖ Unknown db subcommand "${subcommand}".`));
124
131
  console.log('');
125
132
  printDbUsage();
126
133
  console.log('');
@@ -386,24 +386,28 @@ async function runDomainMain(input = {}) {
386
386
  intro(color.bgCyan(color.black(' grada domain 🌐 ')));
387
387
 
388
388
  if (!DOMAIN_SUBCOMMANDS.includes(subcommand)) {
389
- // Closed enum only — never echo the raw user token into telemetry.
390
- const telemetrySubcommand = typeof options.subcommand === 'string' && options.subcommand.trim() !== ''
391
- ? 'unknown'
392
- : 'none';
389
+ // Blank input trims to '' rather than undefined — same missing
390
+ // case the old 'none' telemetry bucket covered.
391
+ if (subcommand === undefined || subcommand === '') {
392
+ // Bare invocation is help-seeking, not an error: usage + exit
393
+ // 0, untracked like --help (keeps probe noise out of error
394
+ // telemetry).
395
+ console.log(color.yellow('\n⚠ Missing domain subcommand.'));
396
+ console.log('');
397
+ printDomainUsage();
398
+ console.log('');
399
+ return { ok: true };
400
+ }
393
401
  return failCommand({
394
402
  noExit,
395
403
  print: () => {
396
- if (subcommand === undefined) {
397
- console.log(color.yellow('\n⚠ Missing domain subcommand.'));
398
- } else {
399
- console.log(color.red(`\n✖ Unknown domain subcommand "${options.subcommand}".`));
400
- }
404
+ console.log(color.red(`\n✖ Unknown domain subcommand "${options.subcommand}".`));
401
405
  console.log('');
402
406
  printDomainUsage();
403
407
  console.log('');
404
408
  },
405
409
  event: 'domain_run',
406
- telemetry: { subcommand: telemetrySubcommand },
410
+ telemetry: { subcommand: 'unknown' },
407
411
  errorCode: 'UNKNOWN_DOMAIN_SUBCOMMAND',
408
412
  reason: 'unknown-domain-subcommand',
409
413
  });
@@ -18,6 +18,8 @@ import {
18
18
  frameworkDefaultPort,
19
19
  frameworkUsesStrippedRunner,
20
20
  isNpmShimCommand,
21
+ detectOrmMigrationCommand,
22
+ ormMappedHintSegment,
21
23
  SUPPORTED_FRAMEWORKS
22
24
  } from '../utils/detector.js';
23
25
  import { detectProjectCapabilities } from '../utils/capabilities.js';
@@ -577,17 +579,18 @@ async function mainStackMain(input = {}) {
577
579
  // gate would fail 100% of deploys. Fail fast headless (re-run with an
578
580
  // explicit node command); warn loudly interactively and continue.
579
581
  if (migrationGateEnabled && isNpmShimCommand(migrationCmd) && target === 'ecs' && frameworkUsesStrippedRunner(config.framework)) {
582
+ const ormHint = ormMappedHintSegment(dirConfig.targetDir, '--setup-ci-migrate=');
580
583
  if (!isInteractive) {
581
584
  return failCommand({
582
585
  message: `\n✖ Refusing to wire the pre-deploy migration gate with "${migrationCmd}": the generated ${config.framework} Dockerfile strips npm/npx from the runner image, so this command would fail with "command not found" on every deploy.\n`,
583
- hint: ' Re-run with an explicit node-based command, e.g. `--setup-ci-migrate="node ./dist/migrate.cjs"`, or wire the gate later with `grada db migrate --cmd "node ./dist/migrate.cjs" --setup-ci`. Ensure your Dockerfile builds the bundle and copies it into the runner image.\n',
586
+ hint: ` Re-run with an explicit node-based command, e.g. \`--setup-ci-migrate="node ./dist/migrate.cjs"\`, or wire the gate later with \`grada db migrate --cmd "node ./dist/migrate.cjs" --setup-ci\`. Ensure your Dockerfile builds the bundle and copies it into the runner image${ormHint}.\n`,
584
587
  event: 'cli-error',
585
588
  telemetry: { step: 'init_setup', cmd_source: migrationCmdSource, error_code: 'NPM_CMD_STRIPPED_RUNNER' },
586
589
  errorCode: 'NPM_CMD_STRIPPED_RUNNER',
587
590
  reason: 'npm-cmd-stripped-runner',
588
591
  });
589
592
  }
590
- console.log(color.yellow(`⚠️ The ${migrationCmdSource} migration command ("${migrationCmd}") starts with npm/npx but the generated ${config.framework} Dockerfile strips those binaries from the runner image — the gate will fail unless you switch to a node-based command (e.g. "node ./dist/migrate.cjs"). Ensure your Dockerfile builds the bundle and copies it into the runner image.`));
593
+ console.log(color.yellow(`⚠️ The ${migrationCmdSource} migration command ("${migrationCmd}") starts with npm/npx but the generated ${config.framework} Dockerfile strips those binaries from the runner image — the gate will fail unless you switch to a node-based command (e.g. "node ./dist/migrate.cjs"). Ensure your Dockerfile builds the bundle and copies it into the runner image.${ormHint}`));
591
594
  trackEvent('npm_cmd_stripped_runner', { projectName: dirConfig.actualProjectName, cmd_source: migrationCmdSource, ci_setup: true });
592
595
  }
593
596
 
@@ -900,7 +903,7 @@ async function mainStackMain(input = {}) {
900
903
  const gated = workflowContent ? injectMigrationGate(workflowContent, { cmd: migrationCmd, cliVersion: CLI_VERSION }) : null;
901
904
  if (gated) {
902
905
  atomicWriteFileSync(deployYmlPath, gated);
903
- console.log(color.green('✅ Wired the pre-deploy database migration gate into .github/workflows/deploy.yml'));
906
+ console.log(color.green('✅ Wired the pre-deploy database migration gate into .github/workflows/deploy.yml (snapshot first, then migrate)'));
904
907
  } else {
905
908
  log.warn(color.yellow('⚠️ Could not wire the migration gate: the deploy workflow anchor was not found.'));
906
909
  }
@@ -1097,6 +1100,19 @@ async function mainStackMain(input = {}) {
1097
1100
  }
1098
1101
  }
1099
1102
 
1103
+ // ORM runner matrix: when the gate was auto-wired to a mapped ORM
1104
+ // command, say which one and what the user must guarantee (the
1105
+ // bundle path / production dependency), while the run is fresh.
1106
+ if (migrationGateEnabled && migrationCmdSource === 'detected') {
1107
+ const ormMapped = detectOrmMigrationCommand(dirConfig.targetDir);
1108
+ if (ormMapped && ormMapped.command === migrationCmd) {
1109
+ const ormWarning = ormMapped.orm === 'drizzle'
1110
+ ? 'Detected Drizzle ORM. Configured migration gate to use \'node ./dist/migrate.cjs\'. Ensure your build script bundles your migrator to this path.'
1111
+ : 'Detected Prisma. Configured migration gate to run via \'node_modules/prisma/build/index.js\'. Ensure Prisma is in your production dependencies.';
1112
+ log.warn(color.yellow(`⚠️ ${ormWarning}`));
1113
+ }
1114
+ }
1115
+
1100
1116
  const isGitInitialized = fsSync.existsSync(path.join(dirConfig.targetDir, '.git'));
1101
1117
  const needsCd = dirConfig.projectName && dirConfig.projectName !== '.';
1102
1118
  const applyStep = needsCd ? `cd ${dirConfig.projectName} && npx --yes grada-run apply` : 'npx --yes grada-run apply';
@@ -303,6 +303,60 @@ export function analyzeAstroConfig(targetDir) {
303
303
  // framework markers. Pure: reads files under `cwd`, never throws (malformed
304
304
  // or unreadable files fall through to the next marker). Returns the shell
305
305
  // command string or null when nothing matches.
306
+ // ORM runner matrix (npx-trap fix): stripped runners have no npm/npx,
307
+ // so marker-detected ORMs map to compiled node commands instead of
308
+ // task-guaranteed-to-fail shims. Returns { command, orm } or null.
309
+ // - Drizzle (dep or config): the prescribed bundle path. The file may
310
+ // not exist until the user builds — callers warn about that.
311
+ // - Prisma v6/v7 (schema or dep): the direct CLI entry. v8 moved the
312
+ // entry (dist/prisma.js) and other majors are unverified, so only
313
+ // 6/7 map; anything else falls through to the npx form (which the
314
+ // stripped-runner guard refuses with a hint).
315
+ export function detectOrmMigrationCommand(cwd = process.cwd()) {
316
+ const readJson = (file) => {
317
+ try {
318
+ return JSON.parse(fsSync.readFileSync(path.join(cwd, file), 'utf-8'));
319
+ } catch {
320
+ return null;
321
+ }
322
+ };
323
+ const exists = (file) => {
324
+ try {
325
+ return fsSync.existsSync(path.join(cwd, file));
326
+ } catch {
327
+ return false;
328
+ }
329
+ };
330
+ const pkg = readJson('package.json');
331
+ const deps = pkg && typeof pkg === 'object'
332
+ ? { ...(pkg.dependencies || {}), ...(pkg.devDependencies || {}) }
333
+ : {};
334
+ if (deps['drizzle-kit'] || deps['drizzle-orm']
335
+ || exists('drizzle.config.ts') || exists('drizzle.config.js') || exists('drizzle.config.mjs')) {
336
+ return { command: 'node ./dist/migrate.cjs', orm: 'drizzle' };
337
+ }
338
+ const hasPrismaMarkers = exists(path.join('prisma', 'schema.prisma')) || deps.prisma;
339
+ if (hasPrismaMarkers) {
340
+ const major = /^\D*(\d+)/.exec(String(deps.prisma ?? ''))?.[1];
341
+ if (major === '6' || major === '7') {
342
+ return { command: 'node ./node_modules/prisma/build/index.js migrate deploy', orm: 'prisma' };
343
+ }
344
+ }
345
+ return null;
346
+ }
347
+
348
+ const ORM_DISPLAY_NAMES = { drizzle: 'Drizzle ORM', prisma: 'Prisma' };
349
+
350
+ // Shared refusal-hint sentence naming the mapped ORM command, so the
351
+ // migrate/init guard sites can't skew. Empty when nothing maps.
352
+ // `flagForm` carries the caller's joiner ('--cmd ' vs '--setup-ci-migrate=').
353
+ export function ormMappedHintSegment(cwd, flagForm) {
354
+ const mapped = detectOrmMigrationCommand(cwd);
355
+ if (!mapped) return '';
356
+ const label = ORM_DISPLAY_NAMES[mapped.orm] || mapped.orm;
357
+ return ` Detected ${label} — re-run with ${flagForm}"${mapped.command}" instead`;
358
+ }
359
+
306
360
  export function detectMigrationCommand(cwd = process.cwd()) {
307
361
  const readJson = (file) => {
308
362
  try {
@@ -337,7 +391,12 @@ export function detectMigrationCommand(cwd = process.cwd()) {
337
391
  return 'npm run migrate';
338
392
  }
339
393
 
340
- // 2. Prisma: schema file or dependency in either dep block.
394
+ // 2. ORM matrix: stripped-runner-safe node commands win over shims.
395
+ const ormMapped = detectOrmMigrationCommand(cwd);
396
+ if (ormMapped) return ormMapped.command;
397
+
398
+ // 3. Unmappable Prisma (other majors, unresolvable range): legacy npx
399
+ // form, which the stripped-runner guard refuses with a hint.
341
400
  const deps = pkg && typeof pkg === 'object'
342
401
  ? { ...(pkg.dependencies || {}), ...(pkg.devDependencies || {}) }
343
402
  : {};
@@ -345,11 +404,6 @@ export function detectMigrationCommand(cwd = process.cwd()) {
345
404
  return 'npx prisma migrate deploy';
346
405
  }
347
406
 
348
- // 3. Drizzle: config file in any supported extension.
349
- if (exists('drizzle.config.ts') || exists('drizzle.config.js') || exists('drizzle.config.mjs')) {
350
- return 'npx drizzle-kit migrate';
351
- }
352
-
353
407
  // 4. Alembic.
354
408
  if (exists('alembic.ini')) {
355
409
  return 'alembic upgrade head';