fix(onboarding): streamline backup restore
This commit is contained in:
1 parent
30cb066b7f
commit
174e0a7606
7 files changed
+63
-17
No files matched your search
@@ -172,6 +172,29 @@ const reEncryptSecrets = (tempDb: InstanceType<typeof Database>, importedKeyHex:
|
||||
transaction();
|
||||
};
|
||||
|
||||
const getHomeBoardName = (tempDb: InstanceType<typeof Database>): string | null => {
|
||||
const row = tempDb
|
||||
.prepare(
|
||||
`SELECT "name" FROM (
|
||||
SELECT "board"."name" AS "name", 0 AS "priority"
|
||||
FROM "group"
|
||||
INNER JOIN "board" ON "board"."id" = "group"."home_board_id"
|
||||
WHERE "group"."name" = 'everyone'
|
||||
UNION ALL
|
||||
SELECT "board"."name" AS "name", 1 AS "priority"
|
||||
FROM "user"
|
||||
INNER JOIN "board" ON "board"."id" = "user"."home_board_id"
|
||||
UNION ALL
|
||||
SELECT "board"."name" AS "name", 2 AS "priority"
|
||||
FROM "board"
|
||||
)
|
||||
ORDER BY "priority", "name"
|
||||
LIMIT 1`,
|
||||
)
|
||||
.get() as { name: string } | undefined;
|
||||
return row?.name ?? null;
|
||||
};
|
||||
|
||||
const isOnboardingActiveAsync = async (): Promise<boolean> => {
|
||||
const onboardingRow = await db.query.onboarding.findFirst();
|
||||
if (!onboardingRow) return false;
|
||||
@@ -289,6 +312,8 @@ export async function POST(req: Request) {
|
||||
reEncryptSecrets(tempDb, importedKey);
|
||||
}
|
||||
|
||||
const homeBoardName = getHomeBoardName(tempDb);
|
||||
|
||||
tempDb.close();
|
||||
tempDb = null;
|
||||
|
||||
@@ -313,6 +338,7 @@ export async function POST(req: Request) {
|
||||
success: true,
|
||||
message: "Database restored. Server is restarting...",
|
||||
restartAfterMs: RESTART_DELAY_MS,
|
||||
homeBoardName,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("[backup/import] Restore failed:", error);
|
||||
|
||||
@@ -128,7 +128,11 @@ describe("POST /api/backup/import", () => {
|
||||
const response = await POST(createImportRequest(backup));
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
await expect(response.json()).resolves.toMatchObject({ success: true, restartAfterMs: 500 });
|
||||
await expect(response.json()).resolves.toMatchObject({
|
||||
success: true,
|
||||
restartAfterMs: 500,
|
||||
homeBoardName: "Restored board",
|
||||
});
|
||||
expect(readBoardNames(activeDatabasePath)).toEqual(["Restored board"]);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user