@akal/supaforge 0.0.32 → 0.0.34

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 (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +66 -11
  3. package/dist/base-command.js +4 -3
  4. package/dist/{chunk-DMIWAJRB.js → chunk-3WKWPSFN.js} +6 -6
  5. package/dist/{chunk-GZREXCQZ.js → chunk-5STH2A6K.js} +17 -10
  6. package/dist/{chunk-6LJERPUN.js → chunk-6ERVCWLY.js} +20 -12
  7. package/dist/{chunk-GEHPTPNZ.js → chunk-7DL63NWP.js} +3 -3
  8. package/dist/{chunk-UWAVXC57.js → chunk-DQJSSTIJ.js} +39 -15
  9. package/dist/{chunk-ORQJVE57.js → chunk-EFKQOQGG.js} +15 -16
  10. package/dist/{chunk-7NAZGZPV.js → chunk-F46FFUKC.js} +16 -17
  11. package/dist/chunk-GQPGH6YR.js +50 -0
  12. package/dist/{chunk-6Q7MHFBM.js → chunk-HNJ6BNNZ.js} +2 -2
  13. package/dist/{chunk-MIRLB5JM.js → chunk-ICSCHS72.js} +66 -14
  14. package/dist/{chunk-6WAMNZLO.js → chunk-KNXHLVF7.js} +126 -4
  15. package/dist/{chunk-SQPCWGQO.js → chunk-MG3SFV5J.js} +22 -121
  16. package/dist/{chunk-BUOWHE36.js → chunk-N5VNNOA2.js} +37 -52
  17. package/dist/{chunk-3HGAV5CC.js → chunk-OB5GP7UB.js} +19 -16
  18. package/dist/{chunk-4IVN7QVY.js → chunk-PYAGSMFB.js} +23 -15
  19. package/dist/{chunk-SC2XHGIS.js → chunk-S5L4A3UR.js} +3 -3
  20. package/dist/{chunk-2SELREHW.js → chunk-TPX2MAO4.js} +7 -9
  21. package/dist/{chunk-NTUASFQ3.js → chunk-V2SBZERO.js} +4 -4
  22. package/dist/{chunk-G2DIPIYU.js → chunk-WK5YTINL.js} +29 -2
  23. package/dist/{chunk-BLKJWDTL.js → chunk-ZI435CAU.js} +2 -2
  24. package/dist/commands/clone.js +11 -11
  25. package/dist/commands/diff.d.ts +13 -1
  26. package/dist/commands/diff.js +19 -16
  27. package/dist/commands/hukam.js +15 -14
  28. package/dist/commands/init.js +5 -1
  29. package/dist/commands/mcp.d.ts +1 -0
  30. package/dist/commands/mcp.js +26 -10
  31. package/dist/commands/migrate/baseline.js +5 -4
  32. package/dist/commands/migrate/create.js +8 -7
  33. package/dist/commands/migrate/list.js +6 -5
  34. package/dist/commands/migrate/run.js +8 -7
  35. package/dist/commands/report.js +5 -4
  36. package/dist/commands/restore.js +13 -12
  37. package/dist/commands/snapshot.d.ts +7 -0
  38. package/dist/commands/snapshot.js +36 -8
  39. package/dist/commands/sync.js +15 -14
  40. package/dist/index.js +14 -14
  41. package/package.json +10 -8
  42. package/bin/dev.js +0 -10
  43. package/dist/base-command.js.map +0 -1
  44. package/dist/chunk-2SELREHW.js.map +0 -1
  45. package/dist/chunk-3HGAV5CC.js.map +0 -1
  46. package/dist/chunk-4IVN7QVY.js.map +0 -1
  47. package/dist/chunk-6LJERPUN.js.map +0 -1
  48. package/dist/chunk-6Q7MHFBM.js.map +0 -1
  49. package/dist/chunk-6WAMNZLO.js.map +0 -1
  50. package/dist/chunk-7NAZGZPV.js.map +0 -1
  51. package/dist/chunk-BLKJWDTL.js.map +0 -1
  52. package/dist/chunk-BUOWHE36.js.map +0 -1
  53. package/dist/chunk-DMIWAJRB.js.map +0 -1
  54. package/dist/chunk-DQQ5E563.js.map +0 -1
  55. package/dist/chunk-G2DIPIYU.js.map +0 -1
  56. package/dist/chunk-GEHPTPNZ.js.map +0 -1
  57. package/dist/chunk-GZREXCQZ.js.map +0 -1
  58. package/dist/chunk-MIRLB5JM.js.map +0 -1
  59. package/dist/chunk-NTUASFQ3.js.map +0 -1
  60. package/dist/chunk-ORQJVE57.js.map +0 -1
  61. package/dist/chunk-SC2XHGIS.js.map +0 -1
  62. package/dist/chunk-SQPCWGQO.js.map +0 -1
  63. package/dist/chunk-UWAVXC57.js.map +0 -1
  64. package/dist/commands/clone.js.map +0 -1
  65. package/dist/commands/diff.js.map +0 -1
  66. package/dist/commands/help.js.map +0 -1
  67. package/dist/commands/hukam.js.map +0 -1
  68. package/dist/commands/init.js.map +0 -1
  69. package/dist/commands/mcp.js.map +0 -1
  70. package/dist/commands/migrate/baseline.js.map +0 -1
  71. package/dist/commands/migrate/create.js.map +0 -1
  72. package/dist/commands/migrate/list.js.map +0 -1
  73. package/dist/commands/migrate/run.js.map +0 -1
  74. package/dist/commands/report.js.map +0 -1
  75. package/dist/commands/restore.js.map +0 -1
  76. package/dist/commands/snapshot.js.map +0 -1
  77. package/dist/commands/sync.js.map +0 -1
  78. package/dist/help.js.map +0 -1
  79. package/dist/index.js.map +0 -1
@@ -1,10 +1,26 @@
1
1
  // src/utils/sql-split.ts
2
+ var ROUTINE_HEAD = /^CREATE\s+(?:OR\s+REPLACE\s+)?(?:FUNCTION|PROCEDURE)\b/i;
3
+ function withoutLeadingComments(text) {
4
+ let rest = text.trimStart();
5
+ for (; ; ) {
6
+ if (rest.startsWith("--")) {
7
+ const newline = rest.indexOf("\n");
8
+ rest = newline === -1 ? "" : rest.slice(newline + 1).trimStart();
9
+ } else if (rest.startsWith("/*")) {
10
+ const close = rest.indexOf("*/");
11
+ rest = close === -1 ? "" : rest.slice(close + 2).trimStart();
12
+ } else {
13
+ return rest;
14
+ }
15
+ }
16
+ }
2
17
  var DOLLAR_TAG = /^\$(?:[A-Za-z_][A-Za-z0-9_]*)?\$/;
3
18
  function splitSqlStatements(sql) {
4
19
  const statements = [];
5
20
  let start = 0;
6
21
  let i = 0;
7
22
  let blockDepth = 0;
23
+ let beginDepth = 0;
8
24
  const push = (end) => {
9
25
  const piece = sql.slice(start, end).trim();
10
26
  if (piece.length > 0) statements.push(piece);
@@ -61,7 +77,18 @@ function splitSqlStatements(sql) {
61
77
  i++;
62
78
  continue;
63
79
  }
64
- if (ch === ";") {
80
+ if (/[A-Za-z_]/.test(ch)) {
81
+ const word = /^[A-Za-z_][A-Za-z0-9_]*/.exec(sql.slice(i, i + 64))[0];
82
+ const upper = word.toUpperCase();
83
+ if ((upper === "BEGIN" || upper === "CASE") && ROUTINE_HEAD.test(withoutLeadingComments(sql.slice(start, i)))) {
84
+ beginDepth++;
85
+ } else if (upper === "END" && beginDepth > 0) {
86
+ beginDepth--;
87
+ }
88
+ i += word.length;
89
+ continue;
90
+ }
91
+ if (ch === ";" && beginDepth === 0) {
65
92
  push(i);
66
93
  i++;
67
94
  start = i;
@@ -91,4 +118,4 @@ export {
91
118
  stripPsqlMetaCommands,
92
119
  isPsqlMetaCommand
93
120
  };
94
- //# sourceMappingURL=chunk-G2DIPIYU.js.map
121
+ //# sourceMappingURL=chunk-WK5YTINL.js.map
@@ -2,7 +2,7 @@ import {
2
2
  CLONE_SKIP_FLAGS,
3
3
  cmd,
4
4
  dim
5
- } from "./chunk-6WAMNZLO.js";
5
+ } from "./chunk-KNXHLVF7.js";
6
6
 
7
7
  // src/tips.ts
8
8
  function applyTip(sourceIsClone, driftedChecks) {
@@ -150,4 +150,4 @@ function renderTip(ctx) {
150
150
  export {
151
151
  renderTip
152
152
  };
153
- //# sourceMappingURL=chunk-BLKJWDTL.js.map
153
+ //# sourceMappingURL=chunk-ZI435CAU.js.map
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  renderTip
3
- } from "../chunk-BLKJWDTL.js";
3
+ } from "../chunk-ZI435CAU.js";
4
4
  import {
5
5
  BaseCommand
6
- } from "../chunk-GZREXCQZ.js";
6
+ } from "../chunk-5STH2A6K.js";
7
7
  import {
8
8
  addBranchToManifest,
9
9
  cloneRemoteToLocal,
@@ -11,22 +11,21 @@ import {
11
11
  listBranches,
12
12
  reconcileClones,
13
13
  replaceDbName
14
- } from "../chunk-ORQJVE57.js";
14
+ } from "../chunk-EFKQOQGG.js";
15
15
  import {
16
16
  captureSnapshot,
17
17
  checkPgDumpCompat,
18
18
  formatSnapshotLayers
19
- } from "../chunk-MIRLB5JM.js";
19
+ } from "../chunk-ICSCHS72.js";
20
20
  import "../chunk-DQQ5E563.js";
21
21
  import {
22
22
  DEFAULT_LOCAL_PORT,
23
23
  LOCAL_PG_PASSWORD,
24
24
  LOCAL_PG_USER,
25
- errMsg,
26
- pgClientConfig,
27
- redactUrls,
25
+ newPgClient,
28
26
  startLocalPg
29
- } from "../chunk-SQPCWGQO.js";
27
+ } from "../chunk-MG3SFV5J.js";
28
+ import "../chunk-GQPGH6YR.js";
30
29
  import {
31
30
  CLONE_EXTRA_EXCLUDE_SCHEMAS,
32
31
  CLONE_SKIP_FLAGS,
@@ -36,16 +35,17 @@ import {
36
35
  bold,
37
36
  cmd,
38
37
  dim,
38
+ errMsg,
39
39
  loadConfig,
40
40
  ok,
41
+ redactUrls,
41
42
  warn
42
- } from "../chunk-6WAMNZLO.js";
43
+ } from "../chunk-KNXHLVF7.js";
43
44
 
44
45
  // src/commands/clone.ts
45
46
  import { writeFile, mkdir } from "fs/promises";
46
47
  import { resolve } from "path";
47
48
  import { Flags } from "@oclif/core";
48
- import pg from "pg";
49
49
  var CLONE_EXCLUDE_SCHEMAS = [.../* @__PURE__ */ new Set([
50
50
  ...DEFAULT_IGNORE_SCHEMAS,
51
51
  ...CLONE_EXTRA_EXCLUDE_SCHEMAS
@@ -211,7 +211,7 @@ var Clone = class _Clone extends BaseCommand {
211
211
  });
212
212
  pre.addCheck("Target database", async () => {
213
213
  try {
214
- const client = new pg.Client(pgClientConfig(localBaseUrl));
214
+ const client = newPgClient(localBaseUrl);
215
215
  await client.connect();
216
216
  const { rows } = await client.query(
217
217
  "SELECT 1 FROM pg_database WHERE datname = $1",
@@ -3,6 +3,18 @@ import { BaseCommand } from '../base-command.js';
3
3
  import '@oclif/core';
4
4
  import '../config-CTbeRlJk.js';
5
5
 
6
+ /**
7
+ * What to do after a rolled-back apply.
8
+ *
9
+ * Usually: apply the fixes that work without the one that failed. Not when
10
+ * the failure is replacing a view or type something else depends on — the
11
+ * others may be what depends on it, and applying them alone leaves the two
12
+ * out of step — so that one is named to fix or leave out instead.
13
+ */
14
+ declare function rollbackHint(errors: ReadonlyArray<{
15
+ issueId: string;
16
+ error: string;
17
+ }>): string;
6
18
  /** Which apply-only flags this invocation will silently ignore. */
7
19
  declare function inertApplyFlags(flags: Record<string, unknown>): ReadonlyArray<{
8
20
  flag: string;
@@ -78,4 +90,4 @@ declare class Diff extends BaseCommand {
78
90
  private preflightBothDatabases;
79
91
  }
80
92
 
81
- export { Diff as default, inertApplyFlags };
93
+ export { Diff as default, inertApplyFlags, rollbackHint };
@@ -1,23 +1,26 @@
1
1
  import {
2
2
  Diff,
3
- inertApplyFlags
4
- } from "../chunk-4IVN7QVY.js";
5
- import "../chunk-6Q7MHFBM.js";
6
- import "../chunk-GEHPTPNZ.js";
7
- import "../chunk-3HGAV5CC.js";
8
- import "../chunk-DMIWAJRB.js";
9
- import "../chunk-UWAVXC57.js";
10
- import "../chunk-BUOWHE36.js";
11
- import "../chunk-G2DIPIYU.js";
12
- import "../chunk-BLKJWDTL.js";
13
- import "../chunk-GZREXCQZ.js";
14
- import "../chunk-ORQJVE57.js";
15
- import "../chunk-MIRLB5JM.js";
3
+ inertApplyFlags,
4
+ rollbackHint
5
+ } from "../chunk-PYAGSMFB.js";
6
+ import "../chunk-HNJ6BNNZ.js";
7
+ import "../chunk-7DL63NWP.js";
8
+ import "../chunk-OB5GP7UB.js";
9
+ import "../chunk-3WKWPSFN.js";
10
+ import "../chunk-DQJSSTIJ.js";
11
+ import "../chunk-N5VNNOA2.js";
12
+ import "../chunk-WK5YTINL.js";
13
+ import "../chunk-ZI435CAU.js";
14
+ import "../chunk-5STH2A6K.js";
15
+ import "../chunk-EFKQOQGG.js";
16
+ import "../chunk-ICSCHS72.js";
16
17
  import "../chunk-DQQ5E563.js";
17
- import "../chunk-SQPCWGQO.js";
18
- import "../chunk-6WAMNZLO.js";
18
+ import "../chunk-MG3SFV5J.js";
19
+ import "../chunk-GQPGH6YR.js";
20
+ import "../chunk-KNXHLVF7.js";
19
21
  export {
20
22
  Diff as default,
21
- inertApplyFlags
23
+ inertApplyFlags,
24
+ rollbackHint
22
25
  };
23
26
  //# sourceMappingURL=diff.js.map
@@ -1,20 +1,21 @@
1
1
  import {
2
2
  Diff
3
- } from "../chunk-4IVN7QVY.js";
4
- import "../chunk-6Q7MHFBM.js";
5
- import "../chunk-GEHPTPNZ.js";
6
- import "../chunk-3HGAV5CC.js";
7
- import "../chunk-DMIWAJRB.js";
8
- import "../chunk-UWAVXC57.js";
9
- import "../chunk-BUOWHE36.js";
10
- import "../chunk-G2DIPIYU.js";
11
- import "../chunk-BLKJWDTL.js";
12
- import "../chunk-GZREXCQZ.js";
13
- import "../chunk-ORQJVE57.js";
14
- import "../chunk-MIRLB5JM.js";
3
+ } from "../chunk-PYAGSMFB.js";
4
+ import "../chunk-HNJ6BNNZ.js";
5
+ import "../chunk-7DL63NWP.js";
6
+ import "../chunk-OB5GP7UB.js";
7
+ import "../chunk-3WKWPSFN.js";
8
+ import "../chunk-DQJSSTIJ.js";
9
+ import "../chunk-N5VNNOA2.js";
10
+ import "../chunk-WK5YTINL.js";
11
+ import "../chunk-ZI435CAU.js";
12
+ import "../chunk-5STH2A6K.js";
13
+ import "../chunk-EFKQOQGG.js";
14
+ import "../chunk-ICSCHS72.js";
15
15
  import "../chunk-DQQ5E563.js";
16
- import "../chunk-SQPCWGQO.js";
17
- import "../chunk-6WAMNZLO.js";
16
+ import "../chunk-MG3SFV5J.js";
17
+ import "../chunk-GQPGH6YR.js";
18
+ import "../chunk-KNXHLVF7.js";
18
19
 
19
20
  // src/commands/hukam.ts
20
21
  var Hukam = class extends Diff {
@@ -1,3 +1,6 @@
1
+ import {
2
+ installProcessGuard
3
+ } from "../chunk-GQPGH6YR.js";
1
4
  import {
2
5
  INIT_HINTS,
3
6
  SUPAFORGE_DIR,
@@ -12,7 +15,7 @@ import {
12
15
  validateConfig,
13
16
  validateSingleEnvConfig,
14
17
  warn
15
- } from "../chunk-6WAMNZLO.js";
18
+ } from "../chunk-KNXHLVF7.js";
16
19
 
17
20
  // src/commands/init.ts
18
21
  import { Command, Flags } from "@oclif/core";
@@ -248,6 +251,7 @@ var Init = class _Init extends Command {
248
251
  })
249
252
  };
250
253
  async run() {
254
+ installProcessGuard(this.argv);
251
255
  const { flags } = await this.parse(_Init);
252
256
  const configPath = resolve(process.cwd(), CONFIG_FILENAME);
253
257
  if (!flags.force) {
@@ -5,6 +5,7 @@ declare class Mcp extends Command {
5
5
  static description: string;
6
6
  static examples: string[];
7
7
  static flags: {
8
+ project: _oclif_core_interfaces.OptionFlag<string | undefined, _oclif_core_interfaces.CustomOptions>;
8
9
  'allow-config-path': _oclif_core_interfaces.BooleanFlag<boolean>;
9
10
  };
10
11
  run(): Promise<void>;
@@ -1,17 +1,23 @@
1
1
  import {
2
2
  createServer
3
- } from "../chunk-6LJERPUN.js";
4
- import "../chunk-NTUASFQ3.js";
5
- import "../chunk-3HGAV5CC.js";
6
- import "../chunk-UWAVXC57.js";
7
- import "../chunk-BUOWHE36.js";
8
- import "../chunk-G2DIPIYU.js";
9
- import "../chunk-MIRLB5JM.js";
3
+ } from "../chunk-6ERVCWLY.js";
4
+ import "../chunk-V2SBZERO.js";
5
+ import "../chunk-OB5GP7UB.js";
6
+ import "../chunk-DQJSSTIJ.js";
7
+ import "../chunk-N5VNNOA2.js";
8
+ import "../chunk-WK5YTINL.js";
9
+ import "../chunk-ICSCHS72.js";
10
10
  import "../chunk-DQQ5E563.js";
11
- import "../chunk-SQPCWGQO.js";
12
- import "../chunk-6WAMNZLO.js";
11
+ import "../chunk-MG3SFV5J.js";
12
+ import {
13
+ installProcessGuard,
14
+ keepRunningOnStrayErrors
15
+ } from "../chunk-GQPGH6YR.js";
16
+ import "../chunk-KNXHLVF7.js";
13
17
 
14
18
  // src/commands/mcp.ts
19
+ import { existsSync, statSync } from "fs";
20
+ import { resolve } from "path";
15
21
  import { Command, Flags } from "@oclif/core";
16
22
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
17
23
  var Mcp = class _Mcp extends Command {
@@ -19,17 +25,27 @@ var Mcp = class _Mcp extends Command {
19
25
  static examples = [
20
26
  "<%= config.bin %> mcp",
21
27
  "<%= config.bin %> mcp --allow-config-path",
28
+ "<%= config.bin %> mcp --project ~/code/my-app",
22
29
  '# Claude Desktop / Cursor config:\n# { "mcpServers": { "supaforge": { "command": "supaforge", "args": ["mcp"] } } }'
23
30
  ];
24
31
  static flags = {
32
+ project: Flags.string({
33
+ description: "The project directory, holding supaforge.config.json. Defaults to the directory the server starts in \u2014 which an AI client may not let you choose, so name it here."
34
+ }),
25
35
  "allow-config-path": Flags.boolean({
26
36
  description: "Let a client choose which supaforge.config.json to load. Off by default: a tool call, or a prompt injected into one, could otherwise point the server at any config on disk \u2014 including one holding production credentials \u2014 bypassing the one it was started with.",
27
37
  default: false
28
38
  })
29
39
  };
30
40
  async run() {
41
+ keepRunningOnStrayErrors();
42
+ installProcessGuard(this.argv);
31
43
  const { flags } = await this.parse(_Mcp);
32
- const server = createServer(process.cwd(), {
44
+ const project = resolve(flags.project ?? process.cwd());
45
+ if (!existsSync(project) || !statSync(project).isDirectory()) {
46
+ this.error(`--project: ${project} is not a directory`);
47
+ }
48
+ const server = createServer(project, {
33
49
  allowConfigPath: flags["allow-config-path"]
34
50
  });
35
51
  const transport = new StdioServerTransport();
@@ -1,15 +1,16 @@
1
1
  import {
2
2
  baselineMigrations
3
- } from "../../chunk-SC2XHGIS.js";
3
+ } from "../../chunk-S5L4A3UR.js";
4
4
  import {
5
5
  BaseCommand
6
- } from "../../chunk-GZREXCQZ.js";
7
- import "../../chunk-SQPCWGQO.js";
6
+ } from "../../chunk-5STH2A6K.js";
7
+ import "../../chunk-MG3SFV5J.js";
8
+ import "../../chunk-GQPGH6YR.js";
8
9
  import {
9
10
  bold,
10
11
  dim,
11
12
  ok
12
- } from "../../chunk-6WAMNZLO.js";
13
+ } from "../../chunk-KNXHLVF7.js";
13
14
 
14
15
  // src/commands/migrate/baseline.ts
15
16
  import { Flags } from "@oclif/core";
@@ -1,21 +1,22 @@
1
1
  import {
2
2
  truncateSql
3
- } from "../../chunk-2SELREHW.js";
4
- import "../../chunk-SC2XHGIS.js";
3
+ } from "../../chunk-TPX2MAO4.js";
4
+ import "../../chunk-S5L4A3UR.js";
5
5
  import {
6
6
  isDestructiveSql,
7
7
  runDbDiff
8
- } from "../../chunk-BUOWHE36.js";
8
+ } from "../../chunk-N5VNNOA2.js";
9
9
  import {
10
10
  splitSqlStatements
11
- } from "../../chunk-G2DIPIYU.js";
11
+ } from "../../chunk-WK5YTINL.js";
12
12
  import {
13
13
  BaseCommand
14
- } from "../../chunk-GZREXCQZ.js";
14
+ } from "../../chunk-5STH2A6K.js";
15
15
  import {
16
16
  slugify
17
17
  } from "../../chunk-DQQ5E563.js";
18
- import "../../chunk-SQPCWGQO.js";
18
+ import "../../chunk-MG3SFV5J.js";
19
+ import "../../chunk-GQPGH6YR.js";
19
20
  import {
20
21
  DEFAULT_IGNORE_SCHEMAS,
21
22
  bold,
@@ -23,7 +24,7 @@ import {
23
24
  dim,
24
25
  ok,
25
26
  warn
26
- } from "../../chunk-6WAMNZLO.js";
27
+ } from "../../chunk-KNXHLVF7.js";
27
28
 
28
29
  // src/commands/migrate/create.ts
29
30
  import { writeFile, mkdir } from "fs/promises";
@@ -1,20 +1,21 @@
1
1
  import {
2
2
  getAppliedVersions
3
- } from "../../chunk-SC2XHGIS.js";
3
+ } from "../../chunk-S5L4A3UR.js";
4
4
  import {
5
5
  BaseCommand
6
- } from "../../chunk-GZREXCQZ.js";
6
+ } from "../../chunk-5STH2A6K.js";
7
7
  import {
8
- errMsg,
9
8
  pgQuery,
10
9
  readLocalMigrations
11
- } from "../../chunk-SQPCWGQO.js";
10
+ } from "../../chunk-MG3SFV5J.js";
11
+ import "../../chunk-GQPGH6YR.js";
12
12
  import {
13
13
  bold,
14
14
  dim,
15
+ errMsg,
15
16
  ok,
16
17
  warn
17
- } from "../../chunk-6WAMNZLO.js";
18
+ } from "../../chunk-KNXHLVF7.js";
18
19
 
19
20
  // src/commands/migrate/list.ts
20
21
  import { Flags } from "@oclif/core";
@@ -2,14 +2,15 @@ import {
2
2
  MigrateRun,
3
3
  findDestructiveStatements,
4
4
  truncateSql
5
- } from "../../chunk-2SELREHW.js";
6
- import "../../chunk-SC2XHGIS.js";
7
- import "../../chunk-BUOWHE36.js";
8
- import "../../chunk-G2DIPIYU.js";
9
- import "../../chunk-GZREXCQZ.js";
5
+ } from "../../chunk-TPX2MAO4.js";
6
+ import "../../chunk-S5L4A3UR.js";
7
+ import "../../chunk-N5VNNOA2.js";
8
+ import "../../chunk-WK5YTINL.js";
9
+ import "../../chunk-5STH2A6K.js";
10
10
  import "../../chunk-DQQ5E563.js";
