addes folder backup attachments logging
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Generic single-database configuration.
|
||||
@@ -0,0 +1,59 @@
|
||||
from logging.config import fileConfig
|
||||
|
||||
from sqlalchemy import engine_from_config, pool
|
||||
|
||||
from alembic import context
|
||||
|
||||
from app.config import settings
|
||||
from app.database import Base
|
||||
from app.models.db_models import Account, FilterRule, FilterCondition, FilterAction # noqa: F401
|
||||
|
||||
config = context.config
|
||||
|
||||
# Set DB URL from app config
|
||||
config.set_main_option("sqlalchemy.url", settings.database_url)
|
||||
|
||||
if config.config_file_name is not None:
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
target_metadata = Base.metadata
|
||||
|
||||
|
||||
def render_item(type_, obj, autogen_context):
|
||||
"""Custom render for SQLite enum handling."""
|
||||
return False
|
||||
|
||||
|
||||
def run_migrations_offline() -> None:
|
||||
url = config.get_main_option("sqlalchemy.url")
|
||||
context.configure(
|
||||
url=url,
|
||||
target_metadata=target_metadata,
|
||||
literal_binds=True,
|
||||
dialect_opts={"paramstyle": "named"},
|
||||
render_as_batch=True, # Required for SQLite ALTER TABLE
|
||||
)
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
def run_migrations_online() -> None:
|
||||
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,
|
||||
render_as_batch=True, # Required for SQLite ALTER TABLE
|
||||
)
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
run_migrations_online()
|
||||
@@ -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,48 @@
|
||||
"""add processed_mails table
|
||||
|
||||
Revision ID: 0ef2a4f77557
|
||||
Revises: 4f8cb93713e8
|
||||
Create Date: 2026-03-19 13:47:28.217052
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '0ef2a4f77557'
|
||||
down_revision: Union[str, Sequence[str], None] = '4f8cb93713e8'
|
||||
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('processed_mails',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('account_id', sa.Integer(), nullable=False),
|
||||
sa.Column('folder', sa.String(length=255), nullable=False),
|
||||
sa.Column('mail_uid', sa.String(length=100), nullable=False),
|
||||
sa.Column('mail_subject', sa.String(length=500), nullable=True),
|
||||
sa.Column('mail_from', sa.String(length=255), nullable=True),
|
||||
sa.Column('processed_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.ForeignKeyConstraint(['account_id'], ['accounts.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
with op.batch_alter_table('processed_mails', schema=None) as batch_op:
|
||||
batch_op.create_index(batch_op.f('ix_processed_mails_account_id'), ['account_id'], unique=False)
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('processed_mails', schema=None) as batch_op:
|
||||
batch_op.drop_index(batch_op.f('ix_processed_mails_account_id'))
|
||||
|
||||
op.drop_table('processed_mails')
|
||||
# ### end Alembic commands ###
|
||||
@@ -0,0 +1,47 @@
|
||||
"""add filter_logs table
|
||||
|
||||
Revision ID: 4f8cb93713e8
|
||||
Revises: c2a398ed74d6
|
||||
Create Date: 2026-03-19 13:37:33.433556
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '4f8cb93713e8'
|
||||
down_revision: Union[str, Sequence[str], None] = 'c2a398ed74d6'
|
||||
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('filter_logs',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('account_id', sa.Integer(), nullable=True),
|
||||
sa.Column('account_name', sa.String(length=100), nullable=False),
|
||||
sa.Column('level', sa.Enum('INFO', 'WARNING', 'ERROR', 'SUCCESS', name='loglevel'), nullable=False),
|
||||
sa.Column('message', sa.String(length=1000), nullable=False),
|
||||
sa.Column('rule_name', sa.String(length=200), nullable=True),
|
||||
sa.Column('action_type', sa.String(length=50), nullable=True),
|
||||
sa.Column('mail_uid', sa.String(length=100), nullable=True),
|
||||
sa.Column('mail_subject', sa.String(length=500), nullable=True),
|
||||
sa.Column('mail_from', sa.String(length=255), nullable=True),
|
||||
sa.Column('folder', sa.String(length=255), nullable=True),
|
||||
sa.Column('details', sa.String(length=2000), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('filter_logs')
|
||||
# ### end Alembic commands ###
|
||||
@@ -0,0 +1,84 @@
|
||||
"""initial schema
|
||||
|
||||
Revision ID: c2a398ed74d6
|
||||
Revises:
|
||||
Create Date: 2026-03-19 13:28:01.842649
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'c2a398ed74d6'
|
||||
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('accounts',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('name', sa.String(length=100), nullable=False),
|
||||
sa.Column('imap_host', sa.String(length=255), nullable=False),
|
||||
sa.Column('imap_port', sa.Integer(), nullable=False),
|
||||
sa.Column('use_ssl', sa.Boolean(), nullable=False),
|
||||
sa.Column('username', sa.String(length=255), nullable=False),
|
||||
sa.Column('password', sa.String(length=255), nullable=False),
|
||||
sa.Column('smtp_host', sa.String(length=255), nullable=True),
|
||||
sa.Column('smtp_port', sa.Integer(), nullable=True),
|
||||
sa.Column('smtp_username', sa.String(length=255), nullable=True),
|
||||
sa.Column('smtp_password', sa.String(length=255), nullable=True),
|
||||
sa.Column('poll_interval_seconds', sa.Integer(), nullable=False),
|
||||
sa.Column('enabled', sa.Boolean(), nullable=False),
|
||||
sa.Column('last_poll_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('filter_rules',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('account_id', sa.Integer(), nullable=False),
|
||||
sa.Column('name', sa.String(length=200), nullable=False),
|
||||
sa.Column('priority', sa.Integer(), nullable=False),
|
||||
sa.Column('enabled', sa.Boolean(), nullable=False),
|
||||
sa.Column('stop_processing', sa.Boolean(), nullable=False),
|
||||
sa.Column('source_folder', sa.String(length=255), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.ForeignKeyConstraint(['account_id'], ['accounts.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('filter_actions',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('rule_id', sa.Integer(), nullable=False),
|
||||
sa.Column('action_type', sa.Enum('MOVE', 'FORWARD', 'DELETE', 'MARK_READ', name='actiontype'), nullable=False),
|
||||
sa.Column('parameter', sa.String(length=500), nullable=True),
|
||||
sa.ForeignKeyConstraint(['rule_id'], ['filter_rules.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('filter_conditions',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('rule_id', sa.Integer(), nullable=False),
|
||||
sa.Column('field', sa.Enum('FROM', 'TO', 'SUBJECT', 'BODY', 'HAS_ATTACHMENT', 'DATE', name='conditionfield'), nullable=False),
|
||||
sa.Column('match_type', sa.Enum('CONTAINS', 'REGEX', 'EXACT', 'ON_DATE', 'BEFORE', 'AFTER', 'DATE_RANGE', 'YEAR', 'LAST_N_DAYS', 'LAST_N_WEEKS', 'LAST_N_MONTHS', 'OLDER_THAN_DAYS', 'OLDER_THAN_WEEKS', 'OLDER_THAN_MONTHS', name='matchtype'), nullable=False),
|
||||
sa.Column('value', sa.String(length=500), nullable=False),
|
||||
sa.Column('negate', sa.Boolean(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['rule_id'], ['filter_rules.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('filter_conditions')
|
||||
op.drop_table('filter_actions')
|
||||
op.drop_table('filter_rules')
|
||||
op.drop_table('accounts')
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user