Skip to content

Commit

Permalink
[#21] Add repeat column to answer table
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Sep 14, 2023
1 parent d0fe7ad commit b80856e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""add_repeat_column_to_answer_table
Revision ID: 8cd69d641604
Revises: 19c05e6b7198
Create Date: 2023-09-14 04:35:33.215673
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '8cd69d641604'
down_revision = '19c05e6b7198'
branch_labels = None
depends_on = None


def upgrade() -> None:
op.add_column(
"answer",
sa.Column("repeat", sa.Integer(), nullable=True, default=None)
)


def downgrade() -> None:
op.drop_column("answer", "repeat")
7 changes: 6 additions & 1 deletion dev/backend/models/answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,21 @@ class Answer(Base):
text = Column(Text, nullable=True)
value = Column(Float, nullable=True)
options = Column(pg.ARRAY(String), nullable=True)
repeat = Column(Integer, nullable=True)

def __init__(self,
question: int,
data: Optional[int] = None,
text: Optional[str] = None,
value: Optional[float] = None,
options: Optional[List[str]] = None):
options: Optional[List[str]] = None,
repeat: Optional[int] = None):
self.question = question
self.data = data
self.text = text
self.value = value
self.options = options
self.repeat = repeat

def __repr__(self) -> int:
return f"<Answer {self.id}>"
Expand All @@ -57,6 +60,7 @@ def serialize(self) -> AnswerDict:
"text": self.text,
"value": self.value,
"options": self.options,
"repeat": self.repeat
}

@property
Expand Down Expand Up @@ -88,6 +92,7 @@ class AnswerBase(BaseModel):
text: Optional[str] = None
value: Optional[float] = None
options: Optional[List[str]] = None
repeat: Optional[int] = None

class Config:
orm_mode = True

0 comments on commit b80856e

Please sign in to comment.