11
- import "../../chunk-SQPCWGQO.js";
12
- import "../../chunk-6WAMNZLO.js";
11
+ import "../../chunk-MG3SFV5J.js";
12
+ import "../../chunk-GQPGH6YR.js";
13
+ import "../../chunk-KNXHLVF7.js";
13
14
  export {
14
15
  MigrateRun as default,
15
16
  findDestructiveStatements,
@@ -1,19 +1,20 @@
1
1
  import {
2
2
  sanitizeForReport
3
- } from "../chunk-6Q7MHFBM.js";
3
+ } from "../chunk-HNJ6BNNZ.js";
4
4
  import {
5
5
  BaseCommand,
6
6
  readRunLog,
7
7
  runLogPath
8
- } from "../chunk-GZREXCQZ.js";
9
- import "../chunk-SQPCWGQO.js";
8
+ } from "../chunk-5STH2A6K.js";
9
+ import "../chunk-MG3SFV5J.js";
10
+ import "../chunk-GQPGH6YR.js";
10
11
  import {
11
12
  bold,
12
13
  cmd,
13
14
  dim,
14
15
  ok,
15
16
  warn
16
- } from "../chunk-6WAMNZLO.js";
17
+ } from "../chunk-KNXHLVF7.js";
17
18
 
18
19
  // src/commands/report.ts
