Build [v1.9.19]
This commit is contained in:
49
backend/scripts/migrate_v4_v5.py
Normal file
49
backend/scripts/migrate_v4_v5.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import sqlite3
|
||||
import os
|
||||
from ..database import db_path
|
||||
from ..logger import log
|
||||
|
||||
def migrate():
|
||||
"""
|
||||
Migration script to upgrade the items table from schema v4 to v5.
|
||||
Adds columns: description, connector, size, ocr_text.
|
||||
"""
|
||||
log.info(f"🚀 Starting database migration on {db_path}...")
|
||||
|
||||
if not os.path.exists(db_path):
|
||||
log.error(f"❌ Database file not found at {db_path}")
|
||||
return
|
||||
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
try:
|
||||
# Check existing columns
|
||||
cursor.execute("PRAGMA table_info(items)")
|
||||
columns = [row[1] for row in cursor.fetchall()]
|
||||
|
||||
new_columns = [
|
||||
("description", "VARCHAR"),
|
||||
("connector", "VARCHAR"),
|
||||
("size", "VARCHAR"),
|
||||
("ocr_text", "TEXT")
|
||||
]
|
||||
|
||||
for col_name, col_type in new_columns:
|
||||
if col_name not in columns:
|
||||
log.info(f"➕ Adding column '{col_name}' to 'items' table...")
|
||||
cursor.execute(f"ALTER TABLE items ADD COLUMN {col_name} {col_type}")
|
||||
else:
|
||||
log.info(f"✔️ Column '{col_name}' already exists.")
|
||||
|
||||
conn.commit()
|
||||
log.info("✅ Migration completed successfully.")
|
||||
|
||||
except Exception as e:
|
||||
log.error(f"❌ Migration failed: {e}")
|
||||
conn.rollback()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
migrate()
|
||||
Reference in New Issue
Block a user