diff --git a/inbox/models/backends/imap.py b/inbox/models/backends/imap.py index 16886495e..d9ccfd58c 100644 --- a/inbox/models/backends/imap.py +++ b/inbox/models/backends/imap.py @@ -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) diff --git a/migrations/versions/262_drop_folder_id_unique_constraint.py b/migrations/versions/262_drop_folder_id_unique_constraint.py new file mode 100644 index 000000000..0629beac1 --- /dev/null +++ b/migrations/versions/262_drop_folder_id_unique_constraint.py @@ -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")