Skip to content

Commit

Permalink
fix: delete cascade
Browse files Browse the repository at this point in the history
  • Loading branch information
Vann-Dev committed May 6, 2024
1 parent 6ca2f99 commit 51b4ed2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
23 changes: 23 additions & 0 deletions migrations/20240506184725_fix_delete_cascade/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- DropForeignKey
ALTER TABLE `Attendance` DROP FOREIGN KEY `Attendance_date_id_fkey`;

-- DropForeignKey
ALTER TABLE `Attendance` DROP FOREIGN KEY `Attendance_user_id_fkey`;

-- DropForeignKey
ALTER TABLE `Date` DROP FOREIGN KEY `Date_account_id_fkey`;

-- DropForeignKey
ALTER TABLE `User` DROP FOREIGN KEY `User_account_id_fkey`;

-- AddForeignKey
ALTER TABLE `Date` ADD CONSTRAINT `Date_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `Account`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Attendance` ADD CONSTRAINT `Attendance_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Attendance` ADD CONSTRAINT `Attendance_date_id_fkey` FOREIGN KEY (`date_id`) REFERENCES `Date`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `User` ADD CONSTRAINT `User_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `Account`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
8 changes: 4 additions & 4 deletions schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ model Date {
year Int
account_id String
Account Account @relation(fields: [account_id], references: [id])
Account Account @relation(fields: [account_id], references: [id], onDelete: Cascade)
attendances Attendance[]
}
Expand All @@ -39,10 +39,10 @@ model Attendance {
created_at DateTime @default(now())
user_id String
User User @relation(fields: [user_id], references: [id])
User User @relation(fields: [user_id], references: [id], onDelete: Cascade)
date_id String
Date Date @relation(fields: [date_id], references: [id])
Date Date @relation(fields: [date_id], references: [id], onDelete: Cascade)
visitor_identifier String
ip_address String
Expand All @@ -56,7 +56,7 @@ model User {
created_at DateTime @default(now())
account_id String
Account Account @relation(fields: [account_id], references: [id])
Account Account @relation(fields: [account_id], references: [id], onDelete: Cascade)
attendances Attendance[]
}
13 changes: 0 additions & 13 deletions src/routes/account/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@ async def delete_account(id):

await db.connect()

userAvailable = await db.user.find_first(
where={
"account_id": id
}
)

if userAvailable:
await db.user.delete_many(
where={
"account_id": id
}
)

data = await db.account.delete(
where={
"id": id
Expand Down

0 comments on commit 51b4ed2

Please sign in to comment.