Skip to content

Commit

Permalink
chore: migrate schema (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
seaerchin authored Jun 24, 2024
1 parent c7497f8 commit 9c5707e
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 58 deletions.
17 changes: 2 additions & 15 deletions apps/studio/prisma/generated/generatedTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,12 @@ export type Footer = {
id: string
name: string
siteId: string
contactUsLink: string | null
feedbackFormLink: string | null
privacyStatementLink: string | null
termsOfUseLink: string | null
content: unknown
}
export type Navbar = {
id: string
name: string
url: string
description: string
siteId: string
}
export type NavbarItems = {
id: string
name: string
url: string
description: string
navbarId: string
content: unknown
}
export type Permission = {
id: string
Expand Down Expand Up @@ -73,7 +61,6 @@ export type DB = {
Blob: Blob
Footer: Footer
Navbar: Navbar
NavbarItems: NavbarItems
Permission: Permission
Resource: Resource
Site: Site
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Warnings:
- You are about to drop the column `contactUsLink` on the `Footer` table. All the data in the column will be lost.
- You are about to drop the column `feedbackFormLink` on the `Footer` table. All the data in the column will be lost.
- You are about to drop the column `privacyStatementLink` on the `Footer` table. All the data in the column will be lost.
- You are about to drop the column `termsOfUseLink` on the `Footer` table. All the data in the column will be lost.
- You are about to drop the column `description` on the `Navbar` table. All the data in the column will be lost.
- You are about to drop the column `name` on the `Navbar` table. All the data in the column will be lost.
- You are about to drop the column `url` on the `Navbar` table. All the data in the column will be lost.
- You are about to drop the `NavbarItems` table. If the table is not empty, all the data it contains will be lost.
- Added the required column `content` to the `Footer` table without a default value. This is not possible if the table is not empty.
- Added the required column `content` to the `Navbar` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE "NavbarItems" DROP CONSTRAINT "NavbarItems_navbarId_fkey";

-- AlterTable
ALTER TABLE "Footer" DROP COLUMN "contactUsLink",
DROP COLUMN "feedbackFormLink",
DROP COLUMN "privacyStatementLink",
DROP COLUMN "termsOfUseLink",
ADD COLUMN "content" JSONB NOT NULL;

-- AlterTable
ALTER TABLE "Navbar" DROP COLUMN "description",
DROP COLUMN "name",
DROP COLUMN "url",
ADD COLUMN "content" JSONB NOT NULL;

-- DropTable
DROP TABLE "NavbarItems";
33 changes: 9 additions & 24 deletions apps/studio/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,18 @@ model Site {
}

model Navbar {
id String @id @default(cuid())
name String
url String
description String
siteId String @unique
site Site @relation(fields: [siteId], references: [id])
items NavbarItems[]
}

model NavbarItems {
id String @id @default(cuid())
name String
url String
description String
navbar Navbar @relation(fields: [navbarId], references: [id])
navbarId String
id String @id @default(cuid())
siteId String @unique
site Site @relation(fields: [siteId], references: [id])
content Json
}

model Footer {
id String @id @default(cuid())
name String
siteId String @unique
site Site @relation(fields: [siteId], references: [id])
contactUsLink String?
feedbackFormLink String?
privacyStatementLink String?
termsOfUseLink String?
id String @id @default(cuid())
name String
siteId String @unique
site Site @relation(fields: [siteId], references: [id])
content Json
}

model Blob {
Expand Down
38 changes: 19 additions & 19 deletions apps/studio/src/server/modules/resource/resource.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { db } from '../database'
import { type Footer, type Navbar } from './resource.types'

export const getPages = () => {
return (
Expand Down Expand Up @@ -39,25 +40,24 @@ export const getPageById = (id: string) => {
}

// TODO: should be selecting from new table
export const getNavBar = (siteId: string) => {
return (
db
.selectFrom('Navbar')
.where('siteId', '=', siteId)
.innerJoin('NavbarItems', 'id', 'NavbarItems.navbarId')
.selectAll()
// NOTE: Throwing here is acceptable because each site should have a navbar
.executeTakeFirstOrThrow()
)
export const getNavBar = async (siteId: string) => {
const { content, ...rest } = await db
.selectFrom('Navbar')
.where('siteId', '=', siteId)
.selectAll()
// NOTE: Throwing here is acceptable because each site should have a navbar
.executeTakeFirstOrThrow()

return { ...rest, content: content as Navbar }
}

export const getFooter = (siteId: string) => {
return (
db
.selectFrom('Footer')
.where('siteId', '=', siteId)
.selectAll()
// NOTE: Throwing here is acceptable because each site should have a footer
.executeTakeFirstOrThrow()
)
export const getFooter = async (siteId: string) => {
const { content, ...rest } = await db
.selectFrom('Footer')
.where('siteId', '=', siteId)
.selectAll()
// NOTE: Throwing here is acceptable because each site should have a footer
.executeTakeFirstOrThrow()

return { ...rest, content: content as Footer }
}
17 changes: 17 additions & 0 deletions apps/studio/src/server/modules/resource/resource.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export interface NavbarItem {
name: string
url: string
description: string
}

export interface Navbar extends NavbarItem {
items: NavbarItem[]
}

export interface Footer {
name: string
contactUsLink?: string
feedbackFormLink?: string
privacyStatementLink?: string
termsOfUseLink?: string
}

0 comments on commit 9c5707e

Please sign in to comment.