diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6331a2e493b..808fc952394 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -120,16 +120,16 @@ specs: AWS_SECRET_ACCESS_KEY: test CAPYBARA_WAIT_TIME_SECONDS: 5 COVERAGE: 'true' - DOCKER_DB_HOST: postgres + DOCKER_DB_HOST: db-postgres POSTGRES_DB: identity_idp_test POSTGRES_USER: postgres_user POSTGRES_PASSWORD: postgres_password POSTGRES_HOST_AUTH_METHOD: trust RAILS_ENV: test services: - - name: postgres:13.9 + - name: postgis/postgis:13-3.3 alias: db-postgres - command: ["--fsync=false", "--synchronous_commit=false", "--full_page_writes=false"] + command: ['--fsync=false', '--synchronous_commit=false', '--full_page_writes=false'] - name: redis:7.0 alias: db-redis artifacts: @@ -258,4 +258,3 @@ trigger_devops: include: - template: Jobs/SAST.gitlab-ci.yml - template: Jobs/Dependency-Scanning.gitlab-ci.yml - diff --git a/Brewfile b/Brewfile index ac26eeacf37..76ea11b5282 100644 --- a/Brewfile +++ b/Brewfile @@ -1,4 +1,5 @@ brew 'postgresql@14' +brew 'postgis' brew 'redis' brew 'node@16' brew 'yarn' diff --git a/Gemfile b/Gemfile index 40a1feb67f2..a920533f249 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ ruby "~> #{File.read(File.join(__dir__, '.ruby-version')).strip}" gem 'rails', '~> 7.0.0' +gem 'activerecord-postgis-adapter' gem 'ahoy_matey', '~> 3.0' gem 'aws-sdk-kms', '~> 1.4' gem 'aws-sdk-pinpoint' diff --git a/Gemfile.lock b/Gemfile.lock index 1a366e8b663..05e6ae139ef 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -113,6 +113,9 @@ GEM activerecord (7.0.4.3) activemodel (= 7.0.4.3) activesupport (= 7.0.4.3) + activerecord-postgis-adapter (8.0.2) + activerecord (~> 7.0.0) + rgeo-activerecord (~> 7.0.0) activestorage (7.0.4.3) actionpack (= 7.0.4.3) activejob (= 7.0.4.3) @@ -550,6 +553,10 @@ GEM railties (>= 5.0) retries (0.0.5) rexml (3.2.5) + rgeo (3.0.0) + rgeo-activerecord (7.0.1) + activerecord (>= 5.0) + rgeo (>= 1.0.0) rotp (6.2.0) rouge (4.1.1) rqrcode (2.1.0) @@ -722,6 +729,7 @@ PLATFORMS ruby DEPENDENCIES + activerecord-postgis-adapter ahoy_matey (~> 3.0) aws-sdk-cloudwatchlogs aws-sdk-kms (~> 1.4) diff --git a/config/database.yml b/config/database.yml index 0ecc4244307..45e1d71276b 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,5 +1,5 @@ postgresql: &postgresql - adapter: postgresql + adapter: postgis encoding: utf8 database: identity_idp_<%= Rails.env %> port: 5432 diff --git a/db/primary_migrate/20230518221444_add_postgis_extension_to_database.rb b/db/primary_migrate/20230518221444_add_postgis_extension_to_database.rb new file mode 100644 index 00000000000..3e8476ebf8d --- /dev/null +++ b/db/primary_migrate/20230518221444_add_postgis_extension_to_database.rb @@ -0,0 +1,5 @@ +class AddPostgisExtensionToDatabase < ActiveRecord::Migration[7.0] + def change + enable_extension 'postgis' + end +end diff --git a/db/schema.rb b/db/schema.rb index 0443b612784..09edb4958d7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -15,6 +15,7 @@ enable_extension "pg_stat_statements" enable_extension "pgcrypto" enable_extension "plpgsql" + enable_extension "postgis" create_table "account_reset_requests", force: :cascade do |t| t.integer "user_id", null: false diff --git a/docs/local-development.md b/docs/local-development.md index 175d0bd6a86..b4f786bb35c 100644 --- a/docs/local-development.md +++ b/docs/local-development.md @@ -23,6 +23,8 @@ If not using macOS: - [rbenv](https://github.com/rbenv/rbenv) (lets you install and switch between different versions of Ruby) - Ruby. Choose the version [in the `.ruby-version` file](../.ruby-version) - [PostgreSQL](http://www.postgresql.org/download/) + - [PostGIS](https://postgis.net/documentation/getting_started/#installing-postgis) + - Note: if you run into errors installing `postgis` or creating the databse, check [the troubleshooting docs](./troubleshooting.md#errors-related-to-the-databse). - [Redis 7+](http://redis.io/) - [Node.js v16](https://nodejs.org) - [Yarn](https://yarnpkg.com/en/) diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 0867ca17ede..f7b42a19317 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -8,6 +8,30 @@ $ bundle install $ yarn install ``` +### Errors related to the database + +One error you might see is: + +``` +Caused by: +ActiveRecord::StatementInvalid: PG::FeatureNotSupported: ERROR: extension "postgis" is not available +DETAIL: Could not open extension control file "/opt/homebrew/opt/postgresql@15/share/postgresql@15/extension/postgis.control": No such file or directory. +HINT: The extension must first be installed on the system where PostgreSQL is running. +``` + +If you see the above message: + +- double check that `postgis` is installed with `brew list` +- if `postgis` is listed, it means when you brew installed you might have installed `postgis` in a different postgresql db than the app is using + - in this case, look at `brew list` again, and remove any `postgres` db that is not listed in [the Brewfile](../Brewfile) (`brew uninstall __`) + - if you try to run the migration now you might get a: + ``` + connection to server at "::1", port 5432 failed: Connection refused + Is the server running on that host and accepting TCP/IP connections? + ``` + - this likely means postgres is no longer running + - try `brew services start postgresql@14` (or your version) and then re-run the migration + ## I am receiving errors when creating the development and test databases If you receive the following error (where _whoami_ == _your username_):