Skip to content

Commit

Permalink
Delete username unique index from User table
Browse files Browse the repository at this point in the history
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 <dacho@redhat.com>
  • Loading branch information
dcho5 authored and brunoapimentel committed Dec 22, 2021
1 parent 2d19dce commit 92c823c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion cachito/web/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 92c823c

Please sign in to comment.