add join table between portfolio_roles and roles
This commit is contained in:
parent
b711330b9e
commit
31bcb662b5
@ -0,0 +1,33 @@
|
||||
"""add permission sets to portfolio_role
|
||||
|
||||
Revision ID: 938a31795096
|
||||
Revises: db161adbafdf
|
||||
Create Date: 2019-03-07 06:13:05.400911
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '938a31795096'
|
||||
down_revision = 'db161adbafdf'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('portfolio_roles_roles',
|
||||
sa.Column('portfolio_role_id', postgresql.UUID(as_uuid=True), nullable=True),
|
||||
sa.Column('role_id', postgresql.UUID(as_uuid=True), nullable=True),
|
||||
sa.ForeignKeyConstraint(['portfolio_role_id'], ['portfolio_roles.id'], ),
|
||||
sa.ForeignKeyConstraint(['role_id'], ['roles.id'], )
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('portfolio_roles_roles')
|
||||
# ### end Alembic commands ###
|
@ -1,5 +1,5 @@
|
||||
from enum import Enum
|
||||
from sqlalchemy import Index, ForeignKey, Column, Enum as SQLAEnum
|
||||
from sqlalchemy import Index, ForeignKey, Column, Enum as SQLAEnum, Table
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
@ -30,6 +30,14 @@ class Status(Enum):
|
||||
PENDING = "pending"
|
||||
|
||||
|
||||
portfolio_roles_roles = Table(
|
||||
"portfolio_roles_roles",
|
||||
Base.metadata,
|
||||
Column("portfolio_role_id", UUID(as_uuid=True), ForeignKey("portfolio_roles.id")),
|
||||
Column("role_id", UUID(as_uuid=True), ForeignKey("roles.id")),
|
||||
)
|
||||
|
||||
|
||||
class PortfolioRole(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
||||
__tablename__ = "portfolio_roles"
|
||||
|
||||
@ -48,6 +56,8 @@ class PortfolioRole(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
||||
|
||||
status = Column(SQLAEnum(Status, native_enum=False), default=Status.PENDING)
|
||||
|
||||
permission_sets = relationship("Role", secondary=portfolio_roles_roles)
|
||||
|
||||
def __repr__(self):
|
||||
return "<PortfolioRole(role='{}', portfolio='{}', user_id='{}', id='{}')>".format(
|
||||
self.role.name, self.portfolio.name, self.user_id, self.id
|
||||
|
Loading…
x
Reference in New Issue
Block a user