Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
cdb53135fe1296f55fc02cef26b9660a29595f50
# black 26
6bde6e3be9950a783535448c8b4d463aa0726302
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# CHANGELOG

## 1.5.7 (2026-02-18)

**🚀 Nouveautés**

- Mise à jour des dépendances

## 1.5.6 (2025-09-25)

**🐛 Corrections**

- Correction du build du package Python à l'origine de l'échec des tests sur GeoNature (par @jacquesfize)


## 1.5.5 (2025-05-21)

**🚀 Nouveautés**
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.6
1.5.7
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import setuptools
from pathlib import Path


root_dir = Path(__file__).absolute().parent
with (root_dir / "VERSION").open() as f:
version = f.read()
Expand Down
1 change: 0 additions & 1 deletion src/ref_geo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from ref_geo.env import db
from ref_geo.routes import routes


migrate = Migrate()


Expand Down
1 change: 0 additions & 1 deletion src/ref_geo/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow


db_path = environ.get("FLASK_SQLALCHEMY_DB")
if db_path and db_path != f"{__name__}.db":
db_module_name, db_object_name = db_path.rsplit(".", 1)
Expand Down
47 changes: 14 additions & 33 deletions src/ref_geo/migrations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,66 +10,52 @@

from utils_flask_sqla.migrations.utils import logger


schema = "ref_geo"


def geom_4326_exists():
return (
op.get_bind()
.execute(
"""
return op.get_bind().execute("""
SELECT EXISTS (
SELECT 1
FROM information_schema.COLUMNS
WHERE table_schema = 'ref_geo' AND table_name='l_areas' AND column_name = 'geom_4326'
)
"""
)
.scalar()
)
""").scalar()


def delete_area_with_type(area_type):
"""
Supprimer les zones d’un type donnée, e.g. 'DEP', 'COM', …
"""
op.execute(
f"""
op.execute(f"""
DELETE FROM {schema}.l_areas la
USING {schema}.get_id_area_type('{area_type}') as area_type
WHERE la.id_type = area_type
"""
)
""")


def create_temporary_grids_table(schema, temp_table_name):
logger.info("Create temporary grids table…")
op.execute(
f"""
op.execute(f"""
CREATE TABLE {schema}.{temp_table_name} (
gid integer NOT NULL,
cd_sig character varying(21),
code character varying(10),
geom public.geometry(MultiPolygon,2154),
geojson character varying
)
"""
)
op.execute(
f"""
""")
op.execute(f"""
ALTER TABLE ONLY {schema}.{temp_table_name}
ADD CONSTRAINT {temp_table_name}_pkey PRIMARY KEY (gid)
"""
)
""")


def insert_grids_and_drop_temporary_table(schema, temp_table_name, area_type):
logger.info("Copy grids in l_areas…")
if geom_4326_exists():
# We insert geom and geom_4326 to avoid double conversion like 2154 → 3312 → 4326
op.execute(
f"""
op.execute(f"""
INSERT INTO {schema}.l_areas (id_type, area_code, area_name, geom, geom_4326)
SELECT
{schema}.get_id_area_type('{area_type}') AS id_type,
Expand All @@ -78,11 +64,9 @@ def insert_grids_and_drop_temporary_table(schema, temp_table_name, area_type):
ST_Transform(geom, Find_SRID('{schema}', 'l_areas', 'geom')),
ST_SetSRID(ST_GeomFromGeoJSON(geojson), 4326)
FROM {schema}.{temp_table_name}
"""
)
""")
else: # legacy column geojson_4326
op.execute(
f"""
op.execute(f"""
INSERT INTO {schema}.l_areas (id_type, area_code, area_name, geom, geojson_4326)
SELECT
{schema}.get_id_area_type('{area_type}') AS id_type,
Expand All @@ -91,11 +75,9 @@ def insert_grids_and_drop_temporary_table(schema, temp_table_name, area_type):
ST_Transform(geom, Find_SRID('{schema}', 'l_areas', 'geom')),
geojson
FROM {schema}.{temp_table_name}
"""
)
""")
logger.info("Copy grids in li_grids…")
op.execute(
f"""
op.execute(f"""
INSERT INTO {schema}.li_grids(id_grid, id_area, cxmin, cxmax, cymin, cymax)
SELECT
l.area_code,
Expand All @@ -106,8 +88,7 @@ def insert_grids_and_drop_temporary_table(schema, temp_table_name, area_type):
ST_YMax(g.geom)
FROM {schema}.{temp_table_name} g
JOIN {schema}.l_areas l ON l.area_code = cd_sig;
"""
)
""")
logger.info("Re-indexing…")
op.execute(f"REINDEX INDEX {schema}.index_l_areas_geom")
logger.info("Dropping temporary grids table…")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
)
from utils_flask_sqla.migrations.utils import logger, open_remote_file


# revision identifiers, used by Alembic.
revision = "05a0ae652c13"
down_revision = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
)
from utils_flask_sqla.migrations.utils import logger, open_remote_file


