Skip to content

Commit

Permalink
Make title field for tasks a string of 1024 characters (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
uittenbroekrobbert authored Aug 14, 2024
2 parents 3c58081 + dc98b25 commit c067603
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""change title length for task
Revision ID: 66cf279a7f62
Revises: 9ce2341f2922
Create Date: 2024-08-13 15:33:28.001811
"""

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "66cf279a7f62"
down_revision: str | None = "9ce2341f2922"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
with op.batch_alter_table("task", schema=None) as batch_op:
batch_op.alter_column(
"title", existing_type=sa.VARCHAR(length=255), type_=sa.String(length=1024), existing_nullable=False
)


def downgrade() -> None:
op.execute("UPDATE task SET title=SUBSTRING(title,1,255)")

with op.batch_alter_table("task", schema=None) as batch_op:
batch_op.alter_column(
"title", existing_type=sa.String(length=1024), type_=sa.VARCHAR(length=255), existing_nullable=False
)
4 changes: 2 additions & 2 deletions amt/models/task.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlalchemy import ForeignKey
from sqlalchemy import ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column

from amt.models.base import Base
Expand All @@ -8,7 +8,7 @@ class Task(Base):
__tablename__ = "task"

id: Mapped[int] = mapped_column(primary_key=True)
title: Mapped[str]
title: Mapped[str] = mapped_column(String(length=1024))
description: Mapped[str]
sort_order: Mapped[float]
status_id: Mapped[int | None] = mapped_column(default=None)
Expand Down
1 change: 1 addition & 0 deletions amt/repositories/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def save_all(self, tasks: Sequence[Task]) -> None:
self.session.add_all(tasks)
self.session.commit()
except Exception as e:
logger.exception("Could not store tasks")
self.session.rollback()
raise RepositoryError from e

Expand Down
4 changes: 3 additions & 1 deletion amt/services/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def create_instrument_tasks(self, tasks: Sequence[InstrumentTask], project: Proj
[
# TODO: (Christopher) The ticket does not specify what to do when question type is not an
# open questions, hence for now all titles will be set to task.question.
Task(title=task.question, description="", project_id=project.id, status_id=status, sort_order=idx)
Task(
title=task.question[:1024], description="", project_id=project.id, status_id=status, sort_order=idx
)
for idx, task in enumerate(tasks)
]
)
Expand Down

0 comments on commit c067603

Please sign in to comment.