Skip to content

Commit c56c9d5

Browse files
committed
fix(tasks): implement pre-delete cleanup for tasks_comments to prevent foreign key errors
1 parent 7831187 commit c56c9d5

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎apps/codebility/app/home/kanban/[projectId]/[id]/_components/ArchiveColumn.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ export default function ArchiveColumn({ projectId, boardId }: ArchiveColumnProps
115115
if (!supabase) return;
116116

117117
try {
118+
119+
await supabase.from("tasks_comments").delete().eq("task_id", taskId);
120+
await supabase.from("task_ticket_codes").delete().eq("task_id", taskId);
121+
118122
const { error } = await supabase
119123
.from("tasks")
120124
.delete()

‎apps/codebility/app/home/kanban/[projectId]/[id]/actions.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,10 @@ export const createNewTask = async (
220220
if (boardData?.project_id) {
221221
revalidatePath(`/home/kanban/${boardData.project_id}/${columnData.board_id}`);
222222

223-
// Send notification if task is assigned to someone other than the creator
224223
if (codev_id && newTask?.id) {
225224
const { data: { user } } = await supabase.auth.getUser();
226225

227-
// Only send notification if assigning to someone else
226+
228227
if (user && user.id !== codev_id) {
229228
await createNotificationAction({
230229
recipientId: codev_id,
@@ -367,6 +366,9 @@ export const deleteTask = async (
367366
.eq("id", taskId)
368367
.single();
369368

369+
await supabase.from("tasks_comments").delete().eq("task_id", taskId);
370+
await supabase.from("task_ticket_codes").delete().eq("task_id", taskId);
371+
370372
const { error } = await supabase.from("tasks").delete().eq("id", taskId);
371373

372374
if (error) {

0 commit comments

Comments
 (0)