- compose.yml: add postgres service with profiles, healthcheck, pg_isready - compose.yml: add DATABASE_URL env var and conditional depends_on (required: false) - compose.yml: add postgres-data volume; default deploy remains SQLite-only - compose.dev.yml: add postgres service with port 5432 exposed for local dev - compose.dev.yml: add DATABASE_URL env var and conditional depends_on - pkg/diunwebhook/postgres_test.go: build-tagged NewTestPostgresServer helper
30 lines
731 B
Go
30 lines
731 B
Go
//go:build postgres
|
|
|
|
package diunwebhook
|
|
|
|
import (
|
|
"database/sql"
|
|
"os"
|
|
|
|
_ "github.com/jackc/pgx/v5/stdlib"
|
|
)
|
|
|
|
// NewTestPostgresServer constructs a Server backed by a PostgreSQL database.
|
|
// Requires a running PostgreSQL instance. Set TEST_DATABASE_URL to override
|
|
// the default connection string.
|
|
func NewTestPostgresServer() (*Server, error) {
|
|
databaseURL := os.Getenv("TEST_DATABASE_URL")
|
|
if databaseURL == "" {
|
|
databaseURL = "postgres://diun:diun@localhost:5432/diundashboard_test?sslmode=disable"
|
|
}
|
|
db, err := sql.Open("pgx", databaseURL)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := RunPostgresMigrations(db); err != nil {
|
|
return nil, err
|
|
}
|
|
store := NewPostgresStore(db)
|
|
return NewServer(store, ""), nil
|
|
}
|