dx: Add a db script and target to Makefile
This commit is contained in:
parent
57ac5de1df
commit
13d5156e06
2 changed files with 23 additions and 1 deletions
5
Makefile
5
Makefile
|
|
@ -1,4 +1,4 @@
|
|||
.PHONY: help setup run dev build fmt migrate-up migrate-down migrate-status migrate-create generate docker-build
|
||||
.PHONY: help setup run dev build fmt migrate-up migrate-down migrate-status migrate-create db-reset generate docker-build
|
||||
|
||||
.DEFAULT_GOAL := help
|
||||
|
||||
|
|
@ -34,6 +34,9 @@ migrate-status: ## Show migration status
|
|||
migrate-create: ## Create a new migration (name=add_widgets)
|
||||
./scripts/goose-create.sh $(name)
|
||||
|
||||
db-reset: ## Wipe the database and reapply all migrations
|
||||
./scripts/reset-db.sh
|
||||
|
||||
generate: ## Run sqlc codegen
|
||||
sqlc generate
|
||||
|
||||
|
|
|
|||
19
scripts/reset-db.sh
Executable file
19
scripts/reset-db.sh
Executable file
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env bash
|
||||
# Reset the Postgres database configured in .env: drop all its content, then
|
||||
# reapply migrations from scratch.
|
||||
# Usage: ./scripts/reset-db.sh
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
set -a
|
||||
# shellcheck disable=SC1091
|
||||
source "$SCRIPT_DIR/../.env"
|
||||
set +a
|
||||
|
||||
DBSTRING="${GOOSE_DBSTRING:-postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=${DB_SSL_MODE}}"
|
||||
|
||||
echo "Dropping and recreating schema public on ${DB_NAME}..."
|
||||
psql "$DBSTRING" -v ON_ERROR_STOP=1 -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"
|
||||
|
||||
"$SCRIPT_DIR/goose.sh" up
|
||||
Loading…
Reference in a new issue