31 lines
748 B
Python
31 lines
748 B
Python
"""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
|