Skip to content

Commit 7538827

Browse files
committed
ensure postgis is installed
1 parent 90d1def commit 7538827

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

alembic_osm/versions/a1b2c3d4e5f6_tasking_mvp_schema.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,21 @@ def _drop_enum_if_present(bind, name: str) -> None:
4747
bind.execute(text(f'DROP TYPE IF EXISTS "{name}"'))
4848

4949

50-
def _assert_postgis_installed(bind) -> None:
51-
"""Require the postgis extension to be installed in this database."""
50+
def _ensure_postgis(bind) -> None:
51+
52+
bind.execute(text("SELECT public.deploy_postgis()"))
53+
5254
installed = bool(
5355
bind.execute(
5456
text("SELECT 1 FROM pg_extension WHERE extname = 'postgis'")
5557
).scalar()
5658
)
5759
if not installed:
5860
raise RuntimeError(
59-
"postgis extension is not installed in this database. "
60-
"Run `CREATE EXTENSION IF NOT EXISTS postgis;` before migrations."
61+
"postgis extension is not installed after calling "
62+
"`public.deploy_postgis()`. Verify the function exists in "
63+
"this database and that it issues "
64+
"`CREATE EXTENSION IF NOT EXISTS postgis`."
6165
)
6266

6367

@@ -66,7 +70,7 @@ def upgrade() -> None:
6670
assert bind is not None
6771
insp = inspect(bind)
6872

69-
_assert_postgis_installed(bind)
73+
_ensure_postgis(bind)
7074

7175
# ---- teams / team_user -------------------------------------------
7276
#

alembic_task/versions/c5121cbba124_initial_task_schema.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,21 @@
1212
depends_on: Union[str, Sequence[str], None] = None
1313

1414

15-
def _assert_postgis_installed(bind) -> None:
16-
"""Require the postgis extension to be installed in this database."""
15+
def _ensure_postgis(bind) -> None:
16+
17+
bind.execute(text("SELECT public.deploy_postgis()"))
18+
1719
installed = bool(
1820
bind.execute(
1921
text("SELECT 1 FROM pg_extension WHERE extname = 'postgis'")
2022
).scalar()
2123
)
2224
if not installed:
2325
raise RuntimeError(
24-
"postgis extension is not installed in this database. "
25-
"Run `CREATE EXTENSION IF NOT EXISTS postgis;` before migrations."
26+
"postgis extension is not installed after calling "
27+
"`public.deploy_postgis()`. Verify the function exists in "
28+
"this database and that it issues "
29+
"`CREATE EXTENSION IF NOT EXISTS postgis`."
2630
)
2731

2832

@@ -31,7 +35,7 @@ def upgrade() -> None:
3135
assert bind is not None
3236
insp = inspect(bind)
3337

34-
_assert_postgis_installed(bind)
38+
_ensure_postgis(bind)
3539

3640
geometry_column = sa.Column(
3741
"geometry",

0 commit comments

Comments
 (0)