Files
chat/alembic/versions/49846a45b6b0_add_username_to_users_table.py
Andrew K. Choi ddce9f5125
All checks were successful
continuous-integration/drone/push Build is passing
Major fixes and new features
2025-09-25 15:51:48 +09:00

34 lines
979 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""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')