- 将项目重构为前后端分离架构,前端使用Vue 3 + Element Plus,后端使用Flask - 实现基于JWT的身份认证系统,提供登录/登出和用户信息获取API - 引入基于角色的访问控制(RBAC)系统,支持角色继承和权限管理 - 添加数据隔离机制,研究员只能访问自己的数据,管理员拥有全局权限 - 实现数据时间控制功能,支持设置开始时间和永久性标记 - 创建前端管理界面,包括用户管理、角色管理、权限管理和操作日志 - 重构项目结构,分离前后端代码,更新README说明文档 - 添加数据库迁移脚本,支持RBAC相关表的创建和更新 - 集成Vue Router和Pinia状态管理,构建完整的前端应用架构 - 提供字体文件管理和静态资源缓存优化
45 lines
1.8 KiB
Python
45 lines
1.8 KiB
Python
|
|
from app import create_app, db
|
|
from sqlalchemy import text
|
|
|
|
def update_schema():
|
|
app = create_app('default')
|
|
with app.app_context():
|
|
# 创建新表 (security_log)
|
|
db.create_all()
|
|
print("Ensured all tables exist (including security_log)")
|
|
|
|
# 为 data_entry 添加字段
|
|
try:
|
|
db.session.execute(text("ALTER TABLE data_entry ADD COLUMN start_date DATETIME"))
|
|
print("Added start_date to data_entry")
|
|
except Exception as e:
|
|
print(f"Note: start_date might already exist or error: {e}")
|
|
|
|
try:
|
|
db.session.execute(text("ALTER TABLE data_entry ADD COLUMN is_permanent BOOLEAN DEFAULT 1"))
|
|
print("Added is_permanent to data_entry")
|
|
except Exception as e:
|
|
print(f"Note: is_permanent might already exist or error: {e}")
|
|
|
|
try:
|
|
db.session.execute(text("ALTER TABLE data_entry ADD COLUMN researcher_id INTEGER"))
|
|
db.session.execute(text("ALTER TABLE data_entry ADD CONSTRAINT fk_data_entry_researcher FOREIGN KEY (researcher_id) REFERENCES user(id)"))
|
|
print("Added researcher_id to data_entry")
|
|
except Exception as e:
|
|
print(f"Note: researcher_id might already exist or error: {e}")
|
|
|
|
# 为 raw_data_folder 添加字段
|
|
try:
|
|
db.session.execute(text("ALTER TABLE raw_data_folder ADD COLUMN researcher_id INTEGER"))
|
|
db.session.execute(text("ALTER TABLE raw_data_folder ADD CONSTRAINT fk_raw_folder_researcher FOREIGN KEY (researcher_id) REFERENCES user(id)"))
|
|
print("Added researcher_id to raw_data_folder")
|
|
except Exception as e:
|
|
print(f"Note: researcher_id might already exist or error: {e}")
|
|
|
|
db.session.commit()
|
|
print("Schema update completed.")
|
|
|
|
if __name__ == '__main__':
|
|
update_schema()
|