19
20
  import { Flags } from "@oclif/core";
@@ -5,29 +5,30 @@ import {
5
5
  restoreFromMigrations,
6
6
  restoreFromSnapshot,
7
7
  summarizeStatement
8
- } from "../chunk-7NAZGZPV.js";
9
- import "../chunk-NTUASFQ3.js";
10
- import "../chunk-SC2XHGIS.js";
11
- import "../chunk-DMIWAJRB.js";
12
- import "../chunk-UWAVXC57.js";
13
- import "../chunk-BUOWHE36.js";
14
- import "../chunk-G2DIPIYU.js";
8
+ } from "../chunk-F46FFUKC.js";
9
+ import "../chunk-V2SBZERO.js";
10
+ import "../chunk-S5L4A3UR.js";
11
+ import "../chunk-3WKWPSFN.js";
12
+ import "../chunk-DQJSSTIJ.js";
13
+ import "../chunk-N5VNNOA2.js";
14
+ import "../chunk-WK5YTINL.js";
15
15
  import {
16
16
  renderTip
17
- } from "../chunk-BLKJWDTL.js";
17
+ } from "../chunk-ZI435CAU.js";
18
18
  import {
19
19
  BaseCommand
20
- } from "../chunk-GZREXCQZ.js";
20
+ } from "../chunk-5STH2A6K.js";
21
21
  import {
22
22
  findLatestSnapshot,
23
23
  listSnapshots
24
- } from "../chunk-MIRLB5JM.js";
24
+ } from "../chunk-ICSCHS72.js";
25
25
  import "../chunk-DQQ5E563.js";
