39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
"""add column username to user
|
|
|
|
Revision ID: 379f1fcae26d
|
|
Revises: 460871bfa69e
|
|
Create Date: 2025-05-07 10:54:40.589081
|
|
|
|
"""
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '379f1fcae26d'
|
|
down_revision = '460871bfa69e'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
def upgrade():
|
|
bind = op.get_bind()
|
|
|
|
op.add_column('users', sa.Column('username', sa.String(length=80), nullable=True))
|
|
bind.execute(sa.text("UPDATE users SET username=displayname"))
|
|
|
|
if bind.dialect.name == 'postgresql':
|
|
# PostgreSQL: Direct alter column works
|
|
op.alter_column('users', 'username', nullable=False)
|
|
else:
|
|
# SQLite: Use batch mode to alter column nullable constraint
|
|
with op.batch_alter_table('users', schema=None) as batch_op:
|
|
batch_op.alter_column('username',
|
|
existing_type=sa.String(length=80),
|
|
nullable=False)
|
|
|
|
|
|
def downgrade():
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.drop_column('users', 'username')
|
|
# ### end Alembic commands ###
|