Skip to content

Commit

Permalink
Add modifications for delete on cascade from clients to cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
igezt committed Oct 9, 2023
1 parent 537a70d commit 5136f67
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ The data for the new Client. It should include the following fields:

Deletes the client with the provided clientId.

**IMPORTANT** Note that when deleting a client, all linked cases will be deleted at the same time. Be mindful of what you delete.

##### Params

clientId: The ID of the client to be deleted.
Expand Down Expand Up @@ -585,9 +587,11 @@ First off, **Cases** are in a **many-to-one** relationship between both **Client

For Staff, it is rather trivial why cases may not have a staff attached to them. This is because when a case is created, it is not likely that a staff will already be working on the case.

However, for Clients, it is not as simple. The reason why Cases are not deleted on cascade when a client is deleted, even though a case without a client doesn't make sense, is because it would be quite detrimental for a case's details to be destroyed if a client accidentally deletes their account etc.
For Clients, it is not as simple. The reason why Cases are not deleted on cascade when a client is deleted, even though a case without a client doesn't make sense, is because it would be quite detrimental for a case's details to be destroyed if a client accidentally deletes their account etc.

However, on confirmation, I have verified that it should be cascade on delete for clients to case.

Hence, both the referenced client and staff are optional in a case. (Though a client is needed to create the case in the first place, because a newly-created case without a client doesn't make sense).
Hence, both the referenced staff is optional in a case but clients are required to be linked at all times.

## Client Model Decisions

Expand Down
5 changes: 5 additions & 0 deletions prisma/migrations/20231009051000_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- DropForeignKey
ALTER TABLE `case` DROP FOREIGN KEY `Case_cid_fkey`;

-- AddForeignKey
ALTER TABLE `Case` ADD CONSTRAINT `Case_cid_fkey` FOREIGN KEY (`cid`) REFERENCES `Client`(`cid`) ON DELETE CASCADE ON UPDATE CASCADE;
14 changes: 14 additions & 0 deletions prisma/migrations/20231009051243_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Warnings:
- Made the column `cid` on table `case` required. This step will fail if there are existing NULL values in that column.
*/
-- DropForeignKey
ALTER TABLE `case` DROP FOREIGN KEY `Case_cid_fkey`;

-- AlterTable
ALTER TABLE `case` MODIFY `cid` INTEGER NOT NULL;

-- AddForeignKey
ALTER TABLE `Case` ADD CONSTRAINT `Case_cid_fkey` FOREIGN KEY (`cid`) REFERENCES `Client`(`cid`) ON DELETE CASCADE ON UPDATE CASCADE;
4 changes: 2 additions & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ model Case {
status Status
creation_date DateTime @default(now())
request_message String
cid Int?
client Client? @relation(fields: [cid], references: [cid], onDelete: NoAction)
cid Int
client Client @relation(fields: [cid], references: [cid], onDelete: Cascade)
eid Int?
staff Staff? @relation(fields: [eid], references: [eid], onDelete: NoAction)
}
Expand Down

0 comments on commit 5136f67

Please sign in to comment.