feat(pages): add pages and navigation builder baseline
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "Page" (
|
||||
"id" TEXT NOT NULL,
|
||||
"title" TEXT NOT NULL,
|
||||
"slug" TEXT NOT NULL,
|
||||
"status" TEXT NOT NULL,
|
||||
"summary" TEXT,
|
||||
"content" TEXT NOT NULL,
|
||||
"seoTitle" TEXT,
|
||||
"seoDescription" TEXT,
|
||||
"publishedAt" TIMESTAMP(3),
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "Page_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "NavigationMenu" (
|
||||
"id" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"slug" TEXT NOT NULL,
|
||||
"location" TEXT NOT NULL,
|
||||
"isVisible" BOOLEAN NOT NULL DEFAULT true,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "NavigationMenu_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "NavigationItem" (
|
||||
"id" TEXT NOT NULL,
|
||||
"menuId" TEXT NOT NULL,
|
||||
"pageId" TEXT,
|
||||
"label" TEXT NOT NULL,
|
||||
"href" TEXT,
|
||||
"parentId" TEXT,
|
||||
"sortOrder" INTEGER NOT NULL DEFAULT 0,
|
||||
"isVisible" BOOLEAN NOT NULL DEFAULT true,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "NavigationItem_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Page_slug_key" ON "Page"("slug");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Page_status_idx" ON "Page"("status");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "NavigationMenu_slug_key" ON "NavigationMenu"("slug");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "NavigationItem_menuId_idx" ON "NavigationItem"("menuId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "NavigationItem_pageId_idx" ON "NavigationItem"("pageId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "NavigationItem_parentId_idx" ON "NavigationItem"("parentId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "NavigationItem_menuId_parentId_sortOrder_label_key" ON "NavigationItem"("menuId", "parentId", "sortOrder", "label");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "NavigationItem" ADD CONSTRAINT "NavigationItem_menuId_fkey" FOREIGN KEY ("menuId") REFERENCES "NavigationMenu"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "NavigationItem" ADD CONSTRAINT "NavigationItem_pageId_fkey" FOREIGN KEY ("pageId") REFERENCES "Page"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "NavigationItem" ADD CONSTRAINT "NavigationItem_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "NavigationItem"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -252,3 +252,53 @@ model ArtworkTag {
|
||||
@@unique([artworkId, tagId])
|
||||
@@index([tagId])
|
||||
}
|
||||
|
||||
model Page {
|
||||
id String @id @default(uuid())
|
||||
title String
|
||||
slug String @unique
|
||||
status String
|
||||
summary String?
|
||||
content String
|
||||
seoTitle String?
|
||||
seoDescription String?
|
||||
publishedAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
navItems NavigationItem[]
|
||||
|
||||
@@index([status])
|
||||
}
|
||||
|
||||
model NavigationMenu {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
slug String @unique
|
||||
location String
|
||||
isVisible Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
items NavigationItem[]
|
||||
}
|
||||
|
||||
model NavigationItem {
|
||||
id String @id @default(uuid())
|
||||
menuId String
|
||||
pageId String?
|
||||
label String
|
||||
href String?
|
||||
parentId String?
|
||||
sortOrder Int @default(0)
|
||||
isVisible Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
menu NavigationMenu @relation(fields: [menuId], references: [id], onDelete: Cascade)
|
||||
page Page? @relation(fields: [pageId], references: [id], onDelete: SetNull)
|
||||
parent NavigationItem? @relation("NavigationItemParent", fields: [parentId], references: [id], onDelete: Cascade)
|
||||
children NavigationItem[] @relation("NavigationItemParent")
|
||||
|
||||
@@index([menuId])
|
||||
@@index([pageId])
|
||||
@@index([parentId])
|
||||
@@unique([menuId, parentId, sortOrder, label])
|
||||
}
|
||||
|
||||
@@ -95,6 +95,69 @@ async function main() {
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
||||
const homePage = await db.page.upsert({
|
||||
where: { slug: "home" },
|
||||
update: {},
|
||||
create: {
|
||||
title: "Home",
|
||||
slug: "home",
|
||||
status: "published",
|
||||
summary: "Default homepage seeded for pages/navigation baseline.",
|
||||
content: "Welcome to your new artist CMS homepage.",
|
||||
seoTitle: "Home",
|
||||
seoDescription: "Seeded homepage",
|
||||
publishedAt: new Date(),
|
||||
},
|
||||
})
|
||||
|
||||
const primaryMenu = await db.navigationMenu.upsert({
|
||||
where: { slug: "primary" },
|
||||
update: {},
|
||||
create: {
|
||||
name: "Primary",
|
||||
slug: "primary",
|
||||
location: "header",
|
||||
isVisible: true,
|
||||
},
|
||||
})
|
||||
|
||||
const existingHomeItem = await db.navigationItem.findFirst({
|
||||
where: {
|
||||
menuId: primaryMenu.id,
|
||||
parentId: null,
|
||||
sortOrder: 0,
|
||||
label: "Home",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
})
|
||||
|
||||
if (existingHomeItem) {
|
||||
await db.navigationItem.update({
|
||||
where: {
|
||||
id: existingHomeItem.id,
|
||||
},
|
||||
data: {
|
||||
pageId: homePage.id,
|
||||
href: "/",
|
||||
isVisible: true,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
await db.navigationItem.create({
|
||||
data: {
|
||||
menuId: primaryMenu.id,
|
||||
label: "Home",
|
||||
href: "/",
|
||||
pageId: homePage.id,
|
||||
parentId: null,
|
||||
sortOrder: 0,
|
||||
isVisible: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user