diff --git a/app/models.py b/app/models.py index 799b07a12..721f95dc6 100644 --- a/app/models.py +++ b/app/models.py @@ -2075,7 +2075,11 @@ def __repr__(self): class EmailLog(Base, ModelMixin): __tablename__ = "email_log" - __table_args__ = (Index("ix_email_log_created_at", "created_at"),) + __table_args__ = ( + Index("ix_email_log_created_at", "created_at"), + Index("ix_email_log_mailbox_id", "mailbox_id"), + Index("ix_email_log_bounced_mailbox_id", "bounced_mailbox_id"), + ) user_id = sa.Column( sa.ForeignKey(User.id, ondelete="cascade"), nullable=False, index=True diff --git a/migrations/versions/2024_111410_12274da2299f_add_missing_indices_on_email_log.py b/migrations/versions/2024_111410_12274da2299f_add_missing_indices_on_email_log.py new file mode 100644 index 000000000..96de71424 --- /dev/null +++ b/migrations/versions/2024_111410_12274da2299f_add_missing_indices_on_email_log.py @@ -0,0 +1,29 @@ +"""add missing indices on email log + +Revision ID: 12274da2299f +Revises: 842ac670096e +Create Date: 2024-11-14 10:27:20.371191 + +""" +import sqlalchemy_utils +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '12274da2299f' +down_revision = '842ac670096e' +branch_labels = None +depends_on = None + + +def upgrade(): + with op.get_context().autocommit_block(): + op.create_index('ix_email_log_bounced_mailbox_id', 'email_log', ['bounced_mailbox_id'], unique=False) + op.create_index('ix_email_log_mailbox_id', 'email_log', ['mailbox_id'], unique=False) + + +def downgrade(): + with op.get_context().autocommit_block(): + op.drop_index('ix_email_log_mailbox_id', table_name='email_log') + op.drop_index('ix_email_log_bounced_mailbox_id', table_name='email_log')