122 lines
5.8 KiB
Python
122 lines
5.8 KiB
Python
"""Initial schema
|
|
|
|
Revision ID: a3cc170248be
|
|
Revises:
|
|
Create Date: 2026-09-05 07:07:21.453178
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = 'a3cc170248be'
|
|
down_revision: Union[str, Sequence[str], None] = None
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
"""Upgrade schema."""
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.create_table('batches',
|
|
sa.Column('id', sa.String(length=36), nullable=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column('completed_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column('dry_run', sa.Boolean(), nullable=False),
|
|
sa.Column('status', sa.String(length=32), nullable=False),
|
|
sa.Column('total_files', sa.Integer(), nullable=False),
|
|
sa.Column('moved_files', sa.Integer(), nullable=False),
|
|
sa.Column('skipped_files', sa.Integer(), nullable=False),
|
|
sa.Column('failed_files', sa.Integer(), nullable=False),
|
|
sa.Column('quarantined_files', sa.Integer(), nullable=False),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index('ix_batches_created_at', 'batches', ['created_at'], unique=False)
|
|
op.create_table('config_audit',
|
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
|
sa.Column('loaded_at', sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column('config_json', sa.JSON(), nullable=False),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index('ix_config_loaded', 'config_audit', ['loaded_at'], unique=False)
|
|
op.create_table('files',
|
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
|
sa.Column('path', sa.String(length=1024), nullable=False),
|
|
sa.Column('size', sa.Integer(), nullable=False),
|
|
sa.Column('mtime', sa.Float(), nullable=False),
|
|
sa.Column('content_hash', sa.String(length=64), nullable=True),
|
|
sa.Column('status', sa.String(length=32), nullable=False),
|
|
sa.Column('category', sa.String(length=32), nullable=True),
|
|
sa.Column('confidence', sa.Float(), nullable=True),
|
|
sa.Column('first_seen', sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column('last_processed', sa.DateTime(timezone=True), nullable=True),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('path')
|
|
)
|
|
op.create_index('ix_files_path', 'files', ['path'], unique=False)
|
|
op.create_index('ix_files_status', 'files', ['status'], unique=False)
|
|
op.create_table('quarantine',
|
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
|
sa.Column('src', sa.String(length=1024), nullable=False),
|
|
sa.Column('suggested_category', sa.String(length=32), nullable=True),
|
|
sa.Column('confidence', sa.Float(), nullable=True),
|
|
sa.Column('reason', sa.String(length=256), nullable=False),
|
|
sa.Column('signals', sa.JSON(), nullable=True),
|
|
sa.Column('status', sa.String(length=32), nullable=False),
|
|
sa.Column('resolved_path', sa.String(length=1024), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column('resolved_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('src')
|
|
)
|
|
op.create_index('ix_quarantine_src', 'quarantine', ['src'], unique=False)
|
|
op.create_index('ix_quarantine_status', 'quarantine', ['status'], unique=False)
|
|
op.create_table('operations',
|
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
|
sa.Column('batch_id', sa.String(length=36), nullable=False),
|
|
sa.Column('src', sa.String(length=1024), nullable=False),
|
|
sa.Column('dst', sa.String(length=1024), nullable=False),
|
|
sa.Column('action', sa.String(length=32), nullable=False),
|
|
sa.Column('status', sa.String(length=32), nullable=False),
|
|
sa.Column('category', sa.String(length=32), nullable=True),
|
|
sa.Column('confidence', sa.Float(), nullable=True),
|
|
sa.Column('src_hash', sa.String(length=64), nullable=True),
|
|
sa.Column('dst_hash', sa.String(length=64), nullable=True),
|
|
sa.Column('backup_path', sa.String(length=1024), nullable=True),
|
|
sa.Column('details', sa.JSON(), nullable=True),
|
|
sa.Column('error_message', sa.Text(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column('completed_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.ForeignKeyConstraint(['batch_id'], ['batches.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index('ix_operations_batch_id', 'operations', ['batch_id'], unique=False)
|
|
op.create_index('ix_operations_dst', 'operations', ['dst'], unique=False)
|
|
op.create_index('ix_operations_src', 'operations', ['src'], unique=False)
|
|
op.create_index('ix_operations_status', 'operations', ['status'], unique=False)
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
"""Downgrade schema."""
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.drop_index('ix_operations_status', table_name='operations')
|
|
op.drop_index('ix_operations_src', table_name='operations')
|
|
op.drop_index('ix_operations_dst', table_name='operations')
|
|
op.drop_index('ix_operations_batch_id', table_name='operations')
|
|
op.drop_table('operations')
|
|
op.drop_index('ix_quarantine_status', table_name='quarantine')
|
|
op.drop_index('ix_quarantine_src', table_name='quarantine')
|
|
op.drop_table('quarantine')
|
|
op.drop_index('ix_files_status', table_name='files')
|
|
op.drop_index('ix_files_path', table_name='files')
|
|
op.drop_table('files')
|
|
op.drop_index('ix_config_loaded', table_name='config_audit')
|
|
op.drop_table('config_audit')
|
|
op.drop_index('ix_batches_created_at', table_name='batches')
|
|
op.drop_table('batches')
|
|
# ### end Alembic commands ###
|