@profullstack/sh1pt-migrate 0.0.0-stage → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +133 -2
  2. package/dist/apply.d.ts +65 -0
  3. package/dist/apply.d.ts.map +1 -0
  4. package/dist/apply.js +143 -0
  5. package/dist/apply.js.map +1 -0
  6. package/dist/engines/files.d.ts +37 -0
  7. package/dist/engines/files.d.ts.map +1 -0
  8. package/dist/engines/files.js +137 -0
  9. package/dist/engines/files.js.map +1 -0
  10. package/dist/engines/index.d.ts +20 -0
  11. package/dist/engines/index.d.ts.map +1 -0
  12. package/dist/engines/index.js +35 -0
  13. package/dist/engines/index.js.map +1 -0
  14. package/dist/engines/mysql.d.ts +17 -0
  15. package/dist/engines/mysql.d.ts.map +1 -0
  16. package/dist/engines/mysql.js +171 -0
  17. package/dist/engines/mysql.js.map +1 -0
  18. package/dist/engines/object-storage.d.ts +42 -0
  19. package/dist/engines/object-storage.d.ts.map +1 -0
  20. package/dist/engines/object-storage.js +197 -0
  21. package/dist/engines/object-storage.js.map +1 -0
  22. package/dist/engines/postgres.d.ts +34 -0
  23. package/dist/engines/postgres.d.ts.map +1 -0
  24. package/dist/engines/postgres.js +309 -0
  25. package/dist/engines/postgres.js.map +1 -0
  26. package/dist/engines/redis.d.ts +3 -0
  27. package/dist/engines/redis.d.ts.map +1 -0
  28. package/dist/engines/redis.js +87 -0
  29. package/dist/engines/redis.js.map +1 -0
  30. package/dist/engines/sqlite.d.ts +3 -0
  31. package/dist/engines/sqlite.d.ts.map +1 -0
  32. package/dist/engines/sqlite.js +113 -0
  33. package/dist/engines/sqlite.js.map +1 -0
  34. package/dist/exec.d.ts +31 -0
  35. package/dist/exec.d.ts.map +1 -0
  36. package/dist/exec.js +119 -0
  37. package/dist/exec.js.map +1 -0
  38. package/dist/index.d.ts +35 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +31 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/plan.d.ts +115 -0
  43. package/dist/plan.d.ts.map +1 -0
  44. package/dist/plan.js +339 -0
  45. package/dist/plan.js.map +1 -0
  46. package/dist/platforms/index.d.ts +29 -0
  47. package/dist/platforms/index.d.ts.map +1 -0
  48. package/dist/platforms/index.js +51 -0
  49. package/dist/platforms/index.js.map +1 -0
  50. package/dist/platforms/managed.d.ts +41 -0
  51. package/dist/platforms/managed.d.ts.map +1 -0
  52. package/dist/platforms/managed.js +163 -0
  53. package/dist/platforms/managed.js.map +1 -0
  54. package/dist/platforms/railway.d.ts +29 -0
  55. package/dist/platforms/railway.d.ts.map +1 -0
  56. package/dist/platforms/railway.js +135 -0
  57. package/dist/platforms/railway.js.map +1 -0
  58. package/dist/platforms/ssh.d.ts +56 -0
  59. package/dist/platforms/ssh.d.ts.map +1 -0
  60. package/dist/platforms/ssh.js +151 -0
  61. package/dist/platforms/ssh.js.map +1 -0
  62. package/dist/platforms/supabase.d.ts +57 -0
  63. package/dist/platforms/supabase.d.ts.map +1 -0
  64. package/dist/platforms/supabase.js +102 -0
  65. package/dist/platforms/supabase.js.map +1 -0
  66. package/dist/staging.d.ts +27 -0
  67. package/dist/staging.d.ts.map +1 -0
  68. package/dist/staging.js +98 -0
  69. package/dist/staging.js.map +1 -0
  70. package/dist/transforms.d.ts +113 -0
  71. package/dist/transforms.d.ts.map +1 -0
  72. package/dist/transforms.js +179 -0
  73. package/dist/transforms.js.map +1 -0
  74. package/dist/types.d.ts +238 -0
  75. package/dist/types.d.ts.map +1 -0
  76. package/dist/types.js +79 -0
  77. package/dist/types.js.map +1 -0
  78. package/package.json +33 -4
