import sys
import os

# 加入專案路徑
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__))))

from database.manager import DatabaseManager
from database.models import Base, MonthlySummaryAnalysis

def migrate():
    print("Starting database migration for MonthlySummaryAnalysis...")
    try:
        db = DatabaseManager()
        engine = db.engine
        
        # 建立所有尚未存在的資料表 (包含 MonthlySummaryAnalysis)
        Base.metadata.create_all(engine)
        
        print("✓ Database migration completed successfully.")
    except Exception as e:
        print(f"✗ Migration failed: {e}")
        sys.exit(1)

if __name__ == "__main__":
    migrate()
