WIP: created Project and Environment models

This commit is contained in:
richard-dds 2018-08-17 11:35:21 -04:00
parent 01778ada05
commit 8d58b2a7a0
6 changed files with 92 additions and 2 deletions

View 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 ###

View File

@ -11,3 +11,5 @@ from .workspace_role import WorkspaceRole
from .pe_number import PENumber
from .task_order import TaskOrder
from .workspace import Workspace
from .project import Project
from .environment import Environment

View 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
View 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")

View File

@ -10,11 +10,11 @@ class Workspace(Base, TimestampsMixin):
__tablename__ = "workspaces"
id = Id()
name = Column(String, unique=True)
request_id = Column(ForeignKey("requests.id"), nullable=False)
request = relationship("Request")
name = Column(String, unique=True)
projects = relationship("Project", back_populates="workspace")
@property
def owner(self):

View File

@ -42,3 +42,10 @@ def test_creating_workspace_adds_owner():
workspace_user = WorkspaceUsers.get(workspace.id, user.id)
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