26
- import "../chunk-SQPCWGQO.js";
26
+ import "../chunk-MG3SFV5J.js";
27
+ import "../chunk-GQPGH6YR.js";
27
28
  import {
28
29
  cmd,
29
30
  warn
30
- } from "../chunk-6WAMNZLO.js";
31
+ } from "../chunk-KNXHLVF7.js";
31
32
 
32
33
  // src/commands/restore.ts
33
34
  import { Flags } from "@oclif/core";
@@ -24,9 +24,16 @@ declare class Snapshot extends BaseCommand {
24
24
  keep: _oclif_core_interfaces.OptionFlag<number, _oclif_core_interfaces.CustomOptions>;
25
25
  apply: _oclif_core_interfaces.BooleanFlag<boolean>;
26
26
  json: _oclif_core_interfaces.BooleanFlag<boolean>;
27
+ 'allow-schema-json-only': _oclif_core_interfaces.BooleanFlag<boolean>;
27
28
  output: _oclif_core_interfaces.OptionFlag<string | undefined, _oclif_core_interfaces.CustomOptions>;
28
29
  };
29
30
  run(): Promise<void>;
31
+ /**
32
+ * A snapshot without schema.sql cannot restore its schema, and the time to
33
+ * find that out is not during a restore. It is kept — it can still be
34
+ * diffed — but the command fails unless that was asked for.
35
+ */
36
+ private failIfUnrestorable;
30
37
  private logSnapshotResult;
