Finalize SuperOffice production migration and multi-campaign architecture (v1.8)
This commit is contained in:
43
company-explorer/backend/scripts/migrate_matrix_campaign.py
Normal file
43
company-explorer/backend/scripts/migrate_matrix_campaign.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Pfade so setzen, dass das Backend gefunden wird
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
|
||||
|
||||
from backend.database import SessionLocal, engine
|
||||
from sqlalchemy import text
|
||||
|
||||
def migrate():
|
||||
print("🚀 Starting Migration: Adding 'campaign_tag' to MarketingMatrix...")
|
||||
|
||||
conn = engine.connect()
|
||||
|
||||
try:
|
||||
# 1. Prüfen, ob Spalte schon existiert
|
||||
# SQLite Pragma: table_info(marketing_matrix)
|
||||
result = conn.execute(text("PRAGMA table_info(marketing_matrix)")).fetchall()
|
||||
columns = [row[1] for row in result]
|
||||
|
||||
if "campaign_tag" in columns:
|
||||
print("✅ Column 'campaign_tag' already exists. Skipping.")
|
||||
return
|
||||
|
||||
# 2. Spalte hinzufügen (SQLite supports simple ADD COLUMN)
|
||||
print("Adding column 'campaign_tag' (DEFAULT 'standard')...")
|
||||
conn.execute(text("ALTER TABLE marketing_matrix ADD COLUMN campaign_tag VARCHAR DEFAULT 'standard'"))
|
||||
|
||||
# 3. Index erstellen (Optional, aber gut für Performance)
|
||||
print("Creating index on 'campaign_tag'...")
|
||||
conn.execute(text("CREATE INDEX ix_marketing_matrix_campaign_tag ON marketing_matrix (campaign_tag)"))
|
||||
|
||||
conn.commit()
|
||||
print("✅ Migration successful!")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Migration failed: {e}")
|
||||
conn.rollback()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
migrate()
|
||||
Reference in New Issue
Block a user