diff --git a/src/api/qualicharge/migrations/versions/436631d8396b_rename_geo_models_geometry_field.py b/src/api/qualicharge/migrations/versions/436631d8396b_rename_geo_models_geometry_field.py deleted file mode 100644 index 23cc50b4..00000000 --- a/src/api/qualicharge/migrations/versions/436631d8396b_rename_geo_models_geometry_field.py +++ /dev/null @@ -1,170 +0,0 @@ -"""rename geo models geometry field - -Revision ID: 436631d8396b -Revises: d4dc82e07410 -Create Date: 2024-07-24 16:27:15.076485 - -""" - -from typing import Sequence, Union - -from alembic import op -import sqlalchemy as sa -import geoalchemy2 -from sqlalchemy.dialects import postgresql - -# revision identifiers, used by Alembic. -revision: str = "436631d8396b" -down_revision: Union[str, None] = "d4dc82e07410" -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( - "geometry", - geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, - ), - nullable=False, - ), - ) - op.drop_index("idx_city_geom", table_name="city", postgresql_using="gist") - op.drop_column("city", "geom") - op.add_column( - "department", - sa.Column( - "geometry", - geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, - ), - nullable=False, - ), - ) - op.drop_index( - "idx_department_geom", table_name="department", postgresql_using="gist" - ) - op.drop_column("department", "geom") - op.add_column( - "epci", - sa.Column( - "geometry", - geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, - ), - nullable=False, - ), - ) - op.drop_index("idx_epci_geom", table_name="epci", postgresql_using="gist") - op.drop_column("epci", "geom") - op.add_column( - "region", - sa.Column( - "geometry", - geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, - ), - nullable=False, - ), - ) - op.drop_index("idx_region_geom", table_name="region", postgresql_using="gist") - op.drop_column("region", "geom") - # ### end Alembic commands ### - - -def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - op.add_column( - "region", - sa.Column( - "geom", - geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=False, - ), - ) - op.drop_index("idx_region_geometry", table_name="region", postgresql_using="gist") - op.drop_column("region", "geometry") - op.add_column( - "epci", - sa.Column( - "geom", - geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=False, - ), - ) - op.drop_index("idx_epci_geometry", table_name="epci", postgresql_using="gist") - op.drop_column("epci", "geometry") - op.add_column( - "department", - sa.Column( - "geom", - geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=False, - ), - ) - op.drop_index( - "idx_department_geometry", table_name="department", postgresql_using="gist" - ) - op.drop_column("department", "geometry") - op.add_column( - "city", - sa.Column( - "geom", - geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=False, - ), - ) - op.drop_index("idx_city_geometry", table_name="city", postgresql_using="gist") - op.drop_column("city", "geometry") - # ### end Alembic commands ### diff --git a/src/api/qualicharge/migrations/versions/d4dc82e07410_add_geo_models.py b/src/api/qualicharge/migrations/versions/7b8c33d8399d_add_admin_geo_boundaries.py similarity index 78% rename from src/api/qualicharge/migrations/versions/d4dc82e07410_add_geo_models.py rename to src/api/qualicharge/migrations/versions/7b8c33d8399d_add_admin_geo_boundaries.py index 593852be..7cdbbb99 100644 --- a/src/api/qualicharge/migrations/versions/d4dc82e07410_add_geo_models.py +++ b/src/api/qualicharge/migrations/versions/7b8c33d8399d_add_admin_geo_boundaries.py @@ -1,23 +1,20 @@ -"""add geo models +"""add admin geo boundaries -Revision ID: d4dc82e07410 +Revision ID: 7b8c33d8399d Revises: b5ef0fba88a7 -Create Date: 2024-07-24 15:27:22.779483 +Create Date: 2024-07-29 08:57:49.939396 """ from typing import Sequence, Union +from alembic import op import geoalchemy2 import sqlalchemy as sa import sqlmodel -from alembic import op -from sqlalchemy.dialects import postgresql - - # revision identifiers, used by Alembic. -revision: str = "d4dc82e07410" +revision: str = "7b8c33d8399d" down_revision: Union[str, None] = "b5ef0fba88a7" branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None @@ -32,13 +29,9 @@ def upgrade() -> None: sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False), sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column( - "geom", + "geometry", geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, + srid=4326, from_text="ST_GeomFromEWKT", name="geometry", nullable=False ), nullable=False, ), @@ -54,13 +47,9 @@ def upgrade() -> None: sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False), sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column( - "geom", + "geometry", geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, + srid=4326, from_text="ST_GeomFromEWKT", name="geometry", nullable=False ), nullable=False, ), @@ -76,13 +65,9 @@ def upgrade() -> None: sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False), sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column( - "geom", + "geometry", geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, + srid=4326, from_text="ST_GeomFromEWKT", name="geometry", nullable=False ), nullable=False, ), @@ -103,13 +88,9 @@ def upgrade() -> None: sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False), sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), sa.Column( - "geom", + "geometry", geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, + srid=4326, from_text="ST_GeomFromEWKT", name="geometry", nullable=False ), nullable=False, ), @@ -134,17 +115,17 @@ def upgrade() -> None: def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.drop_index(op.f("ix_city_code"), table_name="city") - op.drop_index("idx_city_geom", table_name="city", postgresql_using="gist") + op.drop_index("idx_city_geometry", table_name="city", postgresql_using="gist") op.drop_table("city") op.drop_index(op.f("ix_department_code"), table_name="department") op.drop_index( - "idx_department_geom", table_name="department", postgresql_using="gist" + "idx_department_geometry", table_name="department", postgresql_using="gist" ) op.drop_table("department") op.drop_index(op.f("ix_region_code"), table_name="region") - op.drop_index("idx_region_geom", table_name="region", postgresql_using="gist") + op.drop_index("idx_region_geometry", table_name="region", postgresql_using="gist") op.drop_table("region") op.drop_index(op.f("ix_epci_code"), table_name="epci") - op.drop_index("idx_epci_geom", table_name="epci", postgresql_using="gist") + op.drop_index("idx_epci_geometry", table_name="epci", postgresql_using="gist") op.drop_table("epci") # ### end Alembic commands ### diff --git a/src/api/qualicharge/migrations/versions/b0fe8b2d083d_update_geo_geometry_field_types.py b/src/api/qualicharge/migrations/versions/b0fe8b2d083d_update_geo_geometry_field_types.py deleted file mode 100644 index 57a5dca0..00000000 --- a/src/api/qualicharge/migrations/versions/b0fe8b2d083d_update_geo_geometry_field_types.py +++ /dev/null @@ -1,158 +0,0 @@ -"""update geo geometry field types - -Revision ID: b0fe8b2d083d -Revises: 436631d8396b -Create Date: 2024-07-24 16:50:02.085359 - -""" - -from typing import Sequence, Union - -from alembic import op -import geoalchemy2 -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - -# revision identifiers, used by Alembic. -revision: str = "b0fe8b2d083d" -down_revision: Union[str, None] = "436631d8396b" -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.alter_column( - "city", - "geometry", - existing_type=geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, - _spatial_index_reflected=True, - ), - type_=geoalchemy2.types.Geometry( - srid=4326, from_text="ST_GeomFromEWKT", name="geometry", nullable=False - ), - existing_nullable=False, - ) - op.alter_column( - "department", - "geometry", - existing_type=geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, - _spatial_index_reflected=True, - ), - type_=geoalchemy2.types.Geometry( - srid=4326, from_text="ST_GeomFromEWKT", name="geometry", nullable=False - ), - existing_nullable=False, - ) - op.alter_column( - "epci", - "geometry", - existing_type=geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, - _spatial_index_reflected=True, - ), - type_=geoalchemy2.types.Geometry( - srid=4326, from_text="ST_GeomFromEWKT", name="geometry", nullable=False - ), - existing_nullable=False, - ) - op.alter_column( - "region", - "geometry", - existing_type=geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, - _spatial_index_reflected=True, - ), - type_=geoalchemy2.types.Geometry( - srid=4326, from_text="ST_GeomFromEWKT", name="geometry", nullable=False - ), - existing_nullable=False, - ) - # ### end Alembic commands ### - - -def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - op.alter_column( - "region", - "geometry", - existing_type=geoalchemy2.types.Geometry( - srid=4326, from_text="ST_GeomFromEWKT", name="geometry", nullable=False - ), - type_=geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, - _spatial_index_reflected=True, - ), - existing_nullable=False, - ) - op.alter_column( - "epci", - "geometry", - existing_type=geoalchemy2.types.Geometry( - srid=4326, from_text="ST_GeomFromEWKT", name="geometry", nullable=False - ), - type_=geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, - _spatial_index_reflected=True, - ), - existing_nullable=False, - ) - op.alter_column( - "department", - "geometry", - existing_type=geoalchemy2.types.Geometry( - srid=4326, from_text="ST_GeomFromEWKT", name="geometry", nullable=False - ), - type_=geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, - _spatial_index_reflected=True, - ), - existing_nullable=False, - ) - op.alter_column( - "city", - "geometry", - existing_type=geoalchemy2.types.Geometry( - srid=4326, from_text="ST_GeomFromEWKT", name="geometry", nullable=False - ), - type_=geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - nullable=False, - _spatial_index_reflected=True, - ), - existing_nullable=False, - ) - # ### end Alembic commands ###