@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
@@ -7,118 +7,12 @@ import {
7
7
  RUNTIME_DETECT_TIMEOUT_MS,
8
8
  bold,
9
9
  cmd,
10
+ describeFailure,
10
11
  dim,
11
12
  ok,
13
+ redactUrls,
12
14
  warn
13
- } from "./chunk-6WAMNZLO.js";
14
-
15
- // src/utils/error.ts
16
- var DB_URL_RE = /\b((?:postgres(?:ql)?|mysql|mariadb):\/\/)(\S+)/g;
17
- function redactUrls(message) {
18
- return message.replace(DB_URL_RE, (_, scheme, rest) => {
19
- const lastAt = rest.lastIndexOf("@");
20
- if (lastAt === -1) return scheme + rest;
21
- const creds = rest.slice(0, lastAt);
22
- const hostPart = rest.slice(lastAt);
23
- const colonIdx = creds.indexOf(":");
24
- if (colonIdx === -1) return scheme + rest;
25
- return scheme + creds.slice(0, colonIdx) + ":***" + hostPart;
26
- });
27
- }
28
- var UNDESCRIBED_ERROR = "unknown error \u2014 no message reported";
29
- function describeFailure(err) {
30
- if (typeof err === "string") return err.trim() || UNDESCRIBED_ERROR;
31
- const candidate = err;
32
- const message = typeof candidate?.message === "string" ? candidate.message.trim() : "";
33
- if (message) return message;
34
- const code = typeof candidate?.code === "string" ? candidate.code.trim() : "";
35
- if (code) return `${code} (no further detail reported)`;
36
- const name = typeof candidate?.name === "string" ? candidate.name.trim() : "";
37
- if (name && name !== "Error") return `${name} (no further detail reported)`;
38
- if (err !== null && err !== void 0 && !(err instanceof Error)) {
39
- const rendered = String(err).trim();
40
- if (rendered && rendered !== "[object Object]") return rendered;
41
- }
42
- return UNDESCRIBED_ERROR;
43
- }
44
- function errMsg(err) {
45
- return redactUrls(describeFailure(err));
46
- }
47
- var DiagnosticError = class extends Error {
48
- constructor(message) {
49
- super(message);
50
- this.name = "DiagnosticError";
51
- }
52
- };
53
- function isDiagnosticError(err) {
54
- return err instanceof DiagnosticError || err instanceof Error && err.name === "DiagnosticError";
55
- }
56
- var CONNECTION_ERROR_PATTERNS = [
57
- {
58
- test: (m) => /ECONNREFUSED|Connection refused/i.test(m),
59
- build: (host) => `Cannot connect to PostgreSQL at ${host} \u2014 the server does not appear to be running. Start it and try again.`
60
- },
61
- {
62
- test: (m) => /ENOTFOUND|getaddrinfo/i.test(m),
63
- build: (host) => `Cannot resolve hostname ${host} \u2014 check the database URL in your config.`
64
- },
65
- {
66
- // Before the connection timeout: the server answered, and a query ran
67
- // past its statement_timeout. Calling that a connection problem sent
68
- // people to check a host and port that were fine.
69
- test: (m) => /canceling statement due to statement timeout|57014/i.test(m),
70
- build: (host) => `A query on ${host} was cancelled by statement_timeout \u2014 the server is reachable. Raise statement_timeout for this role or connection and try again.`
71
- },
72
- {
73
- // Deliberately narrow. A bare /timeout/i also matches our own remediation
74
- // text — "set SUPAFORGE_DBDIFF_TIMEOUT=600" contains "TIMEOUT" — which is
75
- // how an accurate "Schema diff timed out after Ns" message was being
76
- // rewritten into a wrong "check the host and port" one (issue #29).
77
- // DiagnosticError below is the primary guard; this is defence in depth.
78
- test: (m) => /ETIMEDOUT|connection timed out|timeout expired/i.test(m),
79
- build: (host) => `Connection to ${host} timed out \u2014 verify the host and port are correct and that the server is reachable.`
80
- },
81
- {
82
- test: (m) => /password authentication failed/i.test(m),
83
- build: (host) => `Authentication failed for ${host} \u2014 check the username and password in your database URL.`
84
- },
85
- {
86
- // Must stay anchored to "database ... does not exist" (Postgres SQLSTATE
87
- // 3D000). A bare /does not exist/ is the same trap as the timeout pattern
88
- // above: it matched dbdiff's own CLI complaint — The "--allow-destructive"
89
- // option does not exist — and rewrote it into "Database does not exist on
90
- // 127.0.0.1:5432", sending you off to check a database name that was fine
91
- // while the real cause (an outdated @dbdiff/cli) went unmentioned.
92
- test: (m) => /database\s+"[^"]*"\s+does not exist|3D000/i.test(m),
93
- build: (host) => `Database does not exist on ${host} \u2014 verify the database name in your config.`
94
- },
95
- {
96
- test: (m) => /SSL.*required|no pg_hba.conf entry/i.test(m),
97
- build: (host) => `Connection rejected by ${host} \u2014 the server requires SSL or your IP is not allowed. Check pg_hba.conf and SSL settings.`
98
- }
99
- ];
100
- function extractHost(dbUrl) {
101
- try {
102
- const url = new URL(dbUrl);
103
- return url.port ? `${url.hostname}:${url.port}` : url.hostname;
104
- } catch {
105
- return "the configured host";
106
- }
107
- }
108
- function friendlyDbError(err, dbUrl) {
109
- const raw = errMsg(err);
110
- if (isDiagnosticError(err)) return raw;
111
- const host = dbUrl ? extractHost(dbUrl) : "the configured host";
112
- for (const pattern of CONNECTION_ERROR_PATTERNS) {
113
- try {
114
- if (pattern.test(raw)) {
115
- return pattern.build(host);
116
- }
117
- } catch {
118
- }
119
- }
120
- return raw;
121
- }
15
+ } from "./chunk-KNXHLVF7.js";
122
16
 
