34 lines
814 B
Python
34 lines
814 B
Python
|
|
"""
|
||
|
|
数据库初始化脚本
|
||
|
|
"""
|
||
|
|
import sys
|
||
|
|
import os
|
||
|
|
|
||
|
|
# 添加项目根目录到 Python 路径
|
||
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||
|
|
|
||
|
|
from app.core.database import SessionLocal, engine
|
||
|
|
from app.models import Base
|
||
|
|
|
||
|
|
|
||
|
|
def init_database():
|
||
|
|
"""初始化数据库"""
|
||
|
|
# 创建所有表
|
||
|
|
Base.metadata.create_all(bind=engine)
|
||
|
|
print("Database tables created successfully")
|
||
|
|
|
||
|
|
# 初始化默认配置
|
||
|
|
db = SessionLocal()
|
||
|
|
try:
|
||
|
|
from app.services.system_service import SystemService
|
||
|
|
SystemService.initialize_default_configs(db)
|
||
|
|
print("Default system configs initialized successfully")
|
||
|
|
except Exception as e:
|
||
|
|
print(f"System config initialization failed: {e}")
|
||
|
|
finally:
|
||
|
|
db.close()
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
init_database()
|