Skip to content
Merged
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
41 changes: 41 additions & 0 deletions packages/db/src/migrations/20250924044343_fix_removal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { type Kysely } from 'kysely';

export async function up(db: Kysely<any>) {
// applications

await db.schema
.alterTable('applications')
.dropConstraint('applications_referral_id_fkey')
.execute();

await db.schema
.alterTable('applications')
.addForeignKeyConstraint(
'applications_referral_id_fkey',
['referral_id'],
'referrals',
['id']
)
.onDelete('cascade')
.execute();

// opportunity_reports

await db.schema
.alterTable('opportunity_reports')
.dropConstraint('opportunity_reports_reporter_id_fkey')
.execute();

await db.schema
.alterTable('opportunity_reports')
.addForeignKeyConstraint(
'opportunity_reports_reporter_id_fkey',
['reporter_id'],
'students',
['id']
)
.onDelete('cascade')
.execute();
}

export async function down(_: Kysely<any>) {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: Empty Down Migration Causes Irreversible Data Changes

The down migration function is empty, making this migration irreversible. If a rollback is needed, the foreign key constraints added with onDelete('cascade') in the up function cannot be reverted. This leaves the database with cascading delete behavior, which could lead to unexpected data deletion.

Fix in Cursor Fix in Web