add migration 002: data-driven process model, sitzung table
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
31
src/shared/db/migrations/002_process_model.sql
Normal file
31
src/shared/db/migrations/002_process_model.sql
Normal file
@@ -0,0 +1,31 @@
|
||||
-- Add tss_kontaktiert_datum before dropping old columns
|
||||
ALTER TABLE nutzer ADD COLUMN tss_kontaktiert_datum DATE;
|
||||
|
||||
-- Migrate existing TSS data
|
||||
UPDATE nutzer SET tss_kontaktiert_datum = tss_beantragt_datum WHERE tss_beantragt = TRUE;
|
||||
|
||||
-- Drop old tracking columns from nutzer
|
||||
ALTER TABLE nutzer DROP COLUMN aktueller_schritt;
|
||||
ALTER TABLE nutzer DROP COLUMN dringlichkeitscode;
|
||||
ALTER TABLE nutzer DROP COLUMN dringlichkeitscode_datum;
|
||||
ALTER TABLE nutzer DROP COLUMN tss_beantragt;
|
||||
ALTER TABLE nutzer DROP COLUMN tss_beantragt_datum;
|
||||
|
||||
-- Create sitzung table
|
||||
CREATE TABLE sitzung (
|
||||
id SERIAL PRIMARY KEY,
|
||||
sprechstunde_id INTEGER NOT NULL REFERENCES sprechstunde(id) ON DELETE CASCADE,
|
||||
datum DATE NOT NULL,
|
||||
erstellt_am TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Migrate existing sprechstunde.datum to sitzung
|
||||
INSERT INTO sitzung (sprechstunde_id, datum)
|
||||
SELECT id, datum FROM sprechstunde WHERE datum IS NOT NULL;
|
||||
|
||||
-- Drop migrated/vestigial columns from sprechstunde
|
||||
ALTER TABLE sprechstunde DROP COLUMN datum;
|
||||
ALTER TABLE sprechstunde DROP COLUMN ergebnis;
|
||||
|
||||
-- One Erstgespräch per therapist
|
||||
ALTER TABLE sprechstunde ADD CONSTRAINT sprechstunde_therapeut_unique UNIQUE (therapeut_id);
|
||||
Reference in New Issue
Block a user