"""Add image fields to users and chores tables Revision ID: 003 Created: 2026-02-02 """ import sqlite3 import os def get_db_path(): """Get database path""" # Use absolute path return r"D:\Hosted\familyhub\backend\data\family_hub.db" def upgrade(): """Add image fields to users and chores""" db_path = get_db_path() print(f"Connecting to database: {db_path}") if not os.path.exists(db_path): print(f"ERROR: Database file not found at {db_path}") return conn = sqlite3.connect(db_path) cursor = conn.cursor() try: # Add avatar_url to users table cursor.execute(""" ALTER TABLE users ADD COLUMN avatar_url VARCHAR(500); """) print("✓ Added avatar_url to users table") # Add image_url to chores table cursor.execute(""" ALTER TABLE chores ADD COLUMN image_url VARCHAR(500); """) print("✓ Added image_url to chores table") conn.commit() print("\n✅ Migration 003 completed successfully!") except sqlite3.OperationalError as e: if "duplicate column name" in str(e).lower(): print(f"⚠️ Column already exists: {e}") else: raise finally: conn.close() def downgrade(): """Remove image fields""" print("Note: SQLite doesn't support DROP COLUMN easily.") print("To rollback, you would need to recreate the tables.") if __name__ == "__main__": upgrade()