From 6845397866dea356d62af24544f2d5208f99a29e Mon Sep 17 00:00:00 2001 From: Lars Date: Thu, 19 Mar 2026 08:39:31 +0100 Subject: [PATCH] fix: Migration-Fehler - meas_id Spalte in ai_insights MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PROBLEM: - Backend crasht beim Start auf Prod - Migration schlägt fehl: column 'meas_id' does not exist - SQLite ai_insights hat Legacy-Spalte meas_id - PostgreSQL schema hat diese Spalte nicht mehr FIX: - COLUMN_WHITELIST für ai_insights hinzugefügt - Nur erlaubte Spalten werden migriert: id, profile_id, scope, content, created - meas_id wird beim Import gefiltert DATEIEN: - backend/migrate_to_postgres.py Co-Authored-By: Claude Opus 4.6 --- backend/migrate_to_postgres.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/backend/migrate_to_postgres.py b/backend/migrate_to_postgres.py index 41a9371..d083974 100644 --- a/backend/migrate_to_postgres.py +++ b/backend/migrate_to_postgres.py @@ -69,6 +69,12 @@ BOOLEAN_COLUMNS = { 'ai_prompts': ['active'], } +# Column whitelist for tables that have schema differences +# Only these columns will be migrated (filters out legacy columns) +COLUMN_WHITELIST = { + 'ai_insights': ['id', 'profile_id', 'scope', 'content', 'created'], +} + # ================================================================ # CONVERSION HELPERS @@ -173,8 +179,17 @@ def migrate_table(pg_conn, table: str) -> Dict[str, int]: # Convert rows converted_rows = [convert_row(row, table) for row in sqlite_rows] - # Get column names - columns = list(converted_rows[0].keys()) + # Get column names - filter if whitelist exists for this table + if table in COLUMN_WHITELIST: + allowed_columns = COLUMN_WHITELIST[table] + # Filter rows to only include allowed columns + converted_rows = [ + {k: v for k, v in row.items() if k in allowed_columns} + for row in converted_rows + ] + columns = allowed_columns + else: + columns = list(converted_rows[0].keys()) cols_str = ', '.join(columns) placeholders = ', '.join(['%s'] * len(columns))