Major fixes and new features
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
34
alembic/versions/49846a45b6b0_add_username_to_users_table.py
Normal file
34
alembic/versions/49846a45b6b0_add_username_to_users_table.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""add_username_to_users_table
|
||||
|
||||
Revision ID: 49846a45b6b0
|
||||
Revises: 050c22851c2d
|
||||
Create Date: 2025-09-25 14:11:11.985379
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '49846a45b6b0'
|
||||
down_revision = '050c22851c2d'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Добавляем колонку username в таблицу users
|
||||
op.add_column('users', sa.Column('username', sa.String(50), nullable=True, unique=True, index=True))
|
||||
|
||||
# Заполняем значения username на основе email (первая часть до @)
|
||||
op.execute("""
|
||||
UPDATE users
|
||||
SET username = split_part(email, '@', 1)
|
||||
""")
|
||||
|
||||
# В будущем можно сделать эту колонку not null, но пока оставим nullable
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# Удаляем колонку username из таблицы users
|
||||
op.drop_column('users', 'username')
|
||||
Reference in New Issue
Block a user