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.ErrorDiceCritOverlap": "Es gibt eine Überlappung zwischen Patzern und Immersiegen.",
|
||||
"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.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.InfoSystemUpdateCompleted": "Aktualisierung des DS4 Systems von Version {currentVersion} auf {targetVersion} erfolgreich!",
|
||||
"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 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 Migrationsversion {currentVersion} auf {targetVersion} erfolgreich!",
|
||||
"DS4.UnitRounds": "Runden",
|
||||
"DS4.UnitRoundsAbbr": "Rnd",
|
||||
"DS4.UnitMinutes": "Minuten",
|
||||
|
|
|
@ -175,9 +175,9 @@
|
|||
"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.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.InfoSystemUpdateStart": "Migrating DS4 system from 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.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 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 migration version {currentVersion} to {targetVersion} successful!",
|
||||
"DS4.UnitRounds": "Rounds",
|
||||
"DS4.UnitRoundsAbbr": "rnd",
|
||||
"DS4.UnitMinutes": "Minutes",
|
||||
|
|
|
@ -8,7 +8,7 @@ import { DS4CharacterActorSheet } from "./actor/sheets/character-sheet";
|
|||
import { DS4CreatureActorSheet } from "./actor/sheets/creature-sheet";
|
||||
import { createCheckRoll } from "./rolls/check-factory";
|
||||
import { registerSystemSettings } from "./settings";
|
||||
import { migrate } from "./migrations";
|
||||
import { migration } from "./migrations";
|
||||
|
||||
Hooks.once("init", async function () {
|
||||
console.log(`DS4 | Initializing the DS4 Game System\n${DS4.ASCII}`);
|
||||
|
@ -18,6 +18,7 @@ Hooks.once("init", async function () {
|
|||
DS4Item,
|
||||
DS4,
|
||||
createCheckRoll,
|
||||
migration,
|
||||
};
|
||||
|
||||
// Record configuration
|
||||
|
@ -130,5 +131,5 @@ Hooks.once("setup", 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) {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentVersion: string = game.settings.get("ds4", "systemMigrationVersion");
|
||||
const targetVersion = game.system.data.version;
|
||||
const oldMigrationVersion: number = game.settings.get("ds4", "systemMigrationVersion");
|
||||
|
||||
if (isFirstWorldStart(currentVersion)) {
|
||||
game.settings.set("ds4", "systemMigrationVersion", targetVersion);
|
||||
const targetMigrationVersion = migrations.length;
|
||||
|
||||
if (isFirstWorldStart(oldMigrationVersion)) {
|
||||
game.settings.set("ds4", "systemMigrationVersion", targetMigrationVersion);
|
||||
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(
|
||||
game.i18n.format("DS4.InfoSystemUpdateStart", {
|
||||
currentVersion: currentVersion,
|
||||
targetVersion: targetVersion,
|
||||
currentVersion: oldMigrationVersion,
|
||||
targetVersion: targetMigrationVersion,
|
||||
}),
|
||||
{ permanent: true },
|
||||
);
|
||||
|
||||
const migrationFunctionsToExecute = Object.entries(migrations)
|
||||
.filter(([version]) => !isNewerVersion(currentVersion, version)) // currentVersion <= version of migration
|
||||
.filter(([version]) => isNewerVersion(targetVersion, version)); // targetVersion > version of migration
|
||||
|
||||
for (const migration of migrationFunctionsToExecute) {
|
||||
for (const [i, migration] of migrationsToExecute.entries()) {
|
||||
const currentMigrationVersion = oldMigrationVersion + i + 1;
|
||||
console.log("executing migration script ", currentMigrationVersion);
|
||||
try {
|
||||
await migration[1]();
|
||||
await migration();
|
||||
game.settings.set("ds4", "systemMigrationVersion", currentMigrationVersion);
|
||||
} catch (err) {
|
||||
ui.notifications.error(
|
||||
game.i18n.format("DS4.ErrorDuringMigration", {
|
||||
currentVersion: currentVersion,
|
||||
targetVersion: targetVersion,
|
||||
migrationVersion: migration[0],
|
||||
currentVersion: oldMigrationVersion,
|
||||
targetVersion: targetMigrationVersion,
|
||||
migrationVersion: currentMigrationVersion,
|
||||
}),
|
||||
{ permanent: true },
|
||||
);
|
||||
|
@ -46,32 +56,26 @@ export async function migrate(): Promise<void> {
|
|||
|
||||
ui.notifications.info(
|
||||
game.i18n.format("DS4.InfoSystemUpdateCompleted", {
|
||||
currentVersion: currentVersion,
|
||||
targetVersion: targetVersion,
|
||||
currentVersion: oldMigrationVersion,
|
||||
targetVersion: targetMigrationVersion,
|
||||
}),
|
||||
{ permanent: true },
|
||||
);
|
||||
game.settings.set("ds4", "systemMigrationVersion", targetVersion);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The migrations to (potentially) execute when a world is loaded. The key
|
||||
* 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 === "";
|
||||
function getTargetMigrationVersion(): number {
|
||||
return migrations.length;
|
||||
}
|
||||
|
||||
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 {
|
||||
/**
|
||||
* 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", {
|
||||
name: "System Migration Version",
|
||||
scope: "world",
|
||||
config: false,
|
||||
type: String,
|
||||
default: "",
|
||||
type: Number,
|
||||
default: -1,
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue