Phase 3.1: Enhanced Chore Logging and Reporting System
This commit is contained in:
56
backend/migrations/003_add_image_fields.py
Normal file
56
backend/migrations/003_add_image_fields.py
Normal file
@@ -0,0 +1,56 @@
|
||||
"""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()
|
||||
Reference in New Issue
Block a user