feat: config portability with generic entity resolver framework

Full configuration export/import system for Homarr with excellent DX:
- Export/import boards, apps, integrations (with re-encrypted secrets),
  users (with bcrypt hashes), groups (with permissions and memberships),
  search engines, and server settings
- Homepage services.yaml import with widget-type mapping
- Generic resolveEntities() utility eliminates per-entity boilerplate
- Declarative entity-fields.ts: adding a new user preference requires
  only one line change (no export/import/schema edits needed)
- User schema uses .catchall(z.unknown()) for forward-compatible prefs
- groupByKey() utility replaces manual Map-building
- CONFIG_ENTITY_KEYS as single source of truth for entity metadata
- Reuse existing entities (apps by name+icon+href, integrations by
  kind+name+url, users by email, groups by name, boards by name)
- Skip duplicates with warnings rather than failing
- Onboarding flow skips user creation step when config includes users
- Reuse existing admin group during onboarding after config import
This commit is contained in:
Thomas Camlong committed 2026-06-06 16:22:59 +02:00
1 parent 1f7b7f0516
commit f6a598b774
48 files changed
+1869 -1435

No files matched your search

@@ -11,20 +11,11 @@ import type {
sectionLayouts,
sections,
} from "@homarr/db/schema";
import { backgroundImageAttachments, backgroundImageRepeats, backgroundImageSizes } from "@homarr/definitions";
import type { HomarrBundle, HomarrBundleBoard } from "../schema";
import { replaceAppRefsInValue, stringifyForDb } from "../utils";
import { buildBoardInsertRow, mustGet, replaceAppRefsInValue, stringifyForDb } from "../utils";
import { doAppsMatch } from "./match-apps";
const mustGet = <T>(map: Map<string, T>, key: string): T => {
const value = map.get(key);
if (value === undefined) {
throw new Error(`Missing map entry for key "${key}"`);
}
return value;
};
export type PreparedBundleImport = {
apps: InferInsertModel<typeof apps>[];
board: InferInsertModel<typeof boards>;
@@ -131,28 +122,7 @@ export const prepareBoardImport = (
integrationRefToId.set(bundleIntegration.ref, existingIntegration.id);
}
const board: PreparedBundleImport["board"] = {
id: boardId,
name: boardName,
creatorId,
isPublic: sourceBoard.settings.isPublic ?? false,
pageTitle: sourceBoard.settings.pageTitle ?? null,
metaTitle: sourceBoard.settings.metaTitle ?? null,
logoImageUrl: sourceBoard.settings.logoImageUrl ?? null,
faviconImageUrl: sourceBoard.settings.faviconImageUrl ?? null,
backgroundImageUrl: sourceBoard.settings.backgroundImageUrl ?? null,
backgroundImageAttachment:
sourceBoard.settings.backgroundImageAttachment ?? backgroundImageAttachments.defaultValue,
backgroundImageRepeat: sourceBoard.settings.backgroundImageRepeat ?? backgroundImageRepeats.defaultValue,
backgroundImageSize: sourceBoard.settings.backgroundImageSize ?? backgroundImageSizes.defaultValue,
primaryColor: sourceBoard.settings.primaryColor,
secondaryColor: sourceBoard.settings.secondaryColor,
opacity: sourceBoard.settings.opacity,
customCss: sourceBoard.settings.customCss ?? null,
iconColor: sourceBoard.settings.iconColor ?? null,
itemRadius: sourceBoard.settings.itemRadius,
disableStatus: sourceBoard.settings.disableStatus ?? false,
};
const board: PreparedBundleImport["board"] = buildBoardInsertRow(boardId, boardName, creatorId, sourceBoard.settings);
const layouts = sourceBoard.layouts.map((layout) => ({
id: mustGet(layoutRefToId, layout.ref),