You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 从app导入应用创建函数和数据库对象
from app import create_app, db
# 从app.models导入User模型
from app.models import User
# 从datetime导入datetime类
from datetime import datetime
def create_structure():
# 创建Flask应用实例
app = create_app()
with app.app_context():
# 删除所有数据库表
db.drop_all()
# 创建所有数据库表
db.create_all()
# 创建管理员用户对象
admin = User(
username='admin',
# 管理员用户名
email='admin@example.com',
# 管理员邮箱
is_admin=True,
# 设置为管理员
real_name='管理员',
# 真实姓名
phone='13800138000',
# 电话
status='active',
# 状态为激活
last_login=datetime.utcnow(),
# 最后登录时间为当前时间
created_at=datetime.utcnow()
# 创建时间为当前时间
)
# 为管理员设置密码
admin.set_password('123456')
# 创建测试用户对象
user = User(
username='test',
# 测试用户名
email='test@example.com',
# 测试用户邮箱
is_admin=False,
# 不是管理员
real_name='测试用户',
# 真实姓名
phone='13900139000',
# 电话
status='active',
# 状态为激活
created_at=datetime.utcnow()
# 创建时间为当前时间
)
# 为测试用户设置密码
user.set_password('123456')
# 将管理员和测试用户添加到数据库会话
db.session.add(admin)
db.session.add(user)
# 提交数据库更改
db.session.commit()
# 打印数据库结构创建成功的提示信息
print('数据库结构创建成功!')
print('管理员账号admin')
print('管理员密码123456')
print('测试账号test')
print('测试密码123456')
# 当脚本作为主程序运行时,调用创建结构函数
if __name__ == '__main__':
create_structure()
#7890
#f7890