diff --git a/alembic/versions/e3f8f2a9b5c1_add_timezone_to_locations.py b/alembic/versions/e3f8f2a9b5c1_add_timezone_to_locations.py new file mode 100644 index 0000000..606e357 --- /dev/null +++ b/alembic/versions/e3f8f2a9b5c1_add_timezone_to_locations.py @@ -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') \ No newline at end of file diff --git a/app/database/models.py b/app/database/models.py index 69a878d..a77cdad 100644 --- a/app/database/models.py +++ b/app/database/models.py @@ -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()) diff --git a/app/graphql/resolvers.py b/app/graphql/resolvers.py index b160f29..172c6cf 100644 --- a/app/graphql/resolvers.py +++ b/app/graphql/resolvers.py @@ -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() @@ -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) diff --git a/app/graphql/types.py b/app/graphql/types.py index 2b745f8..f841e21 100644 --- a/app/graphql/types.py +++ b/app/graphql/types.py @@ -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 @@ -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, @@ -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 @@ -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