forked from EduCraft/curriculum-project-hub
fix(hub): mark bootstrap Inbox as SYSTEM_INBOX
Alpha silo bootstrap created the root Inbox without kind=SYSTEM_INBOX, so Feishu card project creation tried to insert a second Inbox and hit the sibling-name unique index. Tag the bootstrap folder correctly and promote any legacy root Inbox on ensure.
This commit is contained in:
@@ -250,6 +250,7 @@ async function initializeSilo(
|
||||
data: {
|
||||
organizationId: input.organization.id,
|
||||
name: "Inbox",
|
||||
kind: "SYSTEM_INBOX",
|
||||
sortKey: "000000",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -558,6 +558,26 @@ async function ensureInboxFolder(prisma: Prisma.TransactionClient, organizationI
|
||||
select: { id: true },
|
||||
});
|
||||
if (existing !== null) return existing;
|
||||
|
||||
// Bootstrap once created a root "Inbox" without kind=SYSTEM_INBOX. Sibling-name
|
||||
// uniqueness then makes a second create fail. Recover by promoting that row.
|
||||
const legacyRootInbox = await prisma.folder.findFirst({
|
||||
where: {
|
||||
organizationId,
|
||||
parentId: null,
|
||||
name: "Inbox",
|
||||
archivedAt: null,
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
if (legacyRootInbox !== null) {
|
||||
return prisma.folder.update({
|
||||
where: { id: legacyRootInbox.id },
|
||||
data: { kind: "SYSTEM_INBOX" },
|
||||
select: { id: true },
|
||||
});
|
||||
}
|
||||
|
||||
return prisma.folder.create({
|
||||
data: { organizationId, name: "Inbox", kind: "SYSTEM_INBOX", sortKey: "000000" },
|
||||
select: { id: true },
|
||||
|
||||
Reference in New Issue
Block a user