summaryrefslogtreecommitdiff
path: root/apps/web/src/services/storage/migrations/v2-to-v3.ts
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2026-02-01 17:01:59 +0100
committerMaze Winther <mazewinther@gmail.com>2026-02-01 17:01:59 +0100
commit7d5914353b8f78652f12b880fcd16c5ab82b3769 (patch)
tree84d4c6ef4f9a0d735271706a25518bdda3bc1791 /apps/web/src/services/storage/migrations/v2-to-v3.ts
parentee7eaecc9f2125ac821e9d19bb345c1738ee9a54 (diff)
parent22ea6b89256328458bd8d67f6e5a53d9a3623a90 (diff)
downloadopencut-7d5914353b8f78652f12b880fcd16c5ab82b3769.tar.gz
Merge branch 'staging'
Diffstat (limited to 'apps/web/src/services/storage/migrations/v2-to-v3.ts')
-rw-r--r--apps/web/src/services/storage/migrations/v2-to-v3.ts79
1 files changed, 12 insertions, 67 deletions
diff --git a/apps/web/src/services/storage/migrations/v2-to-v3.ts b/apps/web/src/services/storage/migrations/v2-to-v3.ts
index 7869812c..7c52f79d 100644
--- a/apps/web/src/services/storage/migrations/v2-to-v3.ts
+++ b/apps/web/src/services/storage/migrations/v2-to-v3.ts
@@ -1,12 +1,10 @@
/*
- * Adds a "duration" field to each project's metadata,
+ * Adds a "duration" field to each project's metadata
*/
-import { getProjectDurationFromScenes } from "@/lib/scenes";
+
import { IndexedDBAdapter } from "@/services/storage/indexeddb-adapter";
-import type { TScene } from "@/types/timeline";
import { StorageMigration } from "./base";
-
-type ProjectRecord = Record<string, unknown>;
+import { getProjectId, transformProjectV2ToV3 } from "./transformers/v2-to-v3";
export class V2toV3Migration extends StorageMigration {
from = 2;
@@ -21,77 +19,24 @@ export class V2toV3Migration extends StorageMigration {
const projects = await projectsAdapter.getAll();
for (const project of projects) {
- if (!isRecord(project)) {
+ if (typeof project !== "object" || project === null) {
continue;
}
- const projectId = getProjectId({ project });
- if (!projectId) {
+ const result = transformProjectV2ToV3({
+ project: project as Record<string, unknown>,
+ });
+
+ if (result.skipped) {
continue;
}
- if (isV3Project({ project })) {
+ const projectId = getProjectId({ project: result.project });
+ if (!projectId) {
continue;
}
- const scenes = getScenes({ project });
- const duration = getProjectDurationFromScenes({ scenes });
-
- const metadataValue = project.metadata;
- const metadata = isRecord(metadataValue)
- ? { ...metadataValue, duration }
- : { duration };
-
- const migratedProject = {
- ...project,
- metadata,
- version: 3,
- };
-
- await projectsAdapter.set(projectId, migratedProject);
+ await projectsAdapter.set(projectId, result.project);
}
}
}
-
-function getProjectId({ project }: { project: ProjectRecord }): string | null {
- const idValue = project.id;
- if (typeof idValue === "string" && idValue.length > 0) {
- return idValue;
- }
-
- const metadataValue = project.metadata;
- if (!isRecord(metadataValue)) {
- return null;
- }
-
- const metadataId = metadataValue.id;
- if (typeof metadataId === "string" && metadataId.length > 0) {
- return metadataId;
- }
-
- return null;
-}
-
-function getScenes({ project }: { project: ProjectRecord }): TScene[] {
- const scenesValue = project.scenes;
- if (!Array.isArray(scenesValue)) {
- return [];
- }
-
- return scenesValue.filter(isRecord) as unknown as TScene[];
-}
-
-function isV3Project({ project }: { project: ProjectRecord }): boolean {
- const versionValue = project.version;
- if (typeof versionValue === "number" && versionValue >= 3) {
- return true;
- }
-
- return (
- isRecord(project.metadata) && typeof project.metadata.duration === "number"
- );
-}
-
-function isRecord(value: unknown): value is ProjectRecord {
- return typeof value === "object" && value !== null;
-}