Fail gracefully if the database isn't ready
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
PGDATA=/var/lib/postgresql/data
|
||||||
|
POSTGRES_USER=expdbuser
|
||||||
|
POSTGRES_PASSWORD=expDBPass
|
||||||
|
POSTGRES_DB=expenses
|
||||||
@@ -13,6 +13,15 @@ build_release_alpine:
|
|||||||
mkdir -p $(build)/data/
|
mkdir -p $(build)/data/
|
||||||
find $(build) -name "*.ttf" ! -name DejaVuSansMono.ttf -delete
|
find $(build) -name "*.ttf" ! -name DejaVuSansMono.ttf -delete
|
||||||
|
|
||||||
|
devdb_start:
|
||||||
|
podman compose start database
|
||||||
|
|
||||||
|
devdb_status:
|
||||||
|
podman compose stats database
|
||||||
|
|
||||||
|
devdb_stop:
|
||||||
|
podman compose stop database
|
||||||
|
|
||||||
build_image: build_release_alpine
|
build_image: build_release_alpine
|
||||||
docker buildx build -t $(registry)/$(repo)/expensesweb:$(tag) .
|
docker buildx build -t $(registry)/$(repo)/expensesweb:$(tag) .
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# Download a production database's data
|
||||||
|
```bash
|
||||||
|
docker exec -i <container-name> \
|
||||||
|
pg_dump -U <db-user> -a -d <database> > outputfile.sql
|
||||||
|
```
|
||||||
|
|
||||||
|
# Start a local development database
|
||||||
|
|
||||||
|
|
||||||
|
# Upload a database
|
||||||
|
```bash
|
||||||
|
# delete the pgsql-data-dev directory contents
|
||||||
|
# restart the container
|
||||||
|
psql -h 127.0.0.1 -p 5431 -U expdbuser -d expenses -f ./data.sql
|
||||||
|
```
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
services:
|
||||||
|
database:
|
||||||
|
image: docker.io/library/postgres:16
|
||||||
|
container_name: expenses-dev-db
|
||||||
|
hostname: expenses-dev-db
|
||||||
|
env_file:
|
||||||
|
- .pgenv
|
||||||
|
ports:
|
||||||
|
- "5431:5432"
|
||||||
|
restart: unless-stopped
|
||||||
+4
-6
@@ -23,10 +23,8 @@ type ExpApp struct {
|
|||||||
TypeRepo repo.TypeRepository
|
TypeRepo repo.TypeRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
// App provides access to the expenses main service.
|
||||||
// App provides access to the expenses main service.
|
var App *ExpApp
|
||||||
App *ExpApp
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewExpenseApp returns a new instance of our core App.
|
// NewExpenseApp returns a new instance of our core App.
|
||||||
func NewExpenseApp(dbPool *pgxpool.Pool, luaVM *lua.LState) *ExpApp {
|
func NewExpenseApp(dbPool *pgxpool.Pool, luaVM *lua.LState) *ExpApp {
|
||||||
@@ -103,7 +101,7 @@ func createPGXPoolConn(ctx context.Context) (*pgxpool.Pool, error) {
|
|||||||
var result int
|
var result int
|
||||||
err = conn.QueryRow(ctx, "SELECT 1").Scan(&result)
|
err = conn.QueryRow(ctx, "SELECT 1").Scan(&result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("connection test query failed: " + err.Error())
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return conn, nil
|
return conn, nil
|
||||||
@@ -123,7 +121,7 @@ func StartApp() error {
|
|||||||
// Run the migrations
|
// Run the migrations
|
||||||
err = runMigrations(luaVM)
|
err = runMigrations(luaVM)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to run migrations: %v", err)
|
log.Fatalf("Unable to run migrations: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create our final app thing
|
// Create our final app thing
|
||||||
|
|||||||
Reference in New Issue
Block a user