Skip to content
Draft
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
26 changes: 26 additions & 0 deletions alembic/versions/e3f8f2a9b5c1_add_timezone_to_locations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Add timezone column to locations table

Revision ID: e3f8f2a9b5c1
Revises: db1946cbdfc4
Create Date: 2024-09-16 12:45:00.000000

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'e3f8f2a9b5c1'
down_revision = 'db1946cbdfc4'
branch_labels = None
depends_on = None


def upgrade() -> None:
# Add timezone column to api_locations table
op.add_column('api_locations', sa.Column('timezone', sa.String(length=50), nullable=True))


def downgrade() -> None:
# Remove timezone column from api_locations table
op.drop_column('api_locations', 'timezone')
3 changes: 3 additions & 0 deletions app/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class Location(Base):
country = Column(String(100))
postal_code = Column(String(20))

# Timezone information
timezone = Column(String(50)) # e.g., "America/New_York", "UTC", "Europe/London"

# Metadata
created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
Expand Down
5 changes: 3 additions & 2 deletions app/graphql/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ def create_location(self, info: Info, input: CreateLocationInput) -> Location:
longitude=input.longitude,
altitude=input.altitude,
parent_id=input.parent_id,
timezone=input.timezone,
)
db.add(model)
db.commit()
Expand Down Expand Up @@ -427,8 +428,8 @@ def update_location(
model.country = input.country
if input.postal_code is not None:
model.postal_code = input.postal_code
if input.is_active is not None:
model.is_active = input.is_active
if input.timezone is not None:
model.timezone = input.timezone

db.commit()
db.refresh(model)
Expand Down
4 changes: 4 additions & 0 deletions app/graphql/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Location:
city: Optional[str]
country: Optional[str]
postal_code: Optional[str]
timezone: Optional[str]
created_at: datetime
updated_at: Optional[datetime]
is_active: bool
Expand All @@ -74,6 +75,7 @@ def from_model(cls, model: LocationModel) -> "Location":
city=model.city,
country=model.country,
postal_code=model.postal_code,
timezone=model.timezone,
created_at=model.created_at,
updated_at=model.updated_at,
is_active=model.is_active,
Expand Down Expand Up @@ -282,6 +284,7 @@ class CreateLocationInput:
city: Optional[str] = None
country: Optional[str] = None
postal_code: Optional[str] = None
timezone: Optional[str] = None


@strawberry.input
Expand Down Expand Up @@ -336,6 +339,7 @@ class UpdateLocationInput:
city: Optional[str] = None
country: Optional[str] = None
postal_code: Optional[str] = None
timezone: Optional[str] = None


@strawberry.input
Expand Down