@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.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +133 -2
  3. package/dist/apply.d.ts +65 -0
  4. package/dist/apply.d.ts.map +1 -0
  5. package/dist/apply.js +143 -0
  6. package/dist/apply.js.map +1 -0
  7. package/dist/engines/files.d.ts +37 -0
  8. package/dist/engines/files.d.ts.map +1 -0
  9. package/dist/engines/files.js +137 -0
  10. package/dist/engines/files.js.map +1 -0
  11. package/dist/engines/index.d.ts +20 -0
  12. package/dist/engines/index.d.ts.map +1 -0
  13. package/dist/engines/index.js +35 -0
  14. package/dist/engines/index.js.map +1 -0
  15. package/dist/engines/mysql.d.ts +17 -0
  16. package/dist/engines/mysql.d.ts.map +1 -0
  17. package/dist/engines/mysql.js +171 -0
  18. package/dist/engines/mysql.js.map +1 -0
  19. package/dist/engines/object-storage.d.ts +42 -0
  20. package/dist/engines/object-storage.d.ts.map +1 -0
  21. package/dist/engines/object-storage.js +197 -0
  22. package/dist/engines/object-storage.js.map +1 -0
  23. package/dist/engines/postgres.d.ts +34 -0
  24. package/dist/engines/postgres.d.ts.map +1 -0
  25. package/dist/engines/postgres.js +309 -0
  26. package/dist/engines/postgres.js.map +1 -0
  27. package/dist/engines/redis.d.ts +3 -0
  28. package/dist/engines/redis.d.ts.map +1 -0
  29. package/dist/engines/redis.js +87 -0
  30. package/dist/engines/redis.js.map +1 -0
  31. package/dist/engines/sqlite.d.ts +3 -0
  32. package/dist/engines/sqlite.d.ts.map +1 -0
  33. package/dist/engines/sqlite.js +113 -0
  34. package/dist/engines/sqlite.js.map +1 -0
  35. package/dist/exec.d.ts +31 -0
  36. package/dist/exec.d.ts.map +1 -0
  37. package/dist/exec.js +119 -0
  38. package/dist/exec.js.map +1 -0
  39. package/dist/index.d.ts +35 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +31 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/plan.d.ts +115 -0
  44. package/dist/plan.d.ts.map +1 -0
  45. package/dist/plan.js +339 -0
  46. package/dist/plan.js.map +1 -0
  47. package/dist/platforms/index.d.ts +29 -0
  48. package/dist/platforms/index.d.ts.map +1 -0
  49. package/dist/platforms/index.js +51 -0
  50. package/dist/platforms/index.js.map +1 -0
  51. package/dist/platforms/managed.d.ts +41 -0
  52. package/dist/platforms/managed.d.ts.map +1 -0
  53. package/dist/platforms/managed.js +163 -0
  54. package/dist/platforms/managed.js.map +1 -0
  55. package/dist/platforms/railway.d.ts +29 -0
  56. package/dist/platforms/railway.d.ts.map +1 -0
  57. package/dist/platforms/railway.js +135 -0
  58. package/dist/platforms/railway.js.map +1 -0
  59. package/dist/platforms/ssh.d.ts +56 -0
  60. package/dist/platforms/ssh.d.ts.map +1 -0
  61. package/dist/platforms/ssh.js +151 -0
  62. package/dist/platforms/ssh.js.map +1 -0
  63. package/dist/platforms/supabase.d.ts +57 -0
  64. package/dist/platforms/supabase.d.ts.map +1 -0
  65. package/dist/platforms/supabase.js +102 -0
  66. package/dist/platforms/supabase.js.map +1 -0
  67. package/dist/staging.d.ts +27 -0
  68. package/dist/staging.d.ts.map +1 -0
  69. package/dist/staging.js +98 -0
  70. package/dist/staging.js.map +1 -0
  71. package/dist/transforms.d.ts +113 -0
  72. package/dist/transforms.d.ts.map +1 -0
  73. package/dist/transforms.js +179 -0
  74. package/dist/transforms.js.map +1 -0
  75. package/dist/types.d.ts +238 -0
  76. package/dist/types.d.ts.map +1 -0
  77. package/dist/types.js +79 -0
  78. package/dist/types.js.map +1 -0
  79. package/package.json +32 -3
@@ -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"}
@@ -0,0 +1,171 @@
1
+ import { quoteIdent, quoteLiteral } from '../transforms.js';
2
+ /**
3
+ * Moving a MySQL or MariaDB database.
4
+ *
5
+ * PlanetScale, RDS, a MariaDB in a container. Same shape as the Postgres
6
+ * engine and for the same reasons; the differences are all in the tooling.
7
+ *
8
+ * ## The flags that matter
9
+ *
10
+ * `--single-transaction` takes the dump inside one consistent snapshot on
11
+ * InnoDB instead of locking every table for the length of the dump. Without
12
+ * it, a multi-gigabyte dump is an outage, which rather defeats the point of
13
+ * copying while the source is still live.
14
+ *
15
+ * `--set-gtid-purged=OFF`, because a dump carrying GTID state refuses to load
16
+ * into a server with its own replication history, and the error names neither
17
+ * the flag nor the cause.
18
+ *
19
+ * `--no-tablespaces`, because writing tablespace clauses needs PROCESS
20
+ * privilege that a managed provider does not grant, and its absence fails the
21
+ * dump rather than degrading it.
22
+ *
23
+ * PlanetScale specifically does not support foreign key constraints in the
24
+ * usual way, so a dump taken there restores without constraints a plain MySQL
25
+ * would have had. That is recorded as a platform quirk rather than silently
26
+ * handled, because the fix is a schema decision, not a flag.
27
+ */
28
+ const DUMP = 'dump.sql';
29
+ function dsn(r) {
30
+ const url = r.connection.url;
31
+ if (!url)
32
+ throw new Error(`mysql resource '${r.name}' has no connection.url`);
33
+ return url.reveal();
34
+ }
35
+ /**
36
+ * Connection details for the mysql client family.
37
+ *
38
+ * `MYSQL_PWD` rather than `--password=`, for the same reason Postgres uses
39
+ * libpq's variables: a password on the command line is readable by every other
40
+ * user on the box via `ps` for as long as the dump runs. The client warns
41
+ * about `MYSQL_PWD` being insecure on shared machines, which is true and still
42
+ * strictly better than argv.
43
+ */
44
+ export function mysqlConnection(r) {
45
+ const raw = dsn(r);
46
+ let u;
47
+ try {
48
+ u = new URL(raw);
49
+ }
50
+ catch {
51
+ throw new Error(`mysql resource '${r.name}' has a connection.url that is not a URL`);
52
+ }
53
+ const args = [];
54
+ if (u.hostname)
55
+ args.push(`--host=${decodeURIComponent(u.hostname)}`);
56
+ if (u.port)
57
+ args.push(`--port=${u.port}`);
58
+ if (u.username)
59
+ args.push(`--user=${decodeURIComponent(u.username)}`);
60
+ // Managed MySQL is TLS-only in practice, and the client's default is to fall
61
+ // back silently where it is not enforced.
62
+ const sslMode = u.searchParams.get('ssl-mode') ?? 'REQUIRED';
63
+ args.push(`--ssl-mode=${sslMode}`);
64
+ const env = {};
65
+ if (u.password)
66
+ env.MYSQL_PWD = decodeURIComponent(u.password);
67
+ return { args, env };
68
+ }
69
+ export function databaseName(r) {
70
+ const raw = dsn(r);
71
+ const name = new URL(raw).pathname.replace(/^\//, '');
72
+ if (!name)
73
+ throw new Error(`mysql resource '${r.name}' has no database in its connection.url`);
74
+ return decodeURIComponent(name);
75
+ }
76
+ export const mysqlEngine = {
77
+ kind: 'mysql',
78
+ requires: ['mysqldump', 'mysql'],
79
+ async export(ctx, from) {
80
+ const path = `${from.id}/${DUMP}`;
81
+ ctx.log(`mysqldump ${from.name} → ${path}`);
82
+ if (ctx.dryRun)
83
+ return [{ resourceId: from.id, kind: 'mysql', path }];
84
+ const { args, env } = mysqlConnection(from);
85
+ await ctx.exec('mysqldump', [
86
+ ...args,
87
+ // A consistent snapshot instead of locking every table for the length
88
+ // of the dump.
89
+ '--single-transaction',
90
+ '--quick',
91
+ '--routines',
92
+ '--triggers',
93
+ '--events',
94
+ '--set-gtid-purged=OFF',
95
+ '--no-tablespaces',
96
+ databaseName(from),
97
+ ], { env, stdoutFile: `${ctx.staging.dir}/${path}`, timeoutMs: 6 * 60 * 60 * 1000 });
98
+ const artifact = { resourceId: from.id, kind: 'mysql', path };
99
+ await ctx.staging.record(artifact);
100
+ return [artifact];
101
+ },
102
+ async import(ctx, to, artifacts) {
103
+ const dump = artifacts.find((a) => a.kind === 'mysql');
104
+ if (!dump)
105
+ throw new Error(`no mysql dump staged for '${to.name}'`);
106
+ if (ctx.dryRun) {
107
+ ctx.log(`would load ${dump.path} into ${to.name}`);
108
+ return;
109
+ }
110
+ const { args, env } = mysqlConnection(to);
111
+ // Same refusal as Postgres: a non-empty target is not written over. A
112
+ // mysqldump replays CREATE TABLE and INSERT, so aiming it at a populated
113
+ // database is a mess of duplicate-key errors on top of live data.
114
+ const existing = await ctx.exec('mysql', [
115
+ ...args,
116
+ '--batch',
117
+ '--skip-column-names',
118
+ '--execute',
119
+ `select count(*) from information_schema.tables where table_schema = ${quoteLiteral(databaseName(to))}`,
120
+ ], { env, check: false });
121
+ const tableCount = Number.parseInt(existing.stdout.trim(), 10);
122
+ if (Number.isFinite(tableCount) && tableCount > 0) {
123
+ throw new Error(`target database '${to.name}' already has ${tableCount} table(s). Refusing to load over it — drop and recreate it, or point at an empty one.`);
124
+ }
125
+ ctx.log(`mysql < ${dump.path}`);
126
+ await ctx.exec('mysql', [...args, databaseName(to)], {
127
+ env,
128
+ stdinFile: `${ctx.staging.dir}/${dump.path}`,
129
+ timeoutMs: 6 * 60 * 60 * 1000,
130
+ });
131
+ },
132
+ async verify(ctx, from, to) {
133
+ if (ctx.dryRun)
134
+ return { ok: true, checks: ['dry run: not compared'], problems: [] };
135
+ const counts = async (r) => {
136
+ const { args, env } = mysqlConnection(r);
137
+ const res = await ctx.exec('mysql', [
138
+ ...args,
139
+ '--batch',
140
+ '--skip-column-names',
141
+ '--execute',
142
+ `select table_name, table_rows from information_schema.tables
143
+ where table_schema = ${quoteLiteral(databaseName(r))} order by table_name`,
144
+ ], { env, check: false });
145
+ const map = new Map();
146
+ for (const line of res.stdout.split('\n')) {
147
+ const [name, n] = line.split('\t');
148
+ if (name && n !== undefined)
149
+ map.set(name.trim(), Number.parseInt(n, 10) || 0);
150
+ }
151
+ return map;
152
+ };
153
+ const [a, b] = await Promise.all([counts(from), counts(to)]);
154
+ const checks = [];
155
+ const problems = [];
156
+ for (const [table, sourceRows] of a) {
157
+ const targetRows = b.get(table);
158
+ if (targetRows === undefined) {
159
+ problems.push(`${table}: missing on the target`);
160
+ continue;
161
+ }
162
+ // information_schema.table_rows is an ESTIMATE on InnoDB, not a count.
163
+ // Treating it as exact would fail every verification, so a table present
164
+ // on both sides is reported rather than judged, and only a missing table
165
+ // is a problem.
166
+ checks.push(`${quoteIdent(table)}: ~${sourceRows} → ~${targetRows} (estimated)`);
167
+ }
168
+ return { ok: problems.length === 0, checks, problems };
169
+ },
170
+ };
171
+ //# sourceMappingURL=mysql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mysql.js","sourceRoot":"","sources":["../../src/engines/mysql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAG5D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,MAAM,IAAI,GAAG,UAAU,CAAC;AAExB,SAAS,GAAG,CAAC,CAAW;IACtB,MAAM,GAAG,GAAG,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC;IAC7B,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC,IAAI,yBAAyB,CAAC,CAAC;IAC9E,OAAO,GAAG,CAAC,MAAM,EAAE,CAAC;AACtB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,CAAW;IACzC,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IACnB,IAAI,CAAM,CAAC;IACX,IAAI,CAAC;QACH,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,C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AC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC7D,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAa,EAAE,CAAC;QAE9B,KAAK,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACpC,MAAM,UAAU,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAChC,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;gBAC7B,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,yBAAyB,CAAC,CAAC;gBACjD,SAAS;YACX,CAAC;YACD,uEAAuE;YACvE,yEAAyE;YACzE,yEAAyE;YACzE,gBAAgB;YAChB,MAAM,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,MAAM,UAAU,OAAO,UAAU,cAAc,CAAC,CAAC;QACnF,CAAC;QAED,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IACzD,CAAC;CACF,CAAC"}
@@ -0,0 +1,42 @@
1
+ import type { Engine, Resource } from '../types.js';
2
+ /**
3
+ * Moving a bucket of objects.
4
+ *
5
+ * S3, R2, B2, Spaces, Supabase storage, MinIO on a dedicated box. They all
6
+ * speak S3 or something close enough, and the differences are endpoint URLs
7
+ * and auth styles rather than anything structural — so this is one engine with
8
+ * a remote definition per side, not one engine per vendor.
9
+ *
10
+ * ## Why rclone rather than an SDK
11
+ *
12
+ * Copying 8,410 objects across 9.56 GB from a script means reimplementing
13
+ * concurrency, retries, resume, multipart thresholds and checksum comparison,
14
+ * and getting all five right. rclone has those and is a single static binary.
15
+ * The alternative — `aws s3 sync` — only speaks S3 and needs a credentials
16
+ * file on disk, which is worse for a tool that has to reach six vendors.
17
+ *
18
+ * The cost is a dependency the planner checks for up front (`requires`), so a
19
+ * missing rclone is a blocker before the freeze rather than a failure during
20
+ * it.
21
+ *
22
+ * ## Staging, or not
23
+ *
24
+ * Every other engine dumps to staging and loads from it. Object storage is the
25
+ * exception: pulling 10 GB down to a laptop and pushing it back up doubles the
26
+ * transfer and needs the disk. `export` therefore only writes a manifest, and
27
+ * `import` runs a remote-to-remote copy that rclone streams server-side where
28
+ * it can. The manifest is not busywork — it is what `verify` compares against,
29
+ * and what makes a resumed run able to tell what it already did.
30
+ */
31
+ /**
32
+ * An rclone remote, built inline from the resource's connection.
33
+ *
34
+ * rclone is normally configured from a file; passing the whole remote
35
+ * definition through `RCLONE_CONFIG_*` environment variables instead means no
36
+ * credential is ever written to disk, and none appears in argv.
37
+ */
38
+ export declare function rcloneEnv(r: Resource, alias: string): Record<string, string>;
39
+ /** `remote:bucket/prefix` as rclone wants it. */
40
+ export declare function rclonePath(r: Resource, alias: string): string;
41
+ export declare const objectStorageEngine: Engine;
42
+ //# sourceMappingURL=object-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object-storage.d.ts","sourceRoot":"","sources":["../../src/engines/object-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,MAAM,EAAiB,QAAQ,EAAgB,MAAM,aAAa,CAAC;AAE3F;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA6B5E;AAED,iDAAiD;AACjD,wBAAgB,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAI7D;AASD,eAAO,MAAM,mBAAmB,EAAE,MAiJjC,CAAC"}
@@ -0,0 +1,197 @@
1
+ /**
2
+ * Moving a bucket of objects.
3
+ *
4
+ * S3, R2, B2, Spaces, Supabase storage, MinIO on a dedicated box. They all
5
+ * speak S3 or something close enough, and the differences are endpoint URLs
6
+ * and auth styles rather than anything structural — so this is one engine with
7
+ * a remote definition per side, not one engine per vendor.
8
+ *
9
+ * ## Why rclone rather than an SDK
10
+ *
11
+ * Copying 8,410 objects across 9.56 GB from a script means reimplementing
12
+ * concurrency, retries, resume, multipart thresholds and checksum comparison,
13
+ * and getting all five right. rclone has those and is a single static binary.
14
+ * The alternative — `aws s3 sync` — only speaks S3 and needs a credentials
15
+ * file on disk, which is worse for a tool that has to reach six vendors.
16
+ *
17
+ * The cost is a dependency the planner checks for up front (`requires`), so a
18
+ * missing rclone is a blocker before the freeze rather than a failure during
19
+ * it.
20
+ *
21
+ * ## Staging, or not
22
+ *
23
+ * Every other engine dumps to staging and loads from it. Object storage is the
24
+ * exception: pulling 10 GB down to a laptop and pushing it back up doubles the
25
+ * transfer and needs the disk. `export` therefore only writes a manifest, and
26
+ * `import` runs a remote-to-remote copy that rclone streams server-side where
27
+ * it can. The manifest is not busywork — it is what `verify` compares against,
28
+ * and what makes a resumed run able to tell what it already did.
29
+ */
30
+ /**
31
+ * An rclone remote, built inline from the resource's connection.
32
+ *
33
+ * rclone is normally configured from a file; passing the whole remote
34
+ * definition through `RCLONE_CONFIG_*` environment variables instead means no
35
+ * credential is ever written to disk, and none appears in argv.
36
+ */
37
+ export function rcloneEnv(r, alias) {
38
+ const get = (k) => r.connection[k]?.reveal();
39
+ const bucket = get('bucket');
40
+ if (!bucket)
41
+ throw new Error(`object-storage resource '${r.name}' has no connection.bucket`);
42
+ const prefix = `RCLONE_CONFIG_${alias.toUpperCase()}`;
43
+ const env = {
44
+ [`${prefix}_TYPE`]: 's3',
45
+ // 'Other' keeps rclone from applying provider-specific assumptions to an
46
+ // endpoint that merely speaks S3, which is the case for R2, Supabase,
47
+ // MinIO and Backblaze's S3 gateway.
48
+ [`${prefix}_PROVIDER`]: get('provider') ?? 'Other',
49
+ };
50
+ const accessKey = get('accessKeyId');
51
+ const secretKey = get('secretAccessKey');
52
+ if (accessKey)
53
+ env[`${prefix}_ACCESS_KEY_ID`] = accessKey;
54
+ if (secretKey)
55
+ env[`${prefix}_SECRET_ACCESS_KEY`] = secretKey;
56
+ const endpoint = get('endpoint');
57
+ if (endpoint)
58
+ env[`${prefix}_ENDPOINT`] = endpoint;
59
+ const region = get('region');
60
+ if (region)
61
+ env[`${prefix}_REGION`] = region;
62
+ // Most non-AWS S3 endpoints are path-style; virtual-host style silently
63
+ // resolves to a hostname that does not exist.
64
+ if (endpoint && !get('forcePathStyle'))
65
+ env[`${prefix}_FORCE_PATH_STYLE`] = 'true';
66
+ return env;
67
+ }
68
+ /** `remote:bucket/prefix` as rclone wants it. */
69
+ export function rclonePath(r, alias) {
70
+ const bucket = r.connection.bucket?.reveal() ?? '';
71
+ const prefix = r.connection.prefix?.reveal() ?? '';
72
+ return `${alias}:${bucket}${prefix ? `/${prefix.replace(/^\/+/, '')}` : ''}`;
73
+ }
74
+ const MANIFEST = 'objects.json';
75
+ export const objectStorageEngine = {
76
+ kind: 'object-storage',
77
+ requires: ['rclone'],
78
+ /**
79
+ * List the bucket. Deliberately does not download it — see the note above.
80
+ */
81
+ async export(ctx, from) {
82
+ const path = `${from.id}/${MANIFEST}`;
83
+ ctx.log(`listing ${from.name}`);
84
+ if (ctx.dryRun)
85
+ return [{ resourceId: from.id, kind: 'object-storage', path }];
86
+ const res = await ctx.exec('rclone', ['lsjson', '--recursive', '--files-only', rclonePath(from, 'src')], {
87
+ env: rcloneEnv(from, 'src'),
88
+ timeoutMs: 60 * 60 * 1000,
89
+ });
90
+ let entries;
91
+ try {
92
+ const parsed = JSON.parse(res.stdout || '[]');
93
+ entries = parsed.map((e) => ({ path: e.Path ?? '', size: e.Size ?? 0 })).filter((e) => e.path);
94
+ }
95
+ catch {
96
+ throw new Error(`could not parse the object listing for '${from.name}'`);
97
+ }
98
+ const artifact = {
99
+ resourceId: from.id,
100
+ kind: 'object-storage',
101
+ path,
102
+ sizeBytes: entries.reduce((n, e) => n + e.size, 0),
103
+ metadata: { objectCount: entries.length, manifest: JSON.stringify(entries).length },
104
+ };
105
+ await ctx.staging.record(artifact);
106
+ ctx.log(`${entries.length} object(s) to copy`);
107
+ return [artifact];
108
+ },
109
+ /**
110
+ * Copy source → target directly.
111
+ *
112
+ * `copy`, never `sync`: sync deletes anything at the destination that is not
113
+ * at the source, which for a mistyped target is indistinguishable from
114
+ * wiping a live bucket. Migrations should not be able to delete.
115
+ */
116
+ async import(ctx, to, _artifacts, from) {
117
+ const source = from;
118
+ if (!source) {
119
+ throw new Error(`object-storage import needs the source resource: its objects are copied remote-to-remote rather than staged locally`);
120
+ }
121
+ if (ctx.dryRun) {
122
+ ctx.log(`would rclone copy ${rclonePath(source, 'src')} → ${rclonePath(to, 'dst')}`);
123
+ return;
124
+ }
125
+ ctx.log(`rclone copy → ${to.name}`);
126
+ await ctx.exec('rclone', [
127
+ 'copy',
128
+ rclonePath(source, 'src'),
129
+ rclonePath(to, 'dst'),
130
+ '--transfers=16',
131
+ '--checkers=32',
132
+ // Resume-friendly: an object already present with the same size and
133
+ // modification time is not re-sent, so a re-run after a failure costs
134
+ // a listing rather than the whole bucket.
135
+ '--update',
136
+ '--stats=30s',
137
+ ], {
138
+ env: { ...rcloneEnv(source, 'src'), ...rcloneEnv(to, 'dst') },
139
+ timeoutMs: 12 * 60 * 60 * 1000,
140
+ });
141
+ },
142
+ /**
143
+ * Objects created during the bulk copy.
144
+ *
145
+ * rclone's own `--max-age` does this server-side, so the delta is the same
146
+ * copy restricted to recent objects rather than a different mechanism.
147
+ */
148
+ async delta(ctx, from, since) {
149
+ const path = `${from.id}/delta-${since.toISOString().replace(/[:.]/g, '')}.json`;
150
+ if (ctx.dryRun)
151
+ return [{ resourceId: from.id, kind: 'object-storage', path }];
152
+ const ageSeconds = Math.max(1, Math.round((Date.now() - since.getTime()) / 1000));
153
+ const res = await ctx.exec('rclone', ['lsjson', '--recursive', '--files-only', `--max-age=${ageSeconds}s`, rclonePath(from, 'src')], { env: rcloneEnv(from, 'src') });
154
+ let count = 0;
155
+ try {
156
+ count = JSON.parse(res.stdout || '[]').length;
157
+ }
158
+ catch {
159
+ count = 0;
160
+ }
161
+ ctx.log(`${count} object(s) written during the bulk copy`);
162
+ const artifact = {
163
+ resourceId: from.id,
164
+ kind: 'object-storage',
165
+ path,
166
+ metadata: { objectCount: count, mode: 'delta' },
167
+ };
168
+ await ctx.staging.record(artifact);
169
+ return [artifact];
170
+ },
171
+ /** Object counts and total size on both sides. */
172
+ async verify(ctx, from, to) {
173
+ if (ctx.dryRun)
174
+ return { ok: true, checks: ['dry run: not compared'], problems: [] };
175
+ const size = async (r, alias) => {
176
+ const res = await ctx.exec('rclone', ['size', '--json', rclonePath(r, alias)], {
177
+ env: rcloneEnv(r, alias),
178
+ check: false,
179
+ });
180
+ try {
181
+ const parsed = JSON.parse(res.stdout || '{}');
182
+ return { count: parsed.count ?? 0, bytes: parsed.bytes ?? 0 };
183
+ }
184
+ catch {
185
+ return { count: 0, bytes: 0 };
186
+ }
187
+ };
188
+ const [a, b] = await Promise.all([size(from, 'src'), size(to, 'dst')]);
189
+ const checks = [`${from.name}: ${a.count} objects → ${b.count}`, `bytes: ${a.bytes} → ${b.bytes}`];
190
+ const problems = [];
191
+ if (b.count < a.count) {
192
+ problems.push(`${a.count - b.count} object(s) did not arrive in '${to.name}'`);
193
+ }
194
+ return { ok: problems.length === 0, checks, problems };
195
+ },
196
+ };
197
+ //# sourceMappingURL=object-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object-storage.js","sourceRoot":"","sources":["../../src/engines/object-storage.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,CAAW,EAAE,KAAa;IAClD,MAAM,GAAG,GAAG,CAAC,CAAS,EAAsB,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;IACzE,MAAM,MAAM,GAAG,GAAG,CAA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.js';
2
+ /**
3
+ * Postgres credentials go in the environment, never in argv.
4
+ *
5
+ * `ps` is world-readable on a normal box, so a password spliced into a command
6
+ * line is visible to every other user for as long as the dump runs — which for
7
+ * a migration is hours.
8
+ *
9
+ * These are libpq's own variables, which `pg_dump`, `pg_restore` and `psql`
10
+ * all read directly. That matters more than it looks: `exec` runs commands
11
+ * without a shell, so there is nothing to expand a `$VAR` written into an
12
+ * argument. Passing the connection through the environment is not merely
13
+ * tidier here, it is the only thing that works.
14
+ */
15
+ export declare function pgEnv(r: Resource): Record<string, string>;
16
+ /**
17
+ * The timestamp column the delta sync keys on.
18
+ *
19
+ * This ends up interpolated into SQL, and it comes from a resource's metadata,
20
+ * which comes from a config file a person edits — so it is checked against a
21
+ * plain identifier rather than trusted. `psql -c` would happily run a second
22
+ * statement smuggled in here, against the production database the migration is
23
+ * reading from.
24
+ */
25
+ export declare function deltaColumn(r: Resource): string;
26
+ export declare const postgresEngine: Engine;
27
+ /**
28
+ * The extensions a database uses, for the inventory's quirks.
29
+ *
30
+ * Exported so a platform can call it while building its inventory: the
31
+ * platform knows the DSN, this knows the question worth asking.
32
+ */
33
+ export declare function postgresExtensions(ctx: EngineContext, r: Resource): Promise<string[]>;
34
+ //# sourceMappingURL=postgres.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/engines/postgres.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAgB,MAAM,aAAa,CAAC;AA0C3F;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAoBzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,CAQ/C;AAED,eAAO,MAAM,cAAc,EAAE,MAuP5B,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,aAAa,EAClB,CAAC,EAAE,QAAQ,GACV,OAAO,CAAC,MAAM,EAAE,CAAC,CASnB"}