31
38
  }
32
39
 
@@ -1,30 +1,32 @@
1
1
  import {
2
2
  backup,
3
3
  listMigrationFiles
4
- } from "../chunk-NTUASFQ3.js";
5
- import "../chunk-G2DIPIYU.js";
4
+ } from "../chunk-V2SBZERO.js";
5
+ import "../chunk-WK5YTINL.js";
6
6
  import {
7
7
  renderTip
8
- } from "../chunk-BLKJWDTL.js";
8
+ } from "../chunk-ZI435CAU.js";
9
9
  import {
10
10
  BaseCommand
11
- } from "../chunk-GZREXCQZ.js";
11
+ } from "../chunk-5STH2A6K.js";
12
12
  import {
13
13
  DEFAULT_KEEP_COUNT,
14
14
  captureSnapshot,
15
15
  formatSnapshotLayers,
16
16
  listSnapshots,
17
- pruneSnapshots
18
- } from "../chunk-MIRLB5JM.js";
17
+ pruneSnapshots,
18
+ unrestorableSchema
19
+ } from "../chunk-ICSCHS72.js";
19
20
  import "../chunk-DQQ5E563.js";
20
- import "../chunk-SQPCWGQO.js";
21
+ import "../chunk-MG3SFV5J.js";
22
+ import "../chunk-GQPGH6YR.js";
21
23
  import {
22
24
  bold,
23
25
  cmd,
24
26
  dim,
25
27
  ok,
26
28
  warn
27
- } from "../chunk-6WAMNZLO.js";
29
+ } from "../chunk-KNXHLVF7.js";
28
30
 
