From 100048afdf5c7744f7b7d06029f54d0fdeb84244 Mon Sep 17 00:00:00 2001 From: richard-dds Date: Tue, 11 Sep 2018 15:33:31 -0400 Subject: [PATCH] Add Request.internal_comments Using a one to one relationship to avoid the migration hell that we're temporarily stuck in. --- ...2be7fb7fc_add_request_internal_comments.py | 36 +++++++++++++++++++ atst/models/__init__.py | 1 + atst/models/request.py | 2 ++ atst/models/request_internal_comment.py | 16 +++++++++ 4 files changed, 55 insertions(+) create mode 100644 alembic/versions/2572be7fb7fc_add_request_internal_comments.py create mode 100644 atst/models/request_internal_comment.py diff --git a/alembic/versions/2572be7fb7fc_add_request_internal_comments.py b/alembic/versions/2572be7fb7fc_add_request_internal_comments.py new file mode 100644 index 00000000..f17ee18e --- /dev/null +++ b/alembic/versions/2572be7fb7fc_add_request_internal_comments.py @@ -0,0 +1,36 @@ +"""add request.internal_comments + +Revision ID: 2572be7fb7fc +Revises: dea6b8e09d63 +Create Date: 2018-09-11 15:28:27.252248 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = '2572be7fb7fc' +down_revision = 'dea6b8e09d63' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('request_internal_comments', + sa.Column('id', sa.BigInteger(), nullable=False), + sa.Column('text', sa.String(), nullable=True), + sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('request_id', postgresql.UUID(as_uuid=True), nullable=True), + sa.ForeignKeyConstraint(['request_id'], ['requests.id'], ondelete='CASCADE'), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('request_internal_comments') + # ### end Alembic commands ### diff --git a/atst/models/__init__.py b/atst/models/__init__.py index 245e3806..0b8a95df 100644 --- a/atst/models/__init__.py +++ b/atst/models/__init__.py @@ -16,3 +16,4 @@ from .environment import Environment from .attachment import Attachment from .request_revision import RequestRevision from .request_review import RequestReview +from .request_internal_comment import RequestInternalComment diff --git a/atst/models/request.py b/atst/models/request.py index 8205410c..2462c60f 100644 --- a/atst/models/request.py +++ b/atst/models/request.py @@ -46,6 +46,8 @@ class Request(Base): "RequestRevision", back_populates="request", order_by="RequestRevision.sequence" ) + internal_comments = relationship("RequestInternalComment", uselist=False) + @property def latest_revision(self): if self.revisions: diff --git a/atst/models/request_internal_comment.py b/atst/models/request_internal_comment.py new file mode 100644 index 00000000..f3633910 --- /dev/null +++ b/atst/models/request_internal_comment.py @@ -0,0 +1,16 @@ +from sqlalchemy import Column, BigInteger, String, ForeignKey +from sqlalchemy.orm import relationship + +from atst.models import Base + + +class RequestInternalComment(Base): + __tablename__ = "request_internal_comments" + + id = Column(BigInteger, primary_key=True) + text = Column(String()) + + user_id = Column(ForeignKey("users.id"), nullable=False) + user = relationship("User") + + request_id = Column(ForeignKey("requests.id", ondelete="CASCADE"))