"""Phase 1: Add missing columns to holding_strategies for decisions.json→DB migration"""
import sqlite3

db = sqlite3.connect('/home/hmo/web-dashboard/data/mofin.db')

new_cols = {
    'avg_price': 'REAL',
    'decision_timestamp': 'TEXT',  # avoids conflict with SQLite timestamp
    'note': 'TEXT',
    'quality_check': 'TEXT',
    'quality_checked_at': 'TEXT',
    'quality_issues_json': 'TEXT',
    'position_advice': 'TEXT',
    'signal_factors_json': 'TEXT',
    'time_horizon': 'TEXT',
    'decision_type': 'TEXT',
}

# Get existing columns
existing = {r[1] for r in db.execute("PRAGMA table_info(holding_strategies)")}

for col, ctype in new_cols.items():
    if col in existing:
        print(f"SKIP: {col} already exists")
    else:
        db.execute(f"ALTER TABLE holding_strategies ADD COLUMN {col} {ctype}")
        print(f"ADDED: {col} {ctype}")

db.commit()
db.close()
print("\nSchema migration done.")
