Skip to content

Commit

Permalink
Migration
Browse files Browse the repository at this point in the history
  • Loading branch information
squeaky-pl committed Oct 29, 2024
1 parent 008ac6b commit 7ca0518
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion 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
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")

0 comments on commit 7ca0518

Please sign in to comment.