From 21f54f478bd893605e08cca480375905b406266d Mon Sep 17 00:00:00 2001 From: rene Date: Sun, 7 Jun 2026 17:22:59 +0200 Subject: [PATCH] =?UTF-8?q?Fix:=20partner=5Fprofiles=20Alt-Schema-Migratio?= =?UTF-8?q?n=20=E2=80=94=20Tabelle=20aus=20verlorener=20v1102-Session=20ex?= =?UTF-8?q?istiert=20auf=20Staging/Prod=20(photos=20statt=20photos=5Fjson)?= =?UTF-8?q?;=20Umbau=20mit=20Daten=C3=BCbernahme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/database.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/backend/database.py b/backend/database.py index 5b5b0c8..1ddfc8e 100644 --- a/backend/database.py +++ b/backend/database.py @@ -1633,6 +1633,38 @@ def _migrate(conn_factory): # Partner-Profile (öffentlicher Showcase auf /#partner) # approved: 0=Entwurf/in Prüfung, 1=freigegeben, -1=abgelehnt try: + # Alt-Schema aus der verlorenen v1102-Session (photos statt photos_json, + # id-Autoincrement-PK) kann auf Staging/Prod noch existieren → umbauen. + existing_cols = [r[1] for r in conn.execute( + "PRAGMA table_info(partner_profiles)" + ).fetchall()] + if existing_cols and "photos_json" not in existing_cols: + conn.executescript(""" + ALTER TABLE partner_profiles RENAME TO partner_profiles_old; + CREATE TABLE partner_profiles ( + user_id INTEGER PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE, + display_name TEXT, + tagline TEXT, + bio TEXT, + website TEXT, + instagram TEXT, + logo_url TEXT, + photos_json TEXT NOT NULL DEFAULT '[]', + approved INTEGER NOT NULL DEFAULT 0, + submitted_at TEXT, + updated_at TEXT, + created_at TEXT NOT NULL DEFAULT (datetime('now')) + ); + INSERT INTO partner_profiles + (user_id, display_name, tagline, bio, website, instagram, + logo_url, photos_json, approved, submitted_at, updated_at, created_at) + SELECT user_id, display_name, tagline, bio, website, instagram, + logo_url, COALESCE(photos, '[]'), COALESCE(approved, 0), + submitted_at, NULL, datetime('now') + FROM partner_profiles_old; + DROP TABLE partner_profiles_old; + """) + logger.info("Migration: partner_profiles Alt-Schema → neues Schema umgebaut.") conn.executescript(""" CREATE TABLE IF NOT EXISTS partner_profiles ( user_id INTEGER PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,