forked from zhouxiaoka/autoclip
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_database.py
More file actions
56 lines (44 loc) · 1.45 KB
/
init_database.py
File metadata and controls
56 lines (44 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
"""
数据库初始化脚本
"""
import sys
from pathlib import Path
# 添加项目根目录到路径
current_dir = Path(__file__).parent
sys.path.insert(0, str(current_dir))
sys.path.insert(0, str(current_dir / "backend"))
# 设置工作目录
import os
os.chdir(current_dir)
def init_database():
"""初始化数据库"""
print("🚀 开始初始化数据库...")
try:
# 导入所有模型确保表被创建
from backend.models import Base, BilibiliAccount, UploadRecord
from backend.core.database import init_database, create_tables
print("✅ 所有模型导入成功")
# 初始化数据库
if init_database():
print("✅ 数据库初始化成功")
else:
print("❌ 数据库初始化失败")
return False
# 创建表
create_tables()
print("✅ 数据库表创建成功")
return True
except Exception as e:
print(f"❌ 数据库初始化失败: {e}")
return False
if __name__ == "__main__":
success = init_database()
if success:
print("\n🎉 数据库初始化完成!")
print("现在可以启动系统了:")
print("1. ./start_autoclip_with_upload.sh")
print("2. 或者手动启动各个服务")
else:
print("\n❌ 数据库初始化失败,请检查错误信息")
sys.exit(1)