mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 15:43:13 +09:00
Let plugins migrate the data core stores for them
Plugins had no way to update the config fields and permissions core stores for them, so renaming inventory_sync needed migrations in core packages. A plugin can now declare a migrationEntrypoint. It's loaded on the controller and hosts before configs and roles are read, for every plugin in the plugin list, and attaches handlers to sync hooks for the controller, host and instance configs and roles. lib gets helpers to rename config fields and permissions, and each config gets a hidden <plugin>.version field set after load so migrations can tell which version saved the data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
24586a4b7c
commit
aec0fc7a1e
19 files changed
+562
-7
No files matched your search
@@ -10,6 +10,7 @@ import { StringEnum } from "../data/composites.js";
|
||||
import { safeOutputFile } from "../file_ops.js";
|
||||
import * as validators from "./validators.js";
|
||||
import { RequestError } from "../errors.js";
|
||||
import type { SyncHook } from "../SyncHook.js";
|
||||
|
||||
const ConfigLocation = StringEnum(["controller", "host", "control"]);
|
||||
export type ConfigLocation = Static<typeof ConfigLocation>;
|
||||
@@ -224,6 +225,12 @@ export class Config<
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrations attached by plugins, run after {@link Config.migrations}.
|
||||
* Declared by each subclass that plugins can add fields to.
|
||||
*/
|
||||
declare static pluginMigrations?: SyncHook<ConfigSchema>;
|
||||
|
||||
/** Defines the default access locations for the config class */
|
||||
static defaultAccess: ConfigLocation[] = ["controller", "host", "control"];
|
||||
|
||||
@@ -269,7 +276,11 @@ export class Config<
|
||||
) as Fields;
|
||||
|
||||
if (fields) {
|
||||
this.update(this.constructor.migrations(fields), false, location);
|
||||
let migrated = this.constructor.migrations(fields);
|
||||
if (this.constructor.pluginMigrations) {
|
||||
migrated = this.constructor.pluginMigrations.reduce(migrated);
|
||||
}
|
||||
this.update(migrated, false, location);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user