@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
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { plain, secret } from '../types.js';
|
|
2
|
+
export const sshPlatform = {
|
|
3
|
+
id: 'ssh',
|
|
4
|
+
label: 'dedicated / VPS over ssh',
|
|
5
|
+
role: 'both',
|
|
6
|
+
supports: ['postgres', 'mysql', 'sqlite', 'redis', 'files', 'object-storage'],
|
|
7
|
+
async inventory(ctx, config) {
|
|
8
|
+
if (!config.host)
|
|
9
|
+
throw new Error('ssh platform needs a host');
|
|
10
|
+
const resources = [];
|
|
11
|
+
const notes = [];
|
|
12
|
+
for (const db of config.postgres ?? []) {
|
|
13
|
+
resources.push({
|
|
14
|
+
kind: 'postgres',
|
|
15
|
+
id: `pg-${db.name}`,
|
|
16
|
+
name: db.name,
|
|
17
|
+
connection: { url: secret(db.url) },
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
for (const db of config.mysql ?? []) {
|
|
21
|
+
resources.push({
|
|
22
|
+
kind: 'mysql',
|
|
23
|
+
id: `mysql-${db.name}`,
|
|
24
|
+
name: db.name,
|
|
25
|
+
connection: { url: secret(db.url) },
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
for (const db of config.sqlite ?? []) {
|
|
29
|
+
resources.push({
|
|
30
|
+
kind: 'sqlite',
|
|
31
|
+
id: `sqlite-${db.name}`,
|
|
32
|
+
name: db.name,
|
|
33
|
+
connection: { path: plain(db.path) },
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
for (const r of config.redis ?? []) {
|
|
37
|
+
resources.push({
|
|
38
|
+
kind: 'redis',
|
|
39
|
+
id: `redis-${r.name}`,
|
|
40
|
+
name: r.name,
|
|
41
|
+
connection: {
|
|
42
|
+
url: secret(r.url),
|
|
43
|
+
...(r.dataDir ? { dataDir: plain(r.dataDir) } : {}),
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
for (const dir of config.files ?? []) {
|
|
48
|
+
resources.push({
|
|
49
|
+
kind: 'files',
|
|
50
|
+
id: `files-${dir.name}`,
|
|
51
|
+
name: dir.name,
|
|
52
|
+
connection: {
|
|
53
|
+
path: plain(dir.path),
|
|
54
|
+
host: plain(config.host),
|
|
55
|
+
...(config.user ? { user: plain(config.user) } : {}),
|
|
56
|
+
...(config.sshKeyPath ? { sshKeyPath: plain(config.sshKeyPath) } : {}),
|
|
57
|
+
...(config.sshPort ? { sshPort: plain(config.sshPort) } : {}),
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
for (const b of config.buckets ?? []) {
|
|
62
|
+
resources.push({
|
|
63
|
+
kind: 'object-storage',
|
|
64
|
+
id: `bucket-${b.name}`,
|
|
65
|
+
name: b.name,
|
|
66
|
+
connection: {
|
|
67
|
+
bucket: plain(b.bucket),
|
|
68
|
+
endpoint: plain(b.endpoint),
|
|
69
|
+
accessKeyId: secret(b.accessKeyId),
|
|
70
|
+
secretAccessKey: secret(b.secretAccessKey),
|
|
71
|
+
...(b.region ? { region: plain(b.region) } : {}),
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (!resources.length) {
|
|
76
|
+
notes.push('Nothing is declared for this box. A server has no API to enumerate itself, so its databases and directories have to be listed in config.');
|
|
77
|
+
}
|
|
78
|
+
ctx.log(`${config.host}: ${resources.length} declared resource(s)`);
|
|
79
|
+
return { platform: 'ssh', scope: config.host, resources, notes };
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
* The target side of a move onto a box.
|
|
83
|
+
*
|
|
84
|
+
* A resource arriving here keeps its name and gets this box's connection
|
|
85
|
+
* details. Nothing is created remotely: the database or directory is
|
|
86
|
+
* expected to exist, because provisioning a Postgres on someone's server is
|
|
87
|
+
* a decision about disks and versions and backups that a migration tool
|
|
88
|
+
* should not be quietly making.
|
|
89
|
+
*/
|
|
90
|
+
async provision(ctx, resource, config) {
|
|
91
|
+
const match = (() => {
|
|
92
|
+
switch (resource.kind) {
|
|
93
|
+
case 'postgres': {
|
|
94
|
+
const db = config.postgres?.find((d) => d.name === resource.name) ?? config.postgres?.[0];
|
|
95
|
+
return db ? { url: secret(db.url) } : undefined;
|
|
96
|
+
}
|
|
97
|
+
case 'mysql': {
|
|
98
|
+
const db = config.mysql?.find((d) => d.name === resource.name) ?? config.mysql?.[0];
|
|
99
|
+
return db ? { url: secret(db.url) } : undefined;
|
|
100
|
+
}
|
|
101
|
+
case 'sqlite': {
|
|
102
|
+
const db = config.sqlite?.find((d) => d.name === resource.name) ?? config.sqlite?.[0];
|
|
103
|
+
return db ? { path: plain(db.path) } : undefined;
|
|
104
|
+
}
|
|
105
|
+
case 'redis': {
|
|
106
|
+
const r = config.redis?.find((d) => d.name === resource.name) ?? config.redis?.[0];
|
|
107
|
+
return r
|
|
108
|
+
? { url: secret(r.url), ...(r.dataDir ? { dataDir: plain(r.dataDir) } : {}) }
|
|
109
|
+
: undefined;
|
|
110
|
+
}
|
|
111
|
+
case 'files': {
|
|
112
|
+
const d = config.files?.find((x) => x.name === resource.name) ?? config.files?.[0];
|
|
113
|
+
return d
|
|
114
|
+
? {
|
|
115
|
+
path: plain(d.path),
|
|
116
|
+
host: plain(config.host),
|
|
117
|
+
...(config.user ? { user: plain(config.user) } : {}),
|
|
118
|
+
...(config.sshKeyPath ? { sshKeyPath: plain(config.sshKeyPath) } : {}),
|
|
119
|
+
...(config.sshPort ? { sshPort: plain(config.sshPort) } : {}),
|
|
120
|
+
}
|
|
121
|
+
: undefined;
|
|
122
|
+
}
|
|
123
|
+
case 'object-storage': {
|
|
124
|
+
const b = config.buckets?.find((x) => x.name === resource.name) ?? config.buckets?.[0];
|
|
125
|
+
return b
|
|
126
|
+
? {
|
|
127
|
+
bucket: plain(b.bucket),
|
|
128
|
+
endpoint: plain(b.endpoint),
|
|
129
|
+
accessKeyId: secret(b.accessKeyId),
|
|
130
|
+
secretAccessKey: secret(b.secretAccessKey),
|
|
131
|
+
...(b.region ? { region: plain(b.region) } : {}),
|
|
132
|
+
}
|
|
133
|
+
: undefined;
|
|
134
|
+
}
|
|
135
|
+
default:
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
})();
|
|
139
|
+
if (!match) {
|
|
140
|
+
throw new Error(`nothing on ${config.host} is declared to receive ${resource.kind} '${resource.name}'. Add it to the target config.`);
|
|
141
|
+
}
|
|
142
|
+
ctx.log(`${resource.name} → ${config.host}`);
|
|
143
|
+
return { ...resource, id: `${resource.id}@${config.host}`, connection: match };
|
|
144
|
+
},
|
|
145
|
+
async check(ctx, config) {
|
|
146
|
+
if (!config.host)
|
|
147
|
+
throw new Error('ssh platform needs a host');
|
|
148
|
+
ctx.log(`target box is ${config.user ? `${config.user}@` : ''}${config.host}`);
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
//# sourceMappingURL=ssh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssh.js","sourceRoot":"","sources":["../../src/platforms/ssh.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAyC5C,MAAM,CAAC,MAAM,WAAW,GAAwB;IAC9C,EAAE,EAAE,KAAK;IACT,KAAK,EAAE,0BAA0B;IACjC,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,CAAC;IAE7E,KAAK,CAAC,SAAS,CAAC,GAAoB,EAAE,MAAiB;QACrD,IAAI,CAAC,MAAM,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAE/D,MAAM,SAAS,GAAe,EAAE,CAAC;QACjC,MAAM,KAAK,GAAa,EAAE,CAAC;QAE3B,KAAK,MAAM,EAAE,IAAI,MAAM,CAAC,QAAQ,IAAI,EAAE,EAAE,CAAC;YACvC,SAAS,CAAC,IAAI,CAAC;gBACb,IAAI,EAAE,UAAU;gBAChB,EAAE,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE;gBACnB,IAAI,EAAE,EAAE,CAAC,IAAI;gBACb,UAAU,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE;aACpC,CAAC,CAAC;QACL,CAAC;QAED,KAAK,MAAM,EAAE,IAAI,MAAM,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC;YACpC,SAAS,CAAC,IAAI,CAAC;gBACb,IAAI,EAAE,OAAO;gBACb,EAAE,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE;gBACtB,IAAI,EAAE,EAAE,CAAC,I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KAAK,CACb,cAAc,MAAM,CAAC,IAAI,2BAA2B,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,iCAAiC,CACrH,CAAC;QACJ,CAAC;QAED,GAAG,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,IAAI,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7C,OAAO,EAAE,GAAG,QAAQ,EAAE,EAAE,EAAE,GAAG,QAAQ,CAAC,EAAE,IAAI,MAAM,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IACjF,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,GAAoB,EAAE,MAAiB;QACjD,IAAI,CAAC,MAAM,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC/D,GAAG,CAAC,GAAG,CAAC,iBAAiB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IACjF,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Platform } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Supabase.
|
|
4
|
+
*
|
|
5
|
+
* A Supabase project is a Postgres with a lot bolted on, and the bolted-on
|
|
6
|
+
* parts are what make migrating off it interesting. The database moves with
|
|
7
|
+
* pg_dump like any other Postgres; storage is S3-compatible and moves with the
|
|
8
|
+
* object-storage engine. What does not move cleanly is everything in between,
|
|
9
|
+
* and the value of this inventory is naming those things up front as quirks so
|
|
10
|
+
* the planner warns rather than letting them be discovered afterwards.
|
|
11
|
+
*
|
|
12
|
+
* The list comes from a migration that actually happened (crawlproof.com,
|
|
13
|
+
* 2026-09-24): 128 tables, 113 users in `auth.users`, 204 functions, 10
|
|
14
|
+
* pg_cron jobs, a realtime publication, and three public buckets holding 8,410
|
|
15
|
+
* objects.
|
|
16
|
+
*
|
|
17
|
+
* ## The ones that bite
|
|
18
|
+
*
|
|
19
|
+
* `auth.users` is a real table in the dump, so users migrate — but the GoTrue
|
|
20
|
+
* service that reads it does not, and neither do the JWT secrets. Restoring
|
|
21
|
+
* `auth.users` somewhere with a different JWT secret logs everyone out and
|
|
22
|
+
* invalidates every refresh token.
|
|
23
|
+
*
|
|
24
|
+
* Row Level Security policies reference roles (`authenticated`, `anon`,
|
|
25
|
+
* `service_role`) that do not exist on a plain Postgres. The policies restore;
|
|
26
|
+
* the roles have to be created first or every policy fails.
|
|
27
|
+
*
|
|
28
|
+
* pg_cron jobs restore and start running immediately, which is how a migration
|
|
29
|
+
* ends up with two schedulers on one dataset.
|
|
30
|
+
*/
|
|
31
|
+
export interface SupabaseConfig {
|
|
32
|
+
projectRef: string;
|
|
33
|
+
/** The database password; the rest of the DSN is derived from the ref. */
|
|
34
|
+
dbPassword?: string;
|
|
35
|
+
/** Full DSN, when the project uses a pooler or a custom host. */
|
|
36
|
+
databaseUrl?: string;
|
|
37
|
+
serviceRoleKey?: string;
|
|
38
|
+
/** Buckets to move. Supabase's S3 endpoint is derived from the ref. */
|
|
39
|
+
buckets?: string[];
|
|
40
|
+
region?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Supabase's direct-connection DSN for a project.
|
|
44
|
+
*
|
|
45
|
+
* Direct rather than the pooler: pgbouncer in transaction mode does not
|
|
46
|
+
* support the session-level operations a dump and restore need, and the
|
|
47
|
+
* failure is a confusing mid-dump error rather than a refusal.
|
|
48
|
+
*/
|
|
49
|
+
export declare function supabaseDsn(config: SupabaseConfig): string;
|
|
50
|
+
/** The S3-compatible storage endpoint for a project. */
|
|
51
|
+
export declare function supabaseS3Endpoint(projectRef: string): string;
|
|
52
|
+
/** The public object host, which is what ends up embedded in rows. */
|
|
53
|
+
export declare function supabasePublicHost(projectRef: string): string;
|
|
54
|
+
/** What does not survive a plain pg_dump/pg_restore, named up front. */
|
|
55
|
+
export declare const SUPABASE_QUIRKS: readonly string[];
|
|
56
|
+
export declare const supabasePlatform: Platform<SupabaseConfig>;
|
|
57
|
+
//# sourceMappingURL=supabase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/platforms/supabase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,QAAQ,EAA6B,MAAM,aAAa,CAAC;AAGlF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,0EAA0E;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iEAAiE;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAO1D;AAED,wDAAwD;AACxD,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,sEAAsE;AACtE,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,wEAAwE;AACxE,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAMnC,CAAC;AAEX,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,cAAc,CA2ErD,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { plain, secret } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Supabase's direct-connection DSN for a project.
|
|
4
|
+
*
|
|
5
|
+
* Direct rather than the pooler: pgbouncer in transaction mode does not
|
|
6
|
+
* support the session-level operations a dump and restore need, and the
|
|
7
|
+
* failure is a confusing mid-dump error rather than a refusal.
|
|
8
|
+
*/
|
|
9
|
+
export function supabaseDsn(config) {
|
|
10
|
+
if (config.databaseUrl)
|
|
11
|
+
return config.databaseUrl;
|
|
12
|
+
if (!config.dbPassword) {
|
|
13
|
+
throw new Error('Supabase needs either databaseUrl or dbPassword');
|
|
14
|
+
}
|
|
15
|
+
const pw = encodeURIComponent(config.dbPassword);
|
|
16
|
+
return `postgresql://postgres:${pw}@db.${config.projectRef}.supabase.co:5432/postgres`;
|
|
17
|
+
}
|
|
18
|
+
/** The S3-compatible storage endpoint for a project. */
|
|
19
|
+
export function supabaseS3Endpoint(projectRef) {
|
|
20
|
+
return `https://${projectRef}.supabase.co/storage/v1/s3`;
|
|
21
|
+
}
|
|
22
|
+
/** The public object host, which is what ends up embedded in rows. */
|
|
23
|
+
export function supabasePublicHost(projectRef) {
|
|
24
|
+
return `${projectRef}.supabase.co`;
|
|
25
|
+
}
|
|
26
|
+
/** What does not survive a plain pg_dump/pg_restore, named up front. */
|
|
27
|
+
export const SUPABASE_QUIRKS = [
|
|
28
|
+
'auth.users restores as data, but GoTrue and the JWT secret do not move with it: everyone is logged out and every refresh token is invalid unless the JWT secret is carried across',
|
|
29
|
+
'RLS policies reference the roles anon, authenticated and service_role, which do not exist on a plain Postgres and must be created before the restore',
|
|
30
|
+
'pg_cron jobs restore already enabled and begin firing immediately, so they must be disabled on the source before the cutover or two schedulers run against one dataset',
|
|
31
|
+
'the realtime publication (supabase_realtime) is recreated by the dump but nothing subscribes to it without the realtime service',
|
|
32
|
+
'storage.objects rows are metadata; the bytes live in the bucket and move separately',
|
|
33
|
+
];
|
|
34
|
+
export const supabasePlatform = {
|
|
35
|
+
id: 'supabase',
|
|
36
|
+
label: 'Supabase',
|
|
37
|
+
role: 'both',
|
|
38
|
+
supports: ['postgres', 'object-storage', 'cron'],
|
|
39
|
+
async inventory(ctx, config) {
|
|
40
|
+
if (!config.projectRef)
|
|
41
|
+
throw new Error('Supabase needs a projectRef');
|
|
42
|
+
const resources = [];
|
|
43
|
+
resources.push({
|
|
44
|
+
kind: 'postgres',
|
|
45
|
+
id: `pg-${config.projectRef}`,
|
|
46
|
+
name: 'postgres',
|
|
47
|
+
connection: { url: secret(supabaseDsn(config)) },
|
|
48
|
+
quirks: [...SUPABASE_QUIRKS],
|
|
49
|
+
metadata: { projectRef: config.projectRef, publicHost: supabasePublicHost(config.projectRef) },
|
|
50
|
+
});
|
|
51
|
+
const serviceKey = config.serviceRoleKey ?? ctx.secret('SUPABASE_SERVICE_ROLE_KEY');
|
|
52
|
+
for (const bucket of config.buckets ?? []) {
|
|
53
|
+
if (!serviceKey) {
|
|
54
|
+
throw new Error(`bucket '${bucket}' needs SUPABASE_SERVICE_ROLE_KEY to read Supabase storage over S3`);
|
|
55
|
+
}
|
|
56
|
+
resources.push({
|
|
57
|
+
kind: 'object-storage',
|
|
58
|
+
id: `bucket-${bucket}`,
|
|
59
|
+
name: bucket,
|
|
60
|
+
connection: {
|
|
61
|
+
bucket: plain(bucket),
|
|
62
|
+
endpoint: plain(supabaseS3Endpoint(config.projectRef)),
|
|
63
|
+
// Supabase's S3 gateway takes the project ref as the access key and
|
|
64
|
+
// the service role key as the secret.
|
|
65
|
+
accessKeyId: plain(config.projectRef),
|
|
66
|
+
secretAccessKey: secret(serviceKey),
|
|
67
|
+
region: plain(config.region ?? 'us-east-1'),
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const notes = [
|
|
72
|
+
`rows may hold absolute URLs to ${supabasePublicHost(config.projectRef)}; pass --rewrite-host ${supabasePublicHost(config.projectRef)}=<new origin> so they are rewritten rather than 404ing when this project is deleted`,
|
|
73
|
+
];
|
|
74
|
+
ctx.log(`supabase ${config.projectRef}: ${resources.length} resource(s)`);
|
|
75
|
+
return { platform: 'supabase', scope: config.projectRef, resources, notes };
|
|
76
|
+
},
|
|
77
|
+
async provision(_ctx, resource, config) {
|
|
78
|
+
if (resource.kind === 'postgres') {
|
|
79
|
+
return { ...resource, id: `pg-${config.projectRef}`, connection: { url: secret(supabaseDsn(config)) } };
|
|
80
|
+
}
|
|
81
|
+
if (resource.kind === 'object-storage') {
|
|
82
|
+
const serviceKey = config.serviceRoleKey;
|
|
83
|
+
if (!serviceKey)
|
|
84
|
+
throw new Error('writing to Supabase storage needs a serviceRoleKey');
|
|
85
|
+
return {
|
|
86
|
+
...resource,
|
|
87
|
+
connection: {
|
|
88
|
+
bucket: plain(resource.name),
|
|
89
|
+
endpoint: plain(supabaseS3Endpoint(config.projectRef)),
|
|
90
|
+
accessKeyId: plain(config.projectRef),
|
|
91
|
+
secretAccessKey: secret(serviceKey),
|
|
92
|
+
region: plain(config.region ?? 'us-east-1'),
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
throw new Error(`Supabase cannot receive a ${resource.kind}`);
|
|
97
|
+
},
|
|
98
|
+
async check(_ctx, config) {
|
|
99
|
+
supabaseDsn(config);
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=supabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supabase.js","sourceRoot":"","sources":["../../src/platforms/supabase.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AA4C5C;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,MAAsB;IAChD,IAAI,MAAM,CAAC,WAAW;QAAE,OAAO,MAAM,CAAC,WAAW,CAAC;IAClD,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IACD,MAAM,EAAE,GAAG,kBAAkB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACjD,OAAO,yBAAyB,EAAE,OAAO,MAAM,CAAC,UAAU,4BAA4B,CAAC;AACzF,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,kBAAkB,CAAC,UAAk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AC1G,CAAC;QACD,IAAI,QAAQ,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YACvC,MAAM,UAAU,GAAG,MAAM,CAAC,cAAc,CAAC;YACzC,IAAI,CAAC,UAAU;gBAAE,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;YACvF,OAAO;gBACL,GAAG,QAAQ;gBACX,UAAU,EAAE;oBACV,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;oBAC5B,QAAQ,EAAE,KAAK,CAAC,kBAAkB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;oBACtD,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC;oBACrC,eAAe,EAAE,MAAM,CAAC,UAAU,CAAC;oBACnC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,IAAI,WAAW,CAAC;iBAC5C;aACF,CAAC;QACJ,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,6BAA6B,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAqB,EAAE,MAAsB;QACvD,WAAW,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Artifact, Staging } from './types.js';
|
|
2
|
+
export interface StagingOptions {
|
|
3
|
+
/** Root directory. Created if absent. */
|
|
4
|
+
dir: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function openStaging(opts: StagingOptions): Promise<Staging>;
|
|
7
|
+
/**
|
|
8
|
+
* Read the ledger, skipping anything unparseable.
|
|
9
|
+
*
|
|
10
|
+
* A truncated final line is the expected shape of an interrupted run, not an
|
|
11
|
+
* error: the process died mid-write. Throwing here would turn a resumable
|
|
12
|
+
* migration into a manual cleanup, so a bad line is dropped and the rest is
|
|
13
|
+
* used.
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseLedger(text: string): Artifact[];
|
|
16
|
+
/** Checksum a staged file, so a resumed run can tell complete from truncated. */
|
|
17
|
+
export declare function sha256File(path: string): Promise<string>;
|
|
18
|
+
/**
|
|
19
|
+
* An in-memory staging, for tests and for `--dry-run`.
|
|
20
|
+
*
|
|
21
|
+
* A dry run must not create directories on someone's disk as a side effect of
|
|
22
|
+
* being asked what it would do.
|
|
23
|
+
*/
|
|
24
|
+
export declare function memoryStaging(dir?: string): Staging & {
|
|
25
|
+
artifacts: Artifact[];
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=staging.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staging.d.ts","sourceRoot":"","sources":["../src/staging.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAoBpD,MAAM,WAAW,cAAc;IAC7B,yCAAyC;IACzC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,wBAAsB,WAAW,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAuBxE;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,EAAE,CAepD;AAED,iFAAiF;AACjF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAQxD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,SAAa,GAAG,OAAO,GAAG;IAAE,SAAS,EAAE,QAAQ,EAAE,CAAA;CAAE,CAYnF"}
|
package/dist/staging.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { createReadStream } from 'node:fs';
|
|
3
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { dirname, join, resolve } from 'node:path';
|
|
5
|
+
/**
|
|
6
|
+
* Where a migration keeps what it has already done.
|
|
7
|
+
*
|
|
8
|
+
* A migration is long and interrupted runs are normal — a laptop sleeps, a
|
|
9
|
+
* token expires, someone hits ctrl-C during the bulk copy because they
|
|
10
|
+
* realised they picked the wrong project. The staging directory is what makes
|
|
11
|
+
* the next run cheap instead of a restart: a ledger of finished artifacts, on
|
|
12
|
+
* disk, next to the bytes they describe.
|
|
13
|
+
*
|
|
14
|
+
* The ledger is append-only JSON lines rather than one rewritten JSON file.
|
|
15
|
+
* A process killed mid-write corrupts the file it was rewriting; it can only
|
|
16
|
+
* ever truncate the last line of an append-only one, and a half-written line
|
|
17
|
+
* fails to parse and is skipped. That is the difference between resuming and
|
|
18
|
+
* starting over.
|
|
19
|
+
*/
|
|
20
|
+
const LEDGER = 'artifacts.jsonl';
|
|
21
|
+
export async function openStaging(opts) {
|
|
22
|
+
const dir = resolve(opts.dir);
|
|
23
|
+
await mkdir(dir, { recursive: true });
|
|
24
|
+
const ledgerPath = join(dir, LEDGER);
|
|
25
|
+
return {
|
|
26
|
+
dir,
|
|
27
|
+
async record(artifact) {
|
|
28
|
+
await mkdir(dirname(join(dir, artifact.path)), { recursive: true });
|
|
29
|
+
await writeFile(ledgerPath, `${JSON.stringify(artifact)}\n`, { flag: 'a' });
|
|
30
|
+
},
|
|
31
|
+
async existing(resourceId) {
|
|
32
|
+
let text;
|
|
33
|
+
try {
|
|
34
|
+
text = await readFile(ledgerPath, 'utf8');
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
return parseLedger(text).filter((a) => a.resourceId === resourceId);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Read the ledger, skipping anything unparseable.
|
|
45
|
+
*
|
|
46
|
+
* A truncated final line is the expected shape of an interrupted run, not an
|
|
47
|
+
* error: the process died mid-write. Throwing here would turn a resumable
|
|
48
|
+
* migration into a manual cleanup, so a bad line is dropped and the rest is
|
|
49
|
+
* used.
|
|
50
|
+
*/
|
|
51
|
+
export function parseLedger(text) {
|
|
52
|
+
const out = [];
|
|
53
|
+
for (const line of text.split('\n')) {
|
|
54
|
+
const trimmed = line.trim();
|
|
55
|
+
if (!trimmed)
|
|
56
|
+
continue;
|
|
57
|
+
try {
|
|
58
|
+
const parsed = JSON.parse(trimmed);
|
|
59
|
+
if (parsed && typeof parsed.path === 'string' && typeof parsed.resourceId === 'string') {
|
|
60
|
+
out.push(parsed);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// A partial line from an interrupted write. Skip it.
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
/** Checksum a staged file, so a resumed run can tell complete from truncated. */
|
|
70
|
+
export function sha256File(path) {
|
|
71
|
+
return new Promise((res, rej) => {
|
|
72
|
+
const hash = createHash('sha256');
|
|
73
|
+
const stream = createReadStream(path);
|
|
74
|
+
stream.on('error', rej);
|
|
75
|
+
stream.on('data', (chunk) => hash.update(chunk));
|
|
76
|
+
stream.on('end', () => res(hash.digest('hex')));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* An in-memory staging, for tests and for `--dry-run`.
|
|
81
|
+
*
|
|
82
|
+
* A dry run must not create directories on someone's disk as a side effect of
|
|
83
|
+
* being asked what it would do.
|
|
84
|
+
*/
|
|
85
|
+
export function memoryStaging(dir = '/staging') {
|
|
86
|
+
const artifacts = [];
|
|
87
|
+
return {
|
|
88
|
+
dir,
|
|
89
|
+
artifacts,
|
|
90
|
+
async record(a) {
|
|
91
|
+
artifacts.push(a);
|
|
92
|
+
},
|
|
93
|
+
async existing(resourceId) {
|
|
94
|
+
return artifacts.filter((a) => a.resourceId === resourceId);
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=staging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staging.js","sourceRoot":"","sources":["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,CAAC,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,GAAG,GAAG,UAAU;IAC5C,MAAM,SAAS,GAAe,EAAE,CAAC;IACjC,OAAO;QACL,GAAG;QACH,SAAS;QACT,KAAK,CAAC,MAAM,CAAC,CAAC;YACZ,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;QACD,KAAK,CAAC,QAAQ,CAAC,UAAU;YACvB,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC;QAC9D,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rewriting absolute URLs that point at the place you just left.
|
|
3
|
+
*
|
|
4
|
+
* This is the failure that makes migrations dangerous months after they look
|
|
5
|
+
* successful. An app stores an uploaded file and, instead of keeping a key,
|
|
6
|
+
* writes the whole URL into a row:
|
|
7
|
+
*
|
|
8
|
+
* https://ywcizjsgrcmhgyplldac.supabase.co/storage/v1/object/public/ads/x.png
|
|
9
|
+
*
|
|
10
|
+
* Migrate the bucket and the database, cut DNS over, check the site: every
|
|
11
|
+
* image loads. They load because the OLD account still exists and is still
|
|
12
|
+
* serving them. The day that account is closed — which is the whole point of
|
|
13
|
+
* migrating, and which happens weeks later once everyone is confident — every
|
|
14
|
+
* one of those rows 404s at once, and nothing connects the outage to the
|
|
15
|
+
* migration.
|
|
16
|
+
*
|
|
17
|
+
* crawlproof.com had 2,928 such rows across four tables. They were found by
|
|
18
|
+
* looking, not by anything failing.
|
|
19
|
+
*
|
|
20
|
+
* So this is a first-class step rather than a footnote: find every column that
|
|
21
|
+
* could hold one, report what is there, and rewrite it inside the same
|
|
22
|
+
* transaction that a person can roll back.
|
|
23
|
+
*
|
|
24
|
+
* Nothing here executes SQL. It builds statements and the caller runs them,
|
|
25
|
+
* which keeps it testable and keeps the generated SQL reviewable before it
|
|
26
|
+
* touches a database.
|
|
27
|
+
*/
|
|
28
|
+
/** A host whose URLs must be rewritten, and what to replace it with. */
|
|
29
|
+
export interface HostRewrite {
|
|
30
|
+
/** The old host, e.g. `abc123.supabase.co`. No scheme, no path. */
|
|
31
|
+
from: string;
|
|
32
|
+
/** The new origin, e.g. `https://cdn.example.com`. Scheme required. */
|
|
33
|
+
to: string;
|
|
34
|
+
}
|
|
35
|
+
export interface ColumnRef {
|
|
36
|
+
schema: string;
|
|
37
|
+
table: string;
|
|
38
|
+
column: string;
|
|
39
|
+
dataType: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The query that finds columns which could hold a URL.
|
|
43
|
+
*
|
|
44
|
+
* Every text-ish column in a user schema. Deliberately broad: a column called
|
|
45
|
+
* `notes` holding a pasted URL breaks exactly as badly as one called
|
|
46
|
+
* `image_url`, and guessing from names is how the four crawlproof tables would
|
|
47
|
+
* have been missed. The count query that follows narrows it cheaply.
|
|
48
|
+
*/
|
|
49
|
+
export declare function findTextColumnsSql(): string;
|
|
50
|
+
/** True when a column's type can hold a URL. */
|
|
51
|
+
export declare function isScannable(dataType: string): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Postgres identifiers are quoted rather than interpolated bare.
|
|
54
|
+
*
|
|
55
|
+
* These names come from information_schema, so they are real identifiers, but
|
|
56
|
+
* a table legitimately named `user` or `order` is a reserved word and an
|
|
57
|
+
* unquoted reference is a syntax error partway through a migration. Doubling
|
|
58
|
+
* any embedded quote is the standard escape.
|
|
59
|
+
*/
|
|
60
|
+
export declare function quoteIdent(name: string): string;
|
|
61
|
+
/** A single-quoted SQL string literal. */
|
|
62
|
+
export declare function quoteLiteral(value: string): string;
|
|
63
|
+
/** Fully-qualified, safely quoted. */
|
|
64
|
+
export declare function qualify(c: Pick<ColumnRef, 'schema' | 'table'>): string;
|
|
65
|
+
/**
|
|
66
|
+
* Count rows in one column that mention the old host.
|
|
67
|
+
*
|
|
68
|
+
* Run before rewriting anything: it turns "this might be a problem" into "2,928
|
|
69
|
+
* rows in four tables", which is what makes the step reviewable. A cast to text
|
|
70
|
+
* lets one statement cover json and jsonb alongside the plain text types.
|
|
71
|
+
*/
|
|
72
|
+
export declare function countMatchesSql(c: ColumnRef, host: string): string;
|
|
73
|
+
/**
|
|
74
|
+
* Rewrite one column.
|
|
75
|
+
*
|
|
76
|
+
* `replace` on the text form rather than a regex: the host is a literal, a
|
|
77
|
+
* regex would need escaping, and `replace` is index-friendly and predictable.
|
|
78
|
+
* The `where` clause means untouched rows are not rewritten, which keeps the
|
|
79
|
+
* update small and leaves `updated_at` triggers alone on rows that did not
|
|
80
|
+
* change.
|
|
81
|
+
*
|
|
82
|
+
* json and jsonb are cast out to text and back, which is lossy for jsonb key
|
|
83
|
+
* order but not for content — and jsonb does not preserve key order anyway.
|
|
84
|
+
*/
|
|
85
|
+
export declare function rewriteColumnSql(c: ColumnRef, rewrite: HostRewrite): string;
|
|
86
|
+
/**
|
|
87
|
+
* The whole rewrite as one transaction.
|
|
88
|
+
*
|
|
89
|
+
* One transaction so a failure halfway leaves nothing half-rewritten, and so
|
|
90
|
+
* the whole thing can be rolled back by a person watching it. The trailing
|
|
91
|
+
* verification select is what the caller asserts on: after a correct rewrite it
|
|
92
|
+
* returns zero rows, and the crawlproof runbook asserted exactly that.
|
|
93
|
+
*/
|
|
94
|
+
export declare function rewritePlanSql(columns: ColumnRef[], rewrites: HostRewrite[]): string;
|
|
95
|
+
/**
|
|
96
|
+
* The assertion that the rewrite worked.
|
|
97
|
+
*
|
|
98
|
+
* Returns one row per column that still mentions an old host. Zero rows is the
|
|
99
|
+
* pass condition. Run it AFTER committing: a migration that reports success
|
|
100
|
+
* while rows still point at an account about to be closed is worse than one
|
|
101
|
+
* that fails loudly.
|
|
102
|
+
*/
|
|
103
|
+
export declare function remainingMatchesSql(columns: ColumnRef[], hosts: string[]): string;
|
|
104
|
+
/**
|
|
105
|
+
* Turn `--rewrite-host old=new` into a rewrite.
|
|
106
|
+
*
|
|
107
|
+
* Accepts a bare host on the left (`abc.supabase.co`) and a full origin on the
|
|
108
|
+
* right (`https://cdn.example.com`). A missing scheme on the right is the easy
|
|
109
|
+
* mistake and produces a corrupt URL rather than an error at runtime, so it is
|
|
110
|
+
* rejected here.
|
|
111
|
+
*/
|
|
112
|
+
export declare function parseRewrite(spec: string): HostRewrite;
|
|
113
|
+
//# sourceMappingURL=transforms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transforms.d.ts","sourceRoot":"","sources":["../src/transforms.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,wEAAwE;AACxE,MAAM,WAAW,WAAW;IAC1B,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,EAAE,EAAE,MAAM,CAAC;CACZ;AAKD,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAM3C;AAED,gDAAgD;AAChD,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,0CAA0C;AAC1C,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,sCAAsC;AACtC,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,MAAM,CAEtE;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,M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