diff --git a/coderd/database/gen/dump/main.go b/coderd/database/gen/dump/main.go index 0d6364ac56..f99b69bdae 100644 --- a/coderd/database/gen/dump/main.go +++ b/coderd/database/gen/dump/main.go @@ -7,6 +7,8 @@ import ( "path/filepath" "runtime" + "golang.org/x/xerrors" + "github.com/coder/coder/v2/coderd/database/dbtestutil" "github.com/coder/coder/v2/coderd/database/migrations" ) @@ -37,25 +39,34 @@ func main() { } }() - connection, cleanup, err := dbtestutil.OpenContainerized(t, dbtestutil.DBContainerOptions{}) - if err != nil { - panic(err) + connection := os.Getenv("DB_DUMP_CONNECTION_URL") + if connection == "" { + var cleanup func() + var err error + connection, cleanup, err = dbtestutil.OpenContainerized(t, dbtestutil.DBContainerOptions{}) + if err != nil { + err = xerrors.Errorf("open containerized database failed: %w", err) + panic(err) + } + defer cleanup() } - defer cleanup() db, err := sql.Open("postgres", connection) if err != nil { + err = xerrors.Errorf("open database failed: %w", err) panic(err) } defer db.Close() err = migrations.Up(db) if err != nil { + err = xerrors.Errorf("run migrations failed: %w", err) panic(err) } dumpBytes, err := dbtestutil.PGDumpSchemaOnly(connection) if err != nil { + err = xerrors.Errorf("dump schema failed: %w", err) panic(err) } @@ -65,6 +76,7 @@ func main() { } err = os.WriteFile(filepath.Join(mainPath, "..", "..", "..", "dump.sql"), append(preamble, dumpBytes...), 0o600) if err != nil { + err = xerrors.Errorf("write dump failed: %w", err) panic(err) } } diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 22f169c556..7be637cb82 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -72,6 +72,11 @@ the following tools by hand: - [`pg_dump`](https://stackoverflow.com/a/49689589) - on macOS, run `brew install libpq zstd` - on Linux, install [`zstd`](https://github.com/horta/zstd.install) +- PostgreSQL 13 (optional if Docker is available) + - *Note*: If you are using Docker, you can skip this step + - on macOS, run `brew install postgresql@13` and `brew services start postgresql@13` + - To enable schema generation with non-containerized PostgreSQL, set the following environment variable: + - `export DB_DUMP_CONNECTION_URL="postgres://postgres@localhost:5432/postgres?password=postgres&sslmode=disable"` - `pkg-config` - on macOS, run `brew install pkg-config` - `pixman`