Skip to content

Commit

Permalink
Changed raw query in seed script and updated referential actions
Browse files Browse the repository at this point in the history
  • Loading branch information
staldcunha committed Dec 2, 2023
1 parent 56d21c7 commit 0c5e1c0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
42 changes: 21 additions & 21 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ model User {
pictureUrl String? @map("picture_url")
yearOfStudy Int @map("year_of_study")
schoolId Int @map("school_id")
school School? @relation(fields: [schoolId], references: [id])
school School @relation(fields: [schoolId], references: [id], onDelete: Cascade)
events Event[]
UserEventResponse UserEventResponse[]
posts Post[]
Expand All @@ -64,7 +64,7 @@ model Event {
startTime DateTime @map("start_time")
endTime DateTime @map("end_time")
mediaUrl String? @map("media_url")
user User? @relation(fields: [userId], references: [id])
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
eventTags EventTag[]
eventResponses UserEventResponse[]
Expand All @@ -76,8 +76,8 @@ model UserEventResponse {
userId Int @map("user_id")
eventId Int @map("event_id")
participationStatus String @map("participation_status")
user User? @relation(fields: [userId], references: [id])
event Event? @relation(fields: [eventId], references: [id])
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
event Event? @relation(fields: [eventId], references: [id], onDelete: Cascade)
@@id([userId, eventId])
@@index([userId])
Expand All @@ -87,7 +87,7 @@ model UserEventResponse {

model Post {
id Int @id @default(autoincrement())
user User? @relation(fields: [userId], references: [id])
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int @map("user_id")
createdAt DateTime @default(now()) @map("created_at")
title String
Expand All @@ -102,9 +102,9 @@ model Post {

model Comment {
id Int @id @default(autoincrement())
user User? @relation(fields: [userId], references: [id])
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int @map("user_id")
post Post? @relation(fields: [postId], references: [id])
post Post? @relation(fields: [postId], references: [id], onDelete: Cascade)
postId Int @map("post_id")
createdAt DateTime @default(now()) @map("created_at")
text String
Expand All @@ -130,9 +130,9 @@ model UserOrganizationRole {
userId Int @map("user_id")
organizationId Int @map("organization_id")
roleId Int @map("role_id")
user User? @relation(fields: [userId], references: [id])
organization Organization? @relation(fields: [organizationId], references: [id])
role Role? @relation(fields: [roleId], references: [id])
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
organization Organization? @relation(fields: [organizationId], references: [id], onDelete: Cascade)
role Role? @relation(fields: [roleId], references: [id], onDelete: Cascade)
@@id([userId, organizationId, roleId])
@@index([userId])
Expand All @@ -154,9 +154,9 @@ model OrganizationRolePermission {
organizationId Int @map("organization_id")
roleId Int @map("role_id")
permissionId Int @map("permission_id")
organization Organization? @relation(fields: [organizationId], references: [id])
role Role? @relation(fields: [roleId], references: [id])
permission Permission? @relation(fields: [permissionId], references: [id])
organization Organization? @relation(fields: [organizationId], references: [id], onDelete: Cascade)
role Role? @relation(fields: [roleId], references: [id], onDelete: Cascade)
permission Permission? @relation(fields: [permissionId], references: [id], onDelete: Cascade)
@@id([organizationId, roleId, permissionId])
@@index([organizationId])
Expand All @@ -177,8 +177,8 @@ model Enrollment {
programId Int @map("program_id")
userId Int @map("user_id")
degreeType String @map("degree_type")
program Program? @relation(fields: [programId], references: [id])
user User? @relation(fields: [userId], references: [id])
program Program? @relation(fields: [programId], references: [id], onDelete: Cascade)
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
@@id([programId, userId])
@@index([programId])
Expand Down Expand Up @@ -208,8 +208,8 @@ model Topic {
model EventTag {
eventId Int @map("event_id")
topicId Int @map("topic_id")
event Event? @relation(fields: [eventId], references: [id])
topic Topic? @relation(fields: [topicId], references: [id])
event Event? @relation(fields: [eventId], references: [id], onDelete: Cascade)
topic Topic? @relation(fields: [topicId], references: [id], onDelete: Cascade)
@@id([eventId, topicId])
@@index([eventId])
Expand All @@ -220,8 +220,8 @@ model EventTag {
model PostTag {
postId Int @map("post_id")
topicId Int @map("topic_id")
post Post? @relation(fields: [postId], references: [id])
topic Topic? @relation(fields: [topicId], references: [id])
post Post? @relation(fields: [postId], references: [id], onDelete: Cascade)
topic Topic? @relation(fields: [topicId], references: [id], onDelete: Cascade)
@@id([postId, topicId])
@@index([postId])
Expand All @@ -232,8 +232,8 @@ model PostTag {
model TopicSubscription {
userId Int @map("user_id")
topicId Int @map("topic_id")
user User? @relation(fields: [userId], references: [id])
topic Topic @relation(fields: [topicId], references: [id])
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
topic Topic @relation(fields: [topicId], references: [id], onDelete: Cascade)
@@id([userId, topicId])
@@index([userId])
Expand Down
34 changes: 17 additions & 17 deletions backend/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,55 @@ const prisma = new PrismaClient();

const load = async () => {
try {
await prisma.$queryRaw`DELETE FROM school`;
await prisma.school.deleteMany();
console.log('Deleted records in the School table')

await prisma.$queryRaw`DELETE FROM user`;
await prisma.user.deleteMany();
console.log('Deleted records in the User table')

await prisma.$queryRaw`DELETE FROM event`;
await prisma.event.deleteMany();
console.log('Deleted records in the Event table')

await prisma.$queryRaw`DELETE FROM user_event_response`;
await prisma.userEventResponse.deleteMany();
console.log('Deleted records in the User Event Response table')

await prisma.$queryRaw`DELETE FROM post`;
await prisma.post.deleteMany();
console.log('Deleted records in the Post table')

await prisma.$queryRaw`DELETE FROM comment`;
await prisma.comment.deleteMany();
console.log('Deleted records in the Comment table')

await prisma.$queryRaw`DELETE FROM organization`;
await prisma.organization.deleteMany();
console.log('Deleted records in the Organization table')

await prisma.$queryRaw`DELETE FROM user_organization_role`;
await prisma.userOrganizationRole.deleteMany();
console.log('Deleted records in the User Organization Role table')

await prisma.$queryRaw`DELETE FROM role`;
await prisma.role.deleteMany();
console.log('Deleted records in the Role table')

await prisma.$queryRaw`DELETE FROM organization_role_permission`;
await prisma.organizationRolePermission.deleteMany();
console.log('Deleted records in the Organization Role Permission table')

await prisma.$queryRaw`DELETE FROM permission`;
await prisma.permission.deleteMany();
console.log('Deleted records in the Permission table')

await prisma.$queryRaw`DELETE FROM enrollment`;
await prisma.enrollment.deleteMany();
console.log('Deleted records in the Enrollment table')

await prisma.$queryRaw`DELETE FROM program`;
await prisma.program.deleteMany();
console.log('Deleted records in the Program table')

await prisma.$queryRaw`DELETE FROM topic`;
await prisma.topic.deleteMany();
console.log('Deleted records in the Topic table')

await prisma.$queryRaw`DELETE FROM event_tag`;
await prisma.eventTag.deleteMany();
console.log('Deleted records in the Event Tag table')

await prisma.$queryRaw`DELETE FROM post_tag`;
await prisma.postTag.deleteMany();
console.log('Deleted records in the Post Tag table')

await prisma.$queryRaw`DELETE FROM topic_subscription`;
await prisma.topicSubscription.deleteMany();
console.log('Deleted records in the Topic Subscription table')

await prisma.$queryRaw`ALTER TABLE school AUTO_INCREMENT = 1`;
Expand Down

0 comments on commit 0c5e1c0

Please sign in to comment.