refactor(config): dedupe bindings migrations

This commit is contained in:
Peter Steinberger
2026-02-15 16:47:06 +00:00
parent fe303fc016
commit 08f16da8d7

View File

@@ -6,11 +6,12 @@ import {
mergeMissing, mergeMissing,
} from "./legacy.shared.js"; } from "./legacy.shared.js";
export const LEGACY_CONFIG_MIGRATIONS_PART_1: LegacyConfigMigration[] = [ function migrateBindings(
{ raw: Record<string, unknown>,
id: "bindings.match.provider->bindings.match.channel", changes: string[],
describe: "Move bindings[].match.provider to bindings[].match.channel", changeNote: string,
apply: (raw, changes) => { mutator: (match: Record<string, unknown>) => boolean,
) {
const bindings = Array.isArray(raw.bindings) ? raw.bindings : null; const bindings = Array.isArray(raw.bindings) ? raw.bindings : null;
if (!bindings) { if (!bindings) {
return; return;
@@ -25,61 +26,65 @@ export const LEGACY_CONFIG_MIGRATIONS_PART_1: LegacyConfigMigration[] = [
if (!match) { if (!match) {
continue; continue;
} }
if (typeof match.channel === "string" && match.channel.trim()) { if (!mutator(match)) {
continue; continue;
} }
const provider = typeof match.provider === "string" ? match.provider.trim() : "";
if (!provider) {
continue;
}
match.channel = provider;
delete match.provider;
entry.match = match; entry.match = match;
touched = true; touched = true;
} }
if (touched) { if (touched) {
raw.bindings = bindings; raw.bindings = bindings;
changes.push("Moved bindings[].match.provider → bindings[].match.channel."); changes.push(changeNote);
} }
}
export const LEGACY_CONFIG_MIGRATIONS_PART_1: LegacyConfigMigration[] = [
{
id: "bindings.match.provider->bindings.match.channel",
describe: "Move bindings[].match.provider to bindings[].match.channel",
apply: (raw, changes) => {
migrateBindings(
raw,
changes,
"Moved bindings[].match.provider → bindings[].match.channel.",
(match) => {
if (typeof match.channel === "string" && match.channel.trim()) {
return false;
}
const provider = typeof match.provider === "string" ? match.provider.trim() : "";
if (!provider) {
return false;
}
match.channel = provider;
delete match.provider;
return true;
},
);
}, },
}, },
{ {
id: "bindings.match.accountID->bindings.match.accountId", id: "bindings.match.accountID->bindings.match.accountId",
describe: "Move bindings[].match.accountID to bindings[].match.accountId", describe: "Move bindings[].match.accountID to bindings[].match.accountId",
apply: (raw, changes) => { apply: (raw, changes) => {
const bindings = Array.isArray(raw.bindings) ? raw.bindings : null; migrateBindings(
if (!bindings) { raw,
return; changes,
} "Moved bindings[].match.accountID → bindings[].match.accountId.",
(match) => {
let touched = false;
for (const entry of bindings) {
if (!isRecord(entry)) {
continue;
}
const match = getRecord(entry.match);
if (!match) {
continue;
}
if (match.accountId !== undefined) { if (match.accountId !== undefined) {
continue; return false;
} }
const accountID = const accountID =
typeof match.accountID === "string" ? match.accountID.trim() : match.accountID; typeof match.accountID === "string" ? match.accountID.trim() : match.accountID;
if (!accountID) { if (!accountID) {
continue; return false;
} }
match.accountId = accountID; match.accountId = accountID;
delete match.accountID; delete match.accountID;
entry.match = match; return true;
touched = true; },
} );
if (touched) {
raw.bindings = bindings;
changes.push("Moved bindings[].match.accountID → bindings[].match.accountId.");
}
}, },
}, },
{ {