Files
rct/backend/migrations/versions/7fc17cf59320_initial_schema.py
T
yilv 587b36a7fa feat: 重构项目为前后端分离架构并添加RBAC系统
- 将项目重构为前后端分离架构,前端使用Vue 3 + Element Plus,后端使用Flask
- 实现基于JWT的身份认证系统,提供登录/登出和用户信息获取API
- 引入基于角色的访问控制(RBAC)系统,支持角色继承和权限管理
- 添加数据隔离机制,研究员只能访问自己的数据,管理员拥有全局权限
- 实现数据时间控制功能,支持设置开始时间和永久性标记
- 创建前端管理界面,包括用户管理、角色管理、权限管理和操作日志
- 重构项目结构,分离前后端代码,更新README说明文档
- 添加数据库迁移脚本,支持RBAC相关表的创建和更新
- 集成Vue Router和Pinia状态管理,构建完整的前端应用架构
- 提供字体文件管理和静态资源缓存优化
2026-02-27 17:04:22 +08:00

157 lines
6.8 KiB
Python

"""initial_schema
Revision ID: 7fc17cf59320
Revises:
Create Date: 2026-02-03 17:09:17.744360
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '7fc17cf59320'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('data_entry',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=100), nullable=False),
sa.Column('content', sa.Text(), nullable=False),
sa.Column('timestamp', sa.DateTime(), nullable=True),
sa.Column('expiration_date', sa.DateTime(), nullable=True),
sa.Column('associated_filename', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('data_entry', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_data_entry_timestamp'), ['timestamp'], unique=False)
op.create_table('data_source',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('timestamp', sa.DateTime(), nullable=True),
sa.Column('source_type', sa.String(length=50), nullable=False),
sa.Column('status', sa.String(length=50), nullable=False),
sa.Column('raw_filename', sa.String(length=255), nullable=False),
sa.Column('processed_filename', sa.String(length=255), nullable=True),
sa.Column('notes', sa.Text(), nullable=True),
sa.Column('target_folder', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('data_source', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_data_source_timestamp'), ['timestamp'], unique=False)
op.create_table('raw_data_folder',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('folder_name', sa.String(length=255), nullable=False),
sa.Column('status', sa.String(length=50), nullable=False),
sa.Column('last_processed', sa.DateTime(), nullable=True),
sa.Column('summary_generated_at', sa.DateTime(), nullable=True),
sa.Column('processed_file_count', sa.Integer(), nullable=True),
sa.Column('inference_status', sa.String(length=50), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('folder_name')
)
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('username', sa.String(length=64), nullable=True),
sa.Column('email', sa.String(length=120), nullable=True),
sa.Column('password_hash', sa.String(length=255), nullable=True),
sa.Column('role', sa.String(length=10), nullable=True),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_user_email'), ['email'], unique=True)
batch_op.create_index(batch_op.f('ix_user_username'), ['username'], unique=True)
op.create_table('data_visibility',
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('data_entry_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['data_entry_id'], ['data_entry.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('user_id', 'data_entry_id')
)
op.create_table('inference_result',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('folder_id', sa.Integer(), nullable=False),
sa.Column('timestamp', sa.DateTime(), nullable=True),
sa.Column('total_windows', sa.Integer(), nullable=False),
sa.Column('valid_windows', sa.Integer(), nullable=False),
sa.Column('sqa_pass_rate', sa.Float(), nullable=False),
sa.Column('positive_count', sa.Integer(), nullable=False),
sa.Column('positive_density', sa.Float(), nullable=False),
sa.Column('diagnosis', sa.String(length=100), nullable=False),
sa.Column('result_csv_filename', sa.String(length=255), nullable=True),
sa.ForeignKeyConstraint(['folder_id'], ['raw_data_folder.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('inference_result', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_inference_result_timestamp'), ['timestamp'], unique=False)
op.create_table('notification',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=120), nullable=False),
sa.Column('content', sa.Text(), nullable=False),
sa.Column('timestamp', sa.DateTime(), nullable=True),
sa.Column('is_published', sa.Boolean(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('notification', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_notification_timestamp'), ['timestamp'], unique=False)
op.create_table('processing_job',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('folder_id', sa.Integer(), nullable=False),
sa.Column('start_time', sa.DateTime(), nullable=True),
sa.Column('end_time', sa.DateTime(), nullable=True),
sa.Column('status', sa.String(length=50), nullable=False),
sa.Column('log', sa.Text(), nullable=True),
sa.ForeignKeyConstraint(['folder_id'], ['raw_data_folder.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('processed_file_log',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('job_id', sa.Integer(), nullable=False),
sa.Column('zip_filename', sa.String(length=255), nullable=False),
sa.Column('processed_at', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['job_id'], ['processing_job.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('job_id', 'zip_filename', name='_job_zip_uc')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('processed_file_log')
op.drop_table('processing_job')
with op.batch_alter_table('notification', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_notification_timestamp'))
op.drop_table('notification')
with op.batch_alter_table('inference_result', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_inference_result_timestamp'))
op.drop_table('inference_result')
op.drop_table('data_visibility')
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_user_username'))
batch_op.drop_index(batch_op.f('ix_user_email'))
op.drop_table('user')
op.drop_table('raw_data_folder')
with op.batch_alter_table('data_source', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_data_source_timestamp'))
op.drop_table('data_source')
with op.batch_alter_table('data_entry', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_data_entry_timestamp'))
op.drop_table('data_entry')
# ### end Alembic commands ###