fix: Migration 024 - remove problematic FK constraints created_by/updated_by
Goal type definitions are global system entities, not user-specific. System types seeded in migration cannot have created_by FK. Changes: - Remove created_by/updated_by columns from goal_type_definitions - Update CREATE/UPDATE endpoints to not use these fields - Migration now runs cleanly on container start - No manual intervention needed for production deployment
This commit is contained in:
parent
b3cc588293
commit
a039a0fad3
|
|
@ -36,9 +36,7 @@ CREATE TABLE IF NOT EXISTS goal_type_definitions (
|
||||||
|
|
||||||
-- Audit
|
-- Audit
|
||||||
created_at TIMESTAMP DEFAULT NOW(),
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
updated_at TIMESTAMP DEFAULT NOW(),
|
updated_at TIMESTAMP DEFAULT NOW()
|
||||||
created_by UUID REFERENCES profiles(id) ON DELETE SET NULL,
|
|
||||||
updated_by UUID REFERENCES profiles(id) ON DELETE SET NULL
|
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_goal_type_definitions_active ON goal_type_definitions(is_active) WHERE is_active = true;
|
CREATE INDEX IF NOT EXISTS idx_goal_type_definitions_active ON goal_type_definitions(is_active) WHERE is_active = true;
|
||||||
|
|
|
||||||
|
|
@ -572,16 +572,14 @@ def create_goal_type_definition(
|
||||||
INSERT INTO goal_type_definitions (
|
INSERT INTO goal_type_definitions (
|
||||||
type_key, label_de, label_en, unit, icon, category,
|
type_key, label_de, label_en, unit, icon, category,
|
||||||
source_table, source_column, aggregation_method,
|
source_table, source_column, aggregation_method,
|
||||||
calculation_formula, description, is_active, is_system,
|
calculation_formula, description, is_active, is_system
|
||||||
created_by, updated_by
|
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||||
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
|
||||||
RETURNING id
|
RETURNING id
|
||||||
""", (
|
""", (
|
||||||
data.type_key, data.label_de, data.label_en, data.unit, data.icon,
|
data.type_key, data.label_de, data.label_en, data.unit, data.icon,
|
||||||
data.category, data.source_table, data.source_column,
|
data.category, data.source_table, data.source_column,
|
||||||
data.aggregation_method, data.calculation_formula, data.description,
|
data.aggregation_method, data.calculation_formula, data.description,
|
||||||
True, False, # is_active=True, is_system=False
|
True, False # is_active=True, is_system=False
|
||||||
pid, pid
|
|
||||||
))
|
))
|
||||||
|
|
||||||
goal_type_id = cur.fetchone()['id']
|
goal_type_id = cur.fetchone()['id']
|
||||||
|
|
@ -677,8 +675,6 @@ def update_goal_type_definition(
|
||||||
raise HTTPException(status_code=400, detail="Keine Änderungen angegeben")
|
raise HTTPException(status_code=400, detail="Keine Änderungen angegeben")
|
||||||
|
|
||||||
updates.append("updated_at = NOW()")
|
updates.append("updated_at = NOW()")
|
||||||
updates.append("updated_by = %s")
|
|
||||||
params.append(pid)
|
|
||||||
params.append(goal_type_id)
|
params.append(goal_type_id)
|
||||||
|
|
||||||
cur.execute(
|
cur.execute(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user