29
31
  // src/commands/snapshot.ts
30
32
  import { Flags } from "@oclif/core";
@@ -84,6 +86,10 @@ var Snapshot = class _Snapshot extends BaseCommand {
84
86
  default: false
85
87
  }),
86
88
  json: Flags.boolean({ description: "Output results as JSON" }),
89
+ "allow-schema-json-only": Flags.boolean({
90
+ description: "Succeed even when no pg_dump could write schema.sql: the snapshot can still be diffed, but restore cannot recreate its schema. Without this, such a snapshot is kept and the command exits 1.",
91
+ default: false
92
+ }),
87
93
  output: Flags.string({
88
94
  char: "o",
89
95
  description: "Custom output directory for snapshot files (timestamp subfolder is created inside)"
@@ -194,6 +200,7 @@ Capturing snapshot of "${envName}" with migration...
194
200
  migration: result.migration,
195
201
  migrationFile: result.migrationFile
196
202
  });
203
+ this.failIfUnrestorable(result.snapshot.manifest, result.snapshot.dir, flags["allow-schema-json-only"]);
197
204
  return;
198
205
  }
199
206
  this.logSnapshotResult(result.snapshot.manifest);
@@ -211,6 +218,7 @@ Capturing snapshot of "${envName}" with migration...
211
218
  } else {
212
219
  this.log(` ${dim("Migration:")} none (no changes detected)`);
213
220
  }
