-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add case insensitive constraint to username (#27266)
This helps us to recognize usernames properly (cherry picked from commit 1d25105)
- Loading branch information
1 parent
9f6c9e4
commit 51194c7
Showing
7 changed files
with
179 additions
and
8 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
...low/migrations/versions/0119_2_4_3_add_case_insensitive_unique_constraint_for_username.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
"""Add case-insensitive unique constraint for username | ||
Revision ID: e07f49787c9d | ||
Revises: b0d31815b5a6 | ||
Create Date: 2022-10-25 17:29:46.432326 | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'e07f49787c9d' | ||
down_revision = 'b0d31815b5a6' | ||
branch_labels = None | ||
depends_on = None | ||
airflow_version = '2.4.3' | ||
|
||
|
||
def upgrade(): | ||
"""Apply Add case-insensitive unique constraint""" | ||
conn = op.get_bind() | ||
if conn.dialect.name == 'postgresql': | ||
op.create_index('idx_ab_user_username', 'ab_user', [sa.text('LOWER(username)')], unique=True) | ||
op.create_index( | ||
"idx_ab_register_user_username", 'ab_register_user', [sa.text('LOWER(username)')], unique=True | ||
) | ||
elif conn.dialect.name == 'sqlite': | ||
with op.batch_alter_table('ab_user') as batch_op: | ||
batch_op.alter_column( | ||
'username', | ||
existing_type=sa.String(64), | ||
_type=sa.String(64, collation='NOCASE'), | ||
unique=True, | ||
nullable=False, | ||
) | ||
with op.batch_alter_table('ab_register_user') as batch_op: | ||
batch_op.alter_column( | ||
'username', | ||
existing_type=sa.String(64), | ||
_type=sa.String(64, collation='NOCASE'), | ||
unique=True, | ||
nullable=False, | ||
) | ||
|
||
|
||
def downgrade(): | ||
"""Unapply Add case-insensitive unique constraint""" | ||
conn = op.get_bind() | ||
if conn.dialect.name == 'postgresql': | ||
op.drop_index('idx_ab_user_username', table_name='ab_user') | ||
op.drop_index('idx_ab_register_user_username', table_name='ab_register_user') | ||
elif conn.dialect.name == 'sqlite': | ||
with op.batch_alter_table('ab_user') as batch_op: | ||
batch_op.alter_column( | ||
'username', | ||
existing_type=sa.String(64, collation='NOCASE'), | ||
_type=sa.String(64), | ||
unique=True, | ||
nullable=False, | ||
) | ||
with op.batch_alter_table('ab_register_user') as batch_op: | ||
batch_op.alter_column( | ||
'username', | ||
existing_type=sa.String(64, collation='NOCASE'), | ||
_type=sa.String(64), | ||
unique=True, | ||
nullable=False, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
a522ff773bc6403318e4a15be19f25d48323208de3acc8a970f7f40ad4782563 | ||
88fe8ef077e673c69080ac260baa0bab33d9189035c0dea5cc652c990ef44ee8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters