WIP: created Project and Environment models
This commit is contained in:
parent
01778ada05
commit
8d58b2a7a0
47
alembic/versions/f064247f2988_projects_and_environments.py
Normal file
47
alembic/versions/f064247f2988_projects_and_environments.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
"""projects and environments
|
||||||
|
|
||||||
|
Revision ID: f064247f2988
|
||||||
|
Revises: a2b499a1dd62
|
||||||
|
Create Date: 2018-08-17 11:30:53.684954
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'f064247f2988'
|
||||||
|
down_revision = 'a2b499a1dd62'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('projects',
|
||||||
|
sa.Column('time_created', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.Column('time_updated', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.Column('id', postgresql.UUID(as_uuid=True), server_default=sa.text('uuid_generate_v4()'), nullable=False),
|
||||||
|
sa.Column('name', sa.String(), nullable=False),
|
||||||
|
sa.Column('description', sa.String(), nullable=False),
|
||||||
|
sa.Column('workspace_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['workspace_id'], ['workspaces.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_table('environments',
|
||||||
|
sa.Column('time_created', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.Column('time_updated', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.Column('id', postgresql.UUID(as_uuid=True), server_default=sa.text('uuid_generate_v4()'), nullable=False),
|
||||||
|
sa.Column('name', sa.String(), nullable=False),
|
||||||
|
sa.Column('project_id', postgresql.UUID(as_uuid=True), nullable=True),
|
||||||
|
sa.ForeignKeyConstraint(['project_id'], ['projects.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_table('environments')
|
||||||
|
op.drop_table('projects')
|
||||||
|
# ### end Alembic commands ###
|
@ -11,3 +11,5 @@ from .workspace_role import WorkspaceRole
|
|||||||
from .pe_number import PENumber
|
from .pe_number import PENumber
|
||||||
from .task_order import TaskOrder
|
from .task_order import TaskOrder
|
||||||
from .workspace import Workspace
|
from .workspace import Workspace
|
||||||
|
from .project import Project
|
||||||
|
from .environment import Environment
|
||||||
|
16
atst/models/environment.py
Normal file
16
atst/models/environment.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
from sqlalchemy import Column, ForeignKey, String
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
|
from atst.models import Base
|
||||||
|
from atst.models.types import Id
|
||||||
|
from atst.models.mixins import TimestampsMixin
|
||||||
|
|
||||||
|
|
||||||
|
class Environment(Base, TimestampsMixin):
|
||||||
|
__tablename__ = "environments"
|
||||||
|
|
||||||
|
id = Id()
|
||||||
|
name = Column(String, nullable=False)
|
||||||
|
|
||||||
|
project_id = Column(ForeignKey("projects.id"))
|
||||||
|
project = relationship("Project")
|
18
atst/models/project.py
Normal file
18
atst/models/project.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from sqlalchemy import Column, ForeignKey, String
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
|
from atst.models import Base
|
||||||
|
from atst.models.types import Id
|
||||||
|
from atst.models.mixins import TimestampsMixin
|
||||||
|
|
||||||
|
|
||||||
|
class Project(Base, TimestampsMixin):
|
||||||
|
__tablename__ = "projects"
|
||||||
|
|
||||||
|
id = Id()
|
||||||
|
name = Column(String, nullable=False)
|
||||||
|
description = Column(String, nullable=False)
|
||||||
|
|
||||||
|
workspace_id = Column(ForeignKey("workspaces.id"), nullable=False)
|
||||||
|
workspace = relationship("Workspace")
|
||||||
|
projects = relationship("Environment", back_populates="project")
|
@ -10,11 +10,11 @@ class Workspace(Base, TimestampsMixin):
|
|||||||
__tablename__ = "workspaces"
|
__tablename__ = "workspaces"
|
||||||
|
|
||||||
id = Id()
|
id = Id()
|
||||||
|
name = Column(String, unique=True)
|
||||||
|
|
||||||
request_id = Column(ForeignKey("requests.id"), nullable=False)
|
request_id = Column(ForeignKey("requests.id"), nullable=False)
|
||||||
request = relationship("Request")
|
request = relationship("Request")
|
||||||
|
projects = relationship("Project", back_populates="workspace")
|
||||||
name = Column(String, unique=True)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def owner(self):
|
def owner(self):
|
||||||
|
@ -42,3 +42,10 @@ def test_creating_workspace_adds_owner():
|
|||||||
workspace_user = WorkspaceUsers.get(workspace.id, user.id)
|
workspace_user = WorkspaceUsers.get(workspace.id, user.id)
|
||||||
assert workspace_user.workspace_role
|
assert workspace_user.workspace_role
|
||||||
|
|
||||||
|
|
||||||
|
def test_workspace_has_timestamps():
|
||||||
|
request = RequestFactory.create()
|
||||||
|
workspace = Workspaces.create(request)
|
||||||
|
assert workspace.request == request
|
||||||
|
assert workspace.name == request.id
|
||||||
|
assert workspace.time_created == workspace.time_updated
|
||||||
|
Loading…
x
Reference in New Issue
Block a user