diff --git a/apps/studio/prisma/generated/generatedTypes.ts b/apps/studio/prisma/generated/generatedTypes.ts index 7cb6f326df..fc0130e34b 100644 --- a/apps/studio/prisma/generated/generatedTypes.ts +++ b/apps/studio/prisma/generated/generatedTypes.ts @@ -9,7 +9,7 @@ export type Generated = export type Timestamp = ColumnType export interface Blob { - id: GeneratedAlways + id: GeneratedAlways /** * @kyselyType(PrismaJson.BlobJsonContent) * [BlobJsonContent] @@ -36,18 +36,18 @@ export interface Navbar { } export interface Permission { id: GeneratedAlways - resourceId: number + resourceId: string userId: string role: RoleType } export interface Resource { - id: GeneratedAlways + id: GeneratedAlways title: string permalink: string siteId: number - parentId: number | null - mainBlobId: number | null - draftBlobId: number | null + parentId: string | null + mainBlobId: string | null + draftBlobId: string | null state: Generated type: ResourceType } diff --git a/apps/studio/prisma/migrations/20240724082002_update_to_bigint/migration.sql b/apps/studio/prisma/migrations/20240724082002_update_to_bigint/migration.sql new file mode 100644 index 0000000000..ec2a58c2a9 --- /dev/null +++ b/apps/studio/prisma/migrations/20240724082002_update_to_bigint/migration.sql @@ -0,0 +1,46 @@ +/* + Warnings: + + - The primary key for the `Blob` table will be changed. If it partially fails, the table could be left without primary key constraint. + - The primary key for the `Resource` table will be changed. If it partially fails, the table could be left without primary key constraint. + +*/ +-- DropForeignKey +ALTER TABLE "Permission" DROP CONSTRAINT "Permission_resourceId_fkey"; + +-- DropForeignKey +ALTER TABLE "Resource" DROP CONSTRAINT "Resource_draftBlobId_fkey"; + +-- DropForeignKey +ALTER TABLE "Resource" DROP CONSTRAINT "Resource_mainBlobId_fkey"; + +-- DropForeignKey +ALTER TABLE "Resource" DROP CONSTRAINT "Resource_parentId_fkey"; + +-- AlterTable +ALTER TABLE "Blob" DROP CONSTRAINT "Blob_pkey", +ALTER COLUMN "id" SET DATA TYPE BIGINT, +ADD CONSTRAINT "Blob_pkey" PRIMARY KEY ("id"); + +-- AlterTable +ALTER TABLE "Permission" ALTER COLUMN "resourceId" SET DATA TYPE BIGINT; + +-- AlterTable +ALTER TABLE "Resource" DROP CONSTRAINT "Resource_pkey", +ALTER COLUMN "id" SET DATA TYPE BIGINT, +ALTER COLUMN "parentId" SET DATA TYPE BIGINT, +ALTER COLUMN "draftBlobId" SET DATA TYPE BIGINT, +ALTER COLUMN "mainBlobId" SET DATA TYPE BIGINT, +ADD CONSTRAINT "Resource_pkey" PRIMARY KEY ("id"); + +-- AddForeignKey +ALTER TABLE "Resource" ADD CONSTRAINT "Resource_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "Resource"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Resource" ADD CONSTRAINT "Resource_mainBlobId_fkey" FOREIGN KEY ("mainBlobId") REFERENCES "Blob"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Resource" ADD CONSTRAINT "Resource_draftBlobId_fkey" FOREIGN KEY ("draftBlobId") REFERENCES "Blob"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Permission" ADD CONSTRAINT "Permission_resourceId_fkey" FOREIGN KEY ("resourceId") REFERENCES "Resource"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/apps/studio/prisma/schema.prisma b/apps/studio/prisma/schema.prisma index e0b067c647..66d0b3e65d 100644 --- a/apps/studio/prisma/schema.prisma +++ b/apps/studio/prisma/schema.prisma @@ -34,23 +34,23 @@ model VerificationToken { } model Resource { - id Int @id @default(autoincrement()) + id BigInt @id @default(autoincrement()) title String permalink String siteId Int site Site @relation(fields: [siteId], references: [id]) - parentId Int? + parentId BigInt? parent Resource? @relation("ParentRelation", fields: [parentId], references: [id]) children Resource[] @relation("ParentRelation") permission Permission[] - mainBlob Blob? @relation("MainBlob", fields: [mainBlobId], references: [id]) - mainBlobId Int? @unique + mainBlob Blob? @relation("MainBlob", fields: [mainBlobId], references: [id]) + mainBlobId BigInt? @unique - draftBlob Blob? @relation("DraftBlob", fields: [draftBlobId], references: [id]) - draftBlobId Int? @unique + draftBlob Blob? @relation("DraftBlob", fields: [draftBlobId], references: [id]) + draftBlobId BigInt? @unique state ResourceState? @default(Draft) type ResourceType @@ -79,7 +79,7 @@ model User { model Permission { id Int @id @default(autoincrement()) - resourceId Int + resourceId BigInt resource Resource @relation(fields: [resourceId], references: [id]) userId String user User @relation(fields: [userId], references: [id]) @@ -125,7 +125,7 @@ model Footer { } model Blob { - id Int @id @default(autoincrement()) + id BigInt @id @default(autoincrement()) /// @kyselyType(PrismaJson.BlobJsonContent) /// [BlobJsonContent] content Json diff --git a/apps/studio/prisma/seed.ts b/apps/studio/prisma/seed.ts index f1a706d439..66f3f4aeb0 100644 --- a/apps/studio/prisma/seed.ts +++ b/apps/studio/prisma/seed.ts @@ -205,10 +205,10 @@ async function main() { ) .execute() - let blobId = 1 + let blobId = BigInt(1) const dedupeBlobId = await db .selectFrom("Blob") - .where("Blob.id", "=", blobId) + .where("Blob.id", "=", String(blobId)) .select("Blob.id") .executeTakeFirst() if (!dedupeBlobId) { @@ -217,13 +217,13 @@ async function main() { .values({ content: jsonb(PAGE_BLOB) }) .returning("id") .executeTakeFirstOrThrow() - blobId = id + blobId = BigInt(id) } await db .insertInto("Resource") .values({ - mainBlobId: blobId, + mainBlobId: String(blobId), permalink: "home", siteId, type: "Page", diff --git a/apps/studio/src/server/modules/folder/folder.router.ts b/apps/studio/src/server/modules/folder/folder.router.ts index fb479e2f44..31596044ae 100644 --- a/apps/studio/src/server/modules/folder/folder.router.ts +++ b/apps/studio/src/server/modules/folder/folder.router.ts @@ -18,12 +18,12 @@ export const folderRouter = router({ const folderResult = await ctx.db .selectFrom("Resource") .selectAll("Resource") - .where("id", "=", input.resourceId) + .where("id", "=", String(input.resourceId)) .executeTakeFirstOrThrow() const childrenResult = await ctx.db .selectFrom("Resource") .selectAll("Resource") - .where("parentId", "=", input.resourceId) + .where("parentId", "=", String(input.resourceId)) .execute() const children = childrenResult.map((c) => { if (c.draftBlobId || c.mainBlobId) { diff --git a/apps/studio/src/server/modules/page/page.router.ts b/apps/studio/src/server/modules/page/page.router.ts index d7204ccdd0..cf3aa3cf55 100644 --- a/apps/studio/src/server/modules/page/page.router.ts +++ b/apps/studio/src/server/modules/page/page.router.ts @@ -62,7 +62,7 @@ export const pageRouter = router({ .where("Resource.siteId", "=", siteId) if (resourceId) { - query = query.where("Resource.parentId", "=", resourceId) + query = query.where("Resource.parentId", "=", String(resourceId)) } return query .select([ @@ -126,7 +126,7 @@ export const pageRouter = router({ title, permalink, siteId, - parentId: folderId, + parentId: String(folderId), draftBlobId: blob.id, type: ResourceType.Page, }) diff --git a/apps/studio/src/server/modules/resource/resource.service.ts b/apps/studio/src/server/modules/resource/resource.service.ts index 32d6cb18e6..0d22a2624c 100644 --- a/apps/studio/src/server/modules/resource/resource.service.ts +++ b/apps/studio/src/server/modules/resource/resource.service.ts @@ -60,7 +60,7 @@ const getById = ({ }) => db .selectFrom("Resource") - .where("Resource.id", "=", resourceId) + .where("Resource.id", "=", String(resourceId)) .where("siteId", "=", siteId) // NOTE: Throw here to fail early if our invariant that a page has a `blobId` is violated @@ -102,7 +102,7 @@ export const updatePageById = ( return tx .updateTable("Resource") .set(rest) - .where("id", "=", id) + .where("id", "=", String(id)) .executeTakeFirstOrThrow() }) } @@ -120,7 +120,7 @@ export const updateBlobById = (props: { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore excessive deep type instantiaton .set({ content }) - .where("Resource.id", "=", id) + .where("Resource.id", "=", String(id)) .executeTakeFirstOrThrow() ) } @@ -155,8 +155,8 @@ export const moveResource = async ( ) => { return db .updateTable("Resource") - .set({ parentId: newParentId }) + .set({ parentId: String(newParentId) }) .where("siteId", "=", siteId) - .where("id", "=", resourceId) + .where("id", "=", String(resourceId)) .executeTakeFirstOrThrow() } diff --git a/apps/studio/tests/msw/handlers/page.ts b/apps/studio/tests/msw/handlers/page.ts index 734d36da83..898ecdd6cc 100644 --- a/apps/studio/tests/msw/handlers/page.ts +++ b/apps/studio/tests/msw/handlers/page.ts @@ -10,23 +10,23 @@ const pageListQuery = (wait?: DelayMode | number) => { } return [ { - id: 4, + id: "4", permalink: "test-page-1", title: "Test page 1", - mainBlobId: 3, + mainBlobId: "3", draftBlobId: null, type: "Page", }, { - id: 5, + id: "5", permalink: "test-page-2", title: "Test page 2", - mainBlobId: 4, + mainBlobId: "4", draftBlobId: null, type: "Page", }, { - id: 6, + id: "6", permalink: "folder", title: "Test folder 1", mainBlobId: null,