Skip to content

Commit d62948c

Browse files
authored
chore: streamline compose migrations (#68)
* chore: address QA findings * chore: pin compose migration image
1 parent 843fa7d commit d62948c

4 files changed

Lines changed: 55 additions & 12 deletions

File tree

.env.example

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ API_KEY=your-secret-api-key-here
1010
# Postgres host port for docker-compose (optional). Default: 5432. Override only if 5432 is in use (e.g. POSTGRES_PORT=5433); keep DATABASE_URL in sync.
1111
# POSTGRES_PORT=5432
1212

13+
# Hub image tag for docker-compose migration container (optional). Default: 0.2.0.
14+
# Use a pinned release tag, not latest, so migration tooling is reproducible.
15+
# HUB_IMAGE_TAG=0.2.0
16+
1317
# Database connection URL (optional). Port must match POSTGRES_PORT when you override it.
1418
# Default: postgres://postgres:postgres@localhost:5432/test_db?sslmode=disable
1519
# Format: postgres://username:password@host:port/database?sslmode=disable
@@ -95,7 +99,7 @@ WEBHOOK_MAX_COUNT=500
9599
# GOOGLE_APPLICATION_CREDENTIALS= (optional; for google-gemini when outside Google Cloud: path to service account key JSON)
96100
# EMBEDDING_MODEL=<model name> (required to enable embeddings; no default)
97101

98-
# River UI basic auth (optional, used when running River UI via docker compose)
99-
# Defaults: admin / changeme if unset
102+
# Local River UI basic auth (optional, used by docker compose). Change these for your local setup as needed.
103+
# compose.yml defaults to admin / changeme if these are unset.
100104
RIVER_BASIC_AUTH_USER=admin
101105
RIVER_BASIC_AUTH_PASS=changeme

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,14 @@ If you want to evaluate Hub quickly, start with the docs:
8383
### Local development in this repository
8484

8585
This repository contains the standalone Hub API and worker. The local
86-
`compose.yml` starts dependency services only: PostgreSQL and River UI. It does
87-
not start `hub-api` or `hub-worker`; run those from this repository after the
88-
database is ready.
86+
`compose.yml` starts dependency services only: PostgreSQL, a one-shot
87+
`hub-migrate` container, and River UI. The migration container uses the packaged
88+
Hub image for `goose` and `river`, and bind-mounts this checkout's
89+
`migrations/` directory so the database schema matches the branch you are
90+
working on. The image tag defaults to the current Hub release and should stay
91+
pinned if you override `HUB_IMAGE_TAG`. Docker setup does not require migration
92+
tools on the host. It does not start `hub-api` or `hub-worker`; run those from
93+
this repository after the database is ready.
8994

9095
For a local Hub setup:
9196

@@ -98,7 +103,15 @@ make run
98103
`make run` applies River queue migrations and starts both `hub-api` and
99104
`hub-worker` for local webhook delivery and embedding jobs. Use `make run-api`
100105
or `make run-worker` only when you intentionally want to run one process on its
101-
own. `make dev-setup` runs the Hub schema migrations through `make init-db`.
106+
own. `make dev-setup` also runs the local Hub schema migrations through
107+
`make init-db`, which is useful when you are changing migration files in this
108+
repository.
109+
110+
The public Docker quickstart at [hub.formbricks.com/quickstart](https://hub.formbricks.com/quickstart/)
111+
is maintained outside this repository. Its Compose example should use the same
112+
one-shot migration service pattern, but rely on the published Hub image's bundled
113+
`/app/migrations` because quickstart users may not have this repository checked
114+
out.
102115

103116
For the full Formbricks XM Suite UI, use the
104117
[`formbricks/formbricks`](https://github.com/formbricks/formbricks) repository

compose.yml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,46 @@ services:
2121
postgres
2222
-c shared_preload_libraries=vector
2323
24+
# One-shot migration container for Docker-only setup. The Hub image supplies goose and river;
25+
# the bind mount keeps migrations aligned with this checkout.
26+
hub-migrate:
27+
image: ghcr.io/formbricks/hub:${HUB_IMAGE_TAG:-0.2.0}
28+
container_name: formbricks_hub_migrate
29+
restart: "no"
30+
entrypoint: ["sh", "-ec"]
31+
command:
32+
- |
33+
test -x /usr/local/bin/goose ||
34+
{ echo "Migration tool missing: /usr/local/bin/goose"; exit 1; }
35+
test -x /usr/local/bin/river ||
36+
{ echo "Migration tool missing: /usr/local/bin/river"; exit 1; }
37+
test -d /app/migrations ||
38+
{ echo "Migration directory missing: /app/migrations"; exit 1; }
39+
/usr/local/bin/goose -dir /app/migrations postgres "$$DATABASE_URL" up
40+
/usr/local/bin/river migrate-up --database-url "$$DATABASE_URL"
41+
environment:
42+
DATABASE_URL: postgres://postgres:postgres@postgres:5432/test_db?sslmode=disable
43+
volumes:
44+
- ./migrations:/app/migrations:ro
45+
depends_on:
46+
postgres:
47+
condition: service_healthy
48+
2449
# River UI - web dashboard for River job queue (webhook delivery jobs)
2550
riverui:
2651
image: ghcr.io/riverqueue/riverui:latest
2752
container_name: formbricks_riverui
2853
environment:
2954
DATABASE_URL: postgres://postgres:postgres@postgres:5432/test_db?sslmode=disable
30-
RIVER_BASIC_AUTH_USER: ${RIVER_BASIC_AUTH_USER}
31-
RIVER_BASIC_AUTH_PASS: ${RIVER_BASIC_AUTH_PASS}
55+
RIVER_BASIC_AUTH_USER: ${RIVER_BASIC_AUTH_USER:-admin}
56+
RIVER_BASIC_AUTH_PASS: ${RIVER_BASIC_AUTH_PASS:-changeme}
3257
ports:
3358
- '8081:8080'
3459
depends_on:
3560
postgres:
3661
condition: service_healthy
62+
hub-migrate:
63+
condition: service_completed_successfully
3764

3865
volumes:
3966
postgres_data:

tests/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ This directory contains integration tests for the Formbricks Hub API.
66

77
Before running the tests, ensure:
88

9-
1. **PostgreSQL is running** (e.g. `make docker-up`). `make docker-up` starts dependency containers, currently PostgreSQL and River UI; it does not start the Hub API or worker. The tests use the connection string from `.env` (`DATABASE_URL`) when set; if empty, the default `postgres://postgres:postgres@localhost:5432/test_db?sslmode=disable` is used. If you set `POSTGRES_PORT` in `.env`, keep `DATABASE_URL` in sync. If you see `password authentication failed for user "postgres"`, start the stack with `make docker-up` and run `make init-db`.
10-
2. **Database schema** has been initialized (`make init-db`).
11-
3. **River queue migrations** have been applied (`make river-migrate`) when testing worker-backed webhook delivery flows.
12-
4. **API_KEY** is set automatically by the tests; you do not need to set it.
9+
1. **PostgreSQL is running** (e.g. `make docker-up`). `make docker-up` starts dependency containers: PostgreSQL, the one-shot `hub-migrate` container, and River UI; it does not start the Hub API or worker. The tests use the connection string from `.env` (`DATABASE_URL`) when set; if empty, the default `postgres://postgres:postgres@localhost:5432/test_db?sslmode=disable` is used. If you set `POSTGRES_PORT` in `.env`, keep `DATABASE_URL` in sync.
10+
2. **Database schema and River queue migrations** have been initialized. The default `make docker-up` path runs them through the packaged `hub-migrate` container, using this checkout's `migrations/` directory. If you are editing local migration files after the stack is already running, run `make init-db` and `make river-migrate` against your test database.
11+
3. **API_KEY** is set automatically by the tests; you do not need to set it.
1312

1413
## Running Tests
1514

0 commit comments

Comments
 (0)