From 30b6d2a09862b46848807b5fc90433c4ed677208 Mon Sep 17 00:00:00 2001 From: Julien Maupetit Date: Thu, 5 Sep 2024 17:29:38 +0200 Subject: [PATCH] WIP: add population + area fields with 0 as default --- ...5cde5d0_admin_level_add_population_area.py | 65 +++++++++++++++++++ src/api/qualicharge/schemas/geo.py | 2 + 2 files changed, 67 insertions(+) create mode 100644 src/api/qualicharge/migrations/versions/b10e85cde5d0_admin_level_add_population_area.py diff --git a/src/api/qualicharge/migrations/versions/b10e85cde5d0_admin_level_add_population_area.py b/src/api/qualicharge/migrations/versions/b10e85cde5d0_admin_level_add_population_area.py new file mode 100644 index 00000000..05f7b180 --- /dev/null +++ b/src/api/qualicharge/migrations/versions/b10e85cde5d0_admin_level_add_population_area.py @@ -0,0 +1,65 @@ +"""admin_level_add_population_area + +Revision ID: b10e85cde5d0 +Revises: d198170d222f +Create Date: 2024-09-05 15:11:38.628739 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision: str = "b10e85cde5d0" +down_revision: Union[str, None] = "d198170d222f" +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( + "city", + sa.Column("population", sa.Integer(), nullable=False, server_default="0"), + ) + op.add_column( + "city", sa.Column("area", sa.Float(), nullable=False, server_default="0.0") + ) + op.add_column( + "department", + sa.Column("population", sa.Integer(), nullable=False, server_default="0"), + ) + op.add_column( + "department", + sa.Column("area", sa.Float(), nullable=False, server_default="0.0"), + ) + op.add_column( + "epci", + sa.Column("population", sa.Integer(), nullable=False, server_default="0"), + ) + op.add_column( + "epci", sa.Column("area", sa.Float(), nullable=False, server_default="0.0") + ) + op.add_column( + "region", + sa.Column("population", sa.Integer(), nullable=False, server_default="0"), + ) + op.add_column( + "region", sa.Column("area", sa.Float(), nullable=False, server_default="0.0") + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("region", "area") + op.drop_column("region", "population") + op.drop_column("epci", "area") + op.drop_column("epci", "population") + op.drop_column("department", "area") + op.drop_column("department", "population") + op.drop_column("city", "area") + op.drop_column("city", "population") + # ### end Alembic commands ### diff --git a/src/api/qualicharge/schemas/geo.py b/src/api/qualicharge/schemas/geo.py index 1e9392a9..f740414b 100644 --- a/src/api/qualicharge/schemas/geo.py +++ b/src/api/qualicharge/schemas/geo.py @@ -26,6 +26,8 @@ class BaseAdministrativeBoundaries(BaseTimestampedSQLModel): spatial_index=True, ) ) # type: ignore[call-overload] + population: int = 0 + area: float = 0.0 class Region(BaseAdministrativeBoundaries, table=True):