package/README.md CHANGED
@@ -1,3 +1,134 @@
1
- # Temporary Holding Version
1
+ # @profullstack/sh1pt-migrate
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Move an application and its data between platforms, in either direction.
4
+
5
+ `packages/cloud/*` provisions machines. This moves what lives on them.
6
+
7
+ ```bash
8
+ sh1pt migrate platforms # what can move where
9
+ sh1pt migrate platforms --from supabase # ...and out of one place
10
+ sh1pt migrate inventory --from supabase -c m.json
11
+ sh1pt migrate plan --from supabase --to ssh -c m.json
12
+ sh1pt migrate apply --from supabase --to ssh -c m.json --until freeze
13
+ sh1pt migrate apply --from supabase --to ssh -c m.json
14
+ ```
15
+
16
+ ## Why it is bidirectional without twice the code
17
+
18
+ Two layers, and the split is the whole design:
19
+
20
+ - **Platforms** answer *what have I got, and what are the credentials* — Railway,
21
+ Supabase, Turso, Neon, PlanetScale, Fly, Render, Heroku, Vercel, a box over ssh.
22
+ A platform never moves a byte.
23
+ - **Engines** move bytes — `postgres`, `sqlite`, `redis`, `object-storage`, `files`.
24
+ An engine does not know which vendor is on either end.
25
+
26
+ So `supabase → ssh` and `ssh → supabase` are the same code path, and a new
27
+ platform costs one `inventory()` rather than one adapter per existing platform.
28
+ Direction is not a property of the system; it is which platform you named first.
29
+
30
+ `compatibleKinds('turso', 'neon')` returns `[]` — sqlite against postgres — and
31
+ says so in a millisecond rather than at a cutover.
32
+
33
+ ## The plan is the product
34
+
35
+ `migrate plan` touches nothing, calls nothing, and is safe against production.
36
+ It reports what moves, what does not and why, an ordered list of steps, and the
37
+ risks. Read it, disagree with it, then apply it.
38
+
39
+ Phase order is enforced, not documented:
40
+
41
+ | phase | what happens |
42
+ |---|---|
43
+ | `check` | credentials and binaries, so a missing `pg_dump` costs a second not three hours |
44
+ | `bulk` | the long copy, while the source is still live and serving |
45
+ | `freeze` | stop the writers. **Downtime starts here** |
46
+ | `delta` | only what changed during `bulk` |
47
+ | `cutover` | point DNS at the target |
48
+ | `enable` | start the writers again, on the target only |
49
+ | `verify` | prove it worked while the old system still exists |
50
+
51
+ Scheduled jobs are stopped on the source before they are started on the target,
52
+ because a cron firing on both sides is how a migration sends every customer a
53
+ duplicate email. Dropping the source is not a phase — that is a decision a
54
+ person makes days later, and this tool does not offer it.
55
+
56
+ `--until freeze` runs the entire bulk copy and stops before anything goes down.
57
+ That is how you rehearse against production.
58
+
59
+ ## The trap this exists for
60
+
61
+ An app that stores a whole URL instead of a key leaves rows pointing at the
62
+ account you just left:
63
+
64
+ ```
65
+ https://ywcizjsgrcmhgyplldac.supabase.co/storage/v1/object/public/ads/x.png
66
+ ```
67
+
68
+ Migrate everything, cut DNS over, check the site: every image loads — because
69
+ the **old** account is still serving them. The day it is closed, which is the
70
+ entire point of migrating and happens weeks later, all of them 404 at once and
71
+ nothing connects the outage to the migration.
72
+
73
+ crawlproof.com had 2,928 such rows across four tables. So the rewrite is a
74
+ first-class step: every text-ish column is scanned (broad on purpose — a column
75
+ called `notes` holding a pasted URL breaks exactly as badly as one called
76
+ `image_url`), rewritten inside one transaction, and then asserted to be zero.
77
+
78
+ ```bash
79
+ --rewrite-host ywcizjsgrcmhgyplldac.supabase.co=https://cdn.example.com
80
+ ```
81
+
82
+ The Supabase platform emits that exact flag for its own hostname, so it is a
83
+ line to copy rather than a thing to remember.
84
+
85
+ ## Safety properties, stated plainly
86
+
87
+ - **Nothing deletes.** `rclone copy`, never `sync`. No `rsync --delete`. No
88
+ `pg_restore --clean`. A non-empty Postgres target is refused rather than
89
+ overwritten.
90
+ - **Credentials never reach a plan file.** Connections are a
91
+ `describe()`/`reveal()` pair; a test asserts a rendered plan contains no
92
+ password.
93
+ - **Credentials never reach `argv`.** libpq environment variables for Postgres,
94
+ `RCLONE_CONFIG_*` for object storage, `TURSO_API_TOKEN` for Turso. `ps` is
95
+ world-readable and a dump runs for hours.
96
+ - **No shell.** `spawn` without one, always — engine arguments come from config
97
+ a person edits.
98
+ - **Resumable.** The staging ledger is append-only JSONL, so an interrupted run
99
+ can only truncate its last line, and the next run skips what is done.
100
+
101
+ ## Config
102
+
103
+ ```json
104
+ {
105
+ "from": {
106
+ "projectRef": "abc123",
107
+ "dbPassword": "...",
108
+ "buckets": ["ads", "articles"]
109
+ },
110
+ "to": {
111
+ "host": "dev2.example.com",
112
+ "user": "anthony",
113
+ "postgres": [{ "name": "postgres", "url": "postgres://app@127.0.0.1:5432/app" }]
114
+ }
115
+ }
116
+ ```
117
+
118
+ Secrets are read from the environment where a platform names one
119
+ (`SUPABASE_SERVICE_ROLE_KEY`, `RAILWAY_TOKEN`, `TURSO_API_TOKEN`,
120
+ `NEON_DATABASE_URL`, …), so they need not be in the file.
121
+
122
+ ## What it needs installed
123
+
124
+ Per engine, checked before anything runs: `pg_dump`/`pg_restore`/`psql`,
125
+ `mysqldump`/`mysql`,
126
+ `sqlite3`, `redis-cli`, `rclone`, `rsync`.
127
+
128
+ ## Known limits
129
+
130
+ - The Postgres delta covers **inserts into tables with a timestamp column**, not
131
+ updates or deletes. The planner says so rather than implying otherwise.
132
+ - Redis has no delta at all. Stop the writers first.
133
+ - rsync cannot copy remote to remote; one side must be local.
134
+ - A Railway volume is only reachable from inside its service.
@@ -0,0 +1,65 @@
1
+ import type { MigrationPlan, Phase, Step } from './plan.js';
2
+ import type { Artifact, Engine, EngineContext, Resource, ResourceKind } from './types.js';
3
+ /**
4
+ * Running a plan.
5
+ *
6
+ * The planner decided what happens and in what order; this does it, and its
7
+ * only real job is refusing to deviate. Two things make a migration
8
+ * catastrophic rather than merely failed: doing a later phase before an
9
+ * earlier one, and carrying on after a step that was supposed to be a gate.
10
+ * Both are prevented here rather than trusted to the caller.
11
+ *
12
+ * Everything that touches the world is injected — `exec`, the clock, the
13
+ * staging — so the whole executor is exercised without a network, a database,
14
+ * or a wall-clock wait.
15
+ */
16
+ export interface ApplyOptions {
17
+ plan: MigrationPlan;
18
+ /** Source resources by id. */
19
+ from: Map<string, Resource>;
20
+ /** Target resources by id, already resolved by the target platform. */
21
+ to: Map<string, Resource>;
22
+ engines: Map<ResourceKind, Engine>;
23
+ ctx: EngineContext;
24
+ /**
25
+ * Stop before this phase. `--until freeze` runs the whole bulk copy and
26
+ * stops before anything goes down, which is how a migration is rehearsed
27
+ * against production without a cutover.
28
+ */
29
+ until?: Phase;
30
+ /** Steps already completed, from a previous run. */
31
+ completed?: Set<string>;
32
+ /** When the bulk copy started, for the delta. Defaults to now at freeze. */
33
+ bulkStartedAt?: Date;
34
+ /** Called after each step so a caller can persist progress. */
35
+ onStep?: (step: Step, outcome: StepOutcome) => void | Promise<void>;
36
+ }
37
+ export interface StepOutcome {
38
+ status: 'done' | 'skipped' | 'failed';
39
+ reason?: string;
40
+ artifacts?: Artifact[];
41
+ error?: Error;
42
+ }
43
+ export interface ApplyResult {
44
+ completed: string[];
45
+ skipped: Array<{
46
+ id: string;
47
+ reason: string;
48
+ }>;
49
+ failed?: {
50
+ id: string;
51
+ error: Error;
52
+ };
53
+ /** True when everything up to `until` ran. */
54
+ ok: boolean;
55
+ stoppedBefore?: Phase;
56
+ }
57
+ /**
58
+ * Execute a plan.
59
+ *
60
+ * Refuses a plan with blockers. The planner already said it was not
61
+ * applyable, and the one thing worse than a migration that will not start is
62
+ * one that starts anyway.
63
+ */
64
+ export declare function applyPlan(opts: ApplyOptions): Promise<ApplyResult>;
65
+ //# sourceMappingURL=apply.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../src/apply.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1F;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,aAAa,CAAC;IACpB,8BAA8B;IAC9B,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC5B,uEAAuE;IACvE,EAAE,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC1B,OAAO,EAAE,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IACnC,GAAG,EAAE,aAAa,CAAC;IACnB;;;;OAIG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,oDAAoD;IACpD,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,4EAA4E;IAC5E,aAAa,CAAC,EAAE,IAAI,CAAC;IACrB,+DAA+D;IAC/D,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrE;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,MAAM,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC;IACtC,8CAA8C;IAC9C,EAAE,EAAE,OAAO,CAAC;IACZ,aAAa,CAAC,EAAE,KAAK,CAAC;CACvB;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CA2ExE"}
package/dist/apply.js ADDED
@@ -0,0 +1,143 @@
1
+ import { PHASES } from './plan.js';
2
+ /**
3
+ * Execute a plan.
4
+ *
5
+ * Refuses a plan with blockers. The planner already said it was not
6
+ * applyable, and the one thing worse than a migration that will not start is
7
+ * one that starts anyway.
8
+ */
9
+ export async function applyPlan(opts) {
10
+ const { plan, ctx, engines } = opts;
11
+ if (!plan.ok) {
12
+ const blockers = plan.risks.filter((r) => r.severity === 'blocker').map((r) => r.message);
13
+ throw new Error(`refusing to apply a plan with blockers:\n ${blockers.join('\n ')}`);
14
+ }
15
+ const completed = new Set(opts.completed ?? []);
16
+ const done = [];
17
+ const skipped = [];
18
+ const stopIndex = opts.until ? PHASES.indexOf(opts.until) : PHASES.length;
19
+ const artifactsByResource = new Map();
20
+ let bulkStartedAt = opts.bulkStartedAt;
21
+ for (const step of plan.steps) {
22
+ if (PHASES.indexOf(step.phase) >= stopIndex) {
23
+ return {
24
+ completed: done,
25
+ skipped,
26
+ ok: true,
27
+ stoppedBefore: opts.until,
28
+ };
29
+ }
30
+ if (completed.has(step.id)) {
31
+ skipped.push({ id: step.id, reason: 'already done in a previous run' });
32
+ await opts.onStep?.(step, { status: 'skipped', reason: 'already done' });
33
+ continue;
34
+ }
35
+ /*
36
+ * A step whose dependency did not run must not run either. The planner
37
+ * ordered the steps, but a resumed run or a skipped step can leave a gap,
38
+ * and "import" running without its "export" would restore whatever was in
39
+ * staging from a previous, possibly different, migration.
40
+ */
41
+ const missing = step.after.filter((dep) => plan.steps.some((s) => s.id === dep) && !completed.has(dep) && !done.includes(dep));
42
+ if (missing.length) {
43
+ skipped.push({ id: step.id, reason: `depends on ${missing.join(', ')}, which did not run` });
44
+ await opts.onStep?.(step, { status: 'skipped', reason: `unmet dependency: ${missing[0]}` });
45
+ continue;
46
+ }
47
+ // The clock for the delta starts when the bulk copy starts, not when the
48
+ // freeze does: anything written during the bulk copy is exactly what the
49
+ // delta has to catch.
50
+ if (step.phase === 'bulk' && !bulkStartedAt)
51
+ bulkStartedAt = new Date();
52
+ try {
53
+ const outcome = await runStep(step, {
54
+ ...opts,
55
+ engines,
56
+ ctx,
57
+ artifactsByResource,
58
+ bulkStartedAt: bulkStartedAt ?? new Date(),
59
+ });
60
+ if (outcome.status === 'skipped') {
61
+ skipped.push({ id: step.id, reason: outcome.reason ?? 'skipped' });
62
+ }
63
+ else {
64
+ done.push(step.id);
65
+ completed.add(step.id);
66
+ }
67
+ await opts.onStep?.(step, outcome);
68
+ }
69
+ catch (err) {
70
+ const error = err instanceof Error ? err : new Error(String(err));
71
+ await opts.onStep?.(step, { status: 'failed', error });
72
+ ctx.log(`step '${step.id}' failed: ${error.message}`, 'error');
73
+ return { completed: done, skipped, failed: { id: step.id, error }, ok: false };
74
+ }
75
+ }
76
+ return { completed: done, skipped, ok: true };
77
+ }
78
+ async function runStep(step, rc) {
79
+ const { ctx, engines, from, to, artifactsByResource } = rc;
80
+ // Steps with no resource are gates and instructions: the freeze, the DNS
81
+ // cutover, the URL rewrite. They are real work, but not work this executor
82
+ // can do unattended — pointing DNS at a new host is not something to do on
83
+ // a caller's behalf without being asked very explicitly.
84
+ if (!step.resourceId) {
85
+ ctx.log(`${step.phase}: ${step.title}`);
86
+ return { status: 'done' };
87
+ }
88
+ const source = from.get(step.resourceId);
89
+ const target = to.get(step.resourceId);
90
+ const kind = step.kind;
91
+ const engine = kind ? engines.get(kind) : undefined;
92
+ if (!engine || !source) {
93
+ return { status: 'skipped', reason: `no engine or source for ${step.resourceId}` };
94
+ }
95
+ const verb = step.id.split(':')[0];
96
+ switch (verb) {
97
+ case 'export': {
98
+ const artifacts = await engine.export(ctx, source);
99
+ artifactsByResource.set(step.resourceId, artifacts);
100
+ return { status: 'done', artifacts };
101
+ }
102
+ case 'import': {
103
+ if (!target)
104
+ return { status: 'skipped', reason: `no target resolved for ${step.resourceId}` };
105
+ const staged = artifactsByResource.get(step.resourceId) ?? (await ctx.staging.existing(step.resourceId));
106
+ await engine.import(ctx, target, staged, source);
107
+ return { status: 'done' };
108
+ }
109
+ case 'delta': {
110
+ if (!engine.delta)
111
+ return { status: 'skipped', reason: 'engine has no delta' };
112
+ const artifacts = await engine.delta(ctx, source, rc.bulkStartedAt);
113
+ if (target && artifacts.length)
114
+ await engine.import(ctx, target, artifacts, source);
115
+ return { status: 'done', artifacts };
116
+ }
117
+ case 'verify': {
118
+ if (!engine.verify)
119
+ return { status: 'skipped', reason: 'engine has no verify' };
120
+ if (!target)
121
+ return { status: 'skipped', reason: 'no target to compare against' };
122
+ const result = await engine.verify(ctx, source, target);
123
+ for (const line of result.checks)
124
+ ctx.log(` ${line}`);
125
+ if (!result.ok) {
126
+ throw new Error(`verification failed for ${source.name}:\n ${result.problems.join('\n ')}`);
127
+ }
128
+ return { status: 'done' };
129
+ }
130
+ case 'disable':
131
+ case 'enable':
132
+ // Scheduled jobs. Surfaced rather than automated, for the same reason as
133
+ // the DNS cutover: turning cron on at the wrong moment is the failure
134
+ // the phase ordering exists to prevent, and doing it silently would put
135
+ // the decision back in the tool.
136
+ ctx.log(`${step.phase}: ${step.title}`, 'warn');
137
+ return { status: 'done' };
138
+ default:
139
+ ctx.log(`${step.phase}: ${step.title}`);
140
+ return { status: 'done' };
141
+ }
142
+ }
143
+ //# sourceMappingURL=apply.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply.js","sourceRoot":"","sources":["../src/apply.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAuDnC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAkB;IAChD,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAEpC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;QACb,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAC1F,MAAM,IAAI,KAAK,CAAC,8CAA8C,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACzF,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE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K,IAAI,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,CAAC;YAChD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QAC5B;YACE,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;YACxC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAC9B,CAAC;AACH,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { Engine, Resource } from '../types.js';
2
+ /**
3
+ * Moving a directory of files — a mounted volume, an uploads directory, a
4
+ * docroot.
5
+ *
6
+ * This is the engine for the thing that is not a database and not a bucket:
7
+ * Railway volumes, Fly volumes, and `~/www/<domain>` on a dedicated box. rsync
8
+ * does it because rsync is what does this, and because its delta algorithm
9
+ * makes the second pass — the one during the cutover window — proportional to
10
+ * what changed rather than to the size of the tree.
11
+ *
12
+ * As with object storage, `--delete` is never passed. rsync's delete is the
13
+ * single most effective way to destroy a directory by typing the wrong target,
14
+ * and a migration has no reason to remove anything.
15
+ */
16
+ /**
17
+ * `[user@host:]/path/` as rsync wants it.
18
+ *
19
+ * The trailing slash is always present and always matters: with it rsync
20
+ * copies the CONTENTS of the directory, without it it nests the directory
21
+ * inside the destination, producing `~/www/app/app/` — which looks from the
22
+ * outside like the copy silently did nothing.
23
+ */
24
+ export declare function endpoint(r: Resource): string;
25
+ export declare function isRemote(r: Resource): boolean;
26
+ /**
27
+ * rsync cannot copy remote to remote.
28
+ *
29
+ * It is a hard limitation of the protocol, not a flag that was missed: one
30
+ * side must be local. A VPS-to-VPS move therefore has to relay through the
31
+ * machine running the migration, which is a real cost (the bytes cross the
32
+ * wire twice) and needs to be said out loud rather than discovered when rsync
33
+ * exits with "The source and destination cannot both be remote."
34
+ */
35
+ export declare function assertCopyable(from: Resource, to: Resource): void;
36
+ export declare const filesEngine: Engine;
37
+ //# sourceMappingURL=files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/engines/files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,MAAM,EAAiB,QAAQ,EAAgB,MAAM,aAAa,CAAC;AAE3F;;;;;;;;;;;;;GAaG;AAEH;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,CAQ5C;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,QAAQ,GAAG,OAAO,CAE7C;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,GAAG,IAAI,CAMjE;AAaD,eAAO,MAAM,WAAW,EAAE,MA0FzB,CAAC"}
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Moving a directory of files — a mounted volume, an uploads directory, a
3
+ * docroot.
4
+ *
5
+ * This is the engine for the thing that is not a database and not a bucket:
6
+ * Railway volumes, Fly volumes, and `~/www/<domain>` on a dedicated box. rsync
7
+ * does it because rsync is what does this, and because its delta algorithm
8
+ * makes the second pass — the one during the cutover window — proportional to
9
+ * what changed rather than to the size of the tree.
10
+ *
11
+ * As with object storage, `--delete` is never passed. rsync's delete is the
12
+ * single most effective way to destroy a directory by typing the wrong target,
13
+ * and a migration has no reason to remove anything.
14
+ */
15
+ /**
16
+ * `[user@host:]/path/` as rsync wants it.
17
+ *
18
+ * The trailing slash is always present and always matters: with it rsync
19
+ * copies the CONTENTS of the directory, without it it nests the directory
20
+ * inside the destination, producing `~/www/app/app/` — which looks from the
21
+ * outside like the copy silently did nothing.
22
+ */
23
+ export function endpoint(r) {
24
+ const path = r.connection.path?.reveal();
25
+ if (!path)
26
+ throw new Error(`files resource '${r.name}' has no connection.path`);
27
+ const withSlash = `${path.replace(/\/*$/, '')}/`;
28
+ const host = r.connection.host?.reveal();
29
+ if (!host)
30
+ return withSlash;
31
+ const user = r.connection.user?.reveal();
32
+ return `${user ? `${user}@` : ''}${host}:${withSlash}`;
33
+ }
34
+ export function isRemote(r) {
35
+ return Boolean(r.connection.host);
36
+ }
37
+ /**
38
+ * rsync cannot copy remote to remote.
39
+ *
40
+ * It is a hard limitation of the protocol, not a flag that was missed: one
41
+ * side must be local. A VPS-to-VPS move therefore has to relay through the
42
+ * machine running the migration, which is a real cost (the bytes cross the
43
+ * wire twice) and needs to be said out loud rather than discovered when rsync
44
+ * exits with "The source and destination cannot both be remote."
45
+ */
46
+ export function assertCopyable(from, to) {
47
+ if (isRemote(from) && isRemote(to)) {
48
+ throw new Error(`rsync cannot copy directly between two remote hosts (${from.name} → ${to.name}). Run the migration from one of them, or stage the directory locally first.`);
49
+ }
50
+ }
51
+ /** The ssh transport, including a key when one is configured. */
52
+ function rsyncTransport(r) {
53
+ const key = r.connection.sshKeyPath?.reveal();
54
+ const port = r.connection.sshPort?.reveal();
55
+ if (!r.connection.host)
56
+ return [];
57
+ const parts = ['ssh', '-o', 'BatchMode=yes'];
58
+ if (key)
59
+ parts.push('-i', key);
60
+ if (port)
61
+ parts.push('-p', port);
62
+ return ['-e', parts.join(' ')];
63
+ }
64
+ export const filesEngine = {
65
+ kind: 'files',
66
+ requires: ['rsync'],
67
+ /**
68
+ * Nothing is staged: like object storage, files go host to host. The export
69
+ * records what is there so `verify` has something to compare and so a plan
70
+ * can show a size.
71
+ */
72
+ async export(ctx, from) {
73
+ const path = `${from.id}/files.manifest`;
74
+ if (ctx.dryRun)
75
+ return [{ resourceId: from.id, kind: 'files', path }];
76
+ const res = await ctx.exec('rsync', [...rsyncTransport(from), '--dry-run', '--archive', '--stats', endpoint(from), '/dev/null'], { check: false });
77
+ const files = /Number of files: ([\d,]+)/.exec(res.stdout)?.[1]?.replace(/,/g, '');
78
+ const artifact = {
79
+ resourceId: from.id,
80
+ kind: 'files',
81
+ path,
82
+ metadata: { fileCount: files ? Number(files) : 0 },
83
+ };
84
+ await ctx.staging.record(artifact);
85
+ return [artifact];
86
+ },
87
+ async import(ctx, to, _artifacts, from) {
88
+ if (!from)
89
+ throw new Error('files import needs the source resource: files are copied host to host');
90
+ assertCopyable(from, to);
91
+ if (ctx.dryRun) {
92
+ ctx.log(`would rsync ${endpoint(from)} → ${endpoint(to)}`);
93
+ return;
94
+ }
95
+ await ctx.exec('rsync', [
96
+ ...rsyncTransport(isRemote(from) ? from : to),
97
+ '--archive',
98
+ '--compress',
99
+ '--partial',
100
+ '--human-readable',
101
+ endpoint(from),
102
+ endpoint(to),
103
+ ], { timeoutMs: 12 * 60 * 60 * 1000 });
104
+ },
105
+ /** The second pass, during the cutover window: only what changed. */
106
+ async delta(ctx, from, _since) {
107
+ const path = `${from.id}/files.delta`;
108
+ if (ctx.dryRun)
109
+ return [{ resourceId: from.id, kind: 'files', path }];
110
+ // rsync compares by size and mtime on its own, so the delta pass is the
111
+ // same command. It is fast because almost nothing has changed.
112
+ const artifact = { resourceId: from.id, kind: 'files', path, metadata: { mode: 'delta' } };
113
+ await ctx.staging.record(artifact);
114
+ return [artifact];
115
+ },
116
+ async verify(ctx, from, to) {
117
+ if (ctx.dryRun)
118
+ return { ok: true, checks: ['dry run: not compared'], problems: [] };
119
+ // A dry-run rsync from source to target lists exactly what still differs.
120
+ // Zero transfers is the pass condition.
121
+ const res = await ctx.exec('rsync', [
122
+ ...rsyncTransport(isRemote(from) ? from : to),
123
+ '--dry-run',
124
+ '--archive',
125
+ '--itemize-changes',
126
+ endpoint(from),
127
+ endpoint(to),
128
+ ], { check: false });
129
+ const differing = res.stdout.split('\n').map((l) => l.trim()).filter(Boolean);
130
+ return {
131
+ ok: differing.length === 0,
132
+ checks: [`${differing.length} path(s) still differ`],
133
+ problems: differing.slice(0, 20),
134
+ };
135
+ },
136
+ };
137
+ //# sourceMappingURL=files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/engines/files.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,CAAW;I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,CAAC;CACF,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { Engine, ResourceKind } from '../types.js';
2
+ import { filesEngine } from './files.js';
3
+ import { mysqlEngine } from './mysql.js';
4
+ import { objectStorageEngine } from './object-storage.js';
5
+ import { postgresEngine } from './postgres.js';
6
+ import { redisEngine } from './redis.js';
7
+ import { sqliteEngine } from './sqlite.js';
8
+ /**
9
+ * Every engine this build can run, keyed by what it moves.
10
+ *
11
+ * The planner takes this map and refuses, up front, to plan a migration for a
12
+ * kind that is not in it — which is the difference between "we do not support
13
+ * that" printed before anything happens and a crash after the freeze.
14
+ */
15
+ export declare const ENGINES: ReadonlyMap<ResourceKind, Engine>;
16
+ export declare function engineFor(kind: ResourceKind): Engine | undefined;
17
+ /** Every binary any engine needs, for a one-shot preflight check. */
18
+ export declare function requiredBinaries(kinds: ResourceKind[]): string[];
19
+ export { filesEngine, mysqlEngine, objectStorageEngine, postgresEngine, redisEngine, sqliteEngine };
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/engines/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,EAAE,WAAW,CAAC,YAAY,EAAE,MAAM,CAOpD,CAAC;AAEH,wBAAgB,SAAS,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAEhE;AAED,qEAAqE;AACrE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,MAAM,EAAE,CAMhE;AAED,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,mBAAmB,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { filesEngine } from './files.js';
2
+ import { mysqlEngine } from './mysql.js';
3
+ import { objectStorageEngine } from './object-storage.js';
4
+ import { postgresEngine } from './postgres.js';
5
+ import { redisEngine } from './redis.js';
6
+ import { sqliteEngine } from './sqlite.js';
7
+ /**
8
+ * Every engine this build can run, keyed by what it moves.
9
+ *
10
+ * The planner takes this map and refuses, up front, to plan a migration for a
11
+ * kind that is not in it — which is the difference between "we do not support
12
+ * that" printed before anything happens and a crash after the freeze.
13
+ */
14
+ export const ENGINES = new Map([
15
+ ['postgres', postgresEngine],
16
+ ['mysql', mysqlEngine],
17
+ ['sqlite', sqliteEngine],
18
+ ['redis', redisEngine],
19
+ ['object-storage', objectStorageEngine],
20
+ ['files', filesEngine],
21
+ ]);
22
+ export function engineFor(kind) {
23
+ return ENGINES.get(kind);
24
+ }
25
+ /** Every binary any engine needs, for a one-shot preflight check. */
26
+ export function requiredBinaries(kinds) {
27
+ const out = new Set();
28
+ for (const kind of kinds) {
29
+ for (const bin of ENGINES.get(kind)?.requires ?? [])
30
+ out.add(bin);
31
+ }
32
+ return [...out].sort();
33
+ }
34
+ export { filesEngine, mysqlEngine, objectStorageEngine, postgresEngine, redisEngine, sqliteEngine };
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/engines/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,OAAO,GAAsC,IAAI,GAAG,CAAuB;IACtF,CAAC,UAAU,EAAE,cAAc,CAAC;IAC5B,CAAC,OAAO,EAAE,WAAW,CAAC;IACtB,CAAC,QAAQ,EAAE,YAAY,CAAC;IACxB,CAAC,OAAO,EAAE,WAAW,CAAC;IACtB,CAAC,gBAAgB,EAAE,mBAAmB,CAAC;IACvC,CAAC,OAAO,EAAE,WAAW,CAAC;CACvB,CAAC,CAAC;AAEH,MAAM,UAAU,SAAS,CAAC,IAAkB;IAC1C,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,gBAAgB,CAAC,KAAqB;IACpD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,QAAQ,IAAI,EAAE;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC;AAED,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,mBAAmB,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { Engine, Resource } from '../types.js';
2
+ /**
3
+ * Connection details for the mysql client family.
4
+ *
5
+ * `MYSQL_PWD` rather than `--password=`, for the same reason Postgres uses
6
+ * libpq's variables: a password on the command line is readable by every other
7
+ * user on the box via `ps` for as long as the dump runs. The client warns
8
+ * about `MYSQL_PWD` being insecure on shared machines, which is true and still
9
+ * strictly better than argv.
10
+ */
11
+ export declare function mysqlConnection(r: Resource): {
12
+ args: string[];
13
+ env: Record<string, string>;
14
+ };
15
+ export declare function databaseName(r: Resource): string;
16
+ export declare const mysqlEngine: Engine;
17
+ //# sourceMappingURL=mysql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../../src/engines/mysql.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,MAAM,EAAiB,QAAQ,EAAgB,MAAM,aAAa,CAAC;AAqC3F;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,QAAQ,GAAG;IAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAuB5F;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,CAKhD;AAED,eAAO,MAAM,WAAW,EAAE,MAoHzB,CAAC"}