Skip to content

Remove old constraint #872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions inbox/models/backends/imap.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ class ImapUid(MailSyncBase, UpdatedAtMixin, DeletedAtMixin):
message = relationship(Message, backref=backref("imapuids", passive_deletes=True))
msg_uid = Column(BigInteger, nullable=False, index=True)

folder_id = Column(ForeignKey(Folder.id, ondelete="CASCADE"), nullable=False)
folder_id = Column(
ForeignKey(Folder.id, ondelete="CASCADE"), nullable=False, index=True
)
# We almost always need the folder name too, so eager load by default.
folder = relationship(
Folder, lazy="joined", backref=backref("imapuids", passive_deletes=True)
Expand Down Expand Up @@ -216,7 +218,6 @@ def categories(self) -> Set[Category]:
return categories

__table_args__ = (
UniqueConstraint("folder_id", "msg_uid", "account_id"),
# This index is used to quickly retrieve IMAP uids
# in local_uids and lastseenuid functions.
# Those queries consistently stay in top 5 most busy SELECTs
Expand Down
27 changes: 27 additions & 0 deletions migrations/versions/262_drop_folder_id_unique_constraint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""drop folder_id unique constraint

Revision ID: ac2d6f8489bb
Revises: e3cf974d07a5
Create Date: 2024-09-03 09:23:07.779381

"""

# revision identifiers, used by Alembic.
revision = "ac2d6f8489bb"
down_revision = "e3cf974d07a5"

from alembic import op


def upgrade():
op.create_index("folder_id_new", "imapuid", ["folder_id"])
op.drop_index("folder_id", table_name="imapuid")
op.execute("ALTER TABLE imapuid RENAME INDEX folder_id_new TO folder_id")


def downgrade():
op.create_index(
"folder_id_old", "imapuid", ["folder_id", "msg_uid", "account_id"], unique=True
)
op.drop_index("folder_id", table_name="imapuid")
op.execute("ALTER TABLE imapuid RENAME INDEX folder_id_old TO folder_id")