Convert role column to a new table
This commit is contained in:
parent
f377b4ce45
commit
7661088814
4 changed files with 54 additions and 2 deletions
|
@ -23,7 +23,7 @@ class AppRole(db.Model):
|
||||||
|
|
||||||
user_id = db.Column(String(length=64), primary_key=True)
|
user_id = db.Column(String(length=64), primary_key=True)
|
||||||
app_id = db.Column(Integer, ForeignKey("app.id"), primary_key=True)
|
app_id = db.Column(Integer, ForeignKey("app.id"), primary_key=True)
|
||||||
role = db.Column(String(length=64))
|
role_id = db.Column(Integer, ForeignKey("role.id"))
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"{self.role} for {self.user_id} on {self.app_id}"
|
return f"{self.role} for {self.user_id} on {self.app_id}"
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
from .users import *
|
from .users import *
|
||||||
|
from .models import *
|
||||||
|
|
10
areas/users/models.py
Normal file
10
areas/users/models.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
from sqlalchemy import Integer, String
|
||||||
|
from database import db
|
||||||
|
|
||||||
|
|
||||||
|
class Role(db.Model):
|
||||||
|
id = db.Column(Integer, primary_key=True)
|
||||||
|
name = db.Column(String(length=64))
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"Role {self.name}"
|
|
@ -0,0 +1,41 @@
|
||||||
|
"""convert role column to table
|
||||||
|
|
||||||
|
Revision ID: 5f462d2d9d25
|
||||||
|
Revises: 27761560bbcb
|
||||||
|
Create Date: 2022-04-13 15:00:27.182898
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import mysql
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = "5f462d2d9d25"
|
||||||
|
down_revision = "27761560bbcb"
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table(
|
||||||
|
"role",
|
||||||
|
sa.Column("id", sa.Integer(), nullable=False),
|
||||||
|
sa.Column("name", sa.String(length=64), nullable=True),
|
||||||
|
sa.PrimaryKeyConstraint("id"),
|
||||||
|
)
|
||||||
|
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 ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.add_column(
|
||||||
|
"app_role", sa.Column("role", mysql.VARCHAR(length=64), nullable=True)
|
||||||
|
)
|
||||||
|
op.drop_constraint(None, "app_role", type_="foreignkey")
|
||||||
|
op.drop_column("app_role", "role_id")
|
||||||
|
op.drop_table("role")
|
||||||
|
# ### end Alembic commands ###
|
Loading…
Reference in a new issue