I got an error on gitlab during execution .gitlab-ci.yml
$ bundle exec rspec
in .gitlab-ci.yml
Locally I have postgresql for dev and test environment. All rspec tests are passing.
But after upload project on gitlab it raises error:
An error occurred while loading ./spec/requests/api/packages_spec.rb.
Failure/Error: ActiveRecord::Migration.maintain_test_schema!
PG::ConnectionBad:
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"
Before I had sqlite3 db. But than I migrated to pg.
database.yml:
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: pg_app_development
test:
<<: *default
database: pg_app_test
Add in database.yml port and host var:
test:
<<: *default
database: pg_app_test
user: postgres
host: <%= ENV.fetch("DATABASE_HOST") { 'localhost' } %>
port: 5432
And db variables to .gitlab-ci.yml
variables:
RAILS_ENV: test
POSTGRES_DB: pg_app_test
POSTGRES_USER: postgres
POSTGRES_HOST_AUTH_METHOD: trust
DATABASE_HOST: postgres