221
+ this.failIfUnrestorable(result.snapshot.manifest, result.snapshot.dir, flags["allow-schema-json-only"]);
214
222
  this.log(`
215
223
  ${ok("Snapshot + migration complete.")}
216
224
  `);
@@ -223,11 +231,13 @@ Capturing snapshot of "${envName}"...
223
231
  const snapshot = await captureSnapshot({ envName, env, config, outputDir: flags.output });
224
232
  if (flags.json) {
225
233
  this.json(snapshot.manifest);
234
+ this.failIfUnrestorable(snapshot.manifest, snapshot.dir, flags["allow-schema-json-only"]);
226
235
  return;
227
236
  }
228
237
  this.logSnapshotResult(snapshot.manifest);
229
238
  this.log(`
230
239
  ${dim("Snapshot saved to:")} ${snapshot.dir}`);
240
+ this.failIfUnrestorable(snapshot.manifest, snapshot.dir, flags["allow-schema-json-only"]);
231
241
  const existing = await listMigrationFiles();
232
242
  if (existing.length > 0) {
233
243
  this.log(` \u2192 Run with ${cmd("--migration")} to also generate an incremental diff.`);
@@ -237,6 +247,24 @@ Capturing snapshot of "${envName}"...
237
247
  this.log("");
238
248
  this.log(renderTip({ command: "snapshot", snapshotMigration: false, snapshotList: false }));
239
249
  }
250
+ /**
251
+ * A snapshot without schema.sql cannot restore its schema, and the time to
252
+ * find that out is not during a restore. It is kept — it can still be
253
+ * diffed — but the command fails unless that was asked for.
254
+ */
255
+ failIfUnrestorable(manifest, dir, allowed) {
256
+ const reason = unrestorableSchema(manifest);
257
+ if (!reason) return;
258
+ if (allowed) {
259
+ this.warn(`This snapshot cannot restore the schema: ${reason}`);
260
+ return;
261
+ }
262
+ this.error(
263
+ `This snapshot cannot restore the schema: ${reason}.
264
+ It was kept at ${dir}, and can still be diffed. Install PostgreSQL client tools at least as new as the server (or set SUPAFORGE_PG_BIN to them) and snapshot again, or pass --allow-schema-json-only to accept a snapshot whose schema cannot be restored.`,
265
+ { exit: 1 }
266
+ );
267
+ }
240
268
  logSnapshotResult(manifest) {
241
269
  for (const line of formatSnapshotLayers(manifest)) {
242
270
  this.log(` ${line}`);