feat: added upgradeToV3 upgrader
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { KGProject } from '../KGProject';
|
||||
import { upgradeToV1 } from './upgradeToV1';
|
||||
import { upgradeToV2 } from './upgradeToV2';
|
||||
import { upgradeToV3 } from './upgradeToV3';
|
||||
|
||||
/**
|
||||
* Upgrade the given project to the latest structure version, one version at a time.
|
||||
@@ -28,6 +29,10 @@ export function upgradeProjectToLatest(project: KGProject): KGProject {
|
||||
workingProject = upgradeToV2(workingProject);
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
workingProject = upgradeToV3(workingProject);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
// If an upgrader is missing, throw to prevent loading incompatible structures
|
||||
throw new Error(`No upgrader found for project structure version ${nextVersion}`);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { KGProject } from '../KGProject';
|
||||
|
||||
/**
|
||||
* Upgrade a project from structure version 2 to 3.
|
||||
* Adds the isLooping and loopingRange fields with default values.
|
||||
*/
|
||||
export function upgradeToV3(project: KGProject): KGProject {
|
||||
try {
|
||||
// Set default isLooping to false if not already set
|
||||
const currentIsLooping = project.getIsLooping?.();
|
||||
if (currentIsLooping === undefined) {
|
||||
project.setIsLooping(false);
|
||||
}
|
||||
|
||||
// Set default loopingRange to [0, 0] if not already set
|
||||
const currentLoopingRange = project.getLoopingRange?.();
|
||||
if (!currentLoopingRange) {
|
||||
project.setLoopingRange([0, 0]);
|
||||
}
|
||||
} finally {
|
||||
// Always set the project structure version to 3 to mark migration complete
|
||||
project.setProjectStructureVersion(3);
|
||||
}
|
||||
|
||||
return project;
|
||||
}
|
||||
Reference in New Issue
Block a user