update
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
-- Migration 064: Add spezifikationen to line items, approval columns, and new status workflow
|
||||
-- 1. spezifikationen JSONB on bestellpositionen
|
||||
-- 2. genehmigt_von / genehmigt_am on bestellungen
|
||||
-- 3. Drop old status CHECK constraint
|
||||
-- 4. Data migration: old statuses → new statuses
|
||||
-- 5. Add new status CHECK constraint with approval workflow statuses
|
||||
-- 6. bestellungen:approve permission + seed for dashboard_kommando
|
||||
|
||||
-- ═══════════════════════════════════════════════════════════════════════════
|
||||
-- 1. Spezifikationen on line items
|
||||
-- ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
ALTER TABLE bestellpositionen
|
||||
ADD COLUMN IF NOT EXISTS spezifikationen JSONB DEFAULT '[]';
|
||||
|
||||
-- ═══════════════════════════════════════════════════════════════════════════
|
||||
-- 2. Approval columns on bestellungen
|
||||
-- ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
ALTER TABLE bestellungen
|
||||
ADD COLUMN IF NOT EXISTS genehmigt_von UUID REFERENCES users(id),
|
||||
ADD COLUMN IF NOT EXISTS genehmigt_am TIMESTAMPTZ;
|
||||
|
||||
-- ═══════════════════════════════════════════════════════════════════════════
|
||||
-- 3. Drop old status CHECK constraint
|
||||
-- ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE bestellungen DROP CONSTRAINT IF EXISTS bestellungen_status_check;
|
||||
EXCEPTION WHEN undefined_object THEN
|
||||
NULL;
|
||||
END $$;
|
||||
|
||||
-- ═══════════════════════════════════════════════════════════════════════════
|
||||
-- 4. Data migration: map old statuses to new ones (before new constraint)
|
||||
-- ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
UPDATE bestellungen SET status = 'bereit_zur_bestellung' WHERE status = 'erstellt';
|
||||
UPDATE bestellungen SET status = 'lieferung_pruefen' WHERE status = 'vollstaendig';
|
||||
|
||||
-- ═══════════════════════════════════════════════════════════════════════════
|
||||
-- 5. Add new status CHECK constraint
|
||||
-- ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
ALTER TABLE bestellungen
|
||||
ADD CONSTRAINT bestellungen_status_check
|
||||
CHECK (status IN ('entwurf','wartet_auf_genehmigung','bereit_zur_bestellung','bestellt','teillieferung','lieferung_pruefen','abgeschlossen'));
|
||||
|
||||
-- ═══════════════════════════════════════════════════════════════════════════
|
||||
-- 6. Add bestellungen:approve permission
|
||||
-- ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
INSERT INTO permissions (id, feature_group_id, label, description, sort_order) VALUES
|
||||
('bestellungen:approve', 'bestellungen', 'Genehmigen', 'Bestellungen genehmigen', 25)
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
|
||||
-- ═══════════════════════════════════════════════════════════════════════════
|
||||
-- 7. Seed grant for dashboard_kommando
|
||||
-- ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
INSERT INTO group_permissions (authentik_group, permission_id) VALUES
|
||||
('dashboard_kommando', 'bestellungen:approve')
|
||||
ON CONFLICT DO NOTHING;
|
||||
Reference in New Issue
Block a user