Add migration for assignment_type column

- Creates migration 004_add_assignment_type.py
- Adds assignment_type VARCHAR(20) to chores table
- Default value: 'any_one' for backward compatibility
- Values: 'any_one' (only one needs to complete) or 'all_assigned' (all must complete)
- Safe to run on existing database
This commit is contained in:
2026-02-02 21:38:25 +11:00
parent a41132c411
commit 041cbff783

View File

@@ -0,0 +1,40 @@
"""Add assignment_type to chores table."""
import sqlite3
import sys
from pathlib import Path
# Add parent directory to path to import from app
sys.path.insert(0, str(Path(__file__).parent.parent))
def upgrade():
"""Add assignment_type column to chores table."""
db_path = Path(__file__).parent.parent / "data" / "family_hub.db"
print(f"Connecting to database: {db_path}")
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
try:
# Add assignment_type column (default 'any_one' for backward compatibility)
print("Adding assignment_type column to chores table...")
cursor.execute("""
ALTER TABLE chores
ADD COLUMN assignment_type VARCHAR(20) DEFAULT 'any_one'
""")
conn.commit()
print("✅ Successfully added assignment_type column")
print(" Values: 'any_one' (only one person needs to complete)")
print(" 'all_assigned' (all assigned people must complete)")
except sqlite3.OperationalError as e:
if "duplicate column name" in str(e).lower():
print("⚠️ Column assignment_type already exists, skipping...")
else:
raise
finally:
conn.close()
if __name__ == "__main__":
upgrade()
print("\n✅ Migration completed!")