PrevEmployment: add FK user_account → employee.user_account with ON UPDATE CASCADE

Aperta
#141 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, sqlalchemy
Ambito
backend, databases

Direzione di ricerca

Start with api/db/schema/prev_employment.py and the Alembic migration for #138 to follow the existing foreign key pattern. Check how migrations detect and report orphaned prev_employment rows, then add the constraint with ON UPDATE CASCADE and default delete behavior. Add tests for cascading employee account updates and rejecting unknown accounts; done when both behaviors pass and orphan handling is explicit.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

PrevEmployment.user_account is a bare UUID column with no relation to Employee. Align it with the decision made for StudentDocuments in #138.

Goal

Add a foreign key PrevEmployment.user_account → employee.user_account with ON UPDATE CASCADE, so that:

  • no PrevEmployment row can reference a non-existent user (referential integrity)
  • remapping employee.user_account (e.g. during the planned account fusion migration) updates PrevEmployment automatically

Lookups keep using the JWT sub directly; no join through Employee is needed.

Tasks
  • Alembic migration adding the FK constraint (ON UPDATE CASCADE; delete behaviour stays as default/restrict)
  • Before adding the constraint: detect orphaned prev_employment rows whose user_account has no matching employee row, and decide how to handle them (delete / report). The migration must not fail silently.
  • Update the SQLModel schema api/db/schema/prev_employment.py (foreign_key="employee.user_account", ondelete/onupdate via sa_column_kwargs or sa_column)
  • Test: updating employee.user_account cascades to prev_employment.user_account
  • Test: inserting a PrevEmployment with an unknown user_account fails
Out of scope
  • Changes to the PrevEmployment endpoints

Related: #138

Lingua principale
Python
Stelle
0
Fork
0
Merge medio
29m
PR unite (30g)
14

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ClockGU/clockwork-backend

Tutte le issue di ClockGU/clockwork-backend

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.