diff --git a/alembic_osm/versions/a1b2c3d4e5f6_tasking_mvp_schema.py b/alembic_osm/versions/a1b2c3d4e5f6_tasking_mvp_schema.py index 068d28d..e1ac389 100644 --- a/alembic_osm/versions/a1b2c3d4e5f6_tasking_mvp_schema.py +++ b/alembic_osm/versions/a1b2c3d4e5f6_tasking_mvp_schema.py @@ -47,8 +47,10 @@ def _drop_enum_if_present(bind, name: str) -> None: bind.execute(text(f'DROP TYPE IF EXISTS "{name}"')) -def _assert_postgis_installed(bind) -> None: - """Require the postgis extension to be installed in this database.""" +def _ensure_postgis(bind) -> None: + + bind.execute(text("SELECT public.deploy_postgis()")) + installed = bool( bind.execute( text("SELECT 1 FROM pg_extension WHERE extname = 'postgis'") @@ -56,8 +58,10 @@ def _assert_postgis_installed(bind) -> None: ) if not installed: raise RuntimeError( - "postgis extension is not installed in this database. " - "Run `CREATE EXTENSION IF NOT EXISTS postgis;` before migrations." + "postgis extension is not installed after calling " + "`public.deploy_postgis()`. Verify the function exists in " + "this database and that it issues " + "`CREATE EXTENSION IF NOT EXISTS postgis`." ) @@ -66,7 +70,7 @@ def upgrade() -> None: assert bind is not None insp = inspect(bind) - _assert_postgis_installed(bind) + _ensure_postgis(bind) # ---- teams / team_user ------------------------------------------- # diff --git a/alembic_task/versions/c5121cbba124_initial_task_schema.py b/alembic_task/versions/c5121cbba124_initial_task_schema.py index a112007..74275ff 100644 --- a/alembic_task/versions/c5121cbba124_initial_task_schema.py +++ b/alembic_task/versions/c5121cbba124_initial_task_schema.py @@ -12,8 +12,10 @@ depends_on: Union[str, Sequence[str], None] = None -def _assert_postgis_installed(bind) -> None: - """Require the postgis extension to be installed in this database.""" +def _ensure_postgis(bind) -> None: + + bind.execute(text("SELECT public.deploy_postgis()")) + installed = bool( bind.execute( text("SELECT 1 FROM pg_extension WHERE extname = 'postgis'") @@ -21,8 +23,10 @@ def _assert_postgis_installed(bind) -> None: ) if not installed: raise RuntimeError( - "postgis extension is not installed in this database. " - "Run `CREATE EXTENSION IF NOT EXISTS postgis;` before migrations." + "postgis extension is not installed after calling " + "`public.deploy_postgis()`. Verify the function exists in " + "this database and that it issues " + "`CREATE EXTENSION IF NOT EXISTS postgis`." ) @@ -31,7 +35,7 @@ def upgrade() -> None: assert bind is not None insp = inspect(bind) - _assert_postgis_installed(bind) + _ensure_postgis(bind) geometry_column = sa.Column( "geometry",