-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A first migration to reflect the new fields (centre, codes postaux) added on the communes, and remove the now useless fields and indices. We'll need a second cleanup migration later on (after the next deployment) to add a spatial index and make the codes_postaux non nullable.
- Loading branch information
Showing
2 changed files
with
81 additions
and
4 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
api/src/alembic/versions/20240830_175854_e3f3dfa4ad01_modified_api__communes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
"""Modified api__communes | ||
Revision ID: e3f3dfa4ad01 | ||
Revises: 517603187775 | ||
Create Date: 2024-08-30 17:58:54.747630 | ||
""" | ||
|
||
import geoalchemy2 | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
from data_inclusion.api.core.db import SortedTextArray | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "e3f3dfa4ad01" | ||
down_revision = "517603187775" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.add_column( | ||
"api__communes", | ||
sa.Column( | ||
"codes_postaux", | ||
SortedTextArray(sa.Text()), | ||
nullable=True, | ||
), | ||
) | ||
op.add_column( | ||
"api__communes", | ||
sa.Column( | ||
"centre", | ||
geoalchemy2.types.Geometry( | ||
srid=4326, from_text="ST_GeomFromEWKT", name="geometry" | ||
), | ||
nullable=True, | ||
), | ||
) | ||
op.drop_index("ix_api__communes__geography", table_name="api__communes") | ||
op.drop_column("api__communes", "geom") | ||
|
||
|
||
def downgrade() -> None: | ||
op.add_column( | ||
"api__communes", | ||
sa.Column( | ||
"geom", | ||
geoalchemy2.types.Geometry( | ||
srid=4326, | ||
spatial_index=False, | ||
from_text="ST_GeomFromEWKT", | ||
name="geometry", | ||
_spatial_index_reflected=True, | ||
), | ||
autoincrement=False, | ||
nullable=True, | ||
), | ||
) | ||
op.drop_index( | ||
"idx_api__communes_centre", table_name="api__communes", postgresql_using="gist" | ||
) | ||
op.create_index( | ||
"ix_api__communes__geography", | ||
"api__communes", | ||
[ | ||
sa.text( | ||
"(st_simplify(geom, 0.01::double precision)::geography(Geometry,4326))" | ||
) | ||
], | ||
unique=False, | ||
) | ||
op.drop_column("api__communes", "centre") | ||
op.drop_column("api__communes", "codes_postaux") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters