Skip to content

Commit

Permalink
Allow running migrations without PostGIS
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Jan 15, 2025
1 parent 7c2ed1c commit de1d2ea
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
ports:
- 6379:6379
postgres:
image: postgis/postgis:15-3.3-alpine
image: postgres:15-alpine
env:
POSTGRES_DB: temba
POSTGRES_USER: temba
Expand Down Expand Up @@ -63,6 +63,8 @@ jobs:
port: 6000

- name: Initialize environment
env:
POSTGIS: 'OFF'
run: |
poetry install --no-root
yarn install
Expand Down
6 changes: 5 additions & 1 deletion temba/locations/migrations/0031_squashed.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ class Migration(migrations.Migration):
("path", models.CharField(max_length=768)),
(
"simplified_geometry",
django.contrib.gis.db.models.fields.MultiPolygonField(null=True, srid=4326),
(
django.contrib.gis.db.models.fields.MultiPolygonField(null=True, srid=4326)
if settings.POSTGIS
else models.TextField()
),
),
("lft", models.PositiveIntegerField(editable=False)),
("rght", models.PositiveIntegerField(editable=False)),
Expand Down
5 changes: 5 additions & 0 deletions temba/locations/migrations/0034_populate_json_geometry.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Generated by Django 5.1.4 on 2025-01-10 14:30

import geojson

from django.conf import settings
from django.db import migrations


def populate_boundary_geometry(apps, schema_editor): # pragma: no cover
if not settings.POSTGIS:
return

AdminBoundary = apps.get_model("locations", "AdminBoundary")

boundaries = AdminBoundary.objects.all().order_by("level", "osm_id")
Expand Down
5 changes: 4 additions & 1 deletion temba/settings_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

DATA_UPLOAD_MAX_NUMBER_FIELDS = 2500 # needed for exports of big workspaces

# Temp workaround to allow running migrations without PostGIS
POSTGIS = os.getenv("POSTGIS") != "OFF"

# -----------------------------------------------------------------------------------
# Tests
# -----------------------------------------------------------------------------------
Expand Down Expand Up @@ -633,7 +636,7 @@
# Database
# -----------------------------------------------------------------------------------
_default_database_config = {
"ENGINE": "django.contrib.gis.db.backends.postgis",
"ENGINE": "django.contrib.gis.db.backends.postgis" if POSTGIS else "django.db.backends.postgresql",
"NAME": "temba",
"USER": "temba",
"PASSWORD": "temba",
Expand Down

0 comments on commit de1d2ea

Please sign in to comment.