Skip to content

Commit

Permalink
Add base models and migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaupetit committed Jul 24, 2024
1 parent cbc386a commit e630680
Show file tree
Hide file tree
Showing 6 changed files with 551 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/api/qualicharge/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
Station,
Status,
)
from qualicharge.schemas.geo import Region, Department, EPCI, City # noqa: F401

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
"""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 ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
"""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 ###
Loading

0 comments on commit e630680

Please sign in to comment.