fix: Correct DB path in migration script

This commit is contained in:
Moltbot-Jarvis
2026-02-18 10:02:20 +00:00
parent c161a8213c
commit 536fdf0988

View File

@@ -1,16 +1,23 @@
import sqlite3
import os
# Adjust path to your actual DB location
DB_PATH = "/home/node/clawd/repos/brancheneinstufung2/company_explorer.db"
# Correct Path for Docker Container
DB_PATH = "/app/companies_v3_fixed_2.db"
def migrate():
if not os.path.exists(DB_PATH):
print(f"Database not found at {DB_PATH}. Maybe it hasn't been created yet?")
return
print(f"Database not found at {DB_PATH}. Please ensure the volume is mounted correctly.")
# Fallback for local testing (optional)
if os.path.exists("companies_v3_fixed_2.db"):
print("⚠️ Found DB in current directory, using that instead.")
db_to_use = "companies_v3_fixed_2.db"
else:
return
else:
db_to_use = DB_PATH
print(f"Migrating database at {DB_PATH}...")
conn = sqlite3.connect(DB_PATH)
print(f"Migrating database at {db_to_use}...")
conn = sqlite3.connect(db_to_use)
cursor = conn.cursor()
columns_to_add = [
@@ -37,17 +44,22 @@ def migrate():
for table, col_name, col_type in columns_to_add:
try:
print(f"Adding column '{col_name}' to '{table}'...")
cursor.execute(f"ALTER TABLE {table} ADD COLUMN {col_name} {col_type}")
except sqlite3.OperationalError as e:
if "duplicate column name" in str(e):
print(f"Column '{col_name}' already exists. Skipping.")
# Check if column exists first to avoid error log spam
cursor.execute(f"PRAGMA table_info({table})")
existing_cols = [row[1] for row in cursor.fetchall()]
if col_name in existing_cols:
print(f" - Column '{col_name}' already exists in '{table}'.")
else:
print(f"Error adding '{col_name}' to '{table}': {e}")
print(f" + Adding column '{col_name}' to '{table}'...")
cursor.execute(f"ALTER TABLE {table} ADD COLUMN {col_name} {col_type}")
except sqlite3.OperationalError as e:
print(f"❌ Error adding '{col_name}' to '{table}': {e}")
conn.commit()
conn.close()
print("Migration complete.")
print("Migration complete.")
if __name__ == "__main__":
migrate()