From 92c823ca74936d75868c4852e9f218ad9932e642 Mon Sep 17 00:00:00 2001 From: Daniel Cho Date: Wed, 15 Dec 2021 15:53:16 -0600 Subject: [PATCH] Delete username unique index from User table CLOUDBLD-7737 Cachito DB currently uses 'username' in table User as both unique constraint and unique index. Alembic will attempt to drop the unique constraint as they are redundant. To prevent this, drop ix_user_username - the unique index. Signed-off-by: Daniel Cho --- ...02229e089b24_delete_user_username_index.py | 26 +++++++++++++++++++ cachito/web/models.py | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 cachito/web/migrations/versions/02229e089b24_delete_user_username_index.py diff --git a/cachito/web/migrations/versions/02229e089b24_delete_user_username_index.py b/cachito/web/migrations/versions/02229e089b24_delete_user_username_index.py new file mode 100644 index 000000000..7382890e4 --- /dev/null +++ b/cachito/web/migrations/versions/02229e089b24_delete_user_username_index.py @@ -0,0 +1,26 @@ +"""Remove User.username unique index + +Revision ID: 02229e089b24 +Revises: 7d979987402d +Create Date: 2021-12-15 21:37:30.582812 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "02229e089b24" +down_revision = "7d979987402d" +branch_labels = None +depends_on = None + + +def upgrade(): + with op.batch_alter_table("user", schema=None) as batch_op: + batch_op.drop_index("ix_user_username") + + +def downgrade(): + with op.batch_alter_table("user", schema=None) as batch_op: + batch_op.create_index("ix_user_username", ["username"], unique=True) diff --git a/cachito/web/models.py b/cachito/web/models.py index 7c7607a20..88106efab 100644 --- a/cachito/web/models.py +++ b/cachito/web/models.py @@ -764,7 +764,7 @@ class User(db.Model, UserMixin): """Represents an external user that owns a Cachito request.""" id = db.Column(db.Integer, primary_key=True) - username = db.Column(db.String, index=True, unique=True, nullable=False) + username = db.Column(db.String, unique=True, nullable=False) requests = db.relationship("Request", foreign_keys=[Request.user_id], back_populates="user") @classmethod