Added migration script
This commit is contained in:
parent
7b5a3f9eb9
commit
603c1aa71e
2 changed files with 31 additions and 2 deletions
|
@ -30,10 +30,8 @@ def upgrade():
|
||||||
|
|
||||||
# Insert default role "admin" as ID 1
|
# Insert default role "admin" as ID 1
|
||||||
op.execute(sa.insert(role_table).values(id=1,name="admin"))
|
op.execute(sa.insert(role_table).values(id=1,name="admin"))
|
||||||
op.execute(sa.insert(role_table).values(id=2,name="user"))
|
|
||||||
# Set role_id 1 to all current "admin" users
|
# Set role_id 1 to all current "admin" users
|
||||||
op.execute("UPDATE app_role SET role_id = 1 WHERE role = 'admin'")
|
op.execute("UPDATE app_role SET role_id = 1 WHERE role = 'admin'")
|
||||||
op.execute("UPDATE app_role SET role_id = 2 WHERE role = 'user'")
|
|
||||||
|
|
||||||
# Drop old column
|
# Drop old column
|
||||||
op.drop_column("app_role", "role")
|
op.drop_column("app_role", "role")
|
||||||
|
|
31
migrations/versions/b514cca2d47b_add_user_role.py
Normal file
31
migrations/versions/b514cca2d47b_add_user_role.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
"""add user role
|
||||||
|
|
||||||
|
Revision ID: b514cca2d47b
|
||||||
|
Revises: 5f462d2d9d25
|
||||||
|
Create Date: 2022-06-08 17:24:51.305129
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'b514cca2d47b'
|
||||||
|
down_revision = '5f462d2d9d25'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
# Insert role "user" as ID 2
|
||||||
|
op.execute("INSERT INTO `role` (id, `name`) VALUES (2, 'user')")
|
||||||
|
# Set role_id 2 to all current "user" users which by have NULL role ID
|
||||||
|
op.execute("UPDATE app_role SET role_id = 2 WHERE role_id IS NULL")
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.execute("UPDATE app_role SET role_id = NULL WHERE role_id = 2")
|
||||||
|
op.execute("DELETE FROM `role` WHERE id = 2")
|
||||||
|
pass
|
Loading…
Reference in a new issue