adjust migration versioning
This commit is contained in:
parent
e385159f29
commit
60ed168053
6 changed files with 56 additions and 51 deletions
|
@ -175,9 +175,9 @@
|
||||||
"DS4.WarningActorCannotOwnItem": "Der Aktor '{actorName}' vom Typ '{actorType}' kann das Item '{itemName}' vom Typ '{itemType}' nicht besitzen.",
|
"DS4.WarningActorCannotOwnItem": "Der Aktor '{actorName}' vom Typ '{actorType}' kann das Item '{itemName}' vom Typ '{itemType}' nicht besitzen.",
|
||||||
"DS4.ErrorDiceCritOverlap": "Es gibt eine Überlappung zwischen Patzern und Immersiegen.",
|
"DS4.ErrorDiceCritOverlap": "Es gibt eine Überlappung zwischen Patzern und Immersiegen.",
|
||||||
"DS4.ErrorExplodingRecursionLimitExceeded": "Die maximale Rekursionstiefe für slayende Würfelwürfe wurde überschritten.",
|
"DS4.ErrorExplodingRecursionLimitExceeded": "Die maximale Rekursionstiefe für slayende Würfelwürfe wurde überschritten.",
|
||||||
"DS4.ErrorDuringMigration": "Fehler während der Aktualisierung des DS4 Systems von Version {currentVersion} auf {targetVersion}. Der Fehler trat während der Ausführung des Migrationsskripts mit der Version {migrationVersion} auf. Spätere Migrationsskripte wurden nicht ausgeführt. Mehr Details finden Sie in der Entwicklerkonsole (F12).",
|
"DS4.ErrorDuringMigration": "Fehler während der Aktualisierung des DS4 Systems von Migrationsversion {currentVersion} auf {targetVersion}. Der Fehler trat während der Ausführung des Migrationsskripts mit der Version {migrationVersion} auf. Spätere Migrationsskripte wurden nicht ausgeführt. Mehr Details finden Sie in der Entwicklerkonsole (F12).",
|
||||||
"DS4.InfoSystemUpdateStart": "Aktualisiere DS4 System von Version {currentVersion} auf {targetVersion}. Bitte haben Sie etwas Geduld, schließen Sie nicht das Spiel und fahren Sie nicht den Server herunter.",
|
"DS4.InfoSystemUpdateStart": "Aktualisiere DS4 System von Migrationsversion {currentVersion} auf {targetVersion}. Bitte haben Sie etwas Geduld, schließen Sie nicht das Spiel und fahren Sie nicht den Server herunter.",
|
||||||
"DS4.InfoSystemUpdateCompleted": "Aktualisierung des DS4 Systems von Version {currentVersion} auf {targetVersion} erfolgreich!",
|
"DS4.InfoSystemUpdateCompleted": "Aktualisierung des DS4 Systems von Migrationsversion {currentVersion} auf {targetVersion} erfolgreich!",
|
||||||
"DS4.UnitRounds": "Runden",
|
"DS4.UnitRounds": "Runden",
|
||||||
"DS4.UnitRoundsAbbr": "Rnd",
|
"DS4.UnitRoundsAbbr": "Rnd",
|
||||||
"DS4.UnitMinutes": "Minuten",
|
"DS4.UnitMinutes": "Minuten",
|
||||||
|
|
|
@ -175,9 +175,9 @@
|
||||||
"DS4.WarningActorCannotOwnItem": "The actor '{actorName}' of type '{actorType}' cannot own the item '{itemName}' of type '{itemType}'.",
|
"DS4.WarningActorCannotOwnItem": "The actor '{actorName}' of type '{actorType}' cannot own the item '{itemName}' of type '{itemType}'.",
|
||||||
"DS4.ErrorDiceCritOverlap": "There's an overlap between Fumbles and Coups",
|
"DS4.ErrorDiceCritOverlap": "There's an overlap between Fumbles and Coups",
|
||||||
"DS4.ErrorExplodingRecursionLimitExceeded": "Maximum recursion depth for exploding dice roll exceeded",
|
"DS4.ErrorExplodingRecursionLimitExceeded": "Maximum recursion depth for exploding dice roll exceeded",
|
||||||
"DS4.ErrorDuringMigration": "Error while migrating DS4 system from version {currentVersion} to {targetVersion}. The error occurred during execution of migration script with version {migrationVersion}. Later migrations have not been executed. For more details, please look at the development console (F12).",
|
"DS4.ErrorDuringMigration": "Error while migrating DS4 system from migration version {currentVersion} to {targetVersion}. The error occurred during execution of migration script with version {migrationVersion}. Later migrations have not been executed. For more details, please look at the development console (F12).",
|
||||||
"DS4.InfoSystemUpdateStart": "Migrating DS4 system from version {currentVersion} to {targetVersion}. Please be patient and do not close your game or shut down your server.",
|
"DS4.InfoSystemUpdateStart": "Migrating DS4 system from migration version {currentVersion} to {targetVersion}. Please be patient and do not close your game or shut down your server.",
|
||||||
"DS4.InfoSystemUpdateCompleted": "Migration of DS4 system from version {currentVersion} to {targetVersion} successful!",
|
"DS4.InfoSystemUpdateCompleted": "Migration of DS4 system from migration version {currentVersion} to {targetVersion} successful!",
|
||||||
"DS4.UnitRounds": "Rounds",
|
"DS4.UnitRounds": "Rounds",
|
||||||
"DS4.UnitRoundsAbbr": "rnd",
|
"DS4.UnitRoundsAbbr": "rnd",
|
||||||
"DS4.UnitMinutes": "Minutes",
|
"DS4.UnitMinutes": "Minutes",
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { DS4CharacterActorSheet } from "./actor/sheets/character-sheet";
|
||||||
import { DS4CreatureActorSheet } from "./actor/sheets/creature-sheet";
|
import { DS4CreatureActorSheet } from "./actor/sheets/creature-sheet";
|
||||||
import { createCheckRoll } from "./rolls/check-factory";
|
import { createCheckRoll } from "./rolls/check-factory";
|
||||||
import { registerSystemSettings } from "./settings";
|
import { registerSystemSettings } from "./settings";
|
||||||
import { migrate } from "./migrations";
|
import { migration } from "./migrations";
|
||||||
|
|
||||||
Hooks.once("init", async function () {
|
Hooks.once("init", async function () {
|
||||||
console.log(`DS4 | Initializing the DS4 Game System\n${DS4.ASCII}`);
|
console.log(`DS4 | Initializing the DS4 Game System\n${DS4.ASCII}`);
|
||||||
|
@ -18,6 +18,7 @@ Hooks.once("init", async function () {
|
||||||
DS4Item,
|
DS4Item,
|
||||||
DS4,
|
DS4,
|
||||||
createCheckRoll,
|
createCheckRoll,
|
||||||
|
migration,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Record configuration
|
// Record configuration
|
||||||
|
@ -130,5 +131,5 @@ Hooks.once("setup", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
Hooks.once("ready", function () {
|
Hooks.once("ready", function () {
|
||||||
migrate();
|
migration.migrate();
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,40 +1,50 @@
|
||||||
import { migrate as migrate0_1_0 } from "./migrations/0-1-0";
|
import { migrate as migrate001 } from "./migrations/001";
|
||||||
|
|
||||||
export async function migrate(): Promise<void> {
|
async function migrate(): Promise<void> {
|
||||||
if (!game.user.isGM) {
|
if (!game.user.isGM) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentVersion: string = game.settings.get("ds4", "systemMigrationVersion");
|
const oldMigrationVersion: number = game.settings.get("ds4", "systemMigrationVersion");
|
||||||
const targetVersion = game.system.data.version;
|
|
||||||
|
|
||||||
if (isFirstWorldStart(currentVersion)) {
|
const targetMigrationVersion = migrations.length;
|
||||||
game.settings.set("ds4", "systemMigrationVersion", targetVersion);
|
|
||||||
|
if (isFirstWorldStart(oldMigrationVersion)) {
|
||||||
|
game.settings.set("ds4", "systemMigrationVersion", targetMigrationVersion);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNewerVersion(targetVersion, currentVersion)) {
|
return migrateFromTo(oldMigrationVersion, targetMigrationVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function migrateFromTo(oldMigrationVersion: number, targetMigrationVersion: number): Promise<void> {
|
||||||
|
if (!game.user.isGM) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const migrationsToExecute = migrations.slice(oldMigrationVersion, targetMigrationVersion);
|
||||||
|
|
||||||
|
if (migrationsToExecute.length > 0) {
|
||||||
ui.notifications.info(
|
ui.notifications.info(
|
||||||
game.i18n.format("DS4.InfoSystemUpdateStart", {
|
game.i18n.format("DS4.InfoSystemUpdateStart", {
|
||||||
currentVersion: currentVersion,
|
currentVersion: oldMigrationVersion,
|
||||||
targetVersion: targetVersion,
|
targetVersion: targetMigrationVersion,
|
||||||
}),
|
}),
|
||||||
{ permanent: true },
|
{ permanent: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
const migrationFunctionsToExecute = Object.entries(migrations)
|
for (const [i, migration] of migrationsToExecute.entries()) {
|
||||||
.filter(([version]) => !isNewerVersion(currentVersion, version)) // currentVersion <= version of migration
|
const currentMigrationVersion = oldMigrationVersion + i + 1;
|
||||||
.filter(([version]) => isNewerVersion(targetVersion, version)); // targetVersion > version of migration
|
console.log("executing migration script ", currentMigrationVersion);
|
||||||
|
|
||||||
for (const migration of migrationFunctionsToExecute) {
|
|
||||||
try {
|
try {
|
||||||
await migration[1]();
|
await migration();
|
||||||
|
game.settings.set("ds4", "systemMigrationVersion", currentMigrationVersion);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ui.notifications.error(
|
ui.notifications.error(
|
||||||
game.i18n.format("DS4.ErrorDuringMigration", {
|
game.i18n.format("DS4.ErrorDuringMigration", {
|
||||||
currentVersion: currentVersion,
|
currentVersion: oldMigrationVersion,
|
||||||
targetVersion: targetVersion,
|
targetVersion: targetMigrationVersion,
|
||||||
migrationVersion: migration[0],
|
migrationVersion: currentMigrationVersion,
|
||||||
}),
|
}),
|
||||||
{ permanent: true },
|
{ permanent: true },
|
||||||
);
|
);
|
||||||
|
@ -46,32 +56,26 @@ export async function migrate(): Promise<void> {
|
||||||
|
|
||||||
ui.notifications.info(
|
ui.notifications.info(
|
||||||
game.i18n.format("DS4.InfoSystemUpdateCompleted", {
|
game.i18n.format("DS4.InfoSystemUpdateCompleted", {
|
||||||
currentVersion: currentVersion,
|
currentVersion: oldMigrationVersion,
|
||||||
targetVersion: targetVersion,
|
targetVersion: targetMigrationVersion,
|
||||||
}),
|
}),
|
||||||
{ permanent: true },
|
{ permanent: true },
|
||||||
);
|
);
|
||||||
game.settings.set("ds4", "systemMigrationVersion", targetVersion);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function getTargetMigrationVersion(): number {
|
||||||
* The migrations to (potentially) execute when a world is loaded. The key
|
return migrations.length;
|
||||||
* specifies the version number _from_ which is being migrated to the next
|
|
||||||
* version.
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* Given the migration version numbers "0.0.1", "0.0.2", "0.1.2", "0.4.9", and
|
|
||||||
* "0.5.0" an update from version "0.0.2" to "0.5.0" would execute the
|
|
||||||
* migrations with version "0.0.2", "0.1.2", and "0.4.9". In particular,
|
|
||||||
* migrations of a version lower than the current version or higher or equal to
|
|
||||||
* the target version are _not_ executed while all others are.
|
|
||||||
*/
|
|
||||||
const migrations: Record<string, () => Promise<void>> = {
|
|
||||||
"0.1.0": migrate0_1_0,
|
|
||||||
};
|
|
||||||
|
|
||||||
function isFirstWorldStart(version: string): boolean {
|
|
||||||
return version === "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const migrations: Array<() => Promise<void>> = [migrate001];
|
||||||
|
|
||||||
|
function isFirstWorldStart(migrationVersion: number): boolean {
|
||||||
|
return migrationVersion < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const migration = {
|
||||||
|
migrate: migrate,
|
||||||
|
migrateFromTo: migrateFromTo,
|
||||||
|
getTargetMigrationVersion: getTargetMigrationVersion,
|
||||||
|
};
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
export function registerSystemSettings(): void {
|
export function registerSystemSettings(): void {
|
||||||
/**
|
/**
|
||||||
* Track the system version upon which point a migration was last applied
|
* Track the migrations version of the latest migration that has been applied
|
||||||
*/
|
*/
|
||||||
game.settings.register("ds4", "systemMigrationVersion", {
|
game.settings.register("ds4", "systemMigrationVersion", {
|
||||||
name: "System Migration Version",
|
name: "System Migration Version",
|
||||||
scope: "world",
|
scope: "world",
|
||||||
config: false,
|
config: false,
|
||||||
type: String,
|
type: Number,
|
||||||
default: "",
|
default: -1,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue