Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ model ProjectMember {
projectId String
userId String
role Role @default(USER)
project Project @relation(fields: [projectId], references: [id])
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, check the actual schema.prisma file at line 61 to confirm the change
sed -n '55,65p' prisma/schema.prisma

Repository: Authormaton/authormaton

Length of output: 396


🏁 Script executed:

# Check if prisma/migrations directory exists and list recent migrations
fd -type d -name migrations prisma/ && fd -e sql . prisma/migrations 2>/dev/null | tail -10 || echo "No migrations found"

Repository: Authormaton/authormaton

Length of output: 274


🏁 Script executed:

# Search for any migration containing CASCADE delete
fd -e sql . prisma/migrations 2>/dev/null -x grep -l "ON DELETE CASCADE" {} \; || echo "No migrations with CASCADE found"

Repository: Authormaton/authormaton

Length of output: 99


Migration file is missing for the cascade delete schema change.

The onDelete: Cascade configuration has been added to the ProjectMember.project relation in the schema, but no corresponding Prisma migration file exists in prisma/migrations/. Without generating and applying the migration, the database schema remains unchanged and will not enforce cascade deletes. This means deleting a project will still cause foreign key constraint violations at the database level.

Run prisma migrate dev --name add_cascade_delete_projectmember to generate the migration, then commit both the schema and migration files.

🤖 Prompt for AI Agents
In prisma/schema.prisma around line 61, you added onDelete: Cascade to the
ProjectMember.project relation but did not create/apply the corresponding Prisma
migration; run prisma migrate dev --name add_cascade_delete_projectmember from
the project root to generate and apply the migration, then commit the updated
prisma/schema.prisma plus the new timestamped folder under prisma/migrations
(include migration SQL and schema file) to ensure the DB enforces cascade
deletes.

user User @relation(fields: [userId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand Down
16 changes: 10 additions & 6 deletions src/actions/projects/deleteProject/logic.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import 'server-only';

import { prisma } from '@/lib/prisma';
import { Result, success } from '@/lib/result';
import { Result, success, err } from '@/lib/result';
import { DeleteProjectInput } from './schema';

export async function deleteProject(input: DeleteProjectInput): Promise<Result<undefined>> {
await prisma.project.delete({
where: { id: input.id }
});

return success(undefined);
try {
await prisma.project.deleteMany({
where: { id: input.id }
});
return success(undefined);
} catch (error) {
console.error("Failed to delete project:", error);
return err("Failed to delete project due to an unexpected error.");
}
}
Loading