addes folder backup attachments logging

This commit is contained in:
2026-03-19 15:31:36 +01:00
parent 61c4384111
commit d148248682
29 changed files with 2298 additions and 115 deletions
@@ -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 ###