summaryrefslogtreecommitdiff
path: root/apps/web/src/services/storage/migrations/transformers/v18-to-v19.ts
blob: 3afa5203c456df4c7e5c8557d9945a92a4231140 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import type { MigrationResult, ProjectRecord } from "./types";
import { getProjectId, isRecord } from "./utils";

export function transformProjectV18ToV19({
	project,
}: {
	project: ProjectRecord;
}): MigrationResult<ProjectRecord> {
	if (!getProjectId({ project })) {
		return { project, skipped: true, reason: "no project id" };
	}

	if (typeof project.version === "number" && project.version >= 19) {
		return { project, skipped: true, reason: "already v19" };
	}

	return {
		project: {
			...migrateCanvasSizeSettings({ project }),
			version: 19,
		},
		skipped: false,
	};
}

function migrateCanvasSizeSettings({
	project,
}: {
	project: ProjectRecord;
}): ProjectRecord {
	const settingsValue = project.settings;
	if (!isRecord(settingsValue)) {
		return project;
	}

	const migratedSettings: Record<string, unknown> = {
		...settingsValue,
		canvasSizeMode: "preset",
		lastCustomCanvasSize: null,
	};

	return {
		...project,
		settings: migratedSettings,
	};
}