fix: Correct DB path in migration script

This commit is contained in:
Moltbot-Jarvis
2026-02-18 10:02:20 +00:00
parent 4072e746cc
commit 31b2c24fdd

View File

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