email headers fixing
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Generic single-database configuration.
|
||||
@@ -0,0 +1,79 @@
|
||||
from logging.config import fileConfig
|
||||
|
||||
from sqlalchemy import engine_from_config
|
||||
from sqlalchemy import pool
|
||||
|
||||
from alembic import context
|
||||
from email_server.models import Base
|
||||
|
||||
# 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)
|
||||
|
||||
# add your model's MetaData object here
|
||||
# for 'autogenerate' support
|
||||
# from myapp import mymodel
|
||||
# target_metadata = mymodel.Base.metadata
|
||||
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()
|
||||
@@ -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, 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,133 @@
|
||||
"""Initial migration
|
||||
|
||||
Revision ID: 53036910f343
|
||||
Revises:
|
||||
Create Date: 2025-06-01 11:14:39.589608
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '53036910f343'
|
||||
down_revision: Union[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! ###
|
||||
# The following columns may already exist, so we skip adding them if present.
|
||||
# op.add_column('esrv_auth_logs', sa.Column('auth_type', sa.String(), nullable=False, server_default='user'))
|
||||
# op.add_column('esrv_auth_logs', sa.Column('identifier', sa.String(), nullable=False, server_default='unknown'))
|
||||
# op.add_column('esrv_auth_logs', sa.Column('ip_address', sa.String(), nullable=True))
|
||||
# op.add_column('esrv_auth_logs', sa.Column('created_at', sa.DateTime(), nullable=True))
|
||||
# SQLite does not support ALTER COLUMN, so we skip changing 'message' type/nullability here.
|
||||
# If you need to change the type/nullability, do a manual migration as described in Alembic docs.
|
||||
# op.drop_column('esrv_auth_logs', 'peer')
|
||||
# op.drop_column('esrv_auth_logs', 'timestamp')
|
||||
# op.drop_column('esrv_auth_logs', 'username')
|
||||
# op.alter_column('esrv_custom_headers', 'created_at',
|
||||
# existing_type=sa.TIMESTAMP(),
|
||||
# type_=sa.DateTime(),
|
||||
# existing_nullable=True,
|
||||
# existing_server_default=sa.text("'2025-05-31 00:00:00'"))
|
||||
op.drop_index(op.f('idx_esrv_custom_headers_domain'), table_name='esrv_custom_headers')
|
||||
op.drop_index(op.f('idx_esrv_dkim_keys_domain'), table_name='esrv_dkim_keys')
|
||||
# op.alter_column('esrv_domains', 'created_at',
|
||||
# existing_type=sa.TIMESTAMP(),
|
||||
# type_=sa.DateTime(),
|
||||
# existing_nullable=True,
|
||||
# existing_server_default=sa.text("'2025-05-31 00:00:00'"))
|
||||
op.drop_column('esrv_domains', 'requires_auth')
|
||||
op.add_column('esrv_email_logs', sa.Column('from_address', sa.String(), nullable=False, server_default='unknown'))
|
||||
op.add_column('esrv_email_logs', sa.Column('to_address', sa.String(), nullable=False, server_default='unknown'))
|
||||
op.add_column('esrv_email_logs', sa.Column('subject', sa.Text(), nullable=True))
|
||||
op.add_column('esrv_email_logs', sa.Column('message', sa.Text(), nullable=True))
|
||||
op.add_column('esrv_email_logs', sa.Column('created_at', sa.DateTime(), nullable=True))
|
||||
op.drop_index(op.f('idx_esrv_email_logs_mail_from'), table_name='esrv_email_logs')
|
||||
op.drop_index(op.f('idx_esrv_email_logs_timestamp'), table_name='esrv_email_logs')
|
||||
# op.drop_column('esrv_email_logs', 'rcpt_tos')
|
||||
# op.drop_column('esrv_email_logs', 'content')
|
||||
# op.drop_column('esrv_email_logs', 'dkim_signed')
|
||||
# op.drop_column('esrv_email_logs', 'peer')
|
||||
# op.drop_column('esrv_email_logs', 'message_id')
|
||||
# op.drop_column('esrv_email_logs', 'mail_from')
|
||||
# op.drop_column('esrv_email_logs', 'timestamp')
|
||||
# op.alter_column('esrv_users', 'created_at',
|
||||
# existing_type=sa.TIMESTAMP(),
|
||||
# type_=sa.DateTime(),
|
||||
# existing_nullable=True,
|
||||
# existing_server_default=sa.text("'2025-05-31 00:00:00'"))
|
||||
op.drop_index(op.f('idx_esrv_users_domain'), table_name='esrv_users')
|
||||
op.drop_index(op.f('idx_esrv_users_email'), table_name='esrv_users')
|
||||
# op.alter_column('esrv_whitelisted_ips', 'created_at',
|
||||
# existing_type=sa.TIMESTAMP(),
|
||||
# type_=sa.DateTime(),
|
||||
# existing_nullable=True,
|
||||
# existing_server_default=sa.text("'2025-05-31 00:00:00'"))
|
||||
op.drop_index(op.f('idx_esrv_whitelisted_ips_domain'), table_name='esrv_whitelisted_ips')
|
||||
op.drop_index(op.f('idx_esrv_whitelisted_ips_ip'), table_name='esrv_whitelisted_ips')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_index(op.f('idx_esrv_whitelisted_ips_ip'), 'esrv_whitelisted_ips', ['ip_address'], unique=False)
|
||||
op.create_index(op.f('idx_esrv_whitelisted_ips_domain'), 'esrv_whitelisted_ips', ['domain_id'], unique=False)
|
||||
op.alter_column('esrv_whitelisted_ips', 'created_at',
|
||||
existing_type=sa.DateTime(),
|
||||
type_=sa.TIMESTAMP(),
|
||||
existing_nullable=True,
|
||||
existing_server_default=sa.text("'2025-05-31 00:00:00'"))
|
||||
op.create_index(op.f('idx_esrv_users_email'), 'esrv_users', ['email'], unique=False)
|
||||
op.create_index(op.f('idx_esrv_users_domain'), 'esrv_users', ['domain_id'], unique=False)
|
||||
op.alter_column('esrv_users', 'created_at',
|
||||
existing_type=sa.DateTime(),
|
||||
type_=sa.TIMESTAMP(),
|
||||
existing_nullable=True,
|
||||
existing_server_default=sa.text("'2025-05-31 00:00:00'"))
|
||||
op.add_column('esrv_email_logs', sa.Column('timestamp', sa.DATETIME(), nullable=False))
|
||||
op.add_column('esrv_email_logs', sa.Column('mail_from', sa.VARCHAR(), nullable=False))
|
||||
op.add_column('esrv_email_logs', sa.Column('message_id', sa.VARCHAR(), nullable=False))
|
||||
op.add_column('esrv_email_logs', sa.Column('peer', sa.VARCHAR(), nullable=False))
|
||||
op.add_column('esrv_email_logs', sa.Column('dkim_signed', sa.BOOLEAN(), nullable=True))
|
||||
op.add_column('esrv_email_logs', sa.Column('content', sa.TEXT(), nullable=False))
|
||||
op.add_column('esrv_email_logs', sa.Column('rcpt_tos', sa.VARCHAR(), nullable=False))
|
||||
op.create_index(op.f('idx_esrv_email_logs_timestamp'), 'esrv_email_logs', ['timestamp'], unique=False)
|
||||
op.create_index(op.f('idx_esrv_email_logs_mail_from'), 'esrv_email_logs', ['mail_from'], unique=False)
|
||||
op.drop_column('esrv_email_logs', 'created_at')
|
||||
op.drop_column('esrv_email_logs', 'message')
|
||||
op.drop_column('esrv_email_logs', 'subject')
|
||||
op.drop_column('esrv_email_logs', 'to_address')
|
||||
op.drop_column('esrv_email_logs', 'from_address')
|
||||
op.add_column('esrv_domains', sa.Column('requires_auth', sa.BOOLEAN(), nullable=True))
|
||||
op.alter_column('esrv_domains', 'created_at',
|
||||
existing_type=sa.DateTime(),
|
||||
type_=sa.TIMESTAMP(),
|
||||
existing_nullable=True,
|
||||
existing_server_default=sa.text("'2025-05-31 00:00:00'"))
|
||||
op.create_index(op.f('idx_esrv_dkim_keys_domain'), 'esrv_dkim_keys', ['domain_id'], unique=False)
|
||||
op.create_index(op.f('idx_esrv_custom_headers_domain'), 'esrv_custom_headers', ['domain_id'], unique=False)
|
||||
op.alter_column('esrv_custom_headers', 'created_at',
|
||||
existing_type=sa.DateTime(),
|
||||
type_=sa.TIMESTAMP(),
|
||||
existing_nullable=True,
|
||||
existing_server_default=sa.text("'2025-05-31 00:00:00'"))
|
||||
op.add_column('esrv_auth_logs', sa.Column('username', sa.VARCHAR(), nullable=True))
|
||||
op.add_column('esrv_auth_logs', sa.Column('timestamp', sa.DATETIME(), nullable=False))
|
||||
op.add_column('esrv_auth_logs', sa.Column('peer', sa.VARCHAR(), nullable=False))
|
||||
op.alter_column('esrv_auth_logs', 'message',
|
||||
existing_type=sa.Text(),
|
||||
type_=sa.VARCHAR(),
|
||||
nullable=False)
|
||||
op.drop_column('esrv_auth_logs', 'created_at')
|
||||
op.drop_column('esrv_auth_logs', 'ip_address')
|
||||
op.drop_column('esrv_auth_logs', 'identifier')
|
||||
op.drop_column('esrv_auth_logs', 'auth_type')
|
||||
# ### end Alembic commands ###
|
||||
@@ -0,0 +1,42 @@
|
||||
"""Add legacy EmailLog columns for backward compatibility
|
||||
|
||||
Revision ID: d02f993649e8
|
||||
Revises: 53036910f343
|
||||
Create Date: 2025-06-01 11:50:54.362830
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'd02f993649e8'
|
||||
down_revision: Union[str, None] = '53036910f343'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# Add legacy columns for backward compatibility with existing EmailRelay code
|
||||
op.add_column('esrv_email_logs', sa.Column('message_id', sa.String(), nullable=True))
|
||||
op.add_column('esrv_email_logs', sa.Column('timestamp', sa.DateTime(), nullable=True))
|
||||
op.add_column('esrv_email_logs', sa.Column('peer', sa.String(), nullable=True))
|
||||
op.add_column('esrv_email_logs', sa.Column('mail_from', sa.String(), nullable=True))
|
||||
op.add_column('esrv_email_logs', sa.Column('rcpt_tos', sa.String(), nullable=True))
|
||||
op.add_column('esrv_email_logs', sa.Column('content', sa.Text(), nullable=True))
|
||||
op.add_column('esrv_email_logs', sa.Column('dkim_signed', sa.Boolean(), nullable=True, default=False))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# Remove the legacy columns
|
||||
op.drop_column('esrv_email_logs', 'dkim_signed')
|
||||
op.drop_column('esrv_email_logs', 'content')
|
||||
op.drop_column('esrv_email_logs', 'rcpt_tos')
|
||||
op.drop_column('esrv_email_logs', 'mail_from')
|
||||
op.drop_column('esrv_email_logs', 'peer')
|
||||
op.drop_column('esrv_email_logs', 'timestamp')
|
||||
op.drop_column('esrv_email_logs', 'message_id')
|
||||
Reference in New Issue
Block a user