From ff1ff4fcf961b1e93db313cbc103efdebd8ea39f Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Tue, 13 Jan 2026 14:27:42 +0000 Subject: [PATCH] Enable PostGIS --- .devcontainer/Dockerfile.postgres | 8 ++++++++ .devcontainer/compose.yaml | 4 +++- .github/workflows/lint.yml | 8 ++++++++ .github/workflows/tests.yml | 2 +- db/migrate/20260113142804_enable_postgis.rb | 7 +++++++ db/structure.sql | 15 +++++++++++++++ doc/MANUAL_INSTALL.md | 4 ++-- docker/postgres/Dockerfile | 7 +++++++ 8 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 .devcontainer/Dockerfile.postgres create mode 100644 db/migrate/20260113142804_enable_postgis.rb diff --git a/.devcontainer/Dockerfile.postgres b/.devcontainer/Dockerfile.postgres new file mode 100644 index 000000000..4c4d369e2 --- /dev/null +++ b/.devcontainer/Dockerfile.postgres @@ -0,0 +1,8 @@ +# Would use postgis:15-3.5, but it doesn't work with Apple Silicon +# (https://github.com/postgis/docker-postgis/issues/216). +# Therefore we use postgres:15 and apt-install Postgis ourselves. +FROM postgres:15 + +RUN apt-get update \ + && apt-get install --no-install-recommends -y \ + postgresql-15-postgis-3 diff --git a/.devcontainer/compose.yaml b/.devcontainer/compose.yaml index 9d636c9a0..b023488e6 100644 --- a/.devcontainer/compose.yaml +++ b/.devcontainer/compose.yaml @@ -36,7 +36,9 @@ services: restart: unless-stopped postgres: - image: postgres:15 + build: + context: . + dockerfile: ./Dockerfile.postgres restart: unless-stopped networks: - default diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 442579507..157a3990c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -123,6 +123,10 @@ jobs: cache: yarn - name: Install node modules run: bundle exec bin/yarn install + - name: Install packages + run: | + sudo apt-get -yqq update + sudo apt-get -yqq install postgresql-postgis - name: Setup database run: | sudo systemctl start postgresql @@ -157,6 +161,10 @@ jobs: cache: yarn - name: Install node modules run: bundle exec bin/yarn install + - name: Install packages + run: | + sudo apt-get -yqq update + sudo apt-get -yqq install postgresql-postgis - name: Setup database run: | sudo systemctl start postgresql diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9029b638d..3fd8d869b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -36,7 +36,7 @@ jobs: - name: Install packages run: | sudo apt-get -yqq update - sudo apt-get -yqq install memcached libvips-dev xvfb mesa-utils libgl1-mesa-dri + sudo apt-get -yqq install memcached libvips-dev xvfb mesa-utils libgl1-mesa-dri postgresql-postgis - name: Create database run: | sudo systemctl start postgresql diff --git a/db/migrate/20260113142804_enable_postgis.rb b/db/migrate/20260113142804_enable_postgis.rb new file mode 100644 index 000000000..b4862f748 --- /dev/null +++ b/db/migrate/20260113142804_enable_postgis.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class EnablePostgis < ActiveRecord::Migration[8.1] + def change + enable_extension "postgis" + end +end diff --git a/db/structure.sql b/db/structure.sql index aaa4cae6f..ba27a3a9f 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -30,6 +30,20 @@ CREATE EXTENSION IF NOT EXISTS btree_gist WITH SCHEMA public; COMMENT ON EXTENSION btree_gist IS 'support for indexing common datatypes in GiST'; +-- +-- Name: postgis; Type: EXTENSION; Schema: -; Owner: - +-- + +CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public; + + +-- +-- Name: EXTENSION postgis; Type: COMMENT; Schema: -; Owner: - +-- + +COMMENT ON EXTENSION postgis IS 'PostGIS geometry and geography spatial types and functions'; + + -- -- Name: format_enum; Type: TYPE; Schema: public; Owner: - -- @@ -3687,6 +3701,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('21'), ('20260223105922'), ('20260218183352'), +('20260113142804'), ('20251218105716'), ('20251121134648'), ('20250704143751'), diff --git a/doc/MANUAL_INSTALL.md b/doc/MANUAL_INSTALL.md index bbe99a6c8..7ecf94a75 100644 --- a/doc/MANUAL_INSTALL.md +++ b/doc/MANUAL_INSTALL.md @@ -21,7 +21,7 @@ sudo apt-get update sudo apt-get install ruby ruby-dev ruby-bundler \ libvips-dev libxml2-dev libxslt1-dev \ nodejs build-essential git-core \ - postgresql postgresql-contrib libpq-dev \ + postgresql postgresql-contrib postgresql-postgis libpq-dev \ libsasl2-dev libffi-dev libgd-dev \ libarchive-dev libyaml-dev libbz2-dev npm sudo npm install --global yarn @@ -40,7 +40,7 @@ sudo npm install --global yarn sudo dnf install ruby ruby-devel rubygem-rdoc rubygem-bundler \ rubygems libxml2-devel nodejs gcc gcc-c++ git \ postgresql postgresql-server \ - postgresql-contrib libpq-devel \ + postgresql-contrib postgis libpq-devel \ perl-podlators libffi-devel gd-devel \ libarchive-devel libyaml-devel bzip2-devel \ nodejs-yarn vips-devel diff --git a/docker/postgres/Dockerfile b/docker/postgres/Dockerfile index ceea80e9e..c0cfb51a1 100644 --- a/docker/postgres/Dockerfile +++ b/docker/postgres/Dockerfile @@ -1,4 +1,11 @@ +# Would use postgis:14-3.5, but it doesn't work with Apple Silicon +# (https://github.com/postgis/docker-postgis/issues/216). +# Therefore we use postgres:14 and apt-install Postgis ourselves. FROM postgres:14 +RUN apt-get update \ + && apt-get install --no-install-recommends -y \ + postgresql-14-postgis-3 + # Add db init script to install OSM-specific Postgres user. ADD docker/postgres/openstreetmap-postgres-init.sh /docker-entrypoint-initdb.d/ -- 2.47.3