#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
重新創建通知表腳本
"""

from app import create_app, db
from app.models import Notification

def recreate_notification_table():
    """重新創建通知表"""
    try:
        app = create_app()
        with app.app_context():
            print("Recreating notification table...")
            
            # 刪除通知表（如果存在）
            try:
                db.engine.execute('DROP TABLE IF EXISTS dt_notifications')
                print("✅ Old notification table dropped")
            except Exception as e:
                print(f"Info: {e}")
            
            # 重新創建通知表
            db.create_all()
            print("✅ New notification table created with correct structure")
            
            # 檢查表結構
            result = db.engine.execute('DESCRIBE dt_notifications')
            columns = result.fetchall()
            print("\nNew table structure:")
            for col in columns:
                print(f"  {col[0]} {col[1]}")
                
    except Exception as e:
        print(f"Error recreating notification table: {e}")
        import traceback
        traceback.print_exc()

if __name__ == '__main__':
    recreate_notification_table()