I'm trying to run a Postgres service in my Pipeline where I created all my test data in a db I'm running on my local machine. I ran a pg_dump to create test data tar file. When I try to pg_restore that tar file in my pipeline, it looks like it works, but the restore script fails and my pipeline errors.
Here is my pipeline file:
image: node:20.10.0
definitions:
services:
postgres:
image: postgres:16
environment:
POSTGRES_DB: reporting
POSTGRES_USER: postgres
POSTGRES_PASSWORD: mysecretpassword
options:
docker: true
pipelines:
default:
- step:
caches:
- docker
script:
- apt-get update && apt-get install -y postgresql-client
- export PGPASSWORD='mysecretpassword'
- npm install
- pg_restore -U postgres -d reporting -h localhost -c -C -v --no-owner --no-acl ./tests/databaseScripts/reportingDump.tar
- npm run unit-tests
- npm run integration-tests
services:
- postgres
And here is the Pipeline output:
+ pg_restore -U postgres -d reporting -h localhost -c -C -v --no-owner --no-acl ./tests/databaseScripts/reportingDump.tar
pg_restore: connecting to database for restore
pg_restore: dropping DATABASE reporting pg_restore: while PROCESSING TOC: pg_restore: from TOC entry 3422; 1262 16384 DATABASE reporting postgres pg_restore: error: could not execute query: ERROR: cannot drop the currently open database Command was: DROP DATABASE reporting;
pg_restore: creating DATABASE "reporting"
pg_restore: error: could not execute query: ERROR: database "reporting" already exists Command was: CREATE DATABASE reporting WITH TEMPLATE = template0 ENCODING = 'UTF8' LOCALE_PROVIDER = libc LOCALE = 'en_US.utf8'; pg_restore: connecting to new database "reporting"
pg_restore: creating SCHEMA "public" pg_restore: creating FUNCTION "public.f_getDataForDeviationCalculation(character varying, date, date)"
pg_restore: creating TABLE "public.Deck"
pg_restore: creating TABLE "public.Impressions"
pg_restore: creating TABLE "public.Presentation-Named"
pg_restore: creating TABLE "public.PresentationSlide"
pg_restore: creating TABLE "public.Session"
pg_restore: creating TABLE "public.Slide"
pg_restore: creating TABLE "public.User"
pg_restore: processing data for table "public.Deck"
pg_restore: processing data for table "public.Impressions"
pg_restore: processing data for table "public.Presentation-Named"
pg_restore: processing data for table "public.PresentationSlide"
pg_restore: processing data for table "public.Session"
pg_restore: processing data for table "public.Slide"
pg_restore: processing data for table "public.User"
pg_restore: creating CONSTRAINT "public.Deck Deck_pkey"
pg_restore: creating CONSTRAINT "public.Impressions Impressions_pkey" pg_restore: creating CONSTRAINT "public.Presentation-Named Presentation-Named_pkey"
pg_restore: creating CONSTRAINT "public.PresentationSlide PresentationSlide_pkey"
pg_restore: creating CONSTRAINT "public.Session Session_pkey"
pg_restore: creating CONSTRAINT "public.Slide Slide_pkey"
pg_restore: creating CONSTRAINT "public.User User_pkey"
pg_restore: warning: errors ignored on restore: 2
Skipping cache upload for failed step
Searching for test report files in directories named [test-results, failsafe-reports, test-reports, TestResults, surefire-reports] down to a depth of 4
Finished scanning for test reports. Found 0 test report files.
Merged test suites, total number tests is 0, with 0 failures and 0 errors.
I see that there is an error trying to drip the reporting database, but that doesn't seem to stop the restore from running. It's still creating the tables, loading the data and adding the constraints. Can someone tell me why this step is failing my pipeline?