diff options
| author | Maze Winther <mazewinther@gmail.com> | 2026-02-05 14:28:16 +0100 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2026-02-05 14:28:16 +0100 |
| commit | d0b4b1a5fc439d68371d8cfa677348250afec88b (patch) | |
| tree | 553771dac501910d10f9176385ea7c93990cd4ae /apps/web/src/services/storage/migrations/runner.ts | |
| parent | 2257ca2e6f9f8834880ea9bab4355c168ee6c33b (diff) | |
| download | opencut-d0b4b1a5fc439d68371d8cfa677348250afec88b.tar.gz | |
fix migration dialog
Diffstat (limited to 'apps/web/src/services/storage/migrations/runner.ts')
| -rw-r--r-- | apps/web/src/services/storage/migrations/runner.ts | 53 |
1 files changed, 46 insertions, 7 deletions
diff --git a/apps/web/src/services/storage/migrations/runner.ts b/apps/web/src/services/storage/migrations/runner.ts index 83e7edae..bd34c661 100644 --- a/apps/web/src/services/storage/migrations/runner.ts +++ b/apps/web/src/services/storage/migrations/runner.ts @@ -4,18 +4,27 @@ import { } from "@/services/storage/indexeddb-adapter"; import type { StorageMigration } from "./base"; import type { ProjectRecord } from "./transformers/types"; -import { getProjectId } from "./transformers/utils"; +import { getProjectId, isRecord } from "./transformers/utils"; export interface StorageMigrationResult { migratedCount: number; } +export interface MigrationProgress { + isMigrating: boolean; + fromVersion: number | null; + toVersion: number | null; + projectName: string | null; +} + let hasCleanedUpMetaDb = false; export async function runStorageMigrations({ migrations, + onProgress, }: { migrations: StorageMigration[]; + onProgress?: (progress: MigrationProgress) => void; }): Promise<StorageMigrationResult> { // One-time cleanup: delete the old global version database if (!hasCleanedUpMetaDb) { @@ -44,8 +53,20 @@ export async function runStorageMigrations({ let projectRecord = project as ProjectRecord; let currentVersion = getProjectVersion({ project: projectRecord }); + const targetVersion = orderedMigrations.at(-1)?.to ?? currentVersion; + + if (currentVersion >= targetVersion) { + continue; + } + + const projectName = getProjectName({ project: projectRecord }); + onProgress?.({ + isMigrating: true, + fromVersion: currentVersion, + toVersion: targetVersion, + projectName, + }); - // Apply migrations sequentially until project is up to date for (const migration of orderedMigrations) { if (migration.from !== currentVersion) { continue; @@ -54,24 +75,28 @@ export async function runStorageMigrations({ const result = await migration.transform(projectRecord); if (result.skipped) { - break; // Project is already at this version or higher + break; } - // Update project with migrated version const projectId = getProjectId({ project: result.project }); if (!projectId) { - break; // Can't save without ID + break; } await projectsAdapter.set(projectId, result.project); migratedCount++; currentVersion = migration.to; - - // Use migrated project for next iteration projectRecord = result.project; } } + onProgress?.({ + isMigrating: false, + fromVersion: null, + toVersion: null, + projectName: null, + }); + return { migratedCount }; } @@ -92,3 +117,17 @@ function getProjectVersion({ project }: { project: ProjectRecord }): number { // v0 - no scenes return 0; } + +function getProjectName({ project }: { project: ProjectRecord }): string | null { + const metadata = project.metadata; + if (isRecord(metadata) && typeof metadata.name === "string") { + return metadata.name; + } + + // v0 had name directly on project + if (typeof project.name === "string") { + return project.name; + } + + return null; +} |
