Skip to content
Open
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
14 changes: 9 additions & 5 deletions alembic_osm/versions/a1b2c3d4e5f6_tasking_mvp_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,21 @@ 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'")
).scalar()
)
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`."
)


Expand All @@ -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 -------------------------------------------
#
Expand Down
14 changes: 9 additions & 5 deletions alembic_task/versions/c5121cbba124_initial_task_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@
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'")
).scalar()
)
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`."
)


Expand All @@ -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",
Expand Down
Loading