Add migration for EnvironmentRole
This commit is contained in:
parent
c00b136c1f
commit
e5a0d69844
@ -0,0 +1,38 @@
|
|||||||
|
"""create environment_roles table
|
||||||
|
|
||||||
|
Revision ID: c1d074288e99
|
||||||
|
Revises: 06aa23166ca9
|
||||||
|
Create Date: 2018-09-06 13:40:12.332241
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'c1d074288e99'
|
||||||
|
down_revision = '06aa23166ca9'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('environment_roles',
|
||||||
|
sa.Column('id', postgresql.UUID(as_uuid=True), server_default=sa.text('uuid_generate_v4()'), nullable=False),
|
||||||
|
sa.Column('environment_id', postgresql.UUID(as_uuid=True), nullable=True),
|
||||||
|
sa.Column('role', sa.String(), nullable=True),
|
||||||
|
sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=True),
|
||||||
|
sa.ForeignKeyConstraint(['environment_id'], ['environments.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_index('environments_role_user_environment', 'environment_roles', ['user_id', 'environment_id'], unique=True)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_index('environments_role_user_environment', table_name='environment_roles')
|
||||||
|
op.drop_table('environment_roles')
|
||||||
|
# ### end Alembic commands ###
|
32
atst/models/environment_role.py
Normal file
32
atst/models/environment_role.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
from enum import Enum
|
||||||
|
from sqlalchemy import Index, ForeignKey, Column, String
|
||||||
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
|
from atst.models import Base
|
||||||
|
from .types import Id
|
||||||
|
|
||||||
|
|
||||||
|
class CSPRole(Enum):
|
||||||
|
NONSENSE_ROLE = "nonesense_role"
|
||||||
|
|
||||||
|
|
||||||
|
class EnvironmentRole(Base):
|
||||||
|
__tablename__ = "environment_roles"
|
||||||
|
|
||||||
|
id = Id()
|
||||||
|
environment_id = Column(UUID(as_uuid=True), ForeignKey("environments.id"))
|
||||||
|
environment = relationship("Environment", backref="roles")
|
||||||
|
|
||||||
|
role = Column(String())
|
||||||
|
|
||||||
|
user_id = Column(UUID(as_uuid=True), ForeignKey("users.id"))
|
||||||
|
user = relationship("User", backref="environment_roles")
|
||||||
|
|
||||||
|
|
||||||
|
Index(
|
||||||
|
"environments_role_user_environment",
|
||||||
|
EnvironmentRole.user_id,
|
||||||
|
EnvironmentRole.environment_id,
|
||||||
|
unique=True,
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user