From 932f3c4fcbfc260f7a7d48f3cf31aa8a72697ec6 Mon Sep 17 00:00:00 2001 From: Maarten de Waard Date: Fri, 15 Apr 2022 11:11:15 +0200 Subject: [PATCH] set role_id for all admin users so no admin role data gets lost during migration --- .../5f462d2d9d25_convert_role_column_to_table.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/migrations/versions/5f462d2d9d25_convert_role_column_to_table.py b/migrations/versions/5f462d2d9d25_convert_role_column_to_table.py index c315ddd..53a8a1d 100644 --- a/migrations/versions/5f462d2d9d25_convert_role_column_to_table.py +++ b/migrations/versions/5f462d2d9d25_convert_role_column_to_table.py @@ -18,7 +18,7 @@ depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_table( + role_table = op.create_table( "role", sa.Column("id", sa.Integer(), nullable=False), 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.create_foreign_key(None, "app_role", "role", ["role_id"], ["id"]) - op.drop_column("app_role", "role") # ### 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(): # ### commands auto generated by Alembic - please adjust! ###