Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added response version to db #1112

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/app/responses/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def post(self):
if not application_form.nominations and len(responses) > 0:
return errors.RESPONSE_ALREADY_SUBMITTED

response = Response(application_form_id, user_id, language)
response = Response(application_form_id, user_id, len(responses) + 1 , 1, language)
if is_submitted:
response.submit()

Expand Down
6 changes: 5 additions & 1 deletion api/app/responses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Response(db.Model):
__tablename__ = "response"

id = db.Column(db.Integer(), primary_key=True)
submission_id = db.Column(db.Integer(), nullable=False)
version_id = db.Column(db.Integer(), nullable=False)
application_form_id = db.Column(db.Integer(), db.ForeignKey("application_form.id"), nullable=False)
user_id = db.Column(db.Integer(), db.ForeignKey("app_user.id"), nullable=False)
is_submitted = db.Column(db.Boolean(), nullable=False)
Expand All @@ -29,9 +31,11 @@ class Response(db.Model):
response_tags = db.relationship('ResponseTag')
reviewers = db.relationship('ResponseReviewer')

def __init__(self, application_form_id, user_id, language):
def __init__(self, application_form_id, user_id, submission_id, version_id, language):
self.application_form_id = application_form_id
self.user_id = user_id
self.submission_id = submission_id
self.version_id = version_id
self.is_submitted = False
self.submitted_timestamp = None
self.is_withdrawn = False
Expand Down
34 changes: 34 additions & 0 deletions api/migrations/versions/094f072eb68b_add_version_to_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Add submission and revision id for response and answer

Revision ID: 094f072eb68b
Revises: 6a073dd1e30d
Create Date: 2023-03-26 20:53:06.593375

"""

# revision identifiers, used by Alembic.
revision = '094f072eb68b'
down_revision = '6a073dd1e30d'

from alembic import op
import sqlalchemy as sa


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('response', sa.Column('submission_id', sa.Integer(), nullable=True))
op.add_column('response', sa.Column('version_id', sa.Integer(), nullable=True))

op.create_unique_constraint('responses_key', 'response', ['id', 'submission_id', 'version_id'])
op.execute("""UPDATE response SET submission_id = 1, version_id = 1;""")

op.alter_column('response', sa.Column('submission_id', sa.Integer(), nullable=False))
op.alter_column('response', sa.Column('version_id', sa.Integer(), nullable=False))

# ### end Alembic commands ###

def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('response', 'version_id')
op.drop_column('response', 'submission_id')
# ### end Alembic commands ###