Skip to content

Commit 71b4499

Browse files
authored
Merge pull request #348 from boostcampwm2023/BE-fix/models
모델 이름 변경, 속성 타입 변경
2 parents eb7c474 + c483c3c commit 71b4499

File tree

2 files changed

+81
-28
lines changed

2 files changed

+81
-28
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
-- DropForeignKey
2+
ALTER TABLE `KakaoUser` DROP FOREIGN KEY `KakaoUser_userUuid_fkey`;
3+
ALTER TABLE `RefreshToken` DROP FOREIGN KEY `RefreshToken_user_id_fkey`;
4+
ALTER TABLE `Profile` DROP FOREIGN KEY `Profile_userId_fkey`;
5+
ALTER TABLE `Profile_space` DROP FOREIGN KEY `Profile_space_profile_uuid_fkey`;
6+
ALTER TABLE `Profile_space` DROP FOREIGN KEY `Profile_space_space_uuid_fkey`;
7+
ALTER TABLE `InviteCode` DROP FOREIGN KEY `InviteCode_space_uuid_fkey`;
8+
9+
-- UserModel
10+
ALTER TABLE `User` MODIFY `uuid` CHAR(36) NOT NULL;
11+
12+
-- RefreshModel
13+
ALTER TABLE `RefreshToken`
14+
RENAME COLUMN `expiry_date` TO `expiryDate`,
15+
RENAME COLUMN `user_id` TO `userUuid`;
16+
ALTER TABLE `RefreshToken` MODIFY `userUuid` CHAR(36) NOT NULL;
17+
18+
-- ProfileModel
19+
ALTER TABLE `Profile` RENAME COLUMN `userId` TO `userUuid`;
20+
ALTER TABLE `Profile`
21+
MODIFY `uuid` CHAR(36) NOT NULL,
22+
MODIFY `userUuid` CHAR(36) NOT NULL,
23+
RENAME INDEX `Profile_userId_key` TO `Profile_userUuid_key`;
24+
25+
-- SpaceModel
26+
ALTER TABLE `Space` MODIFY `uuid` CHAR(36) NOT NULL;
27+
28+
-- ProfileSpaceModel
29+
ALTER TABLE `Profile_space` RENAME `ProfileSpace`;
30+
ALTER TABLE `ProfileSpace`
31+
RENAME COLUMN `space_uuid` TO `spaceUuid`,
32+
RENAME COLUMN `profile_uuid` TO `profileUuid`;
33+
ALTER TABLE `ProfileSpace`
34+
MODIFY `spaceUuid` CHAR(36) NOT NULL,
35+
MODIFY `profileUuid` CHAR(36) NOT NULL,
36+
RENAME INDEX `Profile_space_space_uuid_profile_uuid_key` TO `ProfileSpace_spaceUuid_profileUuid_key`;
37+
38+
-- InviteCodeModel
39+
ALTER TABLE `InviteCode`
40+
RENAME COLUMN `expiry_date` TO `expiryDate`,
41+
RENAME COLUMN `invite_code` TO `inviteCode`,
42+
RENAME COLUMN `space_uuid` TO `spaceUuid`;
43+
ALTER TABLE `InviteCode`
44+
MODIFY `uuid` CHAR(36) NOT NULL,
45+
MODIFY `spaceUuid` CHAR(36) NOT NULL,
46+
RENAME INDEX `InviteCode_invite_code_key` TO `InviteCode_inviteCode_key`;
47+
48+
-- AddForeignKey
49+
ALTER TABLE `KakaoUser` ADD CONSTRAINT `KakaoUser_userUuid_fkey` FOREIGN KEY (`userUuid`) REFERENCES `User`(`uuid`) ON DELETE CASCADE ON UPDATE CASCADE;
50+
ALTER TABLE `RefreshToken` ADD CONSTRAINT `RefreshToken_userUuid_fkey` FOREIGN KEY (`userUuid`) REFERENCES `User`(`uuid`) ON DELETE CASCADE ON UPDATE CASCADE;
51+
ALTER TABLE `Profile` ADD CONSTRAINT `Profile_userUuid_fkey` FOREIGN KEY (`userUuid`) REFERENCES `User`(`uuid`) ON DELETE CASCADE ON UPDATE CASCADE;
52+
ALTER TABLE `ProfileSpace` ADD CONSTRAINT `ProfileSpace_spaceUuid_fkey` FOREIGN KEY (`spaceUuid`) REFERENCES `Space`(`uuid`) ON DELETE CASCADE ON UPDATE CASCADE;
53+
ALTER TABLE `ProfileSpace` ADD CONSTRAINT `ProfileSpace_profileUuid_fkey` FOREIGN KEY (`profileUuid`) REFERENCES `Profile`(`uuid`) ON DELETE CASCADE ON UPDATE CASCADE;
54+
ALTER TABLE `InviteCode` ADD CONSTRAINT `InviteCode_spaceUuid_fkey` FOREIGN KEY (`spaceUuid`) REFERENCES `Space`(`uuid`) ON DELETE CASCADE ON UPDATE CASCADE;

