37 lines
989 B
Python
37 lines
989 B
Python
#!/usr/bin/env python3
|
|
"""重置数据库脚本"""
|
|
|
|
from app import create_app
|
|
from database import db
|
|
from models import User, Server, Script, ExecuteHistory, ExecuteResult
|
|
|
|
def reset_database():
|
|
"""重置数据库"""
|
|
app = create_app()
|
|
|
|
with app.app_context():
|
|
# 删除所有表
|
|
db.drop_all()
|
|
print("已删除所有表")
|
|
|
|
# 创建所有表
|
|
db.create_all()
|
|
print("已创建所有表")
|
|
|
|
# 创建默认管理员用户
|
|
admin_user = User(
|
|
username='admin',
|
|
real_name='系统管理员',
|
|
email='admin@example.com',
|
|
role='admin'
|
|
)
|
|
admin_user.set_password('admin123')
|
|
admin_user.set_permissions(['all'])
|
|
|
|
db.session.add(admin_user)
|
|
db.session.commit()
|
|
print("已创建默认管理员用户 (admin/admin123)")
|
|
|
|
if __name__ == '__main__':
|
|
reset_database()
|
|
print("数据库重置完成!") |