@akal/supaforge 0.0.36 → 0.0.38
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/README.md +12 -7
- package/dist/{chunk-YUJ2MHLM.js → chunk-2HJPUDPP.js} +762 -14
- package/dist/{chunk-M2564IGT.js → chunk-35TXJGDQ.js} +50 -71
- package/dist/chunk-5RMEQPPU.js +27 -0
- package/dist/{chunk-MZPWRWBL.js → chunk-64S3EP7Y.js} +171 -145
- package/dist/{chunk-JX5L253P.js → chunk-EETO4RJO.js} +4 -6
- package/dist/chunk-EHJWKKFL.js +94 -0
- package/dist/{chunk-CCB7ARZU.js → chunk-FBYONIJS.js} +6 -26
- package/dist/{chunk-MRXIE55Y.js → chunk-LJY3AK2P.js} +2 -2
- package/dist/{chunk-CAQ3QQFP.js → chunk-PE5PENCB.js} +48 -4
- package/dist/commands/diff.js +4 -5
- package/dist/commands/hukam.js +4 -5
- package/dist/commands/mcp.js +5 -4
- package/dist/commands/migrate/create.d.ts +3 -2
- package/dist/commands/migrate/create.js +12 -75
- package/dist/commands/migrate/run.js +3 -3
- package/dist/commands/restore.js +2 -3
- package/dist/commands/sync.js +4 -5
- package/dist/index.js +7 -6
- package/package.json +2 -2
- package/dist/chunk-GGZ7YWBZ.js +0 -761
|
@@ -5,22 +5,20 @@ import {
|
|
|
5
5
|
ensureMigrationsTable,
|
|
6
6
|
getAppliedVersions
|
|
7
7
|
} from "./chunk-AL6INEFX.js";
|
|
8
|
-
import {
|
|
9
|
-
dropUnsupportedSetStatements,
|
|
10
|
-
knownParameters
|
|
11
|
-
} from "./chunk-GGZ7YWBZ.js";
|
|
12
8
|
import {
|
|
13
9
|
ABSENT_ON_TARGET,
|
|
14
10
|
EXTENSION_UNAVAILABLE,
|
|
15
11
|
OLDER_SERVER,
|
|
16
12
|
PLATFORM_ROLES,
|
|
13
|
+
dropUnsupportedSetStatements,
|
|
17
14
|
estimateLocks,
|
|
15
|
+
knownParameters,
|
|
18
16
|
lockBudgetWarning,
|
|
19
17
|
readLockBudget,
|
|
20
18
|
rolesNamedBy,
|
|
21
19
|
sqlSkeleton,
|
|
22
20
|
statementSubject
|
|
23
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-2HJPUDPP.js";
|
|
24
22
|
import {
|
|
25
23
|
isCommentOnly,
|
|
26
24
|
isPsqlMetaCommand,
|
|
@@ -902,4 +900,4 @@ export {
|
|
|
902
900
|
previewMigrationRestore,
|
|
903
901
|
summarizeStatement
|
|
904
902
|
};
|
|
905
|
-
//# sourceMappingURL=chunk-
|
|
903
|
+
//# sourceMappingURL=chunk-EETO4RJO.js.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
targetFingerprint,
|
|
3
|
+
writtenAgainstLine
|
|
4
|
+
} from "./chunk-5RMEQPPU.js";
|
|
5
|
+
import {
|
|
6
|
+
RolesCheck,
|
|
7
|
+
isDestructiveSql,
|
|
8
|
+
runDbDiff
|
|
9
|
+
} from "./chunk-2HJPUDPP.js";
|
|
10
|
+
import {
|
|
11
|
+
splitSqlStatements
|
|
12
|
+
} from "./chunk-WK5YTINL.js";
|
|
13
|
+
import {
|
|
14
|
+
slugify
|
|
15
|
+
} from "./chunk-Z2YUOA4W.js";
|
|
16
|
+
import {
|
|
17
|
+
DEFAULT_MIGRATIONS_DIR,
|
|
18
|
+
pgQuery
|
|
19
|
+
} from "./chunk-KT7NMELZ.js";
|
|
20
|
+
import {
|
|
21
|
+
DEFAULT_IGNORE_SCHEMAS
|
|
22
|
+
} from "./chunk-SQ52YBKK.js";
|
|
23
|
+
|
|
24
|
+
// src/migration-file.ts
|
|
25
|
+
import { writeFile, mkdir } from "fs/promises";
|
|
26
|
+
import { join, resolve } from "path";
|
|
27
|
+
function migrationsDir(config, cwd = process.cwd()) {
|
|
28
|
+
return resolve(cwd, config.checks?.migrations?.dir ?? DEFAULT_MIGRATIONS_DIR);
|
|
29
|
+
}
|
|
30
|
+
async function writeMigrationFile(opts) {
|
|
31
|
+
const { config, name, dir } = opts;
|
|
32
|
+
const sourceEnv = config.environments[config.source];
|
|
33
|
+
const targetEnv = config.environments[config.target];
|
|
34
|
+
const ignoreSchemas = config.ignoreSchemas ?? DEFAULT_IGNORE_SCHEMAS;
|
|
35
|
+
const result = await runDbDiff({
|
|
36
|
+
sourceUrl: sourceEnv.dbUrl,
|
|
37
|
+
targetUrl: targetEnv.dbUrl,
|
|
38
|
+
type: "schema",
|
|
39
|
+
include: "both",
|
|
40
|
+
ignoreSchemas
|
|
41
|
+
});
|
|
42
|
+
const grants = (await new RolesCheck(pgQuery, { explicit: true }).scan({
|
|
43
|
+
source: sourceEnv,
|
|
44
|
+
target: targetEnv,
|
|
45
|
+
config
|
|
46
|
+
})).filter((i) => i.id.startsWith("roles-grant-") && i.sql?.up);
|
|
47
|
+
if (!result.up.trim() && grants.length === 0) return { destructive: [] };
|
|
48
|
+
const destructive = splitSqlStatements(result.up).filter(isDestructiveSql);
|
|
49
|
+
const digest = await targetFingerprint(targetEnv.dbUrl, ignoreSchemas).catch(() => void 0);
|
|
50
|
+
const lines = [
|
|
51
|
+
`-- Migration: ${name}`,
|
|
52
|
+
`-- Generated by supaforge migrate create`,
|
|
53
|
+
`-- Source: ${config.source} \u2192 Target: ${config.target}`,
|
|
54
|
+
...digest ? [writtenAgainstLine(config.target, digest)] : [],
|
|
55
|
+
...destructive.length > 0 ? [`-- WARNING: ${destructive.length} destructive statement(s) \u2014 drops or deletes data. Review before running.`] : [],
|
|
56
|
+
"",
|
|
57
|
+
result.up,
|
|
58
|
+
...grants.length > 0 ? ["", "-- Grants", ...grants.map((i) => i.sql.up)] : []
|
|
59
|
+
];
|
|
60
|
+
if (result.down.trim() || grants.length > 0) {
|
|
61
|
+
lines.push(
|
|
62
|
+
"",
|
|
63
|
+
"-- ==================== DOWN ====================",
|
|
64
|
+
"-- To revert this migration, run the SQL below manually:",
|
|
65
|
+
"--",
|
|
66
|
+
...[...grants.map((i) => i.sql?.down ?? "").filter(Boolean).reverse(), result.down].join("\n").split("\n").map((l) => `-- ${l}`)
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
await mkdir(dir, { recursive: true });
|
|
70
|
+
const filePath = join(dir, `${generateTimestamp()}_${slugify(name)}.sql`);
|
|
71
|
+
await writeFile(filePath, lines.join("\n") + "\n", "utf8");
|
|
72
|
+
return { filePath, destructive };
|
|
73
|
+
}
|
|
74
|
+
function generateTimestamp() {
|
|
75
|
+
const now = /* @__PURE__ */ new Date();
|
|
76
|
+
return [
|
|
77
|
+
now.getUTCFullYear(),
|
|
78
|
+
pad(now.getUTCMonth() + 1),
|
|
79
|
+
pad(now.getUTCDate()),
|
|
80
|
+
pad(now.getUTCHours()),
|
|
81
|
+
pad(now.getUTCMinutes()),
|
|
82
|
+
pad(now.getUTCSeconds())
|
|
83
|
+
].join("");
|
|
84
|
+
}
|
|
85
|
+
function pad(n) {
|
|
86
|
+
return String(n).padStart(2, "0");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export {
|
|
90
|
+
migrationsDir,
|
|
91
|
+
writeMigrationFile,
|
|
92
|
+
generateTimestamp
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=chunk-EHJWKKFL.js.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
targetFingerprint,
|
|
3
|
+
writtenAgainst
|
|
4
|
+
} from "./chunk-5RMEQPPU.js";
|
|
1
5
|
import {
|
|
2
6
|
ensureMigrationsTable,
|
|
3
7
|
getAppliedVersions,
|
|
4
8
|
getPendingMigrations,
|
|
5
9
|
runMigration
|
|
6
10
|
} from "./chunk-AL6INEFX.js";
|
|
7
|
-
import {
|
|
8
|
-
comparedSchemas,
|
|
9
|
-
fingerprint
|
|
10
|
-
} from "./chunk-GGZ7YWBZ.js";
|
|
11
11
|
import {
|
|
12
12
|
isDestructiveSql
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-2HJPUDPP.js";
|
|
14
14
|
import {
|
|
15
15
|
splitSqlStatements
|
|
16
16
|
} from "./chunk-WK5YTINL.js";
|
|
@@ -29,24 +29,6 @@ import {
|
|
|
29
29
|
// src/commands/migrate/run.ts
|
|
30
30
|
import { Flags } from "@oclif/core";
|
|
31
31
|
import { readFile } from "fs/promises";
|
|
32
|
-
|
|
33
|
-
// src/written-against.ts
|
|
34
|
-
import { createHash } from "crypto";
|
|
35
|
-
var WRITTEN_AGAINST = "-- supaforge:written-against";
|
|
36
|
-
async function targetFingerprint(dbUrl, ignoreSchemas) {
|
|
37
|
-
const schemas = await comparedSchemas(dbUrl, dbUrl, ignoreSchemas);
|
|
38
|
-
return createHash("sha256").update(await fingerprint(dbUrl, schemas)).digest("hex").slice(0, 16);
|
|
39
|
-
}
|
|
40
|
-
function writtenAgainstLine(env, digest) {
|
|
41
|
-
return `${WRITTEN_AGAINST} ${env} ${digest}`;
|
|
42
|
-
}
|
|
43
|
-
function writtenAgainst(sql) {
|
|
44
|
-
const line = sql.split("\n").find((l) => l.startsWith(WRITTEN_AGAINST + " "));
|
|
45
|
-
const [env, digest] = line?.slice(WRITTEN_AGAINST.length + 1).trim().split(/\s+/) ?? [];
|
|
46
|
-
return env && digest ? { env, digest } : void 0;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// src/commands/migrate/run.ts
|
|
50
32
|
var MigrateRun = class _MigrateRun extends BaseCommand {
|
|
51
33
|
static description = "Execute pending migrations against a Supabase environment";
|
|
52
34
|
static examples = [
|
|
@@ -194,10 +176,8 @@ function truncateSql(sql) {
|
|
|
194
176
|
}
|
|
195
177
|
|
|
196
178
|
export {
|
|
197
|
-
targetFingerprint,
|
|
198
|
-
writtenAgainstLine,
|
|
199
179
|
MigrateRun,
|
|
200
180
|
findDestructiveStatements,
|
|
201
181
|
truncateSql
|
|
202
182
|
};
|
|
203
|
-
//# sourceMappingURL=chunk-
|
|
183
|
+
//# sourceMappingURL=chunk-FBYONIJS.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CHECK_META,
|
|
3
3
|
isComparisonCheck
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-2HJPUDPP.js";
|
|
5
5
|
import {
|
|
6
6
|
CHECK_LINE_PADDING,
|
|
7
7
|
bold,
|
|
@@ -241,4 +241,4 @@ export {
|
|
|
241
241
|
renderDetailed,
|
|
242
242
|
formatSkips
|
|
243
243
|
};
|
|
244
|
-
//# sourceMappingURL=chunk-
|
|
244
|
+
//# sourceMappingURL=chunk-LJY3AK2P.js.map
|
|
@@ -2,18 +2,23 @@ import {
|
|
|
2
2
|
CHECK_NAMES,
|
|
3
3
|
RolesCheck,
|
|
4
4
|
applyTableFilter,
|
|
5
|
+
comparedSchemas,
|
|
5
6
|
destructiveReason,
|
|
6
7
|
isComparisonCheck,
|
|
7
8
|
parseStatements,
|
|
9
|
+
planWork,
|
|
8
10
|
policyOnlyKeys,
|
|
11
|
+
proofScope,
|
|
12
|
+
proveConvergence,
|
|
9
13
|
relationName,
|
|
14
|
+
residualHeldBack,
|
|
10
15
|
resolveTableFilter,
|
|
11
16
|
runDbDiff,
|
|
12
17
|
schemaNotices,
|
|
13
18
|
sqlSkeleton,
|
|
14
19
|
sqlToIssues,
|
|
15
20
|
withoutAbsentRoles
|
|
16
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-2HJPUDPP.js";
|
|
17
22
|
import {
|
|
18
23
|
splitSqlStatements
|
|
19
24
|
} from "./chunk-WK5YTINL.js";
|
|
@@ -53,7 +58,8 @@ import {
|
|
|
53
58
|
SCORE_PENALTY_WARNING,
|
|
54
59
|
STORAGE_LIST_LIMIT,
|
|
55
60
|
SUPABASE_MGMT_API,
|
|
56
|
-
friendlyDbError
|
|
61
|
+
friendlyDbError,
|
|
62
|
+
schemaDiffIgnores
|
|
57
63
|
} from "./chunk-SQ52YBKK.js";
|
|
58
64
|
|
|
59
65
|
// src/scoring.ts
|
|
@@ -2457,12 +2463,50 @@ function createDefaultRegistry(options = {}) {
|
|
|
2457
2463
|
return registry;
|
|
2458
2464
|
}
|
|
2459
2465
|
|
|
2466
|
+
// src/prove-gate.ts
|
|
2467
|
+
async function proveBeforeApply(opts) {
|
|
2468
|
+
const { scanResult, sourceUrl, targetUrl } = opts;
|
|
2469
|
+
const planned = planWork(scanResult, opts.plan);
|
|
2470
|
+
const { replay, unproved } = proofScope(planned.sqlStatements);
|
|
2471
|
+
const proof = replay.length === 0 ? { converged: false, residual: [], cloneName: "", skipped: "none of the planned fixes is one the proof can replay" } : await proveConvergence({
|
|
2472
|
+
sourceUrl,
|
|
2473
|
+
targetUrl,
|
|
2474
|
+
migrationSql: replay.map((s) => s.sql).join("\n"),
|
|
2475
|
+
fixes: replay,
|
|
2476
|
+
// Every schema the schema diff compares, not `public` alone: a migration
|
|
2477
|
+
// dropping a schema the source lacks runs against it.
|
|
2478
|
+
schemas: await comparedSchemas(sourceUrl, targetUrl, schemaDiffIgnores(opts.ignoreSchemas ?? DEFAULT_IGNORE_SCHEMAS)),
|
|
2479
|
+
// The checks this run compares: without the schema check, what the
|
|
2480
|
+
// target already lacks elsewhere is not this migration's to fix.
|
|
2481
|
+
checks: scanResult.checks.map((c) => c.check)
|
|
2482
|
+
});
|
|
2483
|
+
const base2 = {
|
|
2484
|
+
outOfScope: proof.outOfScope ?? [],
|
|
2485
|
+
unproved,
|
|
2486
|
+
notApplied: proof.notApplied ?? [],
|
|
2487
|
+
...proof.data && !proof.skipped ? { data: proof.data } : {}
|
|
2488
|
+
};
|
|
2489
|
+
if (proof.skipped && replay.length === 0) {
|
|
2490
|
+
return { ...base2, proceed: true, verdict: "nothing-to-prove", reason: proof.skipped, residual: [] };
|
|
2491
|
+
}
|
|
2492
|
+
if (proof.skipped) return { ...base2, proceed: false, verdict: "not-proven", reason: proof.skipped, residual: [] };
|
|
2493
|
+
if (proof.converged) return { ...base2, proceed: true, verdict: "converged", residual: [] };
|
|
2494
|
+
const heldBack = [...heldBackSql(scanResult, planned), ...base2.notApplied.map((n) => n.sql)];
|
|
2495
|
+
const { unexplained } = residualHeldBack(proof.residual, heldBack);
|
|
2496
|
+
return unexplained.length === 0 ? { ...base2, proceed: true, verdict: "converged-apart-from-held-back", residual: proof.residual } : { ...base2, proceed: false, verdict: "diverged", residual: unexplained };
|
|
2497
|
+
}
|
|
2498
|
+
function heldBackSql(scanResult, planned) {
|
|
2499
|
+
const skipped = new Set(planned.skipped.map((s) => s.issueId));
|
|
2500
|
+
return scanResult.checks.flatMap((c) => c.issues).filter((i) => skipped.has(i.id) && i.sql?.up).map((i) => i.sql.up);
|
|
2501
|
+
}
|
|
2502
|
+
|
|
2460
2503
|
export {
|
|
2461
2504
|
summarize,
|
|
2462
2505
|
summarizeByKind,
|
|
2463
2506
|
computeScore,
|
|
2464
2507
|
scan,
|
|
2465
2508
|
CheckRegistry,
|
|
2466
|
-
createDefaultRegistry
|
|
2509
|
+
createDefaultRegistry,
|
|
2510
|
+
proveBeforeApply
|
|
2467
2511
|
};
|
|
2468
|
-
//# sourceMappingURL=chunk-
|
|
2512
|
+
//# sourceMappingURL=chunk-PE5PENCB.js.map
|
package/dist/commands/diff.js
CHANGED
|
@@ -2,12 +2,11 @@ import {
|
|
|
2
2
|
Diff,
|
|
3
3
|
inertApplyFlags,
|
|
4
4
|
rollbackHint
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-35TXJGDQ.js";
|
|
6
6
|
import "../chunk-Q43MN6NE.js";
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-YUJ2MHLM.js";
|
|
7
|
+
import "../chunk-LJY3AK2P.js";
|
|
8
|
+
import "../chunk-PE5PENCB.js";
|
|
9
|
+
import "../chunk-2HJPUDPP.js";
|
|
11
10
|
import "../chunk-WK5YTINL.js";
|
|
12
11
|
import "../chunk-RQCXGO37.js";
|
|
13
12
|
import "../chunk-OXS42LJH.js";
|
package/dist/commands/hukam.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Diff
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-35TXJGDQ.js";
|
|
4
4
|
import "../chunk-Q43MN6NE.js";
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-YUJ2MHLM.js";
|
|
5
|
+
import "../chunk-LJY3AK2P.js";
|
|
6
|
+
import "../chunk-PE5PENCB.js";
|
|
7
|
+
import "../chunk-2HJPUDPP.js";
|
|
9
8
|
import "../chunk-WK5YTINL.js";
|
|
10
9
|
import "../chunk-RQCXGO37.js";
|
|
11
10
|
import "../chunk-OXS42LJH.js";
|
package/dist/commands/mcp.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createServer
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-64S3EP7Y.js";
|
|
4
|
+
import "../chunk-EHJWKKFL.js";
|
|
5
|
+
import "../chunk-5RMEQPPU.js";
|
|
6
|
+
import "../chunk-PE5PENCB.js";
|
|
7
|
+
import "../chunk-2HJPUDPP.js";
|
|
7
8
|
import "../chunk-WK5YTINL.js";
|
|
8
9
|
import "../chunk-5UHIWFQG.js";
|
|
9
10
|
import "../chunk-Z2YUOA4W.js";
|
|
@@ -12,6 +12,9 @@ import '../../config-l3ggjw9r.js';
|
|
|
12
12
|
*/
|
|
13
13
|
declare function slugify(name: string, separator?: string): string;
|
|
14
14
|
|
|
15
|
+
/** Generate a UTC timestamp in Supabase migration format: YYYYMMDDHHmmss */
|
|
16
|
+
declare function generateTimestamp(): string;
|
|
17
|
+
|
|
15
18
|
/**
|
|
16
19
|
* Generate a new migration file from the current schema drift.
|
|
17
20
|
*
|
|
@@ -30,7 +33,5 @@ declare class MigrateCreate extends BaseCommand {
|
|
|
30
33
|
};
|
|
31
34
|
run(): Promise<void>;
|
|
32
35
|
}
|
|
33
|
-
/** Generate a UTC timestamp in Supabase migration format: YYYYMMDDHHmmss */
|
|
34
|
-
declare function generateTimestamp(): string;
|
|
35
36
|
|
|
36
37
|
export { MigrateCreate as default, generateTimestamp, slugify };
|
|
@@ -1,30 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
writtenAgainstLine
|
|
5
|
-
} from "../../chunk-CCB7ARZU.js";
|
|
6
|
-
import "../../chunk-AL6INEFX.js";
|
|
7
|
-
import "../../chunk-GGZ7YWBZ.js";
|
|
8
|
-
import {
|
|
9
|
-
RolesCheck,
|
|
10
|
-
isDestructiveSql,
|
|
11
|
-
runDbDiff
|
|
12
|
-
} from "../../chunk-YUJ2MHLM.js";
|
|
2
|
+
truncateSql
|
|
3
|
+
} from "../../chunk-FBYONIJS.js";
|
|
13
4
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
generateTimestamp,
|
|
6
|
+
writeMigrationFile
|
|
7
|
+
} from "../../chunk-EHJWKKFL.js";
|
|
8
|
+
import "../../chunk-5RMEQPPU.js";
|
|
9
|
+
import "../../chunk-AL6INEFX.js";
|
|
10
|
+
import "../../chunk-2HJPUDPP.js";
|
|
11
|
+
import "../../chunk-WK5YTINL.js";
|
|
16
12
|
import {
|
|
17
13
|
BaseCommand
|
|
18
14
|
} from "../../chunk-OXS42LJH.js";
|
|
19
15
|
import {
|
|
20
16
|
slugify
|
|
21
17
|
} from "../../chunk-Z2YUOA4W.js";
|
|
22
|
-
import
|
|
23
|
-
pgQuery
|
|
24
|
-
} from "../../chunk-KT7NMELZ.js";
|
|
18
|
+
import "../../chunk-KT7NMELZ.js";
|
|
25
19
|
import "../../chunk-KHXEES2M.js";
|
|
26
20
|
import {
|
|
27
|
-
DEFAULT_IGNORE_SCHEMAS,
|
|
28
21
|
bold,
|
|
29
22
|
cmd,
|
|
30
23
|
dim,
|
|
@@ -33,8 +26,6 @@ import {
|
|
|
33
26
|
} from "../../chunk-SQ52YBKK.js";
|
|
34
27
|
|
|
35
28
|
// src/commands/migrate/create.ts
|
|
36
|
-
import { writeFile, mkdir } from "fs/promises";
|
|
37
|
-
import { join } from "path";
|
|
38
29
|
import { Flags } from "@oclif/core";
|
|
39
30
|
var MigrateCreate = class _MigrateCreate extends BaseCommand {
|
|
40
31
|
static description = "Generate a new migration file from schema drift between environments";
|
|
@@ -58,55 +49,15 @@ var MigrateCreate = class _MigrateCreate extends BaseCommand {
|
|
|
58
49
|
const sourceEnv = config.environments[config.source];
|
|
59
50
|
const targetEnv = config.environments[config.target];
|
|
60
51
|
const dir = this.resolveMigrationsDir(config);
|
|
61
|
-
const ignoreSchemas = config.ignoreSchemas ?? DEFAULT_IGNORE_SCHEMAS;
|
|
62
52
|
const pre = this.createPreflight("Migrate create preflight checks").addDatabase("Source", config.source, sourceEnv.dbUrl).addDatabase("Target", config.target, targetEnv.dbUrl);
|
|
63
53
|
await this.runPreflight(pre, "Migrate create");
|
|
64
54
|
this.log(`${bold("migrate create")} \u2014 diffing ${dim(config.source)} \u2192 ${dim(config.target)}
|
|
65
55
|
`);
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
targetUrl: targetEnv.dbUrl,
|
|
69
|
-
type: "schema",
|
|
70
|
-
include: "both",
|
|
71
|
-
ignoreSchemas
|
|
72
|
-
});
|
|
73
|
-
const grants = (await new RolesCheck(pgQuery, { explicit: true }).scan({
|
|
74
|
-
source: sourceEnv,
|
|
75
|
-
target: targetEnv,
|
|
76
|
-
config
|
|
77
|
-
})).filter((i) => i.id.startsWith("roles-grant-") && i.sql?.up);
|
|
78
|
-
if (!result.up.trim() && grants.length === 0) {
|
|
56
|
+
const { filePath, destructive } = await writeMigrationFile({ config, name: flags.name, dir });
|
|
57
|
+
if (!filePath) {
|
|
79
58
|
this.log(`${ok("No schema drift detected.")} Nothing to write. \u2713`);
|
|
80
59
|
return;
|
|
81
60
|
}
|
|
82
|
-
const timestamp = generateTimestamp();
|
|
83
|
-
const slug = slugify(flags.name);
|
|
84
|
-
const filename = `${timestamp}_${slug}.sql`;
|
|
85
|
-
const destructive = splitSqlStatements(result.up).filter(isDestructiveSql);
|
|
86
|
-
const digest = await targetFingerprint(targetEnv.dbUrl, ignoreSchemas).catch(() => void 0);
|
|
87
|
-
const lines = [
|
|
88
|
-
`-- Migration: ${flags.name}`,
|
|
89
|
-
`-- Generated by supaforge migrate create`,
|
|
90
|
-
`-- Source: ${config.source} \u2192 Target: ${config.target}`,
|
|
91
|
-
...digest ? [writtenAgainstLine(config.target, digest)] : [],
|
|
92
|
-
...destructive.length > 0 ? [`-- WARNING: ${destructive.length} destructive statement(s) \u2014 drops or deletes data. Review before running.`] : [],
|
|
93
|
-
"",
|
|
94
|
-
result.up,
|
|
95
|
-
...grants.length > 0 ? ["", "-- Grants", ...grants.map((i) => i.sql.up)] : []
|
|
96
|
-
];
|
|
97
|
-
if (result.down.trim() || grants.length > 0) {
|
|
98
|
-
lines.push(
|
|
99
|
-
"",
|
|
100
|
-
"-- ==================== DOWN ====================",
|
|
101
|
-
"-- To revert this migration, run the SQL below manually:",
|
|
102
|
-
"--",
|
|
103
|
-
...[...grants.map((i) => i.sql?.down ?? "").filter(Boolean).reverse(), result.down].join("\n").split("\n").map((l) => `-- ${l}`)
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
const content = lines.join("\n") + "\n";
|
|
107
|
-
await mkdir(dir, { recursive: true });
|
|
108
|
-
const filePath = join(dir, filename);
|
|
109
|
-
await writeFile(filePath, content, "utf8");
|
|
110
61
|
this.log(`${ok("Created migration:")} ${cmd(filePath)}`);
|
|
111
62
|
if (destructive.length > 0) {
|
|
112
63
|
this.log(`
|
|
@@ -120,20 +71,6 @@ ${warn(`${destructive.length} destructive statement(s) in it`)} ${dim("\u2014 th
|
|
|
120
71
|
this.log(` ${dim("To baseline:")} ${cmd(`supaforge migrate baseline --env=${config.target}`)}`);
|
|
121
72
|
}
|
|
122
73
|
};
|
|
123
|
-
function generateTimestamp() {
|
|
124
|
-
const now = /* @__PURE__ */ new Date();
|
|
125
|
-
return [
|
|
126
|
-
now.getUTCFullYear(),
|
|
127
|
-
pad(now.getUTCMonth() + 1),
|
|
128
|
-
pad(now.getUTCDate()),
|
|
129
|
-
pad(now.getUTCHours()),
|
|
130
|
-
pad(now.getUTCMinutes()),
|
|
131
|
-
pad(now.getUTCSeconds())
|
|
132
|
-
].join("");
|
|
133
|
-
}
|
|
134
|
-
function pad(n) {
|
|
135
|
-
return String(n).padStart(2, "0");
|
|
136
|
-
}
|
|
137
74
|
export {
|
|
138
75
|
MigrateCreate as default,
|
|
139
76
|
generateTimestamp,
|
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
MigrateRun,
|
|
3
3
|
findDestructiveStatements,
|
|
4
4
|
truncateSql
|
|
5
|
-
} from "../../chunk-
|
|
5
|
+
} from "../../chunk-FBYONIJS.js";
|
|
6
|
+
import "../../chunk-5RMEQPPU.js";
|
|
6
7
|
import "../../chunk-AL6INEFX.js";
|
|
7
|
-
import "../../chunk-
|
|
8
|
-
import "../../chunk-YUJ2MHLM.js";
|
|
8
|
+
import "../../chunk-2HJPUDPP.js";
|
|
9
9
|
import "../../chunk-WK5YTINL.js";
|
|
10
10
|
import "../../chunk-OXS42LJH.js";
|
|
11
11
|
import "../../chunk-Z2YUOA4W.js";
|
package/dist/commands/restore.js
CHANGED
|
@@ -5,11 +5,10 @@ import {
|
|
|
5
5
|
restoreFromMigrations,
|
|
6
6
|
restoreFromSnapshot,
|
|
7
7
|
summarizeStatement
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-EETO4RJO.js";
|
|
9
9
|
import "../chunk-EWNZIRCD.js";
|
|
10
10
|
import "../chunk-AL6INEFX.js";
|
|
11
|
-
import "../chunk-
|
|
12
|
-
import "../chunk-YUJ2MHLM.js";
|
|
11
|
+
import "../chunk-2HJPUDPP.js";
|
|
13
12
|
import "../chunk-WK5YTINL.js";
|
|
14
13
|
import {
|
|
15
14
|
renderTip
|
package/dist/commands/sync.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Diff
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-35TXJGDQ.js";
|
|
4
4
|
import "../chunk-Q43MN6NE.js";
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-YUJ2MHLM.js";
|
|
5
|
+
import "../chunk-LJY3AK2P.js";
|
|
6
|
+
import "../chunk-PE5PENCB.js";
|
|
7
|
+
import "../chunk-2HJPUDPP.js";
|
|
9
8
|
import "../chunk-WK5YTINL.js";
|
|
10
9
|
import "../chunk-RQCXGO37.js";
|
|
11
10
|
import "../chunk-OXS42LJH.js";
|
package/dist/index.js
CHANGED
|
@@ -3,36 +3,37 @@ import {
|
|
|
3
3
|
createServer,
|
|
4
4
|
getLastScanResult,
|
|
5
5
|
setLastScanResult
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-64S3EP7Y.js";
|
|
7
7
|
import {
|
|
8
8
|
previewMigrationRestore,
|
|
9
9
|
previewSnapshotRestore,
|
|
10
10
|
restoreFromMigrations,
|
|
11
11
|
restoreFromSnapshot
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-EETO4RJO.js";
|
|
13
13
|
import {
|
|
14
14
|
backup,
|
|
15
15
|
listMigrationFiles,
|
|
16
16
|
loadMigrations
|
|
17
17
|
} from "./chunk-EWNZIRCD.js";
|
|
18
|
+
import "./chunk-EHJWKKFL.js";
|
|
19
|
+
import "./chunk-5RMEQPPU.js";
|
|
18
20
|
import "./chunk-AL6INEFX.js";
|
|
19
21
|
import {
|
|
20
22
|
renderDetailed,
|
|
21
23
|
renderSummary
|
|
22
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-LJY3AK2P.js";
|
|
23
25
|
import {
|
|
24
26
|
CheckRegistry,
|
|
25
27
|
computeScore,
|
|
26
28
|
createDefaultRegistry,
|
|
27
29
|
scan,
|
|
28
30
|
summarize
|
|
29
|
-
} from "./chunk-
|
|
30
|
-
import "./chunk-GGZ7YWBZ.js";
|
|
31
|
+
} from "./chunk-PE5PENCB.js";
|
|
31
32
|
import {
|
|
32
33
|
CHECK_META,
|
|
33
34
|
CHECK_NAMES,
|
|
34
35
|
promote
|
|
35
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-2HJPUDPP.js";
|
|
36
37
|
import "./chunk-WK5YTINL.js";
|
|
37
38
|
import {
|
|
38
39
|
BRANCH_DB_PREFIX,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akal/supaforge",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"mcpName": "io.github.akalsoftware/supaforge",
|
|
5
5
|
"description": "Diff and sync your Supabase environments",
|
|
6
6
|
"author": "Akal Software Ltd",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@akal/pg-conformance": "~0.0.16",
|
|
59
|
-
"@dbdiff/cli": "3.0.0-rc.
|
|
59
|
+
"@dbdiff/cli": "3.0.0-rc.31",
|
|
60
60
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
61
61
|
"@oclif/core": "^4",
|
|
62
62
|
"@supabase/supabase-js": "^2.103.0",
|