Fix stale MediaServant project entry surviving the CarrierNode rename
Docker / Docker Build & Push (push) Successful in 1m24s

The configured_central/main rename to CarrierNode only ran when both
lists were still empty, so an already-populated list kept the old
MediaServant entry and gained a duplicate CarrierNode one. Also
migrate the per-project JSON blobs (labels, login, mounts, tab meta)
keyed by the old name so their data isn't orphaned.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Gabriel20xxandClaude Sonnet 5 committed 2026-09-06 21:59:45 +02:00
1 parent 80cf207d37
commit 5ea8551d60
1 file changed
+39 -21
@@ -647,27 +647,51 @@
// MediaServant -> CarrierNode, and the old flat configured_projects list (which mixed
// MediaConfig/MediaServant in with every other project) split into configured_central /
// configured_main.
function migrateLegacySettings(nextSettings: Record<string, string>) {
const renames: [string, string][] = [
const LEGACY_RENAMES: [string, string][] = [
['mediaconfig', 'projectconfigurator'],
['mediaservant', 'carriernode'],
]
renames.forEach(([from, to]) => {
const LEGACY_RENAME_LABELS: Record<string, string> = {
projectconfigurator: 'ProjectConfigurator',
carriernode: 'CarrierNode',
}
// Renames a project name that may still carry a pre-rename base (e.g. "MediaServant" or
// "MediaServant_2"), regardless of whether it lives in a fresh configured_central/main list or
// the old flat configured_projects one - both can still hold the stale name.
function migrateLegacyProjectName(project: string): string {
const base = getBaseProject(project)
const to = LEGACY_RENAMES.find(([from]) => projectKey(base) === from)
if (!to) return project
return project.replace(new RegExp(`^${base}`, 'i'), LEGACY_RENAME_LABELS[to[1]])
}
// Renames legacy base keys inside a settingKey's JSON blob (each keyed by lowercased project
// name, e.g. configured_mounts.mediaservant) so per-project data saved under the old name isn't
// orphaned once the project list itself has been renamed (see migrateLegacyProjectName).
function migrateLegacyKeyedJson(nextSettings: Record<string, string>, settingKey: string) {
const obj = parseJson<Json>(nextSettings[settingKey], {})
let changed = false
LEGACY_RENAMES.forEach(([from, to]) => {
if (obj[from] !== undefined && obj[to] === undefined) {
obj[to] = obj[from]
changed = true
}
})
if (changed) nextSettings[settingKey] = JSON.stringify(obj)
}
function migrateLegacySettings(nextSettings: Record<string, string>) {
LEGACY_RENAMES.forEach(([from, to]) => {
if (nextSettings[`${from}_url`] && !nextSettings[`${to}_url`])
nextSettings[`${to}_url`] = nextSettings[`${from}_url`]
if (nextSettings[`${from}_label`] && !nextSettings[`${to}_label`]) {
nextSettings[`${to}_label`] = nextSettings[`${from}_label`]
}
})
const legacyLogin = parseJson<Json>(nextSettings.configured_login_required, {})
let loginChanged = false
renames.forEach(([from, to]) => {
if (legacyLogin[from] !== undefined && legacyLogin[to] === undefined) {
legacyLogin[to] = legacyLogin[from]
loginChanged = true
}
})
if (loginChanged) nextSettings.configured_login_required = JSON.stringify(legacyLogin)
;['configured_labels', 'configured_login_required', 'configured_project_meta', 'configured_mounts'].forEach(
(settingKey) => migrateLegacyKeyedJson(nextSettings, settingKey),
)
}
async function load() {
@@ -682,17 +706,11 @@
migrateLegacySettings(nextSettings)
settings = nextSettings
let nextCentral = parseJson<string[]>(nextSettings.configured_central, [])
let nextMain = parseJson<string[]>(nextSettings.configured_main, [])
let nextCentral = parseJson<string[]>(nextSettings.configured_central, []).map(migrateLegacyProjectName)
let nextMain = parseJson<string[]>(nextSettings.configured_main, []).map(migrateLegacyProjectName)
if (nextCentral.length === 0 && nextMain.length === 0) {
const centralBases = CENTRAL_KINDS.map((kind) => kind.base.toLowerCase())
const legacyProjects = parseJson<string[]>(nextSettings.configured_projects, []).map((project) =>
projectKey(project) === 'mediaconfig'
? 'ProjectConfigurator'
: projectKey(getBaseProject(project)) === 'mediaservant'
? project.replace(/mediaservant/i, 'CarrierNode')
: project,
)
const legacyProjects = parseJson<string[]>(nextSettings.configured_projects, []).map(migrateLegacyProjectName)
nextCentral = legacyProjects.filter((project) => centralBases.includes(getBaseProject(project).toLowerCase()))
nextMain = legacyProjects.filter((project) => !centralBases.includes(getBaseProject(project).toLowerCase()))
}