diff --git a/web/src/lib/components/migration/MigrationLanding.stories.svelte b/web/src/lib/components/migration/MigrationLanding.stories.svelte index 8a0bcd936..6c12d6462 100644 --- a/web/src/lib/components/migration/MigrationLanding.stories.svelte +++ b/web/src/lib/components/migration/MigrationLanding.stories.svelte @@ -14,7 +14,7 @@ }; }; - const migrate = () => userEvent.click(screen.getByRole("button", { name: /migrate my data/i })); + const migrate = () => userEvent.click(screen.getByRole("button", { name: /start migration/i })); const { Story } = defineMeta({ title: "Migration/MigrationLanding", diff --git a/web/src/lib/components/migration/MigrationLanding.svelte b/web/src/lib/components/migration/MigrationLanding.svelte index 1695e3f8c..506cb75d1 100644 --- a/web/src/lib/components/migration/MigrationLanding.svelte +++ b/web/src/lib/components/migration/MigrationLanding.svelte @@ -1,6 +1,11 @@ - + -
-

Migrating your data

+
+

Migrate your data

- Tangled has a new record format, so your data needs to be migrated before you can keep using - Tangled + Tangled now stores your data in a new record format. Migrate it to keep using Tangled {#if auth.currentUser}as {auth.currentUser.handle}{/if}. It's safe to try again if something goes wrong. + >{/if}. If anything fails, you can safely try again.

- {#if status} -
-

{status}

- {#if progress?.phase === "blobs" || progress?.phase === "importing"} - - {/if} -
- {/if} - -
+
{#if needsGrant} - {:else} {/if} - +
+ + {#if status} +
+

{status}

+
+
+
+
+ {/if}
migrate.run(true)} /> diff --git a/web/src/lib/migration/import.ts b/web/src/lib/migration/import.ts index ff99dc6fd..4aadd01e3 100644 --- a/web/src/lib/migration/import.ts +++ b/web/src/lib/migration/import.ts @@ -28,6 +28,7 @@ export interface ImportProgress { phase: "reading" | "blobs" | "importing" | "finalizing"; done: number; total: number; + overall: { done: number; total: number }; } export class MigrationScopeError extends Error { @@ -168,7 +169,7 @@ export const importFromLiar = async ( ); } - onProgress?.({ phase: "reading", done: 0, total: 0 }); + onProgress?.({ phase: "reading", done: 0, total: 0, overall: { done: 0, total: 0 } }); const records = await readLiarRecords( await fetchLiarRepo(liarPdsUrl, agent.sub, { fetch, signal }) ); @@ -184,22 +185,29 @@ export const importFromLiar = async ( const client = createClient(agent); const blobs = await listLiarBlobs(liarPdsUrl, agent.sub, { fetch, signal }); - onProgress?.({ phase: "blobs", done: 0, total: blobs.length }); + const batches = batchWrites(writes); + const overall = { done: 0, total: blobs.length + batches.length }; + const report = (phase: "blobs" | "importing", done: number, total: number) => + onProgress?.({ phase, done, total, overall: { ...overall } }); + + report("blobs", 0, blobs.length); for (const [i, cid] of blobs.entries()) { const input = await fetchLiarBlob(liarPdsUrl, agent.sub, cid, { fetch, signal }); await ok(client.call(uploadBlobSchema, { input, signal })); - onProgress?.({ phase: "blobs", done: i + 1, total: blobs.length }); + overall.done++; + report("blobs", i + 1, blobs.length); } let done = 0; - onProgress?.({ phase: "importing", done, total: writes.length }); - for (const batch of batchWrites(writes)) { + report("importing", done, writes.length); + for (const batch of batches) { signal?.throwIfAborted(); await ok( client.call(applyWritesSchema, { input: { repo: agent.sub, writes: batch }, signal }) ); done += batch.length; - onProgress?.({ phase: "importing", done, total: writes.length }); + overall.done++; + report("importing", done, writes.length); } clear();