Skip to content

Commit

Permalink
updated state in tast_events table with State enums
Browse files Browse the repository at this point in the history
  • Loading branch information
nrjadkry committed Jul 3, 2024
1 parent fa433bc commit 8682691
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/backend/app/db/db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
ProjectStatus,
ProjectVisibility,
UserRole,
State,
)
from sqlalchemy.orm import (
object_session,
Expand Down Expand Up @@ -202,7 +203,7 @@ class TaskEvent(Base):
user_id = cast(str, Column(String(100), ForeignKey("users.id"), nullable=False))
comment = cast(str, Column(String))

state = cast(TaskStatus, Column(Enum(TaskStatus), nullable=False))
state = cast(State, Column(Enum(TaskStatus), nullable=False))
created_at = cast(datetime, Column(DateTime, default=timestamp))

__table_args__ = (
Expand Down
93 changes: 93 additions & 0 deletions src/backend/app/migrations/versions/bf26afac872d_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
"""
Revision ID: bf26afac872d
Revises: 1ebfe5e4cf1c
Create Date: 2024-07-03 15:27:42.903931
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = "bf26afac872d"
down_revision: Union[str, None] = "1ebfe5e4cf1c"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("projects", sa.Column("overlap_percent", sa.Float(), nullable=True))
op.add_column("projects", sa.Column("gsd_cm_px", sa.Float(), nullable=True))
op.add_column(
"projects",
sa.Column("gimble_angles_degrees", sa.ARRAY(sa.SmallInteger()), nullable=True),
)
op.drop_column("projects", "overlap")
op.drop_column("projects", "gimble_angles")
op.drop_column("projects", "gsd")
op.drop_index("ix_tasks_locked_by", table_name="tasks")
op.drop_index("ix_tasks_mapped_by", table_name="tasks")
op.drop_index("ix_tasks_validated_by", table_name="tasks")
op.drop_constraint("fk_users_validator", "tasks", type_="foreignkey")
op.drop_constraint("fk_users_mapper", "tasks", type_="foreignkey")
op.drop_constraint("fk_users_locked", "tasks", type_="foreignkey")
op.drop_column("tasks", "locked_by")
op.drop_column("tasks", "validated_by")
op.drop_column("tasks", "mapped_by")
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"tasks",
sa.Column("mapped_by", sa.VARCHAR(), autoincrement=False, nullable=True),
)
op.add_column(
"tasks",
sa.Column("validated_by", sa.VARCHAR(), autoincrement=False, nullable=True),
)
op.add_column(
"tasks",
sa.Column("locked_by", sa.VARCHAR(), autoincrement=False, nullable=True),
)
op.create_foreign_key("fk_users_locked", "tasks", "users", ["locked_by"], ["id"])
op.create_foreign_key("fk_users_mapper", "tasks", "users", ["mapped_by"], ["id"])
op.create_foreign_key(
"fk_users_validator", "tasks", "users", ["validated_by"], ["id"]
)
op.create_index("ix_tasks_validated_by", "tasks", ["validated_by"], unique=False)
op.create_index("ix_tasks_mapped_by", "tasks", ["mapped_by"], unique=False)
op.create_index("ix_tasks_locked_by", "tasks", ["locked_by"], unique=False)
op.add_column(
"projects",
sa.Column(
"gsd", sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True
),
)
op.add_column(
"projects",
sa.Column(
"gimble_angles",
postgresql.ARRAY(sa.SMALLINT()),
autoincrement=False,
nullable=True,
),
)
op.add_column(
"projects",
sa.Column(
"overlap",
sa.DOUBLE_PRECISION(precision=53),
autoincrement=False,
nullable=True,
),
)
op.drop_column("projects", "gimble_angles_degrees")
op.drop_column("projects", "gsd_cm_px")
op.drop_column("projects", "overlap_percent")
# ### end Alembic commands ###
48 changes: 48 additions & 0 deletions src/backend/app/models/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,51 @@ class UserRole(IntEnum, Enum):
PROJECT_CREATOR = 1
DRONE_PILOT = 2
BOTH = 3


class State(int, Enum):
"""The state of a task.
The state can be:
- ``unlocked to map``
- ``locked for mapping``
- ``unlocked to validate``
- ``locked for validation``
- ``unlocked done``
"""

UNLOCKED_TO_MAP = 0
LOCKED_FOR_MAPPING = 1
UNLOCKED_TO_VALIDATE = 2
LOCKED_FOR_VALIDATION = 3
UNLOCKED_DONE = 4


class EventType(str, Enum):
"""Events that can be used via the API to update a state
Specify the event type for ``POST`` to:
``/project/{pid}/event`` .
Possible values are:
- ``map`` -- Set to *locked for mapping*, i.e. mapping in progress.
- ``finish`` -- Set to *unlocked to validate*, i.e. is mapped.
- ``validate`` -- Request recent task ready to be validate.
- ``good`` -- Set the state to *unlocked done*.
- ``bad`` -- Set the state *unlocked to map* again, to be mapped once again.
- ``split`` -- Set the state *unlocked done* then generate additional subdivided task areas.
- ``assign`` -- For a requester user to assign a task to another user. Set the state *locked for mapping* passing in the required user id.
- ``comment`` -- Keep the state the same, but simply add a comment.
Note that ``task_id`` must be specified in the endpoint too.
"""

MAP = "map"
FINISH = "finish"
VALIDATE = "validate"
GOOD = "good"
BAD = "bad"
SPLIT = "split"
ASSIGN = "assign"
COMMENT = "comment"

0 comments on commit 8682691

Please sign in to comment.