mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 15:30:41 +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
@@ -110,6 +110,46 @@ describe("lib/plugin_loader", function() {
|
||||
);
|
||||
});
|
||||
});
|
||||
describe("loadPluginMigrations()", function() {
|
||||
const baseDir = path.resolve("temp", "test", "plugin", "migration_plugin");
|
||||
before(async function() {
|
||||
await fs.mkdir(baseDir, { recursive: true });
|
||||
await fs.writeFile(path.join(baseDir, "migrations.js"), `
|
||||
export default function(context) {
|
||||
context.hooks.controllerConfig.attach(context.plugin.name, config => {
|
||||
config.migratedBy = context.plugin.name;
|
||||
return config;
|
||||
});
|
||||
}
|
||||
`);
|
||||
await fs.writeFile(path.join(baseDir, "throwing.js"), `
|
||||
export default function() { throw new Error("load failed"); }
|
||||
`);
|
||||
});
|
||||
afterEach(function() {
|
||||
lib.ControllerConfig.pluginMigrations.clear();
|
||||
});
|
||||
|
||||
function info(entrypoint) {
|
||||
return {
|
||||
name: "test",
|
||||
packagePath: path.join(baseDir, "package.json"),
|
||||
migrationEntrypoint: entrypoint,
|
||||
};
|
||||
}
|
||||
|
||||
it("should attach migrations from the migration entrypoint", async function() {
|
||||
await lib.loadPluginMigrations([info("migrations.js"), { name: "other" }]);
|
||||
assert.deepEqual([...lib.ControllerConfig.pluginMigrations.attached], ["test"]);
|
||||
assert.deepEqual(lib.ControllerConfig.pluginMigrations.reduce({}), { migratedBy: "test" });
|
||||
});
|
||||
it("should reject with a PluginError if the entrypoint throws", async function() {
|
||||
await assert.rejects(
|
||||
lib.loadPluginMigrations([info("throwing.js")]),
|
||||
err => err instanceof lib.PluginError && err.pluginName === "test"
|
||||
);
|
||||
});
|
||||
});
|
||||
describe("loadPlugin()", function() {
|
||||
const baseDir = path.join("temp", "test", "plugin");
|
||||
const functionPlugin = path.resolve(baseDir, "function_plugin");
|
||||
|
||||
Reference in new issue
Block a user