"""
数据库迁移脚本：创建用户系统相关表
运行方式：python create_user_tables.py
"""

import os
from app import create_app
from models import db, User, Folder, Collection

def create_user_tables():
    """创建用户系统相关的数据库表"""
    app = create_app(os.getenv('FLASK_ENV', 'development'))

    with app.app_context():
        print("开始创建用户系统表...")

        try:
            # 创建表（如果不存在）
            db.create_all()
            print("SUCCESS: Database tables created successfully!")

            # 显示创建的表信息
            print("\nCreated tables:")
            print("- users")
            print("- folders")
            print("- collections")

            print("\nMigration completed!")

        except Exception as e:
            print(f"ERROR: Failed to create tables: {str(e)}")
            import traceback
            traceback.print_exc()

if __name__ == '__main__':
    create_user_tables()
