#!/usr/bin/env python3
"""Migrate existing database to add new columns."""

import sqlite3
import os
from pathlib import Path

db_path = os.path.expanduser('~/bitcoin-bot/signals.db')
conn = sqlite3.connect(db_path)
cursor = conn.cursor()

# Check if columns exist
cursor.execute("PRAGMA table_info(signals)")
columns = [row[1] for row in cursor.fetchall()]
print(f"Current columns: {columns}")

# Add missing columns
if 'executed' not in columns:
    cursor.execute("ALTER TABLE signals ADD COLUMN executed INTEGER DEFAULT 0")
    print("Added 'executed' column")
    
if 'trade_id' not in columns:
    cursor.execute("ALTER TABLE signals ADD COLUMN trade_id INTEGER")
    print("Added 'trade_id' column")
    
if 'execution_note' not in columns:
    cursor.execute("ALTER TABLE signals ADD COLUMN execution_note TEXT")
    print("Added 'execution_note' column")

conn.commit()
conn.close()
print("Database migration complete!")
