Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore(coderd/database/gen/dump): add optional DB_DUMP_CONNECTION_URL#16243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mafredri merged 1 commit intomainfrommafredri/chore-allow-custom-db-dump-url
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletionscoderd/database/gen/dump/main.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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"
)
Expand DownExpand Up@@ -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)
}

Expand All@@ -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)
}
}
5 changes: 5 additions & 0 deletionsdocs/CONTRIBUTING.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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"`
Comment on lines +75 to +79
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe add a warning note regardingpg_dump version compatibility:

DB_DUMP_CONNECTION_URL='postgresql://user:pass@ds918.home:5433/coder_tmp?sslmode=disable' make genpg_dump: error: server version: 16.2 (Debian 16.2-1.pgdg120+2); pg_dump version: 13.18pg_dump: error: aborting because of server version mismatchpanic: dump schema failed: exit status 1goroutine 1 [running]:main.main()        /Users/cian/src/coder/coder/coderd/database/gen/dump/main.go:70 +0x354exit status 2make: *** [Makefile:618: coderd/database/dump.sql] Error 1

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think this is an unlikely scenario, you can usepg_dump@16 withpostgresql@13 but not vice-versa as you saw here. Since we're advising to use an older postgresql server here, you'd really have to make an effort to use an even olderpg_dump 😄

johnstcn reacted with thumbs up emoji
- `pkg-config`
- on macOS, run `brew install pkg-config`
- `pixman`
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp