@profullstack/sh1pt-migrate 0.0.0-stage → 0.3.8
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/LICENSE +21 -0
- package/README.md +133 -2
- package/dist/apply.d.ts +65 -0
- package/dist/apply.d.ts.map +1 -0
- package/dist/apply.js +143 -0
- package/dist/apply.js.map +1 -0
- package/dist/engines/files.d.ts +37 -0
- package/dist/engines/files.d.ts.map +1 -0
- package/dist/engines/files.js +137 -0
- package/dist/engines/files.js.map +1 -0
- package/dist/engines/index.d.ts +20 -0
- package/dist/engines/index.d.ts.map +1 -0
- package/dist/engines/index.js +35 -0
- package/dist/engines/index.js.map +1 -0
- package/dist/engines/mysql.d.ts +17 -0
- package/dist/engines/mysql.d.ts.map +1 -0
- package/dist/engines/mysql.js +171 -0
- package/dist/engines/mysql.js.map +1 -0
- package/dist/engines/object-storage.d.ts +42 -0
- package/dist/engines/object-storage.d.ts.map +1 -0
- package/dist/engines/object-storage.js +197 -0
- package/dist/engines/object-storage.js.map +1 -0
- package/dist/engines/postgres.d.ts +34 -0
- package/dist/engines/postgres.d.ts.map +1 -0
- package/dist/engines/postgres.js +309 -0
- package/dist/engines/postgres.js.map +1 -0
- package/dist/engines/redis.d.ts +3 -0
- package/dist/engines/redis.d.ts.map +1 -0
- package/dist/engines/redis.js +87 -0
- package/dist/engines/redis.js.map +1 -0
- package/dist/engines/sqlite.d.ts +3 -0
- package/dist/engines/sqlite.d.ts.map +1 -0
- package/dist/engines/sqlite.js +113 -0
- package/dist/engines/sqlite.js.map +1 -0
- package/dist/exec.d.ts +31 -0
- package/dist/exec.d.ts.map +1 -0
- package/dist/exec.js +119 -0
- package/dist/exec.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/plan.d.ts +115 -0
- package/dist/plan.d.ts.map +1 -0
- package/dist/plan.js +339 -0
- package/dist/plan.js.map +1 -0
- package/dist/platforms/index.d.ts +29 -0
- package/dist/platforms/index.d.ts.map +1 -0
- package/dist/platforms/index.js +51 -0
- package/dist/platforms/index.js.map +1 -0
- package/dist/platforms/managed.d.ts +41 -0
- package/dist/platforms/managed.d.ts.map +1 -0
- package/dist/platforms/managed.js +163 -0
- package/dist/platforms/managed.js.map +1 -0
- package/dist/platforms/railway.d.ts +29 -0
- package/dist/platforms/railway.d.ts.map +1 -0
- package/dist/platforms/railway.js +135 -0
- package/dist/platforms/railway.js.map +1 -0
- package/dist/platforms/ssh.d.ts +56 -0
- package/dist/platforms/ssh.d.ts.map +1 -0
- package/dist/platforms/ssh.js +151 -0
- package/dist/platforms/ssh.js.map +1 -0
- package/dist/platforms/supabase.d.ts +57 -0
- package/dist/platforms/supabase.d.ts.map +1 -0
- package/dist/platforms/supabase.js +102 -0
- package/dist/platforms/supabase.js.map +1 -0
- package/dist/staging.d.ts +27 -0
- package/dist/staging.d.ts.map +1 -0
- package/dist/staging.js +98 -0
- package/dist/staging.js.map +1 -0
- package/dist/transforms.d.ts +113 -0
- package/dist/transforms.d.ts.map +1 -0
- package/dist/transforms.js +179 -0
- package/dist/transforms.js.map +1 -0
- package/dist/types.d.ts +238 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +79 -0
- package/dist/types.js.map +1 -0
- package/package.json +32 -3
package/dist/exec.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createReadStream, createWriteStream } from 'node:fs';
|
|
3
|
+
import { mkdir } from 'node:fs/promises';
|
|
4
|
+
import { dirname } from 'node:path';
|
|
5
|
+
/**
|
|
6
|
+
* Running an external command.
|
|
7
|
+
*
|
|
8
|
+
* The real implementation behind the `exec` every engine receives. It is
|
|
9
|
+
* injected rather than imported so the engines can be tested without any of
|
|
10
|
+
* the tools installed, and so a dry run can be genuinely inert.
|
|
11
|
+
*
|
|
12
|
+
* `spawn` without a shell, always. Engines build argument arrays from
|
|
13
|
+
* connection strings, bucket names and paths, all of which come from config a
|
|
14
|
+
* person edits — running those through a shell would make a bucket named
|
|
15
|
+
* `; rm -rf /` a working attack and a path with a space a silent bug. The
|
|
16
|
+
* cost is that `>` and `<` do not work, which is why redirection is an option
|
|
17
|
+
* rather than a character in the argument list.
|
|
18
|
+
*/
|
|
19
|
+
export function createExec(opts = {}) {
|
|
20
|
+
return async function exec(cmd, args, options = {}) {
|
|
21
|
+
const { env, cwd, check = true, timeoutMs, stdoutFile, stdinFile } = options;
|
|
22
|
+
if (stdoutFile)
|
|
23
|
+
await mkdir(dirname(stdoutFile), { recursive: true });
|
|
24
|
+
// Arguments are logged; the environment never is. That split is the whole
|
|
25
|
+
// reason credentials are passed through env.
|
|
26
|
+
opts.log?.(`$ ${cmd} ${args.join(' ')}`);
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
const child = spawn(cmd, args, {
|
|
29
|
+
env: { ...process.env, ...env },
|
|
30
|
+
...(cwd ? { cwd } : {}),
|
|
31
|
+
stdio: [stdinFile ? 'pipe' : 'ignore', stdoutFile ? 'pipe' : 'pipe', 'pipe'],
|
|
32
|
+
});
|
|
33
|
+
let stdout = '';
|
|
34
|
+
let stderr = '';
|
|
35
|
+
let settled = false;
|
|
36
|
+
const timer = timeoutMs
|
|
37
|
+
? setTimeout(() => {
|
|
38
|
+
if (settled)
|
|
39
|
+
return;
|
|
40
|
+
settled = true;
|
|
41
|
+
child.kill('SIGKILL');
|
|
42
|
+
reject(new Error(`${cmd} timed out after ${Math.round(timeoutMs / 1000)}s`));
|
|
43
|
+
}, timeoutMs)
|
|
44
|
+
: undefined;
|
|
45
|
+
if (stdoutFile && child.stdout) {
|
|
46
|
+
const out = createWriteStream(stdoutFile);
|
|
47
|
+
child.stdout.pipe(out);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
child.stdout?.on('data', (d) => {
|
|
51
|
+
stdout += d.toString();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
child.stderr?.on('data', (d) => {
|
|
55
|
+
stderr += d.toString();
|
|
56
|
+
});
|
|
57
|
+
if (stdinFile && child.stdin) {
|
|
58
|
+
createReadStream(stdinFile).pipe(child.stdin);
|
|
59
|
+
}
|
|
60
|
+
child.on('error', (err) => {
|
|
61
|
+
if (settled)
|
|
62
|
+
return;
|
|
63
|
+
settled = true;
|
|
64
|
+
if (timer)
|
|
65
|
+
clearTimeout(timer);
|
|
66
|
+
// ENOENT here means the binary is missing, which the planner is
|
|
67
|
+
// supposed to have caught. Say which one, so the message is actionable
|
|
68
|
+
// rather than "spawn ENOENT".
|
|
69
|
+
const message = err.code === 'ENOENT'
|
|
70
|
+
? `${cmd} is not installed or not on PATH`
|
|
71
|
+
: err.message;
|
|
72
|
+
reject(new Error(message));
|
|
73
|
+
});
|
|
74
|
+
child.on('close', (code) => {
|
|
75
|
+
if (settled)
|
|
76
|
+
return;
|
|
77
|
+
settled = true;
|
|
78
|
+
if (timer)
|
|
79
|
+
clearTimeout(timer);
|
|
80
|
+
const result = { code: code ?? 0, stdout, stderr };
|
|
81
|
+
if (check && result.code !== 0) {
|
|
82
|
+
reject(new Error(`${cmd} exited ${result.code}${stderr ? `: ${stderr.trim().split('\n').slice(-3).join('\n')}` : ''}`));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
resolve(result);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* An exec that records instead of running, for `--dry-run`.
|
|
92
|
+
*
|
|
93
|
+
* A dry run has to be genuinely inert: the point is to be safe to run against
|
|
94
|
+
* production, and an engine that shells out "just to look" is not.
|
|
95
|
+
*/
|
|
96
|
+
export function recordingExec(recorded = []) {
|
|
97
|
+
const exec = async (cmd, args) => {
|
|
98
|
+
recorded.push([cmd, ...args]);
|
|
99
|
+
return { code: 0, stdout: '', stderr: '' };
|
|
100
|
+
};
|
|
101
|
+
return { exec, recorded };
|
|
102
|
+
}
|
|
103
|
+
/** Which of these binaries are on PATH, for the planner's preflight check. */
|
|
104
|
+
export async function availableBinaries(names) {
|
|
105
|
+
const exec = createExec();
|
|
106
|
+
const found = new Set();
|
|
107
|
+
await Promise.all(names.map(async (name) => {
|
|
108
|
+
try {
|
|
109
|
+
const res = await exec('sh', ['-c', `command -v ${JSON.stringify(name)}`], { check: false });
|
|
110
|
+
if (res.code === 0 && res.stdout.trim())
|
|
111
|
+
found.add(name);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// Missing is the answer, not an error.
|
|
115
|
+
}
|
|
116
|
+
}));
|
|
117
|
+
return found;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=exec.js.map
|
package/dist/exec.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../src/exec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,UAAU,CAAC,OAAwC,EAAE;IACnE,OAAO,KAAK,UAAU,IAAI,CACxB,GAAW,EACX,IAAc,EACd,UAAuB,EAAE;QAEzB,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;QAE7E,IAAI,UAAU;YAAE,MAAM,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAEtE,0EAA0E;QAC1E,6CAA6C;QAC7C,IAAI,CAAC,GAAG,EAAE,C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,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;YAC7F,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE;gBAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC3D,CAAC;QAAC,MAAM,CAAC;YACP,uCAAuC;QACzC,CAAC;IACH,CAAC,CAAC,CACH,CAAC;IACF,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @profullstack/sh1pt-migrate — move an application and its data between
|
|
3
|
+
* platforms, in either direction.
|
|
4
|
+
*
|
|
5
|
+
* `packages/cloud/*` provisions machines. This moves what lives on them.
|
|
6
|
+
*
|
|
7
|
+
* The design in one paragraph: PLATFORMS (Railway, Supabase, Turso, Neon, a
|
|
8
|
+
* box over ssh) resolve credentials and enumerate what they hold, and never
|
|
9
|
+
* move a byte. ENGINES (postgres, sqlite, redis, object-storage, files) move
|
|
10
|
+
* bytes and do not know which vendor is on either end. A migration is possible
|
|
11
|
+
* when the target accepts a kind the source holds, which `compatibleKinds`
|
|
12
|
+
* answers instantly. Direction is not a property of the system — it is which
|
|
13
|
+
* platform you named first.
|
|
14
|
+
*
|
|
15
|
+
* Typical use:
|
|
16
|
+
*
|
|
17
|
+
* const inventory = await supabasePlatform.inventory(ctx, { projectRef, dbPassword });
|
|
18
|
+
* const plan = planMigration(inventory, sshPlatform, { engines: ENGINES });
|
|
19
|
+
* console.log(renderPlan(plan)); // safe against production
|
|
20
|
+
* if (plan.ok) await applyPlan({ plan, ... });
|
|
21
|
+
*/
|
|
22
|
+
export * from './types.js';
|
|
23
|
+
export * from './plan.js';
|
|
24
|
+
export * from './apply.js';
|
|
25
|
+
export * from './staging.js';
|
|
26
|
+
export * from './transforms.js';
|
|
27
|
+
export * from './exec.js';
|
|
28
|
+
export { ENGINES, engineFor, requiredBinaries } from './engines/index.js';
|
|
29
|
+
export { filesEngine, mysqlEngine, objectStorageEngine, postgresEngine, redisEngine, sqliteEngine, } from './engines/index.js';
|
|
30
|
+
export { PLATFORMS, compatibleKinds, platformById, railwayPlatform, sources, sshPlatform, supabasePlatform, targets, tursoPlatform, } from './platforms/index.js';
|
|
31
|
+
export type { SshConfig } from './platforms/ssh.js';
|
|
32
|
+
export type { RailwayConfig } from './platforms/railway.js';
|
|
33
|
+
export type { SupabaseConfig } from './platforms/supabase.js';
|
|
34
|
+
export type { DsnConfig, TursoConfig } from './platforms/managed.js';
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EACL,WAAW,EACX,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,SAAS,EACT,eAAe,EACf,YAAY,EACZ,eAAe,EACf,OAAO,EACP,WAAW,EACX,gBAAgB,EAChB,OAAO,EACP,aAAa,GACd,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,YAAY,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @profullstack/sh1pt-migrate — move an application and its data between
|
|
3
|
+
* platforms, in either direction.
|
|
4
|
+
*
|
|
5
|
+
* `packages/cloud/*` provisions machines. This moves what lives on them.
|
|
6
|
+
*
|
|
7
|
+
* The design in one paragraph: PLATFORMS (Railway, Supabase, Turso, Neon, a
|
|
8
|
+
* box over ssh) resolve credentials and enumerate what they hold, and never
|
|
9
|
+
* move a byte. ENGINES (postgres, sqlite, redis, object-storage, files) move
|
|
10
|
+
* bytes and do not know which vendor is on either end. A migration is possible
|
|
11
|
+
* when the target accepts a kind the source holds, which `compatibleKinds`
|
|
12
|
+
* answers instantly. Direction is not a property of the system — it is which
|
|
13
|
+
* platform you named first.
|
|
14
|
+
*
|
|
15
|
+
* Typical use:
|
|
16
|
+
*
|
|
17
|
+
* const inventory = await supabasePlatform.inventory(ctx, { projectRef, dbPassword });
|
|
18
|
+
* const plan = planMigration(inventory, sshPlatform, { engines: ENGINES });
|
|
19
|
+
* console.log(renderPlan(plan)); // safe against production
|
|
20
|
+
* if (plan.ok) await applyPlan({ plan, ... });
|
|
21
|
+
*/
|
|
22
|
+
export * from './types.js';
|
|
23
|
+
export * from './plan.js';
|
|
24
|
+
export * from './apply.js';
|
|
25
|
+
export * from './staging.js';
|
|
26
|
+
export * from './transforms.js';
|
|
27
|
+
export * from './exec.js';
|
|
28
|
+
export { ENGINES, engineFor, requiredBinaries } from './engines/index.js';
|
|
29
|
+
export { filesEngine, mysqlEngine, objectStorageEngine, postgresEngine, redisEngine, sqliteEngine, } from './engines/index.js';
|
|
30
|
+
export { PLATFORMS, compatibleKinds, platformById, railwayPlatform, sources, sshPlatform, supabasePlatform, targets, tursoPlatform, } from './platforms/index.js';
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EACL,WAAW,EACX,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,SAAS,EACT,eAAe,EACf,YAAY,EACZ,eAAe,EACf,OAAO,EACP,WAAW,EACX,gBAAgB,EAChB,OAAO,EACP,aAAa,GACd,MAAM,sBAAsB,CAAC"}
|
package/dist/plan.d.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { Engine, Inventory, Platform, Resource, ResourceKind } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Turning an inventory into an ordered, reviewable plan.
|
|
4
|
+
*
|
|
5
|
+
* The plan is the product. A migration that goes wrong usually went wrong
|
|
6
|
+
* before anything ran — a resource nobody knew was there, a cutover step in
|
|
7
|
+
* the wrong order, an assumption that the destination supported something it
|
|
8
|
+
* did not. All of that is knowable up front, from a read-only inventory, and
|
|
9
|
+
* this module is where it is worked out so a person can read it and disagree
|
|
10
|
+
* before any bytes move.
|
|
11
|
+
*
|
|
12
|
+
* Nothing here touches the network or mutates anything. Given the same
|
|
13
|
+
* inventory it produces the same plan, which is what makes it testable.
|
|
14
|
+
*/
|
|
15
|
+
/** A single unit of work in the plan. */
|
|
16
|
+
export interface Step {
|
|
17
|
+
id: string;
|
|
18
|
+
phase: Phase;
|
|
19
|
+
/** One line, imperative: "dump postgres 'app' (4.7 GB)". */
|
|
20
|
+
title: string;
|
|
21
|
+
resourceId?: string;
|
|
22
|
+
kind?: ResourceKind;
|
|
23
|
+
/** Steps that must complete before this one. */
|
|
24
|
+
after: string[];
|
|
25
|
+
/** True when this step changes the SOURCE, which is what makes it scary. */
|
|
26
|
+
touchesSource?: boolean;
|
|
27
|
+
/** Set when the step cannot be undone by re-running the migration. */
|
|
28
|
+
irreversible?: boolean;
|
|
29
|
+
estimateBytes?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The phases, in the only order that is safe.
|
|
33
|
+
*
|
|
34
|
+
* The ordering is the part people get wrong, and it is not arbitrary:
|
|
35
|
+
*
|
|
36
|
+
* - `check` first so a missing credential costs a second, not three hours.
|
|
37
|
+
* - `bulk` runs while the source is still live and serving. It is the long
|
|
38
|
+
* part and it is safe to repeat.
|
|
39
|
+
* - `freeze` is the start of downtime: stop the things that write. Scheduled
|
|
40
|
+
* jobs especially — a cron firing on both sides is how a migration sends
|
|
41
|
+
* every customer a duplicate email.
|
|
42
|
+
* - `delta` copies only what changed during `bulk`. Short, because `bulk`
|
|
43
|
+
* already moved the bulk.
|
|
44
|
+
* - `cutover` points the world at the new place.
|
|
45
|
+
* - `enable` starts the writers again, on the target only, and never before
|
|
46
|
+
* `freeze` has stopped them on the source.
|
|
47
|
+
* - `verify` proves it worked while the old system still exists.
|
|
48
|
+
*
|
|
49
|
+
* Deleting the source is not a phase. It is a separate decision a person makes
|
|
50
|
+
* days later, and this tool does not offer it.
|
|
51
|
+
*/
|
|
52
|
+
export type Phase = 'check' | 'bulk' | 'freeze' | 'delta' | 'cutover' | 'enable' | 'verify';
|
|
53
|
+
export declare const PHASES: readonly Phase[];
|
|
54
|
+
export interface Risk {
|
|
55
|
+
severity: 'blocker' | 'warning' | 'note';
|
|
56
|
+
/** What is wrong, in a sentence a person can act on. */
|
|
57
|
+
message: string;
|
|
58
|
+
resourceId?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface MigrationPlan {
|
|
61
|
+
source: string;
|
|
62
|
+
target: string;
|
|
63
|
+
scope: string;
|
|
64
|
+
steps: Step[];
|
|
65
|
+
risks: Risk[];
|
|
66
|
+
/** Resources that will move, paired source → target kind. */
|
|
67
|
+
moving: Resource[];
|
|
68
|
+
/** Resources that will NOT move, and why. */
|
|
69
|
+
skipped: Array<{
|
|
70
|
+
resource: Resource;
|
|
71
|
+
reason: string;
|
|
72
|
+
}>;
|
|
73
|
+
estimateBytes: number;
|
|
74
|
+
/** False when any risk is a blocker. `apply` refuses a plan that is not ok. */
|
|
75
|
+
ok: boolean;
|
|
76
|
+
}
|
|
77
|
+
export interface PlanOptions {
|
|
78
|
+
/** Only migrate these kinds. Empty means everything the target supports. */
|
|
79
|
+
only?: ResourceKind[];
|
|
80
|
+
/** Never migrate these kinds. */
|
|
81
|
+
exclude?: ResourceKind[];
|
|
82
|
+
/**
|
|
83
|
+
* Hosts whose absolute URLs are expected to appear in the data and must be
|
|
84
|
+
* rewritten, e.g. `ywcizjsgrcmhgyplldac.supabase.co`. See `transforms.ts`.
|
|
85
|
+
*/
|
|
86
|
+
rewriteHosts?: string[];
|
|
87
|
+
/** Engines available in this build, by kind. */
|
|
88
|
+
engines: Map<ResourceKind, Engine>;
|
|
89
|
+
/** Binaries present on this machine, for the `requires` check. */
|
|
90
|
+
availableBinaries?: Set<string>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Work out what would happen, without doing any of it.
|
|
94
|
+
*
|
|
95
|
+
* Read-only in the strongest sense: it takes an inventory that has already
|
|
96
|
+
* been gathered and a description of the target, and returns a plan. It does
|
|
97
|
+
* not call the network, so it is fully testable and so `migrate plan` can be
|
|
98
|
+
* run against production with no anxiety.
|
|
99
|
+
*/
|
|
100
|
+
export declare function planMigration(source: Inventory, target: Platform, opts: PlanOptions): MigrationPlan;
|
|
101
|
+
export declare function humanBytes(n: number): string;
|
|
102
|
+
/**
|
|
103
|
+
* Sort steps by phase, then by dependency within the phase.
|
|
104
|
+
*
|
|
105
|
+
* Phase order is absolute and comes first: a `delta` step never runs before a
|
|
106
|
+
* `freeze` step even if nothing declares the dependency, because the phase
|
|
107
|
+
* ordering *is* the safety property. Within a phase, a stable topological sort
|
|
108
|
+
* respects `after`, and a cycle throws rather than quietly picking an order —
|
|
109
|
+
* a cyclic plan is a bug in the planner and running it would be worse than
|
|
110
|
+
* failing.
|
|
111
|
+
*/
|
|
112
|
+
export declare function orderSteps(steps: Step[]): Step[];
|
|
113
|
+
/** Render a plan the way `sh1pt migrate plan` prints it. */
|
|
114
|
+
export declare function renderPlan(plan: MigrationPlan): string;
|
|
115
|
+
//# sourceMappingURL=plan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../src/plan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEtF;;;;;;;;;;;;GAYG;AAEH,yCAAyC;AACzC,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,KAAK,CAAC;IACb,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,gDAAgD;IAChD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,4EAA4E;IAC5E,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,sEAAsE;IACtE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE5F,eAAO,MAAM,MAAM,EAAE,SAAS,KAAK,EAQzB,CAAC;AAEX,MAAM,WAAW,IAAI;IACnB,QAAQ,EAAE,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AU,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CA0CtD"}
|
package/dist/plan.js
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
export const PHASES = [
|
|
2
|
+
'check',
|
|
3
|
+
'bulk',
|
|
4
|
+
'freeze',
|
|
5
|
+
'delta',
|
|
6
|
+
'cutover',
|
|
7
|
+
'enable',
|
|
8
|
+
'verify',
|
|
9
|
+
];
|
|
10
|
+
/** Kinds whose contents are routinely referenced by absolute URL from a database. */
|
|
11
|
+
const URL_BEARING = new Set(['object-storage']);
|
|
12
|
+
/**
|
|
13
|
+
* Kinds that write on a schedule and so must be stopped before the delta, or
|
|
14
|
+
* they run in two places at once.
|
|
15
|
+
*/
|
|
16
|
+
const SCHEDULED = new Set(['cron']);
|
|
17
|
+
function stepId(prefix, resourceId) {
|
|
18
|
+
return `${prefix}:${resourceId}`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Work out what would happen, without doing any of it.
|
|
22
|
+
*
|
|
23
|
+
* Read-only in the strongest sense: it takes an inventory that has already
|
|
24
|
+
* been gathered and a description of the target, and returns a plan. It does
|
|
25
|
+
* not call the network, so it is fully testable and so `migrate plan` can be
|
|
26
|
+
* run against production with no anxiety.
|
|
27
|
+
*/
|
|
28
|
+
export function planMigration(source, target, opts) {
|
|
29
|
+
const risks = [];
|
|
30
|
+
const steps = [];
|
|
31
|
+
const moving = [];
|
|
32
|
+
const skipped = [];
|
|
33
|
+
const only = new Set(opts.only ?? []);
|
|
34
|
+
const exclude = new Set(opts.exclude ?? []);
|
|
35
|
+
const targetKinds = new Set(target.supports);
|
|
36
|
+
if (target.role === 'source') {
|
|
37
|
+
risks.push({
|
|
38
|
+
severity: 'blocker',
|
|
39
|
+
message: `${target.label} cannot be a migration target: it offers no import path.`,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
for (const resource of source.resources) {
|
|
43
|
+
if (only.size && !only.has(resource.kind)) {
|
|
44
|
+
skipped.push({ resource, reason: `not in --only` });
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (exclude.has(resource.kind)) {
|
|
48
|
+
skipped.push({ resource, reason: `excluded by --exclude` });
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (!targetKinds.has(resource.kind)) {
|
|
52
|
+
skipped.push({
|
|
53
|
+
resource,
|
|
54
|
+
reason: `${target.label} does not support ${resource.kind}`,
|
|
55
|
+
});
|
|
56
|
+
risks.push({
|
|
57
|
+
severity: 'blocker',
|
|
58
|
+
resourceId: resource.id,
|
|
59
|
+
message: `${resource.name} is ${resource.kind}, which ${target.label} cannot hold. Exclude it with --exclude ${resource.kind}, or pick a different target.`,
|
|
60
|
+
});
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const engine = opts.engines.get(resource.kind);
|
|
64
|
+
if (!engine) {
|
|
65
|
+
skipped.push({ resource, reason: `no engine for ${resource.kind}` });
|
|
66
|
+
risks.push({
|
|
67
|
+
severity: 'blocker',
|
|
68
|
+
resourceId: resource.id,
|
|
69
|
+
message: `Nothing in this build can move a ${resource.kind}.`,
|
|
70
|
+
});
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
// A missing pg_dump is a blocker, and finding out now beats finding out
|
|
74
|
+
// after the freeze has started.
|
|
75
|
+
if (opts.availableBinaries) {
|
|
76
|
+
const missing = engine.requires.filter((b) => !opts.availableBinaries.has(b));
|
|
77
|
+
if (missing.length) {
|
|
78
|
+
risks.push({
|
|
79
|
+
severity: 'blocker',
|
|
80
|
+
resourceId: resource.id,
|
|
81
|
+
message: `${resource.kind} needs ${missing.join(', ')} on this machine and ${missing.length > 1 ? 'they are' : 'it is'} not installed.`,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
moving.push(resource);
|
|
86
|
+
steps.push({
|
|
87
|
+
id: stepId('export', resource.id),
|
|
88
|
+
phase: 'bulk',
|
|
89
|
+
title: `export ${resource.kind} ${resource.name}${sizeSuffix(resource)}`,
|
|
90
|
+
resourceId: resource.id,
|
|
91
|
+
kind: resource.kind,
|
|
92
|
+
after: ['check:all'],
|
|
93
|
+
estimateBytes: resource.sizeBytes,
|
|
94
|
+
});
|
|
95
|
+
steps.push({
|
|
96
|
+
id: stepId('import', resource.id),
|
|
97
|
+
phase: 'bulk',
|
|
98
|
+
title: `import ${resource.kind} ${resource.name} into ${target.label}`,
|
|
99
|
+
resourceId: resource.id,
|
|
100
|
+
kind: resource.kind,
|
|
101
|
+
after: [stepId('export', resource.id)],
|
|
102
|
+
estimateBytes: resource.sizeBytes,
|
|
103
|
+
});
|
|
104
|
+
if (engine.delta) {
|
|
105
|
+
steps.push({
|
|
106
|
+
id: stepId('delta', resource.id),
|
|
107
|
+
phase: 'delta',
|
|
108
|
+
title: `sync ${resource.name} changes made during the bulk copy`,
|
|
109
|
+
resourceId: resource.id,
|
|
110
|
+
kind: resource.kind,
|
|
111
|
+
after: ['freeze:all', stepId('import', resource.id)],
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
risks.push({
|
|
116
|
+
severity: 'warning',
|
|
117
|
+
resourceId: resource.id,
|
|
118
|
+
message: `${resource.name} (${resource.kind}) has no delta sync, so anything written to it during the bulk copy is lost. Stop writes before the copy, or accept the gap.`,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (engine.verify) {
|
|
122
|
+
steps.push({
|
|
123
|
+
id: stepId('verify', resource.id),
|
|
124
|
+
phase: 'verify',
|
|
125
|
+
title: `verify ${resource.name} matches the source`,
|
|
126
|
+
resourceId: resource.id,
|
|
127
|
+
kind: resource.kind,
|
|
128
|
+
after: ['cutover:dns'],
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
for (const quirk of resource.quirks ?? []) {
|
|
132
|
+
risks.push({
|
|
133
|
+
severity: 'warning',
|
|
134
|
+
resourceId: resource.id,
|
|
135
|
+
message: `${resource.name}: ${quirk}`,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (SCHEDULED.has(resource.kind)) {
|
|
139
|
+
steps.push({
|
|
140
|
+
id: stepId('disable', resource.id),
|
|
141
|
+
phase: 'freeze',
|
|
142
|
+
title: `disable scheduled jobs on the SOURCE (${resource.name})`,
|
|
143
|
+
resourceId: resource.id,
|
|
144
|
+
kind: resource.kind,
|
|
145
|
+
after: [],
|
|
146
|
+
touchesSource: true,
|
|
147
|
+
});
|
|
148
|
+
steps.push({
|
|
149
|
+
id: stepId('enable', resource.id),
|
|
150
|
+
phase: 'enable',
|
|
151
|
+
title: `enable scheduled jobs on the TARGET (${resource.name})`,
|
|
152
|
+
resourceId: resource.id,
|
|
153
|
+
kind: resource.kind,
|
|
154
|
+
// Never before the source's are off. Two schedulers on one dataset is
|
|
155
|
+
// duplicate outbound email and duplicate published posts.
|
|
156
|
+
after: [stepId('disable', resource.id), 'cutover:dns'],
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// The absolute-URL trap. Object storage moves to a new host, but rows that
|
|
161
|
+
// stored `https://<old-host>/...` keep working until the old account is
|
|
162
|
+
// closed and then 404 forever. It is invisible at cutover, which is what
|
|
163
|
+
// makes it dangerous.
|
|
164
|
+
const storage = moving.filter((r) => URL_BEARING.has(r.kind));
|
|
165
|
+
const databases = moving.filter((r) => r.kind === 'postgres' || r.kind === 'mysql');
|
|
166
|
+
if (storage.length && databases.length) {
|
|
167
|
+
const hosts = opts.rewriteHosts ?? [];
|
|
168
|
+
steps.push({
|
|
169
|
+
id: 'rewrite:urls',
|
|
170
|
+
phase: 'delta',
|
|
171
|
+
title: hosts.length
|
|
172
|
+
? `rewrite absolute URLs (${hosts.join(', ')}) to the new host`
|
|
173
|
+
: `scan for absolute URLs pointing at the old storage host`,
|
|
174
|
+
after: databases.map((d) => stepId('import', d.id)),
|
|
175
|
+
irreversible: false,
|
|
176
|
+
});
|
|
177
|
+
if (!hosts.length) {
|
|
178
|
+
risks.push({
|
|
179
|
+
severity: 'warning',
|
|
180
|
+
message: 'Storage and a database are both moving but no --rewrite-host was given. Rows holding absolute URLs to the old storage host keep working until that account is closed, then 404 permanently. The scan step will report what it finds; pass --rewrite-host to fix them.',
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
steps.push({
|
|
185
|
+
id: 'check:all',
|
|
186
|
+
phase: 'check',
|
|
187
|
+
title: `check credentials and connectivity for ${source.platform} and ${target.label}`,
|
|
188
|
+
after: [],
|
|
189
|
+
});
|
|
190
|
+
if (moving.length) {
|
|
191
|
+
steps.push({
|
|
192
|
+
id: 'freeze:all',
|
|
193
|
+
phase: 'freeze',
|
|
194
|
+
title: 'stop writes on the source (downtime starts here)',
|
|
195
|
+
after: moving.map((r) => stepId('import', r.id)),
|
|
196
|
+
touchesSource: true,
|
|
197
|
+
});
|
|
198
|
+
steps.push({
|
|
199
|
+
id: 'cutover:dns',
|
|
200
|
+
phase: 'cutover',
|
|
201
|
+
title: 'point DNS at the target',
|
|
202
|
+
after: ['freeze:all', ...moving.filter(hasDelta(opts)).map((r) => stepId('delta', r.id))],
|
|
203
|
+
irreversible: false,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
for (const note of source.notes ?? []) {
|
|
207
|
+
risks.push({ severity: 'note', message: note });
|
|
208
|
+
}
|
|
209
|
+
if (!moving.length) {
|
|
210
|
+
risks.push({
|
|
211
|
+
severity: 'blocker',
|
|
212
|
+
message: 'Nothing to migrate: every resource was skipped or unsupported.',
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
const ordered = orderSteps(steps);
|
|
216
|
+
const estimateBytes = moving.reduce((sum, r) => sum + (r.sizeBytes ?? 0), 0);
|
|
217
|
+
return {
|
|
218
|
+
source: source.platform,
|
|
219
|
+
target: target.id,
|
|
220
|
+
scope: source.scope,
|
|
221
|
+
steps: ordered,
|
|
222
|
+
risks,
|
|
223
|
+
moving,
|
|
224
|
+
skipped,
|
|
225
|
+
estimateBytes,
|
|
226
|
+
ok: !risks.some((r) => r.severity === 'blocker'),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function hasDelta(opts) {
|
|
230
|
+
return (r) => Boolean(opts.engines.get(r.kind)?.delta);
|
|
231
|
+
}
|
|
232
|
+
function sizeSuffix(r) {
|
|
233
|
+
if (r.sizeBytes)
|
|
234
|
+
return ` (${humanBytes(r.sizeBytes)})`;
|
|
235
|
+
if (r.itemCount)
|
|
236
|
+
return ` (${r.itemCount.toLocaleString()} items)`;
|
|
237
|
+
return '';
|
|
238
|
+
}
|
|
239
|
+
export function humanBytes(n) {
|
|
240
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
241
|
+
let v = n;
|
|
242
|
+
let i = 0;
|
|
243
|
+
while (v >= 1024 && i < units.length - 1) {
|
|
244
|
+
v /= 1024;
|
|
245
|
+
i += 1;
|
|
246
|
+
}
|
|
247
|
+
return `${v >= 10 || i === 0 ? Math.round(v) : v.toFixed(1)} ${units[i]}`;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Sort steps by phase, then by dependency within the phase.
|
|
251
|
+
*
|
|
252
|
+
* Phase order is absolute and comes first: a `delta` step never runs before a
|
|
253
|
+
* `freeze` step even if nothing declares the dependency, because the phase
|
|
254
|
+
* ordering *is* the safety property. Within a phase, a stable topological sort
|
|
255
|
+
* respects `after`, and a cycle throws rather than quietly picking an order —
|
|
256
|
+
* a cyclic plan is a bug in the planner and running it would be worse than
|
|
257
|
+
* failing.
|
|
258
|
+
*/
|
|
259
|
+
export function orderSteps(steps) {
|
|
260
|
+
const byId = new Map(steps.map((s) => [s.id, s]));
|
|
261
|
+
const out = [];
|
|
262
|
+
const done = new Set();
|
|
263
|
+
for (const phase of PHASES) {
|
|
264
|
+
const inPhase = steps.filter((s) => s.phase === phase);
|
|
265
|
+
const pending = new Map(inPhase.map((s) => [s.id, s]));
|
|
266
|
+
while (pending.size) {
|
|
267
|
+
let progressed = false;
|
|
268
|
+
for (const [id, step] of [...pending]) {
|
|
269
|
+
// Only dependencies inside this phase can block; an earlier phase has
|
|
270
|
+
// already run by construction, and a dependency on a later phase would
|
|
271
|
+
// be a planner bug, caught below.
|
|
272
|
+
const blocking = step.after.filter((dep) => pending.has(dep) && dep !== id && byId.get(dep)?.phase === phase);
|
|
273
|
+
if (blocking.length === 0) {
|
|
274
|
+
out.push(step);
|
|
275
|
+
done.add(id);
|
|
276
|
+
pending.delete(id);
|
|
277
|
+
progressed = true;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (!progressed) {
|
|
281
|
+
throw new Error(`migration plan has a dependency cycle in phase '${phase}' among: ${[...pending.keys()].join(', ')}`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
// A dependency naming a step in a LATER phase inverts the safety ordering.
|
|
286
|
+
for (const step of out) {
|
|
287
|
+
for (const dep of step.after) {
|
|
288
|
+
const target = byId.get(dep);
|
|
289
|
+
if (!target)
|
|
290
|
+
continue;
|
|
291
|
+
if (PHASES.indexOf(target.phase) > PHASES.indexOf(step.phase)) {
|
|
292
|
+
throw new Error(`step '${step.id}' (${step.phase}) depends on '${dep}' (${target.phase}), which runs later`);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return out;
|
|
297
|
+
}
|
|
298
|
+
/** Render a plan the way `sh1pt migrate plan` prints it. */
|
|
299
|
+
export function renderPlan(plan) {
|
|
300
|
+
const lines = [];
|
|
301
|
+
lines.push(`${plan.source} → ${plan.target} (${plan.scope})`);
|
|
302
|
+
lines.push('');
|
|
303
|
+
if (plan.moving.length) {
|
|
304
|
+
lines.push(`Moving ${plan.moving.length} resource(s), ${humanBytes(plan.estimateBytes)}:`);
|
|
305
|
+
for (const r of plan.moving)
|
|
306
|
+
lines.push(` ${r.kind.padEnd(15)} ${r.name}${sizeSuffix(r)}`);
|
|
307
|
+
lines.push('');
|
|
308
|
+
}
|
|
309
|
+
if (plan.skipped.length) {
|
|
310
|
+
lines.push('Not moving:');
|
|
311
|
+
for (const s of plan.skipped)
|
|
312
|
+
lines.push(` ${s.resource.name} — ${s.reason}`);
|
|
313
|
+
lines.push('');
|
|
314
|
+
}
|
|
315
|
+
let phase = null;
|
|
316
|
+
for (const step of plan.steps) {
|
|
317
|
+
if (step.phase !== phase) {
|
|
318
|
+
phase = step.phase;
|
|
319
|
+
lines.push(`${phase}:`);
|
|
320
|
+
}
|
|
321
|
+
const marks = [
|
|
322
|
+
step.touchesSource ? 'SOURCE' : null,
|
|
323
|
+
step.irreversible ? 'IRREVERSIBLE' : null,
|
|
324
|
+
].filter(Boolean);
|
|
325
|
+
lines.push(` ${step.title}${marks.length ? ` [${marks.join(' ')}]` : ''}`);
|
|
326
|
+
}
|
|
327
|
+
if (plan.risks.length) {
|
|
328
|
+
lines.push('');
|
|
329
|
+
for (const sev of ['blocker', 'warning', 'note']) {
|
|
330
|
+
for (const r of plan.risks.filter((x) => x.severity === sev)) {
|
|
331
|
+
lines.push(`${sev.toUpperCase()}: ${r.message}`);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
lines.push('');
|
|
336
|
+
lines.push(plan.ok ? 'Plan is applyable.' : 'Plan has blockers and cannot be applied.');
|
|
337
|
+
return lines.join('\n');
|
|
338
|
+
}
|
|
339
|
+
//# sourceMappingURL=plan.js.map
|