123
17
  // src/db.ts
124
18
  import pg from "pg";
@@ -140,17 +34,29 @@ function pgClientConfig(dbUrl, queryTimeoutMs) {
140
34
  }
141
35
  return config;
142
36
  }
37
+ function newPgClient(dbUrl, queryTimeoutMs) {
38
+ const client = new pg.Client(pgClientConfig(dbUrl, queryTimeoutMs));
39
+ client.on("error", () => void 0);
40
+ return client;
41
+ }
42
+ function newPgPool(config) {
43
+ const pool = new pg.Pool(config);
44
+ pool.on("error", () => void 0);
45
+ pool.on("connect", (client) => {
46
+ client.on("error", () => void 0);
47
+ });
48
+ return pool;
49
+ }
143
50
  var pools = /* @__PURE__ */ new Map();
144
51
  var POOL_MAX = 4;
145
52
  function poolFor(dbUrl) {
146
53
  const existing = pools.get(dbUrl);
147
54
  if (existing) return existing;
148
- const pool = new pg.Pool({
55
+ const pool = newPgPool({
149
56
  ...pgClientConfig(dbUrl),
150
57
  max: POOL_MAX,
151
58
  allowExitOnIdle: true
152
59
  });
153
- pool.on("error", () => void 0);
154
60
  pools.set(dbUrl, pool);
155
61
  return pool;
156
62
  }
@@ -175,7 +81,6 @@ async function inRolledBackTransaction(dbUrl, fn) {
175
81
  // src/local-pg.ts
176
82
  import { execFile } from "child_process";
177
83
  import { promisify } from "util";
178
- import pg2 from "pg";
179
84
  var defaultExecFile = promisify(execFile);
180
85
  var PG_IMAGE = "docker.io/library/postgres:17";
181
86
  var DEFAULT_LOCAL_PORT = 5432;
@@ -185,7 +90,7 @@ var LOCAL_PG_PASSWORD = "postgres";
185
90
  var READINESS_RETRIES = 30;
186
91
  var READINESS_INTERVAL_MS = 2e3;
187
92
  async function defaultConnectFn(url) {
188
- const client = new pg2.Client(pgClientConfig(url));
93
+ const client = newPgClient(url);
189
94
  await client.connect();
190
95
  await client.end();
191
96
  }
@@ -294,7 +199,6 @@ function sleep(ms) {
294
199
  }
295
200
 
296
201
  // src/preflight.ts
297
- import pg3 from "pg";
298
202
  var SUPABASE_LOCAL_PORT = "54322";
299
203
  var DEFAULT_PG_PORT = "5432";
300
204
  var CONNECT_TIMEOUT_RE = /timeout expired|connection timeout/i;
@@ -312,7 +216,7 @@ async function checkConnection(dbUrl) {
312
216
  const connectTimeoutMs = resolveConnectTimeoutMs();
313
217
  let client;
314
218
  try {
315
- client = new pg3.Client(pgClientConfig(dbUrl, DB_PROBE_TIMEOUT_MS));
219
+ client = newPgClient(dbUrl, DB_PROBE_TIMEOUT_MS);
316
220
  await client.connect();
317
221
  const { rows } = await client.query("SHOW server_version");
318
222
  const version = rows[0].server_version;
@@ -628,12 +532,9 @@ function markAppliedSql(version, name) {
628
532
  }
629
533
 
630
534
  export {
631
- redactUrls,
632
- describeFailure,
633
- errMsg,
634
- DiagnosticError,
635
- friendlyDbError,
636
535
  pgClientConfig,
536
+ newPgClient,
537
+ newPgPool,
637
538
  pgQuery,
638
539
  inRolledBackTransaction,
639
540
  DEFAULT_LOCAL_PORT,
@@ -654,4 +555,4 @@ export {
654
555
  MigrationsCheck,
655
556
  readLocalMigrations
656
557
  };
657
- //# sourceMappingURL=chunk-SQPCWGQO.js.map
558
+ //# sourceMappingURL=chunk-MG3SFV5J.js.map
@@ -1,19 +1,17 @@
1
1
  import {
2
2
  splitSqlStatements
3
- } from "./chunk-G2DIPIYU.js";
3
+ } from "./chunk-WK5YTINL.js";
4
4
  import {
5
5
  escapeRegex
6
6
  } from "./chunk-DQQ5E563.js";
7
- import {
8
- DiagnosticError,
9
- errMsg,
10
- friendlyDbError
11
- } from "./chunk-SQPCWGQO.js";
12
7
  import {
13
8
  DBDIFF_EXEC_TIMEOUT_MS,
14
9
  DBDIFF_MAX_BUFFER,
10
+ DiagnosticError,
11
+ errMsg,
12
+ friendlyDbError,
15
13
  schemaDiffIgnores
16
- } from "./chunk-6WAMNZLO.js";
14
+ } from "./chunk-KNXHLVF7.js";
17
15
 
18
16
  // src/dbdiff.ts
19
17
  import { execFile } from "child_process";
@@ -412,7 +410,8 @@ var REPLACING_KINDS = {
412
410
  AlterPolicy: "policy",
413
411
  AlterTrigger: "trigger",
414
412
  AlterView: "view",
415
- AlterMatView: "view"
413
+ AlterMatView: "view",
414
+ AlterCollation: "collation"
416
415
  };
417
416
 
418
417
  // src/dbdiff.ts
@@ -585,7 +584,7 @@ var UP_MARKER = "-- ==================== UP ====================";
585
584
  var DOWN_MARKER = "-- ==================== DOWN ====================";
586
585
  var CREATE_FUNCTION = "create-function";
587
586
  var DROP_FUNCTION = "drop-function";
588
- var DROP_TYPES = ["drop", "drop-view", DROP_FUNCTION, "drop-trigger", "drop-type", "drop-sequence"];
587
+ var DROP_TYPES = ["drop", "drop-view", DROP_FUNCTION, "drop-trigger", "drop-type", "drop-sequence", "drop-collation"];
589
588
  function isDestructiveSql(sql) {
590
589
  return destructiveReason(sql) !== void 0;
591
590
  }
@@ -789,8 +788,10 @@ function isCrossSchemaFkUnit(up, down, schemas, ignoredSchemaTables) {
789
788
  }
790
789
  function replacedObject(unit, statements) {
791
790
  const kind = REPLACING_KINDS[unit.kind];
791
+ if (!kind) return void 0;
792
+ if (kind === "view") return replacedView(unit, statements);
792
793
  const drop = statements.find((sql) => replaceablePart(sql)?.drop);
793
- if (!kind || !drop) return void 0;
794
+ if (!drop) return void 0;
794
795
  if (kind === "type") return { kind, name: unit.object };
795
796
  const create = [...statements].reverse().find((sql) => replaceablePart(sql)?.drop === false) ?? drop;
796
797
  return {
@@ -798,6 +799,15 @@ function replacedObject(unit, statements) {
798
799
  name: kind === "routine" ? extractRoutineName(create) + extractRoutineArgs(drop) : REPLACEABLE_NAME[kind](create)
799
800
  };
800
801
  }
802
+ function replacedView(unit, statements) {
803
+ const views = statements.filter((sql) => replaceablePart(sql)?.kind === "view");
804
+ const own = (sql) => bareName2(REPLACEABLE_NAME.view(sql)) === bareName2(unit.object);
805
+ const create = views.find((sql) => replaceablePart(sql)?.drop === false && own(sql)) ?? views.filter((sql) => replaceablePart(sql)?.drop === false).pop();
806
+ const drop = views.find((sql) => replaceablePart(sql)?.drop && own(sql)) ?? views.find((sql) => replaceablePart(sql)?.drop);
807
+ const named2 = create ?? drop;
808
+ return named2 ? { kind: "view", name: REPLACEABLE_NAME.view(named2) } : void 0;
809
+ }
810
+ var bareName2 = (name) => name.slice(name.lastIndexOf(".") + 1).replace(/"/g, "").toLowerCase();
801
811
  function leadStatement(unit, statements) {
802
812
  if (unit.kind.startsWith("AlterTable")) {
803
813
  const alter = statements.find((sql) => /^\s*ALTER\s+TABLE\b/i.test(sql));
@@ -898,7 +908,8 @@ var REPLACEABLE_NAME = {
898
908
  policy: (sql) => policyLabel(sql),
899
909
  // `schema.table.trigger`, for the same reason.
900
910
  trigger: (sql) => triggerLabel(sql),
901
- view: (sql) => extractQualifiedName(sql, AFTER.view)
911
+ view: (sql) => extractQualifiedName(sql, AFTER.view),
912
+ collation: (sql) => extractQualifiedName(sql, AFTER.collation)
902
913
  };
903
914
  var REPLACEABLE_REPORT = {
904
915
  routine: { idPart: "function", label: "Function modified", what: "Function body" },
@@ -906,7 +917,8 @@ var REPLACEABLE_REPORT = {
906
917
  sequence: { idPart: "sequence", label: "Sequence modified", what: "Sequence definition" },
907
918
  policy: { idPart: "policy", label: "Policy modified", what: "Policy definition" },
908
919
  trigger: { idPart: "trigger", label: "Trigger modified", what: "Trigger definition" },
909
- view: { idPart: "view", label: "View modified", what: "View definition" }
920
+ view: { idPart: "view", label: "View modified", what: "View definition" },
921
+ collation: { idPart: "collation", label: "Collation modified", what: "Collation definition" }
910
922
  };
911
923
  function replaceablePart(sql) {
912
924
  if (/^\s*DROP\s+POLICY\b/i.test(sql)) return { kind: "policy", drop: true };
@@ -928,6 +940,10 @@ function replaceablePart(sql) {
928
940
  return { kind: "sequence", drop: false };
929
941
  case "drop-sequence":
930
942
  return { kind: "sequence", drop: true };
943
+ case "create-collation":
944
+ return { kind: "collation", drop: false };
945
+ case "drop-collation":
946
+ return { kind: "collation", drop: true };
931
947
  default:
932
948
  return void 0;
933
949
  }
@@ -1037,45 +1053,7 @@ function hasBrokenRef(sql) {
1037
1053
  }
1038
1054
  function splitStatements(sql) {
1039
1055
  if (!sql) return [];
1040
- const statements = [];
1041
- let buf = "";
1042
- let i = 0;
1043
- while (i < sql.length) {
1044
- if (sql[i] === "$") {
1045
- const tagMatch = sql.slice(i + 1).match(/^([A-Za-z0-9_]*)\$/);
1046
- if (tagMatch) {
1047
- const tag = `$${tagMatch[1]}$`;
1048
- const closeIdx = sql.indexOf(tag, i + tag.length);
1049
- if (closeIdx !== -1) {
1050
- buf += sql.slice(i, closeIdx + tag.length);
1051
- i = closeIdx + tag.length;
1052
- continue;
1053
- }
1054
- }
1055
- }
1056
- if (sql[i] === ";") {
1057
- buf += ";";
1058
- i++;
1059
- let j = i;
1060
- while (j < sql.length && (sql[j] === " " || sql[j] === " " || sql[j] === "\r")) j++;
1061
- if (j >= sql.length || sql[j] === "\n") {
1062
- const stmt = withoutLeadingComments(buf);
1063
- if (stmt.length > 0) {
1064
- statements.push(stmt);
1065
- }
1066
- buf = "";
1067
- i = j < sql.length ? j + 1 : j;
1068
- }
1069
- continue;
1070
- }
1071
- buf += sql[i];
1072
- i++;
1073
- }
1074
- const last = withoutLeadingComments(buf);
1075
- if (last.length > 0) {
1076
- statements.push(last.endsWith(";") ? last : `${last};`);
1077
- }
1078
- return statements;
1056
+ return splitSqlStatements(sql).map((statement) => withoutLeadingComments(statement)).filter((statement) => statement.length > 0).map((statement) => `${statement};`);
1079
1057
  }
1080
1058
  function withoutLeadingComments(chunk) {
1081
1059
  return chunk.trim().replace(/^(?:--[^\n]*(?:\n|$)\s*)+/, "").trim();
@@ -1104,6 +1082,9 @@ function classifyStatement(sql) {
1104
1082
  if (upper.startsWith("DROP TABLE")) return "drop";
1105
1083
  if (upper.startsWith("CREATE INDEX") || upper.startsWith("CREATE UNIQUE INDEX")) return "create-index";
1106
1084
  if (upper.startsWith("DROP INDEX")) return "drop";
1085
+ if (upper.startsWith("CREATE COLLATION")) return "create-collation";
1086
+ if (upper.startsWith("ALTER COLLATION")) return "alter-collation";
1087
+ if (upper.startsWith("DROP COLLATION")) return "drop-collation";
1107
1088
  if (upper.startsWith("CREATE SEQUENCE")) return "create-sequence";
1108
1089
  if (upper.startsWith("ALTER SEQUENCE")) return "alter-sequence";
1109
1090
  if (upper.startsWith("DROP SEQUENCE")) return "drop-sequence";
@@ -1121,6 +1102,7 @@ var AFTER = {
1121
1102
  table: /\bTABLE\s+(?:IF\s+(?:NOT\s+)?EXISTS\s+)?(?:ONLY\s+)?/i,
1122
1103
  index: /\bINDEX\s+(?:CONCURRENTLY\s+)?(?:IF\s+(?:NOT\s+)?EXISTS\s+)?/i,
1123
1104
  policy: /\bPOLICY\s+(?:IF\s+EXISTS\s+)?/i,
1105
+ collation: /\bCOLLATION\s+(?:IF\s+(?:NOT\s+)?EXISTS\s+)?/i,
1124
1106
  on: /\bON\s+(?:ONLY\s+)?/i
1125
1107
  };
1126
1108
  var named = (head) => (sql) => extractQualifiedName(sql, head);
@@ -1193,6 +1175,9 @@ var SCHEMA_RULES = [
1193
1175
  { match: /^\s*COMMENT\s+ON\b/i, label: "Comment changed", name: commentLabel },
1194
1176
  { match: /^\s*CREATE\s+EXTENSION\b/i, label: "Extension missing", name: extensionLabel },
1195
1177
  { match: /^\s*DROP\s+EXTENSION\b/i, label: "Extra extension", name: extensionLabel },
1178
+ { match: /^\s*CREATE\s+COLLATION\b/i, label: "Collation missing", name: named(AFTER.collation) },
1179
+ { match: /^\s*ALTER\s+COLLATION\b/i, label: "Collation altered", name: named(AFTER.collation) },
1180
+ { match: /^\s*DROP\s+COLLATION\b/i, label: "Extra collation", name: named(AFTER.collation) },
1196
1181
  { match: /^\s*CREATE\s+SEQUENCE\b/i, label: "Sequence missing", name: named(AFTER.sequence) },
1197
1182
  { match: /^\s*ALTER\s+SEQUENCE\b/i, label: "Sequence altered", name: named(AFTER.sequence) },
1198
1183
  { match: /^\s*DROP\s+SEQUENCE\b/i, label: "Extra sequence", name: named(AFTER.sequence) }
@@ -1308,4 +1293,4 @@ export {
1308
1293
  destructiveReason,
1309
1294
  sqlToIssues
1310
1295
  };
1311
- //# sourceMappingURL=chunk-BUOWHE36.js.map
1296
+ //# sourceMappingURL=chunk-N5VNNOA2.js.map
@@ -4,16 +4,16 @@ import {
4
4
  applyTableFilter,
5
5
  isComparisonCheck,
6
6
  resolveTableFilter
7
- } from "./chunk-UWAVXC57.js";
7
+ } from "./chunk-DQJSSTIJ.js";
8
8
  import {
9
9
  policyOnlyKeys,
10
10
  runDbDiff,
11
11
  sqlSkeleton,
12
12
  sqlToIssues
13
- } from "./chunk-BUOWHE36.js";
13
+ } from "./chunk-N5VNNOA2.js";
14
14
  import {
15
15
  splitSqlStatements
16
- } from "./chunk-G2DIPIYU.js";
16
+ } from "./chunk-WK5YTINL.js";
17
17
  import {
18
18
  RealtimeCheck,
19
19
  createPolicySql,
@@ -21,13 +21,15 @@ import {
21
21
  diffSchemaPolicies,
22
22
  dropEquivalentPolicyChanges,
23
23
  dropPolicySql,
24
+ httpStatus,
25
+ readJsonArray,
26
+ readJsonObject,
24
27
  schemaPolicySql
25
- } from "./chunk-MIRLB5JM.js";
28
+ } from "./chunk-ICSCHS72.js";
26
29
  import {
27
30
  Check,
28
31
  CheckSkipped,
29
32
  MigrationsCheck,
30
- friendlyDbError,
31
33
  isCheckSkipped,
32
34
  pgQuery,
33
35
  quoteIdent,
@@ -35,7 +37,7 @@ import {
35
37
  quoteName,
36
38
  readOrAbsent,
37
39
  sqlLiteral
38
- } from "./chunk-SQPCWGQO.js";
40
+ } from "./chunk-MG3SFV5J.js";
39
41
  import {
40
42
  DEFAULT_IGNORE_SCHEMAS,
41
43
  SCORE_MAX,
@@ -44,8 +46,9 @@ import {
44
46
  SCORE_PENALTY_INFO,
45
47
  SCORE_PENALTY_WARNING,
46
48
  STORAGE_LIST_LIMIT,
47
- SUPABASE_MGMT_API
48
- } from "./chunk-6WAMNZLO.js";
49
+ SUPABASE_MGMT_API,
50
+ friendlyDbError
51
+ } from "./chunk-KNXHLVF7.js";
49
52
 
50
53
  // src/scoring.ts
51
54
  function summarize(results) {
@@ -625,7 +628,7 @@ async function inventoryFunctionsViaStudio(studioUrl, ref, fetchFn) {
625
628
  if (!listRes.ok) {
626
629
  throw new Error(`Studio functions API returned ${listRes.status} for ${studioUrl}`);
627
630
  }
628
- const listed = await listRes.json();
631
+ const listed = await readJsonArray(listRes, `The Studio functions API at ${studioUrl}`);
629
632
  const out = [];
630
633
  for (const fn of listed) {
631
634
  if (!fn?.slug) continue;
@@ -698,8 +701,8 @@ var EdgeFunctionsCheck = class extends Check {
698
701
  const res = await this.fetchFn(url, {
699
702
  headers: { Authorization: `Bearer ${accessToken}` }
700
703
  });
701
- if (!res.ok) throw new Error(`Failed to list functions for ${projectRef}: ${res.statusText}`);
702
- return res.json();
704
+ if (!res.ok) throw new Error(`Failed to list functions for ${projectRef}: HTTP ${httpStatus(res)}`);
705
+ return readJsonArray(res, `The Edge Function list of ${projectRef}`);
703
706
  }
704
707
  };
705
708
  function makeDeleteAction(slug, targetRef, targetKey) {
@@ -1472,8 +1475,8 @@ var AuthCheck = class extends Check {
1472
1475
  const res = await this.fetchFn(url, {
1473
1476
  headers: { Authorization: `Bearer ${accessToken}` }
1474
1477
  });
1475
- if (!res.ok) throw new Error(`Failed to fetch auth config for ${projectRef}: ${res.statusText}`);
1476
- return res.json();
1478
+ if (!res.ok) throw new Error(`Failed to fetch auth config for ${projectRef}: HTTP ${httpStatus(res)}`);
1479
+ return readJsonObject(res, `The auth config of ${projectRef}`);
1477
1480
  }
1478
1481
  /**
1479
1482
  * GoTrue wants the service-role key in both `apikey` and `Authorization`.
@@ -1484,8 +1487,8 @@ var AuthCheck = class extends Check {
1484
1487
  const res = await this.fetchFn(url, {
1485
1488
  headers: { apikey: serviceKey, Authorization: `Bearer ${serviceKey}` }
1486
1489
  });
1487
- if (!res.ok) throw new Error(`Failed to fetch auth settings from ${apiUrl}: ${res.statusText}`);
1488
- const raw = await res.json();
1490
+ if (!res.ok) throw new Error(`Failed to fetch auth settings from ${apiUrl}: HTTP ${httpStatus(res)}`);
1491
+ const raw = await readJsonObject(res, `The auth settings at ${apiUrl}`);
1489
1492
  return normalizeGoTrueSettings(raw);
1490
1493
  }
1491
1494
  };
@@ -2070,4 +2073,4 @@ export {
2070
2073
  CheckRegistry,
2071
2074
  createDefaultRegistry
2072
2075
  };
2073
- //# sourceMappingURL=chunk-3HGAV5CC.js.map
2076
+ //# sourceMappingURL=chunk-OB5GP7UB.js.map
@@ -1,23 +1,23 @@
1
1
  import {
2
2
  sanitizeForReport
3
- } from "./chunk-6Q7MHFBM.js";
3
+ } from "./chunk-HNJ6BNNZ.js";
4
4
  import {
5
5
  coverage,
6
6
  formatSkips,
7
7
  renderDetailed,
8
8
  renderSummary
9
- } from "./chunk-GEHPTPNZ.js";
9
+ } from "./chunk-7DL63NWP.js";
10
10
  import {
11
11
  createDefaultRegistry,
12
12
  scan,
13
13
  summarizeByKind
14
- } from "./chunk-3HGAV5CC.js";
14
+ } from "./chunk-OB5GP7UB.js";
15
15
  import {
16
16
  comparedSchemas,
17
17
  proofScope,
18
18
  proveConvergence,
19
19
  residualHeldBack
20
- } from "./chunk-DMIWAJRB.js";
20
+ } from "./chunk-3WKWPSFN.js";
21
21
  import {
22
22
  CHECK_META,
23
23
  CHECK_NAMES,
@@ -26,35 +26,35 @@ import {
26
26
  planWork,
27
27
  promote,
28
28
  resolveTableFilter
29
- } from "./chunk-UWAVXC57.js";
29
+ } from "./chunk-DQJSSTIJ.js";
30
30
  import {
31
31
  renderTip
32
- } from "./chunk-BLKJWDTL.js";
32
+ } from "./chunk-ZI435CAU.js";
33
33
  import {
34
34
  BaseCommand
35
- } from "./chunk-GZREXCQZ.js";
35
+ } from "./chunk-5STH2A6K.js";
36
36
  import {
37
37
  isCloneDatabase,
38
38
  sourceLooksLikeCloneOf
39
- } from "./chunk-ORQJVE57.js";
39
+ } from "./chunk-EFKQOQGG.js";
40
40
  import {
41
41
  parseFlagList
42
42
  } from "./chunk-DQQ5E563.js";
43
43
  import {
44
- Preflight,
45
- describeFailure,
46
- redactUrls
47
- } from "./chunk-SQPCWGQO.js";
44
+ Preflight
45
+ } from "./chunk-MG3SFV5J.js";
48
46
  import {
49
47
  CLONE_SKIP_FLAGS,
50
48
  DEFAULT_IGNORE_SCHEMAS,
51
49
  bold,
52
50
  cmd,
51
+ describeFailure,
53
52
  dim,
54
53
  ok,
54
+ redactUrls,
55
55
  schemaDiffIgnores,
56
56
  warn
57
- } from "./chunk-6WAMNZLO.js";
57
+ } from "./chunk-KNXHLVF7.js";
58
58
 
59
59
  // src/commands/diff.ts
60
60
  import { Flags } from "@oclif/core";
@@ -143,6 +143,13 @@ var APPLY_ONLY_FLAGS = [
143
143
  { flag: "apply-posture", shapesThePlan: true },
144
144
  { flag: "allow-destructive", shapesThePlan: true }
145
145
  ];
146
+ function rollbackHint(errors) {
147
+ const replacing = errors.filter((e) => /-alter-(?:view|type)-\d+$/.test(e.issueId) || /depend(?:s)? on it|\b2BP01\b/i.test(e.error));
148
+ if (replacing.length > 0) {
149
+ return `Nothing was written. ${replacing.map((e) => e.issueId).join(", ")} replaces an object others depend on, so the other fixes were not applied without it: fix the cause above, or leave it out with ${cmd("--only")}.`;
150
+ }
151
+ return `Nothing was written. Re-run with ${cmd("--no-transaction")} to apply the fixes that do work.`;
152
+ }
146
153
  function inertApplyFlags(flags) {
147
154
  if (flags["apply"]) return [];
148
155
  const dryRun = Boolean(flags["dry-run"]);
@@ -299,7 +306,7 @@ ${warn(`${result.errors.length} error(s):`)}`);
299
306
  }
300
307
  if (result.rolledBack) {
301
308
  this.log(`
302
- ${dim(`Nothing was written. Re-run with ${cmd("--no-transaction")} to apply the fixes that do work.`)}`);
309
+ ${dim(rollbackHint(result.errors))}`);
303
310
  }
304
311
  }
305
312
  if (dryRun) {
@@ -626,7 +633,8 @@ function stripError(c) {
626
633
  }
627
634
 
628
635
  export {
636
+ rollbackHint,
629
637
  inertApplyFlags,
630
638
  Diff
631
639
  };
632
- //# sourceMappingURL=chunk-4IVN7QVY.js.map
640
+ //# sourceMappingURL=chunk-PYAGSMFB.js.map
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  pgQuery,
3
3
  readLocalMigrations
4
- } from "./chunk-SQPCWGQO.js";
4
+ } from "./chunk-MG3SFV5J.js";
5
5
  import {
6
6
  MIGRATIONS_SCHEMA,
7
7
  MIGRATIONS_TABLE
8
- } from "./chunk-6WAMNZLO.js";
8
+ } from "./chunk-KNXHLVF7.js";
9
9
 
10
10
  // src/migrate.ts
11
11
  import { readFile } from "fs/promises";
@@ -119,4 +119,4 @@ export {
119
119
  runMigration,
120
120
  baselineMigrations
121
121
  };
122
- //# sourceMappingURL=chunk-SC2XHGIS.js.map
122
+ //# sourceMappingURL=chunk-S5L4A3UR.js.map
@@ -3,25 +3,23 @@ import {
3
3
  getAppliedVersions,
4
4
  getPendingMigrations,
5
5
  runMigration
6
- } from "./chunk-SC2XHGIS.js";
6
+ } from "./chunk-S5L4A3UR.js";
7
7
  import {
8
8
  isDestructiveSql
9
- } from "./chunk-BUOWHE36.js";
9
+ } from "./chunk-N5VNNOA2.js";
10
10
  import {
11
11
  splitSqlStatements
12
- } from "./chunk-G2DIPIYU.js";
12
+ } from "./chunk-WK5YTINL.js";
13
13
  import {
14
14
  BaseCommand
15
- } from "./chunk-GZREXCQZ.js";
16
- import {
17
- errMsg
18
- } from "./chunk-SQPCWGQO.js";
15
+ } from "./chunk-5STH2A6K.js";
19
16
  import {
20
17
  bold,
21
18
  dim,
19
+ errMsg,
22
20
  ok,
23
21
  warn
24
- } from "./chunk-6WAMNZLO.js";
22
+ } from "./chunk-KNXHLVF7.js";
25
23
 
26
24
  // src/commands/migrate/run.ts
27
25
  import { Flags } from "@oclif/core";
@@ -153,4 +151,4 @@ export {
153
151
  findDestructiveStatements,
154
152
  truncateSql
155
153
  };
156
- //# sourceMappingURL=chunk-2SELREHW.js.map
154
+ //# sourceMappingURL=chunk-TPX2MAO4.js.map
@@ -1,19 +1,19 @@
1
1
  import {
2
2
  isCommentOnly,
3
3
  splitSqlStatements
4
- } from "./chunk-G2DIPIYU.js";
4
+ } from "./chunk-WK5YTINL.js";
5
5
  import {
6
6
  captureSnapshot,
7
7
  findLatestSnapshot,
8
8
  loadSnapshot
9
- } from "./chunk-MIRLB5JM.js";
9
+ } from "./chunk-ICSCHS72.js";
10
10
  import {
11
11
  slugify
12
12
  } from "./chunk-DQQ5E563.js";
13
13
  import {
14
14
  MIGRATIONS_SUBDIR,
15
15
  SUPAFORGE_DIR
16
- } from "./chunk-6WAMNZLO.js";
16
+ } from "./chunk-KNXHLVF7.js";
17
17
 
18
18
  // src/migration.ts
19
19
  import { mkdir, writeFile, readFile, readdir } from "fs/promises";
@@ -245,4 +245,4 @@ export {
245
245
  loadMigrations,
246
246
  listMigrationFiles
247
247
  };
248
- //# sourceMappingURL=chunk-NTUASFQ3.js.map
248
+ //# sourceMappingURL=chunk-V2SBZERO.js.map