nestjs-BE/server/prisma/schema.prisma

+27-28
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,56 @@ datasource db {
88
}
99

1010
model User {
11-
uuid String @id @db.VarChar(36)
11+
uuid String @id @db.Char(36)
1212
kakaoUser KakaoUser?
1313
profiles Profile[]
14-
refresh_tokens RefreshToken[]
14+
refreshTokens RefreshToken[]
1515
}
1616

1717
model KakaoUser {
1818
id Int @id @default(autoincrement())
1919
email String @unique
2020
userUuid String @unique
21-
user User @relation(fields: [userUuid], references: [uuid])
21+
user User @relation(fields: [userUuid], references: [uuid], onDelete: Cascade)
2222
}
2323

2424
model RefreshToken {
2525
id Int @id @default(autoincrement())
26-
token String @db.VarChar(210)
27-
expiry_date DateTime
28-
user_id String
29-
user User @relation(fields: [user_id], references: [uuid], onDelete: Cascade)
30-
@@unique([token])
26+
token String @db.VarChar(210) @unique
27+
expiryDate DateTime
28+
userUuid String @db.Char(36)
29+
user User @relation(fields: [userUuid], references: [uuid], onDelete: Cascade)
3130
}
3231

3332
model Profile {
34-
uuid String @id @db.VarChar(36)
35-
userId String @unique @db.VarChar(36)
33+
uuid String @id @db.Char(36)
34+
userUuid String @unique @db.Char(36)
3635
image String
3736
nickname String @db.VarChar(20)
38-
user User @relation(fields: [userId], references: [uuid], onDelete: Cascade)
39-
spaces Profile_space[]
37+
user User @relation(fields: [userUuid], references: [uuid], onDelete: Cascade)
38+
spaces ProfileSpace[]
4039
}
4140

4241
model Space {
43-
uuid String @id @db.VarChar(32)
44-
name String @db.VarChar(20)
45-
icon String
46-
profiles Profile_space[]
47-
invite_codes InviteCode[]
42+
uuid String @id @db.Char(36)
43+
name String @db.VarChar(20)
44+
icon String
45+
profileSpaces ProfileSpace[]
46+
inviteCodes InviteCode[]
4847
}
4948

50-
model Profile_space {
51-
space_uuid String @db.VarChar(32)
52-
profile_uuid String @db.VarChar(32)
53-
space Space @relation(fields: [space_uuid], references: [uuid], onDelete: Cascade)
54-
profile Profile @relation(fields: [profile_uuid], references: [uuid], onDelete: Cascade)
55-
@@unique([space_uuid, profile_uuid])
49+
model ProfileSpace {
50+
spaceUuid String @db.Char(36)
51+
profileUuid String @db.Char(36)
52+
space Space @relation(fields: [spaceUuid], references: [uuid], onDelete: Cascade)
53+
profile Profile @relation(fields: [profileUuid], references: [uuid], onDelete: Cascade)
54+
@@unique([spaceUuid, profileUuid])
5655
}
5756

5857
model InviteCode {
59-
uuid String @id @db.VarChar(32)
60-
invite_code String @unique @db.VarChar(10)
61-
space_uuid String @db.VarChar(32)
62-
expiry_date DateTime
63-
space Space @relation(fields: [space_uuid], references: [uuid], onDelete: Cascade)
58+
uuid String @id @db.Char(36)
59+
inviteCode String @unique @db.VarChar(10)
60+
spaceUuid String @db.Char(36)
61+
expiryDate DateTime
62+
space Space @relation(fields: [spaceUuid], references: [uuid], onDelete: Cascade)
6463
}

0 commit comments

Comments
 (0)