Skip to content

Commit d194a07

Browse files
committed
Add dbdump and stat targets to the makefile
This allows to 1. load an existing db dump into the docker compose dev setup 2. rerun the statistic build script in case somebody works on that using this setup
1 parent e66ddcd commit d194a07

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
COMPOSE ?= docker compose -f docker-compose.dev.yml
22

3-
.PHONY: dev dev-detach down shell console test imap logs db-migrate db-reset psql sim-email-once sim-email-stream
3+
.PHONY: dev dev-detach down shell console test imap logs db-migrate db-reset db-import stats psql sim-email-once sim-email-stream
44

55
dev: ## Start dev stack (foreground)
66
$(COMPOSE) up --build
@@ -30,6 +30,18 @@ db-migrate: ## Run db:migrate
3030
db-reset: ## Drop and prepare (create/migrate)
3131
$(COMPOSE) run --rm web bin/rails db:drop && bin/rails db:prepare
3232

33+
db-import: ## Drop dev DB and import a public dump (env: DUMP=/path/to/public-YYYY-MM.sql.gz)
34+
@if [ -z "$(DUMP)" ]; then echo "Set DUMP=/path/to/public-YYYY-MM.sql.gz"; exit 1; fi
35+
$(COMPOSE) exec -T db bash -lc 'psql -U $${POSTGRES_USER:-hackorum} -d postgres -c "DROP DATABASE IF EXISTS $${POSTGRES_DB:-hackorum_development};" -c "CREATE DATABASE $${POSTGRES_DB:-hackorum_development};"'
36+
@if echo "$(DUMP)" | grep -qE '\.gz$$'; then \
37+
gzip -cd "$(DUMP)" | $(COMPOSE) exec -T db bash -lc 'psql -U $${POSTGRES_USER:-hackorum} -d $${POSTGRES_DB:-hackorum_development}'; \
38+
else \
39+
cat "$(DUMP)" | $(COMPOSE) exec -T db bash -lc 'psql -U $${POSTGRES_USER:-hackorum} -d $${POSTGRES_DB:-hackorum_development}'; \
40+
fi
41+
42+
stats: ## Rebuild stats (env: GRANULARITY=all|daily|weekly|monthly)
43+
$(COMPOSE) exec web bundle exec ruby script/build_stats.rb $${GRANULARITY:-all}
44+
3345
psql: ## Open psql against the dev DB
3446
COMPOSE_PROFILES=tools $(COMPOSE) run --rm psql
3547

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ Useful commands:
2323
* Rails console: `docker compose -f docker-compose.dev.yml exec web bin/rails console`
2424
* Migrations/seeds: `docker compose -f docker-compose.dev.yml exec web bin/rails db:prepare`
2525
* Tests: `docker compose -f docker-compose.dev.yml exec web bundle exec rspec`
26+
* Import a public DB dump: `make db-import DUMP=/path/to/public-YYYY-MM.sql.gz`
2627

2728
Makefile shortcuts:
2829
* `make dev` / `make dev-detach` / `make down`
2930
* `make shell` / `make console` / `make logs`
3031
* `make test`
3132
* `make db-migrate` / `make db-reset`
33+
* `make db-import`
3234
* `make psql`
3335

36+
Public database dumps (schema + public data) are published at https://dumps.hackorum.dev/
37+
3438
### Incoming email simulator
3539

3640
There are two helper scripts `script/simulate_email_once.rb` and `simulate_email_stream.rb` that simulate incoming emails.

0 commit comments

Comments
 (0)