Initial commit

This commit is contained in:
jkortis committed 2026-09-30 23:06:14 -04:00
commit 1d235d30e7
58 files changed
+19693

No files matched your search

+1
View File
@@ -0,0 +1 @@
Generic single-database configuration.
+75
View File
@@ -0,0 +1,75 @@
from logging.config import fileConfig
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from alembic import context
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
from media_sorter.models import Base
target_metadata = Base.metadata
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online() -> None:
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata
)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()
+28
View File
@@ -0,0 +1,28 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision: str = ${repr(up_revision)}
down_revision: Union[str, Sequence[str], None] = ${repr(down_revision)}
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
def upgrade() -> None:
"""Upgrade schema."""
${upgrades if upgrades else "pass"}
def downgrade() -> None:
"""Downgrade schema."""
${downgrades if downgrades else "pass"}
@@ -0,0 +1,121 @@
"""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 ###