@akal/supaforge 0.0.31 → 0.0.32
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 +1 -1
- package/dist/base-command.d.ts +1 -0
- package/dist/base-command.js +2 -2
- package/dist/{chunk-BHYLBKYD.js → chunk-2SELREHW.js} +5 -5
- package/dist/{chunk-5Z3SAIQS.js → chunk-3HGAV5CC.js} +97 -831
- package/dist/chunk-3HGAV5CC.js.map +1 -0
- package/dist/{chunk-XMYMIURR.js → chunk-4IVN7QVY.js} +119 -39
- package/dist/chunk-4IVN7QVY.js.map +1 -0
- package/dist/{chunk-NXRSAVRU.js → chunk-6LJERPUN.js} +28 -7
- package/dist/chunk-6LJERPUN.js.map +1 -0
- package/dist/{chunk-4OU7KO5Y.js → chunk-6Q7MHFBM.js} +2 -2
- package/dist/{chunk-PARSNTBD.js → chunk-7NAZGZPV.js} +56 -25
- package/dist/chunk-7NAZGZPV.js.map +1 -0
- package/dist/{chunk-VOXZWQ3N.js → chunk-BUOWHE36.js} +372 -9
- package/dist/chunk-BUOWHE36.js.map +1 -0
- package/dist/{chunk-TQJSQLWA.js → chunk-DMIWAJRB.js} +38 -10
- package/dist/chunk-DMIWAJRB.js.map +1 -0
- package/dist/{chunk-LQXF65MC.js → chunk-GEHPTPNZ.js} +3 -3
- package/dist/chunk-GEHPTPNZ.js.map +1 -0
- package/dist/chunk-GZREXCQZ.js +207 -0
- package/dist/chunk-GZREXCQZ.js.map +1 -0
- package/dist/{chunk-YVDSR4GM.js → chunk-MIRLB5JM.js} +51 -23
- package/dist/chunk-MIRLB5JM.js.map +1 -0
- package/dist/{chunk-KIFJGON5.js → chunk-NTUASFQ3.js} +2 -2
- package/dist/{chunk-5QQBTLWO.js → chunk-ORQJVE57.js} +3 -3
- package/dist/{chunk-VMTBLHN2.js → chunk-SC2XHGIS.js} +2 -2
- package/dist/{chunk-X6V2GGDZ.js → chunk-SQPCWGQO.js} +388 -64
- package/dist/chunk-SQPCWGQO.js.map +1 -0
- package/dist/chunk-UWAVXC57.js +916 -0
- package/dist/chunk-UWAVXC57.js.map +1 -0
- package/dist/commands/clone.js +10 -10
- package/dist/commands/diff.d.ts +16 -0
- package/dist/commands/diff.js +11 -12
- package/dist/commands/hukam.js +11 -12
- package/dist/commands/hukam.js.map +1 -1
- package/dist/commands/mcp.js +7 -8
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/migrate/baseline.js +3 -3
- package/dist/commands/migrate/create.js +5 -6
- package/dist/commands/migrate/create.js.map +1 -1
- package/dist/commands/migrate/list.js +4 -4
- package/dist/commands/migrate/list.js.map +1 -1
- package/dist/commands/migrate/run.js +5 -6
- package/dist/commands/report.js +3 -3
- package/dist/commands/restore.js +11 -13
- package/dist/commands/restore.js.map +1 -1
- package/dist/commands/snapshot.js +6 -8
- package/dist/commands/snapshot.js.map +1 -1
- package/dist/commands/sync.js +11 -12
- package/dist/commands/sync.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +16 -16
- package/package.json +2 -2
- package/dist/chunk-5Z3SAIQS.js.map +0 -1
- package/dist/chunk-H5MJ5DFX.js +0 -16
- package/dist/chunk-H5MJ5DFX.js.map +0 -1
- package/dist/chunk-LQXF65MC.js.map +0 -1
- package/dist/chunk-NXRSAVRU.js.map +0 -1
- package/dist/chunk-PARSNTBD.js.map +0 -1
- package/dist/chunk-RRMI5CZD.js +0 -376
- package/dist/chunk-RRMI5CZD.js.map +0 -1
- package/dist/chunk-SF3YA42C.js +0 -506
- package/dist/chunk-SF3YA42C.js.map +0 -1
- package/dist/chunk-TQJSQLWA.js.map +0 -1
- package/dist/chunk-VOXZWQ3N.js.map +0 -1
- package/dist/chunk-X6V2GGDZ.js.map +0 -1
- package/dist/chunk-XMYMIURR.js.map +0 -1
- package/dist/chunk-YVDSR4GM.js.map +0 -1
- /package/dist/{chunk-BHYLBKYD.js.map → chunk-2SELREHW.js.map} +0 -0
- /package/dist/{chunk-4OU7KO5Y.js.map → chunk-6Q7MHFBM.js.map} +0 -0
- /package/dist/{chunk-KIFJGON5.js.map → chunk-NTUASFQ3.js.map} +0 -0
- /package/dist/{chunk-5QQBTLWO.js.map → chunk-ORQJVE57.js.map} +0 -0
- /package/dist/{chunk-VMTBLHN2.js.map → chunk-SC2XHGIS.js.map} +0 -0
package/dist/commands/restore.js
CHANGED
|
@@ -5,25 +5,25 @@ import {
|
|
|
5
5
|
restoreFromMigrations,
|
|
6
6
|
restoreFromSnapshot,
|
|
7
7
|
summarizeStatement
|
|
8
|
-
} from "../chunk-
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
12
|
-
import "../chunk-
|
|
13
|
-
import "../chunk-
|
|
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
14
|
import "../chunk-G2DIPIYU.js";
|
|
15
15
|
import {
|
|
16
16
|
renderTip
|
|
17
17
|
} from "../chunk-BLKJWDTL.js";
|
|
18
18
|
import {
|
|
19
19
|
BaseCommand
|
|
20
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-GZREXCQZ.js";
|
|
21
21
|
import {
|
|
22
22
|
findLatestSnapshot,
|
|
23
23
|
listSnapshots
|
|
24
|
-
} from "../chunk-
|
|
24
|
+
} from "../chunk-MIRLB5JM.js";
|
|
25
25
|
import "../chunk-DQQ5E563.js";
|
|
26
|
-
import "../chunk-
|
|
26
|
+
import "../chunk-SQPCWGQO.js";
|
|
27
27
|
import {
|
|
28
28
|
cmd,
|
|
29
29
|
warn
|
|
@@ -82,10 +82,8 @@ var Restore = class _Restore extends BaseCommand {
|
|
|
82
82
|
const config = await this.loadConfigOrFail();
|
|
83
83
|
const envName = flags.env;
|
|
84
84
|
const { env } = this.resolveEnv(config, envName);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
await this.runPreflight(pre, "Restore");
|
|
88
|
-
}
|
|
85
|
+
const pre = this.createPreflight("Restore preflight checks").addDatabase("Target", envName, env.dbUrl);
|
|
86
|
+
await this.runPreflight(pre, "Restore");
|
|
89
87
|
if (flags.apply) {
|
|
90
88
|
const tables = await getPublicTables(env.dbUrl);
|
|
91
89
|
if (tables.length > 0 && !flags.force) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/restore.ts"],"sourcesContent":["import { Flags } from '@oclif/core'\nimport { BaseCommand } from '../base-command.js'\nimport { findLatestSnapshot, listSnapshots } from '../snapshot'\nimport {\n restoreFromSnapshot,\n restoreFromMigrations,\n previewSnapshotRestore,\n previewMigrationRestore,\n getPublicTables,\n summarizeStatement,\n} from '../restore'\nimport { warn, cmd } from '../ui.js'\nimport { renderTip } from '../tips.js'\n\nexport default class Restore extends BaseCommand {\n static override description = 'Restore a Supabase environment from a snapshot or migration history'\n\n static override examples = [\n '<%= config.bin %> restore --env=local --from-snapshot=latest',\n '<%= config.bin %> restore --env=local --from-snapshot=latest --apply',\n '<%= config.bin %> restore --env=local --from-migrations --apply',\n '<%= config.bin %> restore --env=local --from-migrations --to=20260407T120000Z --apply',\n '<%= config.bin %> restore --env=local --from-snapshot=latest --apply --force',\n ]\n\n static override flags = {\n env: Flags.string({\n char: 'e',\n description: 'Target environment to restore into',\n required: true,\n }),\n 'from-snapshot': Flags.string({\n description: 'Restore from a snapshot (\"latest\" or a timestamp)',\n exclusive: ['from-migrations'],\n }),\n 'from-migrations': Flags.boolean({\n description: 'Restore by replaying migration files',\n exclusive: ['from-snapshot'],\n }),\n to: Flags.string({\n description: 'Replay migrations up to this version (timestamp)',\n }),\n from: Flags.string({\n description: 'Replay migrations from this version (timestamp)',\n }),\n apply: Flags.boolean({\n description: 'Actually execute the restore (default: dry-run preview)',\n default: false,\n }),\n 'no-transaction': Flags.boolean({\n description:\n 'Apply each statement on its own, keeping whatever succeeds. Off by default: '\n + 'a snapshot restore runs in one transaction, so a failure leaves the target '\n + 'exactly as it was rather than half-restored. Applies to --from-snapshot.',\n default: false,\n }),\n force: Flags.boolean({\n description: 'Allow restore into a non-empty database (destructive)',\n default: false,\n }),\n json: Flags.boolean({ description: 'Output results as JSON' }),\n }\n\n async run(): Promise<void> {\n const { flags } = await this.parse(Restore)\n\n if (!flags['from-snapshot'] && !flags['from-migrations']) {\n this.error('Specify --from-snapshot or --from-migrations')\n }\n\n const config = await this.loadConfigOrFail()\n\n const envName = flags.env\n const { env } = this.resolveEnv(config, envName)\n\n // Preflight: verify database is reachable\n if (!flags.json) {\n const pre = this.createPreflight('Restore preflight checks')\n .addDatabase('Target', envName, env.dbUrl)\n await this.runPreflight(pre, 'Restore')\n }\n\n // Safety: check if target DB has existing tables before destructive restore\n if (flags.apply) {\n const tables = await getPublicTables(env.dbUrl)\n if (tables.length > 0 && !flags.force) {\n if (flags.json) {\n this.json({ error: 'Target database is not empty', tables })\n this.exit(1)\n }\n this.log(`\\n${warn('Target database is not empty.')} Found ${tables.length} table(s) in public schema:`)\n for (const t of tables.slice(0, 10)) {\n this.log(` • ${t}`)\n }\n if (tables.length > 10) {\n this.log(` ... and ${tables.length - 10} more`)\n }\n this.log(`\\n Restore replays SQL into the target and may conflict with existing data.`)\n this.log(` → Use ${cmd('supaforge sync')} to apply only the differences instead.`)\n this.log(` → Add ${cmd('--force')} to drop and replace the schemas this snapshot covers.\\n`)\n // --apply was asked for and refused, so this is not success. Returning\n // 0 made `supaforge restore ... --apply && deploy` continue as though\n // the restore had happened, which is the worst possible reading of a\n // safety guard: it protects the data and then lets the pipeline act on\n // the assumption it did not have to.\n this.exit(1)\n }\n }\n\n if (flags['from-snapshot']) {\n await this.handleSnapshotRestore(flags, env.dbUrl)\n } else {\n await this.handleMigrationRestore(flags, env.dbUrl)\n }\n }\n\n private async handleSnapshotRestore(\n flags: Record<string, unknown>,\n targetUrl: string,\n ): Promise<void> {\n const snapshotRef = flags['from-snapshot'] as string\n let snapshotDir: string\n\n if (snapshotRef === 'latest') {\n const latest = await findLatestSnapshot()\n if (!latest) {\n this.error('No snapshots found. Create one with \"supaforge snapshot\" first.')\n }\n snapshotDir = latest\n } else {\n // Assume it's a timestamp — resolve to path\n const snapshots = await listSnapshots()\n const match = snapshots.find(s => s.manifest.timestamp === snapshotRef)\n if (!match) {\n this.error(`Snapshot \"${snapshotRef}\" not found. Use --from-snapshot=latest or a valid timestamp.`)\n }\n snapshotDir = match.dir\n }\n\n if (!flags.apply) {\n const preview = await previewSnapshotRestore(snapshotDir)\n if (flags.json) {\n this.json({ dryRun: true, snapshot: snapshotDir, layers: preview })\n return\n }\n this.log('\\nRestore preview (dry-run) -- from snapshot\\n')\n if (preview.length === 0) {\n this.log(' No executable SQL found in snapshot.')\n return\n }\n\n for (const { layer, statements } of preview) {\n this.log(` Layer: ${layer} (${statements.length} statements)`)\n // `summarizeStatement`, not the first line: a statement carrying a\n // leading comment — which every layer file's first one does, since the\n // header lands in the same chunk — showed the comment instead of the\n // SQL. A preview you cannot read is the one thing a preview must not\n // be. It is also what the apply path prints, so the two now describe\n // the same statement the same way.\n for (const stmt of statements.slice(0, 3)) {\n this.log(` ${summarizeStatement(stmt)}`)\n }\n if (statements.length > 3) {\n this.log(` ... and ${statements.length - 3} more`)\n }\n this.log('')\n }\n this.log(` → Add --apply to execute the restore.\\n`)\n return\n }\n\n if (!flags.json) this.log(`\\nRestoring from snapshot...\\n`)\n\n const result = await restoreFromSnapshot({\n targetUrl,\n snapshotDir,\n noTransaction: flags['no-transaction'] as boolean,\n // --force means replace: the schemas the snapshot covers are dropped\n // before it is replayed. It used to only skip the not-empty check, so a\n // restore over an existing database failed on every object already there\n // and replaced nothing (issue #95).\n replace: flags.force as boolean,\n })\n\n this.renderResult(result, flags.json as boolean)\n }\n\n private async handleMigrationRestore(\n flags: Record<string, unknown>,\n targetUrl: string,\n ): Promise<void> {\n const toVersion = flags.to as string | undefined\n const fromVersion = flags.from as string | undefined\n\n if (!flags.apply) {\n const migrations = await previewMigrationRestore(process.cwd(), toVersion, fromVersion)\n if (flags.json) {\n this.json({\n dryRun: true,\n migrations: migrations.map(m => ({\n version: m.version,\n description: m.description,\n layers: m.layers,\n sqlStatements: m.up.sql.length,\n apiActions: m.up.api.length,\n })),\n })\n return\n }\n this.log('\\nRestore preview (dry-run) -- from migrations\\n')\n if (migrations.length === 0) {\n this.log(' No migrations found.')\n return\n }\n\n for (const m of migrations) {\n this.log(` ${m.version} ${m.description}`)\n this.log(` Layers: ${m.layers.join(', ')}`)\n this.log(` SQL: ${m.up.sql.length} statements`)\n this.log(` API: ${m.up.api.length} actions`)\n this.log('')\n }\n this.log(` → Add --apply to execute the restore.\\n`)\n return\n }\n\n if (!flags.json) this.log(`\\nRestoring from migrations...\\n`)\n\n // --no-transaction is deliberately not forwarded: the migration path\n // applies and records one migration at a time, so wrapping the set in a\n // single transaction would roll back migrations that had already been\n // recorded as applied. Per-migration transactions belong with the rest of\n // the migration work in #92 rather than here.\n const result = await restoreFromMigrations({\n targetUrl,\n toVersion,\n fromVersion,\n })\n\n this.renderResult(result, flags.json as boolean)\n }\n\n private renderResult(\n result: Awaited<ReturnType<typeof restoreFromSnapshot>>,\n json: boolean,\n ): void {\n if (json) {\n // Only the JSON on stdout, so it parses, and the same exit code as the\n // text report: a restore that failed or left things out is not one a\n // script should read as success.\n this.json(result)\n if (result.errors.length > 0 || result.incomplete) this.exit(1)\n return\n }\n\n if (result.applied.length > 0) {\n this.log(`✅ Applied ${result.applied.length} operation(s):`)\n for (const op of result.applied.slice(0, 20)) {\n this.log(` ✓ [${op.type}] ${op.label}`)\n }\n if (result.applied.length > 20) {\n this.log(` ... and ${result.applied.length - 20} more`)\n }\n }\n\n if (result.skipped.length > 0) {\n this.log(`\\n⏭ Skipped ${result.skipped.length} operation(s):`)\n for (const op of result.skipped) {\n this.log(` ○ [${op.type}] ${op.label}: ${op.reason}`)\n }\n }\n\n if (result.rolledBack && result.rolledBack.length > 0) {\n // Reported apart from `applied`, which is empty: a restore that rolled\n // back applied nothing, and saying otherwise would be the most\n // misleading thing this command could print (issue #95).\n this.log(`\\n↩ Rolled back ${result.rolledBack.length} operation(s) — the target is unchanged.`)\n }\n\n if (result.incomplete && result.errors.length === 0) {\n // Restored, but not all of it: what was left out is listed above, each\n // with what it needed. Not a success a script should take as one.\n this.log(`\\n⚠ Restored everything this target can hold. What it cannot is listed above as skipped.`)\n process.exitCode = 1\n }\n\n if (result.errors.length > 0) {\n this.log(`\\n❌ ${result.errors.length} error(s):`)\n for (const op of result.errors) {\n this.log(` ✖ [${op.type}] ${op.label}: ${op.error}`)\n }\n if (result.rolledBack && result.rolledBack.length > 0) {\n this.log(`\\n Nothing was written. Re-run with ${cmd('--no-transaction')} to keep the parts that work.`)\n }\n this.exit(1)\n }\n\n this.log(renderTip({ command: 'restore' }))\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;AActB,IAAqB,UAArB,MAAqB,iBAAgB,YAAY;AAAA,EAC/C,OAAgB,cAAc;AAAA,EAE9B,OAAgB,WAAW;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EAEA,OAAgB,QAAQ;AAAA,IACtB,KAAK,MAAM,OAAO;AAAA,MAChB,MAAM;AAAA,MACN,aAAa;AAAA,MACb,UAAU;AAAA,IACZ,CAAC;AAAA,IACD,iBAAiB,MAAM,OAAO;AAAA,MAC5B,aAAa;AAAA,MACb,WAAW,CAAC,iBAAiB;AAAA,IAC/B,CAAC;AAAA,IACD,mBAAmB,MAAM,QAAQ;AAAA,MAC/B,aAAa;AAAA,MACb,WAAW,CAAC,eAAe;AAAA,IAC7B,CAAC;AAAA,IACD,IAAI,MAAM,OAAO;AAAA,MACf,aAAa;AAAA,IACf,CAAC;AAAA,IACD,MAAM,MAAM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,MAAM,+CAA0C;AAAA,IACjG;AAEA,QAAI,OAAO,cAAc,OAAO,OAAO,WAAW,GAAG;AAGnD,WAAK,IAAI;AAAA,6FAA2F;AACpG,cAAQ,WAAW;AAAA,IACrB;AAEA,QAAI,OAAO,OAAO,SAAS,GAAG;AAC5B,WAAK,IAAI;AAAA,SAAO,OAAO,OAAO,MAAM,YAAY;AAChD,iBAAW,MAAM,OAAO,QAAQ;AAC9B,aAAK,IAAI,aAAQ,GAAG,IAAI,KAAK,GAAG,KAAK,KAAK,GAAG,KAAK,EAAE;AAAA,MACtD;AACA,UAAI,OAAO,cAAc,OAAO,WAAW,SAAS,GAAG;AACrD,aAAK,IAAI;AAAA,qCAAwC,IAAI,kBAAkB,CAAC,+BAA+B;AAAA,MACzG;AACA,WAAK,KAAK,CAAC;AAAA,IACb;AAEA,SAAK,IAAI,UAAU,EAAE,SAAS,UAAU,CAAC,CAAC;AAAA,EAC5C;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/commands/restore.ts"],"sourcesContent":["import { Flags } from '@oclif/core'\nimport { BaseCommand } from '../base-command.js'\nimport { findLatestSnapshot, listSnapshots } from '../snapshot'\nimport {\n restoreFromSnapshot,\n restoreFromMigrations,\n previewSnapshotRestore,\n previewMigrationRestore,\n getPublicTables,\n summarizeStatement,\n} from '../restore'\nimport { warn, cmd } from '../ui.js'\nimport { renderTip } from '../tips.js'\n\nexport default class Restore extends BaseCommand {\n static override description = 'Restore a Supabase environment from a snapshot or migration history'\n\n static override examples = [\n '<%= config.bin %> restore --env=local --from-snapshot=latest',\n '<%= config.bin %> restore --env=local --from-snapshot=latest --apply',\n '<%= config.bin %> restore --env=local --from-migrations --apply',\n '<%= config.bin %> restore --env=local --from-migrations --to=20260407T120000Z --apply',\n '<%= config.bin %> restore --env=local --from-snapshot=latest --apply --force',\n ]\n\n static override flags = {\n env: Flags.string({\n char: 'e',\n description: 'Target environment to restore into',\n required: true,\n }),\n 'from-snapshot': Flags.string({\n description: 'Restore from a snapshot (\"latest\" or a timestamp)',\n exclusive: ['from-migrations'],\n }),\n 'from-migrations': Flags.boolean({\n description: 'Restore by replaying migration files',\n exclusive: ['from-snapshot'],\n }),\n to: Flags.string({\n description: 'Replay migrations up to this version (timestamp)',\n }),\n from: Flags.string({\n description: 'Replay migrations from this version (timestamp)',\n }),\n apply: Flags.boolean({\n description: 'Actually execute the restore (default: dry-run preview)',\n default: false,\n }),\n 'no-transaction': Flags.boolean({\n description:\n 'Apply each statement on its own, keeping whatever succeeds. Off by default: '\n + 'a snapshot restore runs in one transaction, so a failure leaves the target '\n + 'exactly as it was rather than half-restored. Applies to --from-snapshot.',\n default: false,\n }),\n force: Flags.boolean({\n description: 'Allow restore into a non-empty database (destructive)',\n default: false,\n }),\n json: Flags.boolean({ description: 'Output results as JSON' }),\n }\n\n async run(): Promise<void> {\n const { flags } = await this.parse(Restore)\n\n if (!flags['from-snapshot'] && !flags['from-migrations']) {\n this.error('Specify --from-snapshot or --from-migrations')\n }\n\n const config = await this.loadConfigOrFail()\n\n const envName = flags.env\n const { env } = this.resolveEnv(config, envName)\n\n // Preflight: verify database is reachable. Under --json too, where its\n // lines go to stderr and a failure is reported as JSON.\n const pre = this.createPreflight('Restore preflight checks')\n .addDatabase('Target', envName, env.dbUrl)\n await this.runPreflight(pre, 'Restore')\n\n // Safety: check if target DB has existing tables before destructive restore\n if (flags.apply) {\n const tables = await getPublicTables(env.dbUrl)\n if (tables.length > 0 && !flags.force) {\n if (flags.json) {\n this.json({ error: 'Target database is not empty', tables })\n this.exit(1)\n }\n this.log(`\\n${warn('Target database is not empty.')} Found ${tables.length} table(s) in public schema:`)\n for (const t of tables.slice(0, 10)) {\n this.log(` • ${t}`)\n }\n if (tables.length > 10) {\n this.log(` ... and ${tables.length - 10} more`)\n }\n this.log(`\\n Restore replays SQL into the target and may conflict with existing data.`)\n this.log(` → Use ${cmd('supaforge sync')} to apply only the differences instead.`)\n this.log(` → Add ${cmd('--force')} to drop and replace the schemas this snapshot covers.\\n`)\n // --apply was asked for and refused, so this is not success. Returning\n // 0 made `supaforge restore ... --apply && deploy` continue as though\n // the restore had happened, which is the worst possible reading of a\n // safety guard: it protects the data and then lets the pipeline act on\n // the assumption it did not have to.\n this.exit(1)\n }\n }\n\n if (flags['from-snapshot']) {\n await this.handleSnapshotRestore(flags, env.dbUrl)\n } else {\n await this.handleMigrationRestore(flags, env.dbUrl)\n }\n }\n\n private async handleSnapshotRestore(\n flags: Record<string, unknown>,\n targetUrl: string,\n ): Promise<void> {\n const snapshotRef = flags['from-snapshot'] as string\n let snapshotDir: string\n\n if (snapshotRef === 'latest') {\n const latest = await findLatestSnapshot()\n if (!latest) {\n this.error('No snapshots found. Create one with \"supaforge snapshot\" first.')\n }\n snapshotDir = latest\n } else {\n // Assume it's a timestamp — resolve to path\n const snapshots = await listSnapshots()\n const match = snapshots.find(s => s.manifest.timestamp === snapshotRef)\n if (!match) {\n this.error(`Snapshot \"${snapshotRef}\" not found. Use --from-snapshot=latest or a valid timestamp.`)\n }\n snapshotDir = match.dir\n }\n\n if (!flags.apply) {\n const preview = await previewSnapshotRestore(snapshotDir)\n if (flags.json) {\n this.json({ dryRun: true, snapshot: snapshotDir, layers: preview })\n return\n }\n this.log('\\nRestore preview (dry-run) -- from snapshot\\n')\n if (preview.length === 0) {\n this.log(' No executable SQL found in snapshot.')\n return\n }\n\n for (const { layer, statements } of preview) {\n this.log(` Layer: ${layer} (${statements.length} statements)`)\n // `summarizeStatement`, not the first line: a statement carrying a\n // leading comment — which every layer file's first one does, since the\n // header lands in the same chunk — showed the comment instead of the\n // SQL. A preview you cannot read is the one thing a preview must not\n // be. It is also what the apply path prints, so the two now describe\n // the same statement the same way.\n for (const stmt of statements.slice(0, 3)) {\n this.log(` ${summarizeStatement(stmt)}`)\n }\n if (statements.length > 3) {\n this.log(` ... and ${statements.length - 3} more`)\n }\n this.log('')\n }\n this.log(` → Add --apply to execute the restore.\\n`)\n return\n }\n\n if (!flags.json) this.log(`\\nRestoring from snapshot...\\n`)\n\n const result = await restoreFromSnapshot({\n targetUrl,\n snapshotDir,\n noTransaction: flags['no-transaction'] as boolean,\n // --force means replace: the schemas the snapshot covers are dropped\n // before it is replayed. It used to only skip the not-empty check, so a\n // restore over an existing database failed on every object already there\n // and replaced nothing (issue #95).\n replace: flags.force as boolean,\n })\n\n this.renderResult(result, flags.json as boolean)\n }\n\n private async handleMigrationRestore(\n flags: Record<string, unknown>,\n targetUrl: string,\n ): Promise<void> {\n const toVersion = flags.to as string | undefined\n const fromVersion = flags.from as string | undefined\n\n if (!flags.apply) {\n const migrations = await previewMigrationRestore(process.cwd(), toVersion, fromVersion)\n if (flags.json) {\n this.json({\n dryRun: true,\n migrations: migrations.map(m => ({\n version: m.version,\n description: m.description,\n layers: m.layers,\n sqlStatements: m.up.sql.length,\n apiActions: m.up.api.length,\n })),\n })\n return\n }\n this.log('\\nRestore preview (dry-run) -- from migrations\\n')\n if (migrations.length === 0) {\n this.log(' No migrations found.')\n return\n }\n\n for (const m of migrations) {\n this.log(` ${m.version} ${m.description}`)\n this.log(` Layers: ${m.layers.join(', ')}`)\n this.log(` SQL: ${m.up.sql.length} statements`)\n this.log(` API: ${m.up.api.length} actions`)\n this.log('')\n }\n this.log(` → Add --apply to execute the restore.\\n`)\n return\n }\n\n if (!flags.json) this.log(`\\nRestoring from migrations...\\n`)\n\n // --no-transaction is deliberately not forwarded: the migration path\n // applies and records one migration at a time, so wrapping the set in a\n // single transaction would roll back migrations that had already been\n // recorded as applied. Per-migration transactions belong with the rest of\n // the migration work in #92 rather than here.\n const result = await restoreFromMigrations({\n targetUrl,\n toVersion,\n fromVersion,\n })\n\n this.renderResult(result, flags.json as boolean)\n }\n\n private renderResult(\n result: Awaited<ReturnType<typeof restoreFromSnapshot>>,\n json: boolean,\n ): void {\n if (json) {\n // Only the JSON on stdout, so it parses, and the same exit code as the\n // text report: a restore that failed or left things out is not one a\n // script should read as success.\n this.json(result)\n if (result.errors.length > 0 || result.incomplete) this.exit(1)\n return\n }\n\n if (result.applied.length > 0) {\n this.log(`✅ Applied ${result.applied.length} operation(s):`)\n for (const op of result.applied.slice(0, 20)) {\n this.log(` ✓ [${op.type}] ${op.label}`)\n }\n if (result.applied.length > 20) {\n this.log(` ... and ${result.applied.length - 20} more`)\n }\n }\n\n if (result.skipped.length > 0) {\n this.log(`\\n⏭ Skipped ${result.skipped.length} operation(s):`)\n for (const op of result.skipped) {\n this.log(` ○ [${op.type}] ${op.label}: ${op.reason}`)\n }\n }\n\n if (result.rolledBack && result.rolledBack.length > 0) {\n // Reported apart from `applied`, which is empty: a restore that rolled\n // back applied nothing, and saying otherwise would be the most\n // misleading thing this command could print (issue #95).\n this.log(`\\n↩ Rolled back ${result.rolledBack.length} operation(s) — the target is unchanged.`)\n }\n\n if (result.incomplete && result.errors.length === 0) {\n // Restored, but not all of it: what was left out is listed above, each\n // with what it needed. Not a success a script should take as one.\n this.log(`\\n⚠ Restored everything this target can hold. What it cannot is listed above as skipped.`)\n process.exitCode = 1\n }\n\n if (result.errors.length > 0) {\n this.log(`\\n❌ ${result.errors.length} error(s):`)\n for (const op of result.errors) {\n this.log(` ✖ [${op.type}] ${op.label}: ${op.error}`)\n }\n if (result.rolledBack && result.rolledBack.length > 0) {\n this.log(`\\n Nothing was written. Re-run with ${cmd('--no-transaction')} to keep the parts that work.`)\n }\n this.exit(1)\n }\n\n this.log(renderTip({ command: 'restore' }))\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;AActB,IAAqB,UAArB,MAAqB,iBAAgB,YAAY;AAAA,EAC/C,OAAgB,cAAc;AAAA,EAE9B,OAAgB,WAAW;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EAEA,OAAgB,QAAQ;AAAA,IACtB,KAAK,MAAM,OAAO;AAAA,MAChB,MAAM;AAAA,MACN,aAAa;AAAA,MACb,UAAU;AAAA,IACZ,CAA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AQ,MAAM,gBAAgB;AAC9D,iBAAW,MAAM,OAAO,SAAS;AAC/B,aAAK,IAAI,aAAQ,GAAG,IAAI,KAAK,GAAG,KAAK,KAAK,GAAG,MAAM,EAAE;AAAA,MACvD;AAAA,IACF;AAEA,QAAI,OAAO,cAAc,OAAO,WAAW,SAAS,GAAG;AAIrD,WAAK,IAAI;AAAA,sBAAoB,OAAO,WAAW,MAAM,+CAA0C;AAAA,IACjG;AAEA,QAAI,OAAO,cAAc,OAAO,OAAO,WAAW,GAAG;AAGnD,WAAK,IAAI;AAAA,6FAA2F;AACpG,cAAQ,WAAW;AAAA,IACrB;AAEA,QAAI,OAAO,OAAO,SAAS,GAAG;AAC5B,WAAK,IAAI;AAAA,SAAO,OAAO,OAAO,MAAM,YAAY;AAChD,iBAAW,MAAM,OAAO,QAAQ;AAC9B,aAAK,IAAI,aAAQ,GAAG,IAAI,KAAK,GAAG,KAAK,KAAK,GAAG,KAAK,EAAE;AAAA,MACtD;AACA,UAAI,OAAO,cAAc,OAAO,WAAW,SAAS,GAAG;AACrD,aAAK,IAAI;AAAA,qCAAwC,IAAI,kBAAkB,CAAC,+BAA+B;AAAA,MACzG;AACA,WAAK,KAAK,CAAC;AAAA,IACb;AAEA,SAAK,IAAI,UAAU,EAAE,SAAS,UAAU,CAAC,CAAC;AAAA,EAC5C;AACF;","names":[]}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
backup,
|
|
3
3
|
listMigrationFiles
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-NTUASFQ3.js";
|
|
5
5
|
import "../chunk-G2DIPIYU.js";
|
|
6
6
|
import {
|
|
7
7
|
renderTip
|
|
8
8
|
} from "../chunk-BLKJWDTL.js";
|
|
9
9
|
import {
|
|
10
10
|
BaseCommand
|
|
11
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-GZREXCQZ.js";
|
|
12
12
|
import {
|
|
13
13
|
DEFAULT_KEEP_COUNT,
|
|
14
14
|
captureSnapshot,
|
|
15
15
|
formatSnapshotLayers,
|
|
16
16
|
listSnapshots,
|
|
17
17
|
pruneSnapshots
|
|
18
|
-
} from "../chunk-
|
|
18
|
+
} from "../chunk-MIRLB5JM.js";
|
|
19
19
|
import "../chunk-DQQ5E563.js";
|
|
20
|
-
import "../chunk-
|
|
20
|
+
import "../chunk-SQPCWGQO.js";
|
|
21
21
|
import {
|
|
22
22
|
bold,
|
|
23
23
|
cmd,
|
|
@@ -151,10 +151,8 @@ Prune: ${snapshots.length} snapshot(s) found, keeping ${keepCount}.`);
|
|
|
151
151
|
return;
|
|
152
152
|
}
|
|
153
153
|
const { envName, env } = this.resolveEnv(config, flags.env);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
await this.runPreflight(pre, "Snapshot");
|
|
157
|
-
}
|
|
154
|
+
const pre = this.createPreflight("Snapshot preflight checks").addDatabase("Database", envName, env.dbUrl);
|
|
155
|
+
await this.runPreflight(pre, "Snapshot");
|
|
158
156
|
if (!flags.apply) {
|
|
159
157
|
if (flags.json) {
|
|
160
158
|
this.json({ dryRun: true, environment: envName, migration: flags.migration });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/snapshot.ts"],"sourcesContent":["import { Flags } from '@oclif/core'\nimport { BaseCommand } from '../base-command.js'\nimport { captureSnapshot, listSnapshots, pruneSnapshots, formatSnapshotLayers, DEFAULT_KEEP_COUNT } from '../snapshot.js'\nimport { backup, listMigrationFiles } from '../migration.js'\nimport type { SnapshotManifest } from '../types/config.js'\nimport { ok, warn, dim, cmd, bold } from '../ui.js'\nimport { renderTip } from '../tips.js'\n\n/** Human-readable layer names captured by a snapshot, shown in the dry-run preview. */\nconst SNAPSHOT_LAYERS = [\n 'schema (tables, columns, indexes, constraints)',\n 'rls (row-level security policies)',\n 'edge-functions (via Management API)',\n 'storage (buckets + policies)',\n 'auth (config via Management API)',\n 'cron (pg_cron jobs)',\n 'data (reference tables from checks.data.tables)',\n 'webhooks (database webhook triggers)',\n 'extensions (installed Postgres extensions)',\n]\n\n/**\n * Capture and manage environment state snapshots.\n *\n * Default: dry-run preview of what would be captured (requires --apply)\n * --apply: actually capture the snapshot\n * --migration: also generate an incremental migration diff (was: backup)\n * --list: list existing snapshots\n * --prune: delete old snapshots\n */\nexport default class Snapshot extends BaseCommand {\n static override description = 'Capture a point-in-time snapshot of a Supabase environment'\n\n static override examples = [\n '<%= config.bin %> snapshot',\n '<%= config.bin %> snapshot --apply',\n '<%= config.bin %> snapshot --env=production --apply',\n '<%= config.bin %> snapshot --migration --apply',\n '<%= config.bin %> snapshot --migration --apply --description=\"added profiles table\"',\n '<%= config.bin %> snapshot --list',\n '<%= config.bin %> snapshot --prune',\n '<%= config.bin %> snapshot --prune --keep=5 --apply',\n '<%= config.bin %> snapshot --output=./backups --apply',\n ]\n\n static override flags = {\n env: Flags.string({\n char: 'e',\n description: 'Environment to snapshot (defaults to config source)',\n }),\n migration: Flags.boolean({\n description: 'Also generate an incremental migration diff against the previous snapshot',\n default: false,\n }),\n description: Flags.string({\n char: 'd',\n description: 'Human-readable description for the migration',\n default: 'auto-backup',\n }),\n list: Flags.boolean({\n description: 'List existing snapshots',\n default: false,\n }),\n prune: Flags.boolean({\n description: `Delete old snapshots, keeping the most recent (default: ${DEFAULT_KEEP_COUNT})`,\n default: false,\n }),\n keep: Flags.integer({\n description: 'Number of snapshots to keep when pruning',\n default: DEFAULT_KEEP_COUNT,\n min: 1,\n }),\n apply: Flags.boolean({\n description: 'Execute the snapshot (default: dry-run preview). Also required for --prune.',\n default: false,\n }),\n json: Flags.boolean({ description: 'Output results as JSON' }),\n output: Flags.string({\n char: 'o',\n description: 'Custom output directory for snapshot files (timestamp subfolder is created inside)',\n }),\n }\n\n async run(): Promise<void> {\n const { flags } = await this.parse(Snapshot)\n\n const config = await this.loadConfigOrFail()\n\n // ── List mode ────────────────────────────────────────────────────────────\n if (flags.list) {\n const snapshots = await listSnapshots()\n if (snapshots.length === 0) {\n this.log('No snapshots found.')\n return\n }\n if (flags.json) {\n this.json(snapshots.map(s => s.manifest))\n return\n }\n this.log(`\\n${bold(`${snapshots.length} snapshot(s):`)}\\n`)\n for (const { manifest } of snapshots) {\n const layerCount = Object.values(manifest.layers).filter(l => l.captured).length\n const itemCount = Object.values(manifest.layers).reduce((sum, l) => sum + l.itemCount, 0)\n this.log(` ${bold(manifest.timestamp)} ${dim('env=')}${manifest.environment} ${dim('layers=')}${layerCount} ${dim('items=')}${itemCount}`)\n }\n this.log('')\n this.log(renderTip({ command: 'snapshot', snapshotList: true }))\n return\n }\n\n // ── Prune mode ───────────────────────────────────────────────────────────\n if (flags.prune) {\n const keepCount = flags.keep\n const snapshots = await listSnapshots()\n const deleteCount = Math.max(0, snapshots.length - keepCount)\n\n if (deleteCount === 0) {\n this.log(`\\nNothing to prune — ${snapshots.length} snapshot(s), keeping ${keepCount}.\\n`)\n return\n }\n\n this.log(`\\nPrune: ${snapshots.length} snapshot(s) found, keeping ${keepCount}.`)\n this.log(` ${deleteCount} snapshot(s) would be deleted:\\n`)\n\n const toDelete = snapshots.slice(0, deleteCount)\n for (const { manifest } of toDelete) {\n this.log(` ${warn('✗')} ${manifest.timestamp} ${dim('env=')}${manifest.environment}`)\n }\n this.log('')\n\n if (!flags.apply) {\n this.log(` → Add ${cmd('--apply')} to delete these snapshots.\\n`)\n return\n }\n\n const result = await pruneSnapshots(keepCount)\n\n if (flags.json) {\n this.json(result)\n return\n }\n\n this.log(` Deleted ${result.deleted.length} snapshot(s), ${result.kept.length} remaining.`)\n if (result.retainedForMigrations && result.retainedForMigrations.length > 0) {\n // Kept past the budget on purpose: a migration names each of these as\n // its parent, and deleting one breaks that migration's chain (#92).\n this.log(` ${result.retainedForMigrations.length} kept beyond --keep: a migration names each as its parent.`)\n }\n this.log('')\n return\n }\n\n // ── Capture snapshot (with optional migration) ───────────────────────────\n const { envName, env } = this.resolveEnv(config, flags.env)\n\n // Preflight: verify database is reachable\n if (!flags.json) {\n const pre = this.createPreflight('Snapshot preflight checks')\n .addDatabase('Database', envName, env.dbUrl)\n await this.runPreflight(pre, 'Snapshot')\n }\n\n // ── Dry-run gate ─────────────────────────────────────────────────────────\n // Like clone / diff / restore, snapshot is a preview unless --apply is given.\n if (!flags.apply) {\n if (flags.json) {\n this.json({ dryRun: true, environment: envName, migration: flags.migration })\n return\n }\n this.log(`\\n ${bold('Snapshot preview')} ${dim('(dry-run)')}\\n`)\n this.log(` Environment: ${envName}`)\n this.log(` Mode: ${flags.migration ? 'snapshot + incremental migration' : 'snapshot'}`)\n this.log('')\n this.log(' Layers that will be captured (when present):')\n for (const layer of SNAPSHOT_LAYERS) {\n this.log(` ${dim('•')} ${layer}`)\n }\n this.log('')\n this.log(` ${dim('Layers with no data (e.g. no cron, no storage) are skipped automatically.')}`)\n this.log(`\\n → Add ${cmd('--apply')} to capture the snapshot.\\n`)\n this.log(renderTip({ command: 'snapshot', snapshotMigration: flags.migration, snapshotList: false }))\n return\n }\n\n if (flags.migration) {\n // Capture + generate migration (was: backup command)\n this.log(`\\nCapturing snapshot of \"${envName}\" with migration...\\n`)\n\n const result = await backup({\n envName,\n env,\n config,\n description: flags.description,\n outputDir: flags.output,\n })\n\n if (flags.json) {\n this.json({\n isBaseline: result.isBaseline,\n snapshot: result.snapshot.manifest,\n migration: result.migration,\n migrationFile: result.migrationFile,\n })\n return\n }\n\n this.logSnapshotResult(result.snapshot.manifest)\n this.log(` ${dim('Snapshot:')} ${result.snapshot.dir}`)\n\n if (result.isBaseline) {\n this.log(` ${dim('Type:')} baseline (first snapshot)`)\n } else {\n this.log(` ${dim('Type:')} incremental diff`)\n }\n\n if (result.migration) {\n this.log(` ${dim('Migration:')} ${result.migrationFile}`)\n this.log(` ${dim('Layers:')} ${result.migration.layers.join(', ')}`)\n this.log(` ${dim('SQL up:')} ${result.migration.up.sql.length} statement(s)`)\n this.log(` ${dim('API up:')} ${result.migration.up.api.length} action(s)`)\n } else {\n this.log(` ${dim('Migration:')} none (no changes detected)`)\n }\n\n this.log(`\\n ${ok('Snapshot + migration complete.')}\\n`)\n this.log(renderTip({ command: 'snapshot', snapshotMigration: true }))\n return\n }\n\n // Plain snapshot — just capture, no dry-run gate\n this.log(`\\nCapturing snapshot of \"${envName}\"...\\n`)\n\n const snapshot = await captureSnapshot({ envName, env, config, outputDir: flags.output })\n\n if (flags.json) {\n this.json(snapshot.manifest)\n return\n }\n\n this.logSnapshotResult(snapshot.manifest)\n this.log(`\\n ${dim('Snapshot saved to:')} ${snapshot.dir}`)\n\n // Show migration hint\n const existing = await listMigrationFiles()\n if (existing.length > 0) {\n this.log(` → Run with ${cmd('--migration')} to also generate an incremental diff.`)\n } else {\n this.log(` → Run with ${cmd('--migration')} to save a baseline migration.`)\n }\n this.log('')\n this.log(renderTip({ command: 'snapshot', snapshotMigration: false, snapshotList: false }))\n }\n\n private logSnapshotResult(manifest: SnapshotManifest): void {\n for (const line of formatSnapshotLayers(manifest)) {\n this.log(` ${line}`)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;AAStB,IAAM,kBAAkB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAWA,IAAqB,WAArB,MAAqB,kBAAiB,YAAY;AAAA,EAChD,OAAgB,cAAc;AAAA,EAE9B,OAAgB,WAAW;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EAEA,OAAgB,QAAQ;AAAA,IACtB,KAAK,MAAM,OAAO;AAAA,MAChB,MAAM;AAAA,MACN,aAAa;AAAA,IACf,CAAC;AAAA,IACD,WAAW,MAAM,QAAQ;AAAA,MACvB,aAAa;AAAA,MACb,SAAS;AAAA,IACX,CAAC;AAAA,IACD,aAAa,MAAM,OAAO;AAAA,MACx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AACxC,SAAK,IAAI;AAAA,IAAO,IAAI,oBAAoB,CAAC,IAAI,SAAS,GAAG,EAAE;AAG3D,UAAM,WAAW,MAAM,mBAAmB;AAC1C,QAAI,SAAS,SAAS,GAAG;AACvB,WAAK,IAAI,qBAAgB,IAAI,aAAa,CAAC,wCAAwC;AAAA,IACrF,OAAO;AACL,WAAK,IAAI,qBAAgB,IAAI,aAAa,CAAC,gCAAgC;AAAA,IAC7E;AACA,SAAK,IAAI,EAAE;AACX,SAAK,IAAI,UAAU,EAAE,SAAS,YAAY,mBAAmB,OAAO,cAAc,MAAM,CAAC,CAAC;AAAA,EAC5F;AAAA,EAEQ,kBAAkB,UAAkC;AAC1D,eAAW,QAAQ,qBAAqB,QAAQ,GAAG;AACjD,WAAK,IAAI,KAAK,IAAI,EAAE;AAAA,IACtB;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/commands/snapshot.ts"],"sourcesContent":["import { Flags } from '@oclif/core'\nimport { BaseCommand } from '../base-command.js'\nimport { captureSnapshot, listSnapshots, pruneSnapshots, formatSnapshotLayers, DEFAULT_KEEP_COUNT } from '../snapshot.js'\nimport { backup, listMigrationFiles } from '../migration.js'\nimport type { SnapshotManifest } from '../types/config.js'\nimport { ok, warn, dim, cmd, bold } from '../ui.js'\nimport { renderTip } from '../tips.js'\n\n/** Human-readable layer names captured by a snapshot, shown in the dry-run preview. */\nconst SNAPSHOT_LAYERS = [\n 'schema (tables, columns, indexes, constraints)',\n 'rls (row-level security policies)',\n 'edge-functions (via Management API)',\n 'storage (buckets + policies)',\n 'auth (config via Management API)',\n 'cron (pg_cron jobs)',\n 'data (reference tables from checks.data.tables)',\n 'webhooks (database webhook triggers)',\n 'extensions (installed Postgres extensions)',\n]\n\n/**\n * Capture and manage environment state snapshots.\n *\n * Default: dry-run preview of what would be captured (requires --apply)\n * --apply: actually capture the snapshot\n * --migration: also generate an incremental migration diff (was: backup)\n * --list: list existing snapshots\n * --prune: delete old snapshots\n */\nexport default class Snapshot extends BaseCommand {\n static override description = 'Capture a point-in-time snapshot of a Supabase environment'\n\n static override examples = [\n '<%= config.bin %> snapshot',\n '<%= config.bin %> snapshot --apply',\n '<%= config.bin %> snapshot --env=production --apply',\n '<%= config.bin %> snapshot --migration --apply',\n '<%= config.bin %> snapshot --migration --apply --description=\"added profiles table\"',\n '<%= config.bin %> snapshot --list',\n '<%= config.bin %> snapshot --prune',\n '<%= config.bin %> snapshot --prune --keep=5 --apply',\n '<%= config.bin %> snapshot --output=./backups --apply',\n ]\n\n static override flags = {\n env: Flags.string({\n char: 'e',\n description: 'Environment to snapshot (defaults to config source)',\n }),\n migration: Flags.boolean({\n description: 'Also generate an incremental migration diff against the previous snapshot',\n default: false,\n }),\n description: Flags.string({\n char: 'd',\n description: 'Human-readable description for the migration',\n default: 'auto-backup',\n }),\n list: Flags.boolean({\n description: 'List existing snapshots',\n default: false,\n }),\n prune: Flags.boolean({\n description: `Delete old snapshots, keeping the most recent (default: ${DEFAULT_KEEP_COUNT})`,\n default: false,\n }),\n keep: Flags.integer({\n description: 'Number of snapshots to keep when pruning',\n default: DEFAULT_KEEP_COUNT,\n min: 1,\n }),\n apply: Flags.boolean({\n description: 'Execute the snapshot (default: dry-run preview). Also required for --prune.',\n default: false,\n }),\n json: Flags.boolean({ description: 'Output results as JSON' }),\n output: Flags.string({\n char: 'o',\n description: 'Custom output directory for snapshot files (timestamp subfolder is created inside)',\n }),\n }\n\n async run(): Promise<void> {\n const { flags } = await this.parse(Snapshot)\n\n const config = await this.loadConfigOrFail()\n\n // ── List mode ────────────────────────────────────────────────────────────\n if (flags.list) {\n const snapshots = await listSnapshots()\n if (snapshots.length === 0) {\n this.log('No snapshots found.')\n return\n }\n if (flags.json) {\n this.json(snapshots.map(s => s.manifest))\n return\n }\n this.log(`\\n${bold(`${snapshots.length} snapshot(s):`)}\\n`)\n for (const { manifest } of snapshots) {\n const layerCount = Object.values(manifest.layers).filter(l => l.captured).length\n const itemCount = Object.values(manifest.layers).reduce((sum, l) => sum + l.itemCount, 0)\n this.log(` ${bold(manifest.timestamp)} ${dim('env=')}${manifest.environment} ${dim('layers=')}${layerCount} ${dim('items=')}${itemCount}`)\n }\n this.log('')\n this.log(renderTip({ command: 'snapshot', snapshotList: true }))\n return\n }\n\n // ── Prune mode ───────────────────────────────────────────────────────────\n if (flags.prune) {\n const keepCount = flags.keep\n const snapshots = await listSnapshots()\n const deleteCount = Math.max(0, snapshots.length - keepCount)\n\n if (deleteCount === 0) {\n this.log(`\\nNothing to prune — ${snapshots.length} snapshot(s), keeping ${keepCount}.\\n`)\n return\n }\n\n this.log(`\\nPrune: ${snapshots.length} snapshot(s) found, keeping ${keepCount}.`)\n this.log(` ${deleteCount} snapshot(s) would be deleted:\\n`)\n\n const toDelete = snapshots.slice(0, deleteCount)\n for (const { manifest } of toDelete) {\n this.log(` ${warn('✗')} ${manifest.timestamp} ${dim('env=')}${manifest.environment}`)\n }\n this.log('')\n\n if (!flags.apply) {\n this.log(` → Add ${cmd('--apply')} to delete these snapshots.\\n`)\n return\n }\n\n const result = await pruneSnapshots(keepCount)\n\n if (flags.json) {\n this.json(result)\n return\n }\n\n this.log(` Deleted ${result.deleted.length} snapshot(s), ${result.kept.length} remaining.`)\n if (result.retainedForMigrations && result.retainedForMigrations.length > 0) {\n // Kept past the budget on purpose: a migration names each of these as\n // its parent, and deleting one breaks that migration's chain (#92).\n this.log(` ${result.retainedForMigrations.length} kept beyond --keep: a migration names each as its parent.`)\n }\n this.log('')\n return\n }\n\n // ── Capture snapshot (with optional migration) ───────────────────────────\n const { envName, env } = this.resolveEnv(config, flags.env)\n\n // Preflight: verify database is reachable. Under --json too, where its\n // lines go to stderr and a failure is reported as JSON.\n const pre = this.createPreflight('Snapshot preflight checks')\n .addDatabase('Database', envName, env.dbUrl)\n await this.runPreflight(pre, 'Snapshot')\n\n // ── Dry-run gate ─────────────────────────────────────────────────────────\n // Like clone / diff / restore, snapshot is a preview unless --apply is given.\n if (!flags.apply) {\n if (flags.json) {\n this.json({ dryRun: true, environment: envName, migration: flags.migration })\n return\n }\n this.log(`\\n ${bold('Snapshot preview')} ${dim('(dry-run)')}\\n`)\n this.log(` Environment: ${envName}`)\n this.log(` Mode: ${flags.migration ? 'snapshot + incremental migration' : 'snapshot'}`)\n this.log('')\n this.log(' Layers that will be captured (when present):')\n for (const layer of SNAPSHOT_LAYERS) {\n this.log(` ${dim('•')} ${layer}`)\n }\n this.log('')\n this.log(` ${dim('Layers with no data (e.g. no cron, no storage) are skipped automatically.')}`)\n this.log(`\\n → Add ${cmd('--apply')} to capture the snapshot.\\n`)\n this.log(renderTip({ command: 'snapshot', snapshotMigration: flags.migration, snapshotList: false }))\n return\n }\n\n if (flags.migration) {\n // Capture + generate migration (was: backup command)\n this.log(`\\nCapturing snapshot of \"${envName}\" with migration...\\n`)\n\n const result = await backup({\n envName,\n env,\n config,\n description: flags.description,\n outputDir: flags.output,\n })\n\n if (flags.json) {\n this.json({\n isBaseline: result.isBaseline,\n snapshot: result.snapshot.manifest,\n migration: result.migration,\n migrationFile: result.migrationFile,\n })\n return\n }\n\n this.logSnapshotResult(result.snapshot.manifest)\n this.log(` ${dim('Snapshot:')} ${result.snapshot.dir}`)\n\n if (result.isBaseline) {\n this.log(` ${dim('Type:')} baseline (first snapshot)`)\n } else {\n this.log(` ${dim('Type:')} incremental diff`)\n }\n\n if (result.migration) {\n this.log(` ${dim('Migration:')} ${result.migrationFile}`)\n this.log(` ${dim('Layers:')} ${result.migration.layers.join(', ')}`)\n this.log(` ${dim('SQL up:')} ${result.migration.up.sql.length} statement(s)`)\n this.log(` ${dim('API up:')} ${result.migration.up.api.length} action(s)`)\n } else {\n this.log(` ${dim('Migration:')} none (no changes detected)`)\n }\n\n this.log(`\\n ${ok('Snapshot + migration complete.')}\\n`)\n this.log(renderTip({ command: 'snapshot', snapshotMigration: true }))\n return\n }\n\n // Plain snapshot — just capture, no dry-run gate\n this.log(`\\nCapturing snapshot of \"${envName}\"...\\n`)\n\n const snapshot = await captureSnapshot({ envName, env, config, outputDir: flags.output })\n\n if (flags.json) {\n this.json(snapshot.manifest)\n return\n }\n\n this.logSnapshotResult(snapshot.manifest)\n this.log(`\\n ${dim('Snapshot saved to:')} ${snapshot.dir}`)\n\n // Show migration hint\n const existing = await listMigrationFiles()\n if (existing.length > 0) {\n this.log(` → Run with ${cmd('--migration')} to also generate an incremental diff.`)\n } else {\n this.log(` → Run with ${cmd('--migration')} to save a baseline migration.`)\n }\n this.log('')\n this.log(renderTip({ command: 'snapshot', snapshotMigration: false, snapshotList: false }))\n }\n\n private logSnapshotResult(manifest: SnapshotManifest): void {\n for (const line of formatSnapshotLayers(manifest)) {\n this.log(` ${line}`)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;AAStB,IAAM,kBAAkB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAWA,IAAqB,WAArB,MAAqB,kBAAiB,YAAY;AAAA,EAChD,OAAgB,cAAc;AAAA,EAE9B,OAAgB,WAAW;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EAEA,OAAgB,QAAQ;AAAA,IACtB,KAAK,MAAM,OAAO;AAAA,MAChB,MAAM;AAAA,MACN,aAAa;AAAA,IACf,CAAC;AAAA,IACD,WAAW,MAAM,QAAQ;AAAA,MACvB,aAAa;AAAA,MACb,SAAS;AAAA,IACX,CAAC;AAAA,IACD,aAAa,MAAM,OAAO;AAAA,MACxB,MAAM;AAAA,MACN,aAAa;AAAA,MACb,SAAS;AAAA,IACX,CAAC;AAAA,IACD,MAAM,MAAM,QAAQ;AAAA,MAClB,aAAa;AAAA,MACb,SAAS;AAAA,IACX,CAAC;AAAA,IACD,OAAO,MAAM,QAAQ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;AACL,WAAK,IAAI,qBAAgB,IAAI,aAAa,CAAC,gCAAgC;AAAA,IAC7E;AACA,SAAK,IAAI,EAAE;AACX,SAAK,IAAI,UAAU,EAAE,SAAS,YAAY,mBAAmB,OAAO,cAAc,MAAM,CAAC,CAAC;AAAA,EAC5F;AAAA,EAEQ,kBAAkB,UAAkC;AAC1D,eAAW,QAAQ,qBAAqB,QAAQ,GAAG;AACjD,WAAK,IAAI,KAAK,IAAI,EAAE;AAAA,IACtB;AAAA,EACF;AACF;","names":[]}
|
package/dist/commands/sync.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Diff
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-RRMI5CZD.js";
|
|
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";
|
|
11
10
|
import "../chunk-G2DIPIYU.js";
|
|
12
11
|
import "../chunk-BLKJWDTL.js";
|
|
13
|
-
import "../chunk-
|
|
14
|
-
import "../chunk-
|
|
15
|
-
import "../chunk-
|
|
12
|
+
import "../chunk-GZREXCQZ.js";
|
|
13
|
+
import "../chunk-ORQJVE57.js";
|
|
14
|
+
import "../chunk-MIRLB5JM.js";
|
|
16
15
|
import "../chunk-DQQ5E563.js";
|
|
17
|
-
import "../chunk-
|
|
16
|
+
import "../chunk-SQPCWGQO.js";
|
|
18
17
|
import "../chunk-6WAMNZLO.js";
|
|
19
18
|
|
|
20
19
|
// src/commands/sync.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/sync.ts"],"sourcesContent":["import Diff from './diff.js'\n\n/**\n * Alias for `diff --apply` — detect and fix drift in one step.\n */\nexport default class Sync extends Diff {\n static override description = 'Detect and fix drift (alias for diff --apply)'\n\n static override examples = [\n '<%= config.bin %> sync',\n '<%= config.bin %> sync --check=rls',\n '<%= config.bin %> sync --source=staging --target=production',\n ]\n\n async run(): Promise<void> {\n // Inject --apply before delegating to Diff\n const argv = [...this.argv]\n if (!argv.includes('--apply')) {\n argv.push('--apply')\n }\n\n // Re-parse with injected --apply flag\n await Diff.run(argv, this.config)\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/commands/sync.ts"],"sourcesContent":["import Diff from './diff.js'\n\n/**\n * Alias for `diff --apply` — detect and fix drift in one step.\n */\nexport default class Sync extends Diff {\n static override description = 'Detect and fix drift (alias for diff --apply)'\n\n static override examples = [\n '<%= config.bin %> sync',\n '<%= config.bin %> sync --check=rls',\n '<%= config.bin %> sync --source=staging --target=production',\n ]\n\n async run(): Promise<void> {\n // Inject --apply before delegating to Diff\n const argv = [...this.argv]\n if (!argv.includes('--apply')) {\n argv.push('--apply')\n }\n\n // Re-parse with injected --apply flag\n await Diff.run(argv, this.config)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAKA,IAAqB,OAArB,cAAkC,KAAK;AAAA,EACrC,OAAgB,cAAc;AAAA,EAE9B,OAAgB,WAAW;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EAEA,MAAM,MAAqB;AAEzB,UAAM,OAAO,CAAC,GAAG,KAAK,IAAI;AAC1B,QAAI,CAAC,KAAK,SAAS,SAAS,GAAG;AAC7B,WAAK,KAAK,SAAS;AAAA,IACrB;AAGA,UAAM,KAAK,IAAI,MAAM,KAAK,MAAM;AAAA,EAClC;AACF;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -67,6 +67,11 @@ interface DriftIssue {
|
|
|
67
67
|
* instead of being told there is nothing to be done.
|
|
68
68
|
*/
|
|
69
69
|
manualOnly?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Why this fix waits for --allow-destructive, when that isn't visible from
|
|
72
|
+
* its SQL: a webhook is a trigger, and dropping a trigger usually isn't.
|
|
73
|
+
*/
|
|
74
|
+
destructive?: string;
|
|
70
75
|
}
|
|
71
76
|
interface CheckResult {
|
|
72
77
|
check: CheckName;
|
package/dist/index.js
CHANGED
|
@@ -3,37 +3,37 @@ import {
|
|
|
3
3
|
createServer,
|
|
4
4
|
getLastScanResult,
|
|
5
5
|
setLastScanResult
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-6LJERPUN.js";
|
|
7
7
|
import {
|
|
8
8
|
previewMigrationRestore,
|
|
9
9
|
previewSnapshotRestore,
|
|
10
10
|
restoreFromMigrations,
|
|
11
11
|
restoreFromSnapshot
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-7NAZGZPV.js";
|
|
13
13
|
import {
|
|
14
14
|
backup,
|
|
15
15
|
listMigrationFiles,
|
|
16
16
|
loadMigrations
|
|
17
|
-
} from "./chunk-
|
|
18
|
-
import "./chunk-
|
|
17
|
+
} from "./chunk-NTUASFQ3.js";
|
|
18
|
+
import "./chunk-SC2XHGIS.js";
|
|
19
19
|
import {
|
|
20
20
|
renderDetailed,
|
|
21
21
|
renderSummary
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-GEHPTPNZ.js";
|
|
23
23
|
import {
|
|
24
|
-
CHECK_META,
|
|
25
|
-
CHECK_NAMES,
|
|
26
24
|
CheckRegistry,
|
|
27
25
|
computeScore,
|
|
28
26
|
createDefaultRegistry,
|
|
29
|
-
promote,
|
|
30
27
|
scan,
|
|
31
28
|
summarize
|
|
32
|
-
} from "./chunk-
|
|
33
|
-
import "./chunk-
|
|
34
|
-
import
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
} from "./chunk-3HGAV5CC.js";
|
|
30
|
+
import "./chunk-DMIWAJRB.js";
|
|
31
|
+
import {
|
|
32
|
+
CHECK_META,
|
|
33
|
+
CHECK_NAMES,
|
|
34
|
+
promote
|
|
35
|
+
} from "./chunk-UWAVXC57.js";
|
|
36
|
+
import "./chunk-BUOWHE36.js";
|
|
37
37
|
import "./chunk-G2DIPIYU.js";
|
|
38
38
|
import {
|
|
39
39
|
BRANCH_DB_PREFIX,
|
|
@@ -43,17 +43,17 @@ import {
|
|
|
43
43
|
listBranches,
|
|
44
44
|
loadManifest,
|
|
45
45
|
replaceDbName
|
|
46
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-ORQJVE57.js";
|
|
47
47
|
import {
|
|
48
48
|
captureSnapshot,
|
|
49
49
|
findLatestSnapshot,
|
|
50
50
|
listSnapshots,
|
|
51
51
|
loadSnapshot
|
|
52
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-MIRLB5JM.js";
|
|
53
53
|
import "./chunk-DQQ5E563.js";
|
|
54
54
|
import {
|
|
55
55
|
Check
|
|
56
|
-
} from "./chunk-
|
|
56
|
+
} from "./chunk-SQPCWGQO.js";
|
|
57
57
|
import {
|
|
58
58
|
loadConfig,
|
|
59
59
|
resolveConfig,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akal/supaforge",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"description": "Diff and sync your Supabase environments",
|
|
5
5
|
"author": "Akal Software Ltd",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@akal/pg-conformance": "~0.0.15",
|
|
57
|
-
"@dbdiff/cli": "3.0.0-rc.
|
|
57
|
+
"@dbdiff/cli": "3.0.0-rc.25",
|
|
58
58
|
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
59
59
|
"@oclif/core": "^4",
|
|
60
60
|
"@supabase/supabase-js": "^2.103.0",
|