Closed ReimarBauer closed 3 months ago
The mig script builder does the base but the created script needs first allow nullable so that we afterwards set the default for the existing data
Then the default is changed for the new attribute to nullable=False
cat e62d08ce88a4_to_version_9_0_0.py
"""To version 9.0.0
Revision ID: e62d08ce88a4
Revises: 27a026b0daec
Create Date: 2024-06-07 16:53:43.314338
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'e62d08ce88a4'
down_revision = '27a026b0daec'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.add_column(sa.Column('authentication_backend', sa.String(length=255), nullable=True))
op.execute('UPDATE users SET authentication_backend = \'local\' WHERE authentication_backend IS NULL')
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.alter_column('authentication_backend', existing_type=sa.String(length=255), nullable=False)
batch_op.drop_constraint('users_password_key', type_='unique')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.create_unique_constraint('users_password_key', ['password'])
batch_op.drop_column('authentication_backend')
# ### end Alembic commands ###
we have to add the migration script for the enhanced user authentication backends