From 4cf6824a82d9386cc7f8e3044bff9430310e2b58 Mon Sep 17 00:00:00 2001 From: Jake Bromberg Date: Sat, 21 Feb 2026 08:59:22 -0800 Subject: [PATCH] fix: change shift_covers.schedule_id from serial to integer FK columns should not auto-increment. Using serial meant inserts without explicit schedule_id would get sequence-generated values that may not reference valid schedule rows. Co-authored-by: Cursor --- shared/database/src/schema.ts | 2 +- tests/unit/database/schema.shift-covers.test.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 tests/unit/database/schema.shift-covers.test.ts diff --git a/shared/database/src/schema.ts b/shared/database/src/schema.ts index 7a9bfc5..a3bef89 100644 --- a/shared/database/src/schema.ts +++ b/shared/database/src/schema.ts @@ -186,7 +186,7 @@ export type NewShiftCover = InferInsertModel; export type ShiftCover = InferSelectModel; export const shift_covers = wxyc_schema.table('shift_covers', { id: serial('id').primaryKey(), - schedule_id: serial('schedule_id') + schedule_id: integer('schedule_id') .references(() => schedule.id) .notNull(), shift_timestamp: timestamp('shift_timestamp').notNull(), //Timestamp to expire cover requests diff --git a/tests/unit/database/schema.shift-covers.test.ts b/tests/unit/database/schema.shift-covers.test.ts new file mode 100644 index 0000000..68a173b --- /dev/null +++ b/tests/unit/database/schema.shift-covers.test.ts @@ -0,0 +1,8 @@ +import { shift_covers } from '../../../shared/database/src/schema'; + +describe('shift_covers schema', () => { + it('schedule_id should not be a serial/auto-increment column', () => { + const column = shift_covers.schedule_id; + expect(column.columnType).not.toBe('PgSerial'); + }); +});