# revision identifiers, used by Alembic.
revision = "0dfdbfbccd63"
down_revision = None
Expand All @@ -29,8 +28,7 @@

def upgrade():
logger.info("Create temporary municipalities table…")
op.execute(
f"""
op.execute(f"""
CREATE TABLE {schema}.{temp_table_name} (
gid integer NOT NULL,
id character varying(24),
Expand All @@ -48,22 +46,18 @@ def upgrade():
geom public.geometry(MultiPolygon,2154),
geojson character varying
)
"""
)
op.execute(
f"""
""")
op.execute(f"""
ALTER TABLE ONLY {schema}.{temp_table_name}
ADD CONSTRAINT {temp_table_name}_pkey PRIMARY KEY (gid)
"""
)
""")
cursor = op.get_bind().connection.cursor()
with open_remote_file(base_url, filename) as geofile:
logger.info("Inserting municipalities data in temporary table…")
cursor.copy_expert(f"COPY {schema}.{temp_table_name} FROM STDIN", geofile)
logger.info("Copy municipalities in l_areas…")
if geom_4326_exists():
op.execute(
f"""
op.execute(f"""
INSERT INTO {schema}.l_areas (
id_type,
area_code,
Expand All @@ -78,11 +72,9 @@ def upgrade():
ST_TRANSFORM(geom, Find_SRID('{schema}', 'l_areas', 'geom')),
ST_SetSRID(ST_GeomFromGeoJSON(geojson), 4326)
FROM {schema}.{temp_table_name}
"""
)
""")
else:
op.execute(
f"""
op.execute(f"""
INSERT INTO {schema}.l_areas (
id_type,
area_code,
Expand All @@ -97,18 +89,15 @@ def upgrade():
ST_TRANSFORM(geom, Find_SRID('{schema}', 'l_areas', 'geom')),
geojson
FROM {schema}.{temp_table_name}
"""
)
""")
logger.info("Copy municipalities in li_municipalities…")
op.execute(
f"""
op.execute(f"""
INSERT INTO ref_geo.li_municipalities
(id_municipality, id_area, status, insee_com, nom_com, insee_arr, insee_dep, insee_reg, code_epci)
SELECT id, a.id_area, statut, insee_com, nom_com, insee_arr, insee_dep, insee_reg, code_epci
FROM ref_geo.temp_fr_municipalities t
JOIN ref_geo.l_areas a ON a.area_code = t.insee_com
"""
)
""")
logger.info("Re-indexing…")
op.execute(f"REINDEX INDEX {schema}.index_l_areas_geom")
logger.info("Dropping temporary municipalities table…")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
insert_grids_and_drop_temporary_table,
)


# revision identifiers, used by Alembic.
revision = "10a587fb63d1"
down_revision = None
Expand All @@ -30,8 +29,7 @@


def upgrade():
op.execute(
f"""
op.execute(f"""
INSERT INTO {schema}.bib_areas_types (type_name,
type_code,
type_desc,
Expand All @@ -40,8 +38,7 @@ def upgrade():
num_version)
VALUES ('Mailles {grid}*{grid}', 'M{grid}', 'Type maille INPN {grid}*{grid}km', NULL, NULL, NULL)
ON CONFLICT (type_code) DO NOTHING;
"""
)
""")
create_temporary_grids_table(schema, temp_table_name)
cursor = op.get_bind().connection.cursor()
with open_remote_file(base_url, filename) as geofile:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@


def upgrade():
op.execute(
f"""
op.execute(f"""
INSERT INTO {schema}.bib_areas_types (type_name,
type_code,
type_desc,
Expand All @@ -39,8 +38,7 @@ def upgrade():
num_version)
VALUES ('Mailles {grid}*{grid}', 'M{grid}', 'Type maille INPN {grid}*{grid}km', NULL, NULL, NULL)
ON CONFLICT (type_code) DO NOTHING;
"""
)
""")
create_temporary_grids_table(schema, temp_table_name)
cursor = op.get_bind().connection.cursor()
with open_remote_file(base_url, filename) as geofile:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "1fdac7036dd9"
down_revision = "f22d70b8fcfa"
Expand All @@ -18,8 +17,7 @@


def upgrade():
op.execute(
"""
op.execute("""
CREATE OR REPLACE FUNCTION ref_geo.fct_get_altitude_intersection(
mygeom geometry
)
Expand Down Expand Up @@ -75,13 +73,11 @@ def upgrade():
END;

$BODY$;
"""
)
""")


def downgrade():
op.execute(
"""
op.execute("""
CREATE OR REPLACE FUNCTION ref_geo.fct_get_altitude_intersection(
mygeom geometry
)
Expand Down Expand Up @@ -131,5 +127,4 @@ def downgrade():
END;

$BODY$;
"""
)
""")
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "1ca7fd0d2ea"
down_revision = "1fdac7036dd9"
Expand Down
Loading