Skip to content

Commit f7ebe81

Browse files
committed
modified: database schema
1 parent 552e77f commit f7ebe81

File tree

2 files changed

+57
-12
lines changed

2 files changed

+57
-12
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Warnings:
3+
4+
- The primary key for the `Post` table will be changed. If it partially fails, the table could be left without primary key constraint.
5+
- The primary key for the `Profile` table will be changed. If it partially fails, the table could be left without primary key constraint.
6+
- The primary key for the `User` table will be changed. If it partially fails, the table could be left without primary key constraint.
7+
8+
*/
9+
-- DropForeignKey
10+
ALTER TABLE "public"."Post" DROP CONSTRAINT "Post_authorId_fkey";
11+
12+
-- DropForeignKey
13+
ALTER TABLE "public"."Profile" DROP CONSTRAINT "Profile_userId_fkey";
14+
15+
-- AlterTable
16+
ALTER TABLE "Post" DROP CONSTRAINT "Post_pkey",
17+
ALTER COLUMN "id" DROP DEFAULT,
18+
ALTER COLUMN "id" SET DATA TYPE TEXT,
19+
ALTER COLUMN "authorId" SET DATA TYPE TEXT,
20+
ADD CONSTRAINT "Post_pkey" PRIMARY KEY ("id");
21+
DROP SEQUENCE "Post_id_seq";
22+
23+
-- AlterTable
24+
ALTER TABLE "Profile" DROP CONSTRAINT "Profile_pkey",
25+
ALTER COLUMN "id" DROP DEFAULT,
26+
ALTER COLUMN "id" SET DATA TYPE TEXT,
27+
ALTER COLUMN "userId" SET DATA TYPE TEXT,
28+
ADD CONSTRAINT "Profile_pkey" PRIMARY KEY ("id");
29+
DROP SEQUENCE "Profile_id_seq";
30+
31+
-- AlterTable
32+
ALTER TABLE "User" DROP CONSTRAINT "User_pkey",
33+
ALTER COLUMN "id" DROP DEFAULT,
34+
ALTER COLUMN "id" SET DATA TYPE TEXT,
35+
ADD CONSTRAINT "User_pkey" PRIMARY KEY ("id");
36+
DROP SEQUENCE "User_id_seq";
37+
38+
-- AddForeignKey
39+
ALTER TABLE "Profile" ADD CONSTRAINT "Profile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
40+
41+
-- AddForeignKey
42+
ALTER TABLE "Post" ADD CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

prisma/schema.prisma

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ datasource db {
99
}
1010

1111
model User {
12-
id Int @id @default(autoincrement())
12+
id String @id @default(uuid())
1313
email String @unique
1414
password String
1515
name String?
@@ -21,23 +21,26 @@ model User {
2121
}
2222

2323
model Profile {
24-
id Int @id @default(autoincrement())
24+
id String @id @default(uuid())
2525
bio String?
26-
user User @relation(fields: [userId], references: [id])
27-
userId Int @unique
28-
createdAt DateTime @default(now())
29-
updatedAt DateTime @updatedAt
26+
user User @relation(fields: [userId], references: [id])
27+
userId String @unique
28+
createdAt DateTime @default(now())
29+
updatedAt DateTime @updatedAt
3030
}
3131

32+
33+
34+
3235
model Post {
33-
id Int @id @default(autoincrement())
36+
id String @id @default(uuid())
3437
title String
3538
content String?
36-
published Boolean @default(false)
37-
author User @relation(fields: [authorId], references: [id])
38-
authorId Int
39-
createdAt DateTime @default(now())
40-
updatedAt DateTime @updatedAt
39+
published Boolean @default(false)
40+
author User @relation(fields: [authorId], references: [id])
41+
authorId String
42+
createdAt DateTime @default(now())
43+
updatedAt DateTime @updatedAt
4144
}
4245

4346
enum Role {

0 commit comments

Comments
 (0)