From 3f72edc882f2c8d0756985cecb84d98300cf8338 Mon Sep 17 00:00:00 2001 From: Ernesto Ruge Date: Wed, 20 Nov 2024 10:08:18 +0100 Subject: [PATCH 1/2] Allow Realtime Opening Status Null --- ...9210_allow_realtime_opening_status_null.py | 57 +++++++++++++++++++ webapp/models/parking_site.py | 6 +- webapp/models/parking_site_history.py | 4 +- 3 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 migrations/versions/2024-11-20-09-06-51_4f09ed999210_allow_realtime_opening_status_null.py diff --git a/migrations/versions/2024-11-20-09-06-51_4f09ed999210_allow_realtime_opening_status_null.py b/migrations/versions/2024-11-20-09-06-51_4f09ed999210_allow_realtime_opening_status_null.py new file mode 100644 index 0000000..d307334 --- /dev/null +++ b/migrations/versions/2024-11-20-09-06-51_4f09ed999210_allow_realtime_opening_status_null.py @@ -0,0 +1,57 @@ +"""allow realtime opening status null + +Revision ID: 4f09ed999210 +Revises: 95992608c5d1 +Create Date: 2024-11-20 09:06:51.525217 + +""" + +import sqlalchemy as sa +from alembic import op +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = '4f09ed999210' +down_revision = '95992608c5d1' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('parking_site', schema=None) as batch_op: + batch_op.alter_column( + 'realtime_opening_status', + existing_type=postgresql.ENUM('OPEN', 'CLOSED', 'UNKNOWN', name='openingstatus'), + nullable=True, + ) + + with op.batch_alter_table('parking_site_history', schema=None) as batch_op: + batch_op.alter_column( + 'realtime_opening_status', + existing_type=postgresql.ENUM('OPEN', 'CLOSED', 'UNKNOWN', name='history_openingstatus'), + type_=sa.Enum('OPEN', 'CLOSED', 'UNKNOWN', name='history_openingstatus'), + nullable=True, + ) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('parking_site_history', schema=None) as batch_op: + batch_op.alter_column( + 'realtime_opening_status', + existing_type=sa.Enum('OPEN', 'CLOSED', 'UNKNOWN', name='history_openingstatus'), + type_=postgresql.ENUM('OPEN', 'CLOSED', 'UNKNOWN', name='history_openingstatus'), + nullable=False, + ) + + with op.batch_alter_table('parking_site', schema=None) as batch_op: + batch_op.alter_column( + 'realtime_opening_status', + existing_type=postgresql.ENUM('OPEN', 'CLOSED', 'UNKNOWN', name='openingstatus'), + nullable=False, + ) + + # ### end Alembic commands ### diff --git a/webapp/models/parking_site.py b/webapp/models/parking_site.py index 5496c33..259a5b2 100644 --- a/webapp/models/parking_site.py +++ b/webapp/models/parking_site.py @@ -106,8 +106,10 @@ class ParkingSite(BaseModel): has_realtime_data: Mapped[Optional[bool]] = mapped_column(Boolean(), nullable=False, default=False) static_data_updated_at: Mapped[Optional[datetime]] = mapped_column(UtcDateTime(), nullable=True) realtime_data_updated_at: Mapped[Optional[datetime]] = mapped_column(UtcDateTime(), nullable=True) - realtime_opening_status: Mapped[OpeningStatus] = mapped_column( - SqlalchemyEnum(OpeningStatus), nullable=False, default=OpeningStatus.UNKNOWN + realtime_opening_status: Mapped[OpeningStatus | None] = mapped_column( + SqlalchemyEnum(OpeningStatus), + nullable=True, + default=None, ) lat: Mapped[Decimal] = mapped_column(Numeric(precision=10, scale=7), nullable=False) diff --git a/webapp/models/parking_site_history.py b/webapp/models/parking_site_history.py index 9a33a4c..1448330 100644 --- a/webapp/models/parking_site_history.py +++ b/webapp/models/parking_site_history.py @@ -25,8 +25,8 @@ class ParkingSiteHistory(BaseModel): static_data_updated_at: Mapped[Optional[datetime]] = mapped_column(UtcDateTime(), nullable=True) realtime_data_updated_at: Mapped[Optional[datetime]] = mapped_column(UtcDateTime(), nullable=True) - realtime_opening_status: Mapped[OpeningStatus] = mapped_column( - SqlalchemyEnum(OpeningStatus), nullable=False, default=OpeningStatus.UNKNOWN + realtime_opening_status: Mapped[OpeningStatus | None] = mapped_column( + SqlalchemyEnum(OpeningStatus), nullable=True, default=None ) capacity: Mapped[Optional[int]] = mapped_column(Integer(), nullable=True) From 170f3f9e4d8438cc63d0a9797df76d37053ec567 Mon Sep 17 00:00:00 2001 From: Ernesto Ruge Date: Wed, 20 Nov 2024 10:09:10 +0100 Subject: [PATCH 2/2] adapt docs --- webapp/public_rest_api/parking_sites/parking_sites_schema.py | 1 + 1 file changed, 1 insertion(+) diff --git a/webapp/public_rest_api/parking_sites/parking_sites_schema.py b/webapp/public_rest_api/parking_sites/parking_sites_schema.py index fd5e88d..e86433a 100644 --- a/webapp/public_rest_api/parking_sites/parking_sites_schema.py +++ b/webapp/public_rest_api/parking_sites/parking_sites_schema.py @@ -125,6 +125,7 @@ 'realtime_opening_status': EnumField( enum=OpeningStatus, required=False, + nullable=True, description='Realtime opening status which is reported by the client.', ), 'lat': DecimalField(precision=10, scale=7),