Drop meal_booking→menu FK (cancelled rows survive menu delete) + Param::OptText/OptI64
Browse files at this commitfcca31c36fa262d7e6568334b2ffa79d72031688Parent: ddc470a- fix
- drop meal_booking→menu FK (cancelled rows survive menu delete) + Param::OptText/OptI64
2 changed files +12 -1
migrations/school/20260912000004_food_appointments_fees.sqlmodified+5 -1
| @@ -108,7 +108,11 @@ CREATE TABLE dietary_profile ( | |||
| 108 | -- A cancel flips `status` and stamps `cancelled_at`; the row stays so the | 108 | -- A cancel flips `status` and stamps `cancelled_at`; the row stays so the |
| 109 | -- freed seat is still auditable against the ledger line it charged. | 109 | -- freed seat is still auditable against the ledger line it charged. |
| 110 | CREATE TABLE meal_booking ( | 110 | CREATE TABLE meal_booking ( |
| 111 | - menu TEXT NOT NULL REFERENCES menu(id) ON DELETE NO ACTION, | 111 | + -- No FK to menu(id) ON PURPOSE: cancelled booking rows must survive menu |
| 112 | + -- deletion (their attempt counter keeps meal_ledger (booking, attempt) | ||
| 113 | + -- ids unique across a republish — the pinned meal_bookings_round_trip | ||
| 114 | + -- contract). A booking's menu exists at write time by app transaction. | ||
| 115 | + menu TEXT NOT NULL, | ||
| 112 | student uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, | 116 | student uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, |
| 113 | booked_by uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, | 117 | booked_by uuid NOT NULL REFERENCES app_user(id) ON DELETE NO ACTION, |
| 114 | status TEXT NOT NULL DEFAULT 'booked' | 118 | status TEXT NOT NULL DEFAULT 'booked' |
src/db/page.rsmodified+7 -0
| @@ -62,6 +62,11 @@ pub(crate) enum Param { | |||
| 62 | /// still named, so `IS NOT DISTINCT FROM $n` compares an absent link | 62 | /// still named, so `IS NOT DISTINCT FROM $n` compares an absent link |
| 63 | /// truthfully. | 63 | /// truthfully. |
| 64 | OptUuid(Option<Uuid>), | 64 | OptUuid(Option<Uuid>), |
| 65 | + /// Nullable TEXT column clear/set — same NULL-with-type rationale as | ||
| 66 | + /// OptUuid. | ||
| 67 | + OptText(Option<String>), | ||
| 68 | + /// Nullable BIGINT column clear/set. | ||
| 69 | + OptI64(Option<i64>), | ||
| 65 | } | 70 | } |
| 66 | 71 | ||
| 67 | impl Param { | 72 | impl Param { |
| @@ -73,6 +78,8 @@ impl Param { | |||
| 73 | Param::Text(value) => args.add(value), | 78 | Param::Text(value) => args.add(value), |
| 74 | Param::Uuid(value) => args.add(value), | 79 | Param::Uuid(value) => args.add(value), |
| 75 | Param::OptUuid(value) => args.add(value), | 80 | Param::OptUuid(value) => args.add(value), |
| 81 | + Param::OptText(value) => args.add(value), | ||
| 82 | + Param::OptI64(value) => args.add(value), | ||
| 76 | }; | 83 | }; |
| 77 | } | 84 | } |
| 78 | } | 85 | } |