Skip to content

generate: fix PGDATASOURCE for internal/database/gen.sh with nix

Administrator requested to merge nsc/db-migrate-gen-nixfix into main

Created by: Strum355

With Nix, I have the following env-var set:

PGDATASOURCE=postgresql:///postgres?host=/home/noah/.sourcegraph/postgres
PGDATA=/home/noah/.sourcegraph/postgres/13.6
PGDATABASE=postgres
PGUSER=noah
PGHOST=/home/noah/.sourcegraph/postgres

As this datasource uses Unix socket instead of TCP, it was resulting in a PGDATASOURCE that wouldnt work:

+ export PGDATASOURCE=postgres://noah:@/home/noah/.sourcegraph/postgres:/sg-squasher-frontend
+ PGDATASOURCE=postgres://noah:@/home/noah/.sourcegraph/postgres:/sg-squasher-frontend
+ export CODEINTEL_PGDATASOURCE=postgres://noah:@/home/noah/.sourcegraph/postgres:/sg-squasher-codeintel
+ CODEINTEL_PGDATASOURCE=postgres://noah:@/home/noah/.sourcegraph/postgres:/sg-squasher-codeintel
+ export CODEINSIGHTS_PGDATASOURCE=postgres://noah:@/home/noah/.sourcegraph/postgres:/sg-squasher-codeinsights
+ CODEINSIGHTS_PGDATASOURCE=postgres://noah:@/home/noah/.sourcegraph/postgres:/sg-squasher-codeinsights
+ ./tmp-sg migration describe -db frontend --format=psql -force -out internal/database/schema.md
❌ DB not available: failed to connect to `host=/home/noah/.sourcegraph/postgres user=noah database=home/noah/.sourcegraph/postgres:/sg-squasher-frontend`: server error (FATAL: database "home/noah/.sourcegraph/postgres:/sg-squasher-frontend" does not exist (SQLSTATE 3D000))

This change makes it look like this instead:

+ test -d /home/noah/.sourcegraph/postgres
+ IS_UNIX_POSTGRES=0
+ '[' 0 ']'
+ PGDATASOURCE_BASE='postgresql:///postgres?host=/home/noah/.sourcegraph/postgres'
+ export 'PGDATASOURCE=postgresql:///postgres?host=/home/noah/.sourcegraph/postgres&dbname=sg-squasher-frontend'
+ PGDATASOURCE='postgresql:///postgres?host=/home/noah/.sourcegraph/postgres&dbname=sg-squasher-frontend'
+ export 'CODEINTEL_PGDATASOURCE=postgresql:///postgres?host=/home/noah/.sourcegraph/postgres&dbname=sg-squasher-codeintel'
+ CODEINTEL_PGDATASOURCE='postgresql:///postgres?host=/home/noah/.sourcegraph/postgres&dbname=sg-squasher-codeintel'
+ export 'CODEINSIGHTS_PGDATASOURCE=postgresql:///postgres?host=/home/noah/.sourcegraph/postgres&dbname=sg-squasher-codeinsights'
+ CODEINSIGHTS_PGDATASOURCE='postgresql:///postgres?host=/home/noah/.sourcegraph/postgres&dbname=sg-squasher-codeinsights'
+ ./tmp-sg migration describe -db frontend --format=psql -force -out internal/database/schema.md

cc'ing @keegancsmith in case he has a better solution

Test plan

I ran the thing : ) maybe someone outside of Nix should also run the thing and edit this message

Merge request reports

Loading