Skip to content

Commit

Permalink
refactor: revert and update migrations with '_at' for date columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Pradip-p committed Jul 13, 2024
1 parent a579f58 commit 625e437
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/backend/app/db/db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class DbProject(Base):
short_description = cast(str, Column(String))
description = cast(str, Column(String))
per_task_instructions = cast(str, Column(String))
created = cast(datetime, Column(DateTime, default=timestamp, nullable=False))
created_at = cast(datetime, Column(DateTime, default=timestamp, nullable=False))
last_updated = cast(datetime, Column(DateTime, default=timestamp))
deadline = cast(datetime, Column(DateTime, default=timestamp))
deadline_at = cast(datetime, Column(DateTime, default=timestamp))
# GEOMETRY
outline = cast(WKBElement, Column(Geometry("POLYGON", srid=4326)))
centroid = cast(WKBElement, Column(Geometry("POINT", srid=4326)))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""refine field name
Revision ID: acee47666167
Revises: 88ae62ec8876
Create Date: 2024-07-13 10:51:33.020864
"""
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 = 'acee47666167'
down_revision: Union[str, None] = '88ae62ec8876'
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('created_at', sa.DateTime(), nullable=False))
op.add_column('projects', sa.Column('deadline_at', sa.DateTime(), nullable=True))
op.drop_column('projects', 'created')
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
#op.add_column('projects', sa.Column('created', postgresql.TIMESTAMP(), autoincrement=False, nullable=False))
op.drop_column('projects', 'deadline_at')
op.drop_column('projects', 'created_at')
# ### end Alembic commands ###
6 changes: 3 additions & 3 deletions src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async def create_project_with_project_info(
_id = uuid.uuid4()
query = """
INSERT INTO projects (
id, author_id, name, short_description, description, per_task_instructions, status, visibility, outline, no_fly_zones, dem_url, output_orthophoto_url, output_pointcloud_url, output_raw_url, task_split_dimension, deadline, created)
id, author_id, name, short_description, description, per_task_instructions, status, visibility, outline, no_fly_zones, dem_url, output_orthophoto_url, output_pointcloud_url, output_raw_url, task_split_dimension, deadline_at, created_at)
VALUES (
:id,
:author_id,
Expand All @@ -36,7 +36,7 @@ async def create_project_with_project_info(
:output_pointcloud_url,
:output_raw_url,
:task_split_dimension,
:deadline,
:deadline_at,
CURRENT_TIMESTAMP
)
RETURNING id
Expand All @@ -60,7 +60,7 @@ async def create_project_with_project_info(
"output_pointcloud_url": project_metadata.output_pointcloud_url,
"output_raw_url": project_metadata.output_raw_url,
"task_split_dimension": project_metadata.task_split_dimension,
"deadline": project_metadata.deadline,
"deadline_at": project_metadata.deadline_at,
},
)
return project_id
Expand Down
2 changes: 1 addition & 1 deletion src/backend/app/projects/project_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ProjectIn(BaseModel):
output_orthophoto_url: Optional[str] = None
output_pointcloud_url: Optional[str] = None
output_raw_url: Optional[str] = None
deadline: Optional[date] = None
deadline_at: Optional[date] = None

@computed_field
@property
Expand Down

0 comments on commit 625e437

Please sign in to comment.