set role_id for all admin users so no admin role data gets lost during migration
This commit is contained in:
parent
b494650398
commit
932f3c4fcb
1 changed files with 9 additions and 2 deletions
|
@ -18,7 +18,7 @@ depends_on = None
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
op.create_table(
|
role_table = op.create_table(
|
||||||
"role",
|
"role",
|
||||||
sa.Column("id", sa.Integer(), nullable=False),
|
sa.Column("id", sa.Integer(), nullable=False),
|
||||||
sa.Column("name", sa.String(length=64), nullable=True),
|
sa.Column("name", sa.String(length=64), nullable=True),
|
||||||
|
@ -26,9 +26,16 @@ def upgrade():
|
||||||
)
|
)
|
||||||
op.add_column("app_role", sa.Column("role_id", sa.Integer(), nullable=True))
|
op.add_column("app_role", sa.Column("role_id", sa.Integer(), nullable=True))
|
||||||
op.create_foreign_key(None, "app_role", "role", ["role_id"], ["id"])
|
op.create_foreign_key(None, "app_role", "role", ["role_id"], ["id"])
|
||||||
op.drop_column("app_role", "role")
|
|
||||||
# ### end Alembic commands ###
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
# Insert default role "admin" as ID 1
|
||||||
|
op.execute(sa.insert(role_table).values(id=1,name="admin"))
|
||||||
|
# Set role_id 1 to all current "admin" users
|
||||||
|
op.execute("UPDATE app_role SET role_id = 1 WHERE role = 'admin'")
|
||||||
|
|
||||||
|
# Drop old column
|
||||||
|
op.drop_column("app_role", "role")
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
|
Loading…
Reference in a new issue