Skip to content

Open-source status page, incident response and uptime monitoring

fix: add db-migrate one-shot service so self-hosted compose runs migrations (#2428)

Moulik Aggarwal27ee91a1c4d0
diff --git a/DOCKER.md b/DOCKER.md
index 66cffa94e..c29c46a45 100644
--- a/DOCKER.md
+++ b/DOCKER.md
@@ -11,18 +11,18 @@ cp .env.docker.example .env.docker
# 2. Configure required variables (see Configuration section)
vim .env.docker
-# 3. Build and start services (migrations will run automatically)
+# 3. Build and start services (the db-migrate one-shot applies migrations before apps start)
export DOCKER_BUILDKIT=1
docker compose up -d
# 4. Check service health
docker compose ps
-# 5. (Optional) Seed database with test data
-docker run --rm --network openstatus \
- -e DATABASE_URL=http://libsql:8080 \
- $(docker build -q -f apps/workflows/Dockerfile --target build .) \
- sh -c "cd /app/packages/db && deno run -A --sloppy-imports src/seed.mts"
+# 5. (Optional) Seed database with test data (uses libsql's host-published
+# port — seed refuses non-localhost databases by design)
+docker run --rm --network host \
+ -e DATABASE_URL=http://localhost:8080 \
+ --entrypoint deno openstatus/db-migrate:latest task seed
# 6. (Optional) Deploy Tinybird local - requires tb CLI
cd packages/tinybird
@@ -51,6 +51,7 @@ docker builder prune
| Service | Port | Purpose |
|---------|------|---------|
+| db-migrate | — | One-shot DB migrations (exits after applying) |
| workflows | 3000 | Background jobs |
| server | 3001 | API backend (tRPC) |
| dashboard | 3002 | Admin interface |
@@ -87,17 +88,15 @@ docker builder prune
### Automatic Migrations
-Migrations run **automatically** when you start the stack with `docker compose up -d`.
+Migrations run **automatically** when you start the stack with `docker compose up -d`: the `db-migrate` one-shot service applies all drizzle migrations and exits before the app services boot (they wait on its `service_completed_successfully` condition). Re-running `docker compose up -d` is safe — drizzle records applied migrations in the `__drizzle_migrations` table and skips them on subsequent runs.
**Verifying migrations:**
```bash
-# Check workflows logs for migration output
-docker compose logs workflows | grep -A 5 "Running database migrations"
+docker compose logs db-migrate
# Should show:
-# openstatus-workflows | Running database migrations...
-# openstatus-workflows | Migrated successfully
-# openstatus-workflows | Starting workflows service...
+# openstatus-db-migrate | Running migrations
+# openstatus-db-migrate | Migrated successfully
```
**Manual migration:**
@@ -105,13 +104,13 @@ docker compose logs workflows | grep -A 5 "Running database migrations"
If you need to re-run migrations or troubleshoot:
```bash
-# Run migrations using workflows container
-docker compose exec workflows sh -c "cd /app/packages/db && deno run -A src/migrate.mts"
-
-# Or restart workflows to trigger migrations again
-docker compose restart workflows
+docker compose run --rm db-migrate
```
+**Troubleshooting `no such table` errors:**
+
+A `SQLITE_UNKNOWN: no such table` error from dashboard or status-page means the database is unmigrated. Check `docker compose logs db-migrate` for the failure — common causes are a wrong `DATABASE_AUTH_TOKEN` in `.env.docker` or libsql not being healthy. (`DATABASE_URL` is pinned to `http://libsql:8080` by the compose files, so it cannot be misconfigured via `.env.docker`.) Fix the cause, then run `docker compose up -d` again.
+
### Seeding Test Data (Optional)
**Note:** Migrations run automatically, but seeding does **not**. You must manually seed the database if you want test data.
@@ -119,15 +118,16 @@ docker compose restart workflows
After migrations complete, seed the database with sample data:
```bash
-docker run --rm --network openstatus \
- -e DATABASE_URL=http://libsql:8080 \
- $(docker build -q -f apps/workflows/Dockerfile --target build .) \
- sh -c "cd /app/packages/db && deno run -A --sloppy-imports src/seed.mts"
+# Uses libsql's host-published port 8080 — seed refuses non-localhost
+# databases by design, so it cannot run over the compose-internal network
+docker run --rm --network host \
+ -e DATABASE_URL=http://localhost:8080 \
+ --entrypoint deno openstatus/db-migrate:latest task seed
```
This creates:
- 3 workspaces (`love-openstatus`, `test2`, `test3`)
-- 5 sample monitors and 1 status page with slug `status`
+- Sample monitors and 2 status pages (slugs `status` and `acme`)
- Test user account: `[email protected]`
- Sample incidents, status reports, and maintenance windows
@@ -137,7 +137,7 @@ This creates:
curl -s http://localhost:8080/ -H "Content-Type: application/json" \
-d '{"statements":["SELECT COUNT(*) FROM page"]}' | jq -r '.[0].results.rows[0][0]'
-# Should output: 1
+# Should output: 2
```
**Accessing Seeded Data:**
diff --git a/docker-compose-lightweight.yaml b/docker-compose-lightweight.yaml
index 1b125af7f..8b03b9ea5 100644
--- a/docker-compose-lightweight.yaml
+++ b/docker-compose-lightweight.yaml
@@ -33,25 +33,26 @@ services:
start_period: 10s
restart: unless-stopped
+ # Idempotent: drizzle skips already-applied migrations on every up
db-migrate:
container_name: openstatus-db-migrate
build:
context: .
- dockerfile: apps/workflows/Dockerfile
- target: build
+ dockerfile: packages/db/Dockerfile
+ image: openstatus/db-migrate:latest
+ # rebuild on every up so a stale image never skips new migrations
+ pull_policy: build
networks:
- openstatus
- working_dir: /app/packages/db
env_file:
- .env.docker
environment:
- DATABASE_URL=http://libsql:8080
- command: ["deno", "run", "-A", "src/migrate.mts"]
depends_on:
libsql:
condition: service_healthy
- restart: "no"
-
+ # retries absorb transient DB races; still settles to failure for the gates
+ restart: on-failure:3
dashboard:
container_name: openstatus-dashboard
diff --git a/docker-compose.github-packages.yaml b/docker-compose.github-packages.yaml
index 833ac298a..c047928b7 100644
--- a/docker-compose.github-packages.yaml
+++ b/docker-compose.github-packages.yaml
@@ -54,6 +54,30 @@ services:
restart: unless-stopped
# Internal Services - Using GitHub Packages
+ # Idempotent: drizzle skips already-applied migrations on every up.
+ # Intentionally the only locally-built service in this file; a
+ # ghcr-published image could replace it later.
+ db-migrate:
+ container_name: openstatus-db-migrate
+ build:
+ context: .
+ dockerfile: packages/db/Dockerfile
+ image: openstatus/db-migrate:latest
+ # rebuild on every up so a stale image never skips new migrations;
+ # also exempts this service from `docker compose pull`
+ pull_policy: build
+ networks:
+ - openstatus
+ env_file:
+ - .env.docker
+ environment:
+ - DATABASE_URL=http://libsql:8080
+ depends_on:
+ libsql:
+ condition: service_healthy
+ # retries absorb transient DB races; still settles to failure for the gates
+ restart: on-failure:3
+
workflows:
container_name: openstatus-workflows
image: ghcr.io/openstatushq/openstatus-workflows:latest
@@ -69,6 +93,8 @@ services:
- DATABASE_URL=http://libsql:8080
- PORT=3000
depends_on:
+ db-migrate:
+ condition: service_completed_successfully
libsql:
condition: service_healthy
healthcheck:
@@ -92,6 +118,8 @@ services:
- DATABASE_URL=http://libsql:8080
- PORT=3000
depends_on:
+ db-migrate:
+ condition: service_completed_successfully
workflows:
condition: service_healthy
libsql:
@@ -174,6 +202,8 @@ services:
- HOSTNAME=0.0.0.0
- AUTH_TRUST_HOST=true
depends_on:
+ db-migrate:
+ condition: service_completed_successfully
workflows:
condition: service_healthy
libsql:
@@ -203,6 +233,8 @@ services:
- HOSTNAME=0.0.0.0
- AUTH_TRUST_HOST=true
depends_on:
+ db-migrate:
+ condition: service_completed_successfully
workflows:
condition: service_healthy
libsql:
diff --git a/docker-compose.yaml b/docker-compose.yaml
index a161ab129..1a03b12cb 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -54,6 +54,27 @@ services:
restart: unless-stopped
# Internal Services
+ # Idempotent: drizzle skips already-applied migrations on every up
+ db-migrate:
+ container_name: openstatus-db-migrate
+ build:
+ context: .
+ dockerfile: packages/db/Dockerfile
+ image: openstatus/db-migrate:latest
+ # rebuild on every up so a stale image never skips new migrations
+ pull_policy: build
+ networks:
+ - openstatus
+ env_file:
+ - .env.docker
+ environment:
+ - DATABASE_URL=http://libsql:8080
+ depends_on:
+ libsql:
+ condition: service_healthy
+ # retries absorb transient DB races; still settles to failure for the gates
+ restart: on-failure:3
+
workflows:
container_name: openstatus-workflows
build:
@@ -72,6 +93,8 @@ services:
- DATABASE_URL=http://libsql:8080
- PORT=3000
depends_on:
+ db-migrate:
+ condition: service_completed_successfully
libsql:
condition: service_healthy
healthcheck:
@@ -98,6 +121,8 @@ services:
- DATABASE_URL=http://libsql:8080
- PORT=3000
depends_on:
+ db-migrate:
+ condition: service_completed_successfully
workflows:
condition: service_healthy
libsql:
@@ -164,6 +189,8 @@ services:
- HOSTNAME=0.0.0.0
- AUTH_TRUST_HOST=true
depends_on:
+ db-migrate:
+ condition: service_completed_successfully
workflows:
condition: service_healthy
libsql:
@@ -196,6 +223,8 @@ services:
- HOSTNAME=0.0.0.0
- AUTH_TRUST_HOST=true
depends_on:
+ db-migrate:
+ condition: service_completed_successfully
workflows:
condition: service_healthy
libsql:
diff --git a/packages/db/.dockerignore b/packages/db/.dockerignore
new file mode 100644
index 000000000..ae8b40e45
--- /dev/null
+++ b/packages/db/.dockerignore
@@ -0,0 +1,4 @@
+# This file is generated by Dofigen v2.8.0
+# See https://github.com/lenra-io/dofigen
+
+node_modules
diff --git a/packages/db/Dockerfile b/packages/db/Dockerfile
new file mode 100644
index 000000000..34e996425
--- /dev/null
+++ b/packages/db/Dockerfile
@@ -0,0 +1,76 @@
+# syntax=docker/dockerfile:1.19.0
+# This file is generated by Dofigen v2.8.0
+# See https://github.com/lenra-io/dofigen
+
+# install
+FROM node@sha256:6f7b03f7c2c8e2e784dcf9295400527b9b1270fd37b7e9a7285cf83b6951452d AS install
+LABEL \
+ org.opencontainers.image.base.digest="sha256:6f7b03f7c2c8e2e784dcf9295400527b9b1270fd37b7e9a7285cf83b6951452d" \
+ org.opencontainers.image.base.name="docker.io/node:24-slim" \
+ org.opencontainers.image.stage="install"
+WORKDIR /app/
+RUN \
+ --mount=type=bind,target=pnpm-workspace.yaml,source=pnpm-workspace.yaml \
+ --mount=type=bind,target=pnpm-lock.yaml,source=pnpm-lock.yaml \
+ --mount=type=bind,target=package.json,source=package.json \
+ --mount=type=bind,target=packages/db/package.json,source=packages/db/package.json \
+ --mount=type=bind,target=packages/assertions/package.json,source=packages/assertions/package.json \
+ --mount=type=bind,target=packages/locales/package.json,source=packages/locales/package.json \
+ --mount=type=bind,target=packages/regions/package.json,source=packages/regions/package.json \
+ --mount=type=bind,target=packages/theme-store/package.json,source=packages/theme-store/package.json \
+ --mount=type=bind,target=packages/utils/package.json,source=packages/utils/package.json \
+ --mount=type=cache,target=/root/.local/share/pnpm/store,sharing=locked \
+ <<EOF
+corepack enable pnpm
+pnpm install --prod --frozen-lockfile --filter=@openstatus/db... --verbose
+EOF
+
+# runtime
+FROM denoland/deno@sha256:69a9f3033e3f381770452648b1cbf4ae96ea409f7ef24f30afeff3d380705f62 AS runtime
+LABEL \
+ io.dofigen.version="2.8.0" \
+ org.opencontainers.image.authors="OpenStatus Team" \
+ org.opencontainers.image.base.digest="sha256:69a9f3033e3f381770452648b1cbf4ae96ea409f7ef24f30afeff3d380705f62" \
+ org.opencontainers.image.base.name="docker.io/denoland/deno:2.9.2" \
+ org.opencontainers.image.description="One-shot database migration runner for OpenStatus" \
+ org.opencontainers.image.source="https://github.com/openstatusHQ/openstatus" \
+ org.opencontainers.image.title="OpenStatus DB Migrate" \
+ org.opencontainers.image.vendor="OpenStatus"
+ENV DENO_DIR="/tmp/deno-dir"
+WORKDIR /app/packages/db
+COPY \
+ --chown=1000:1000 \
+ --link \
+ "packages/db" "/app/packages/db"
+COPY \
+ --chown=1000:1000 \
+ --link \
+ "packages/assertions" "/app/packages/assertions"
+COPY \
+ --chown=1000:1000 \
+ --link \
+ "packages/locales" "/app/packages/locales"
+COPY \
+ --chown=1000:1000 \
+ --link \
+ "packages/regions" "/app/packages/regions"
+COPY \
+ --chown=1000:1000 \
+ --link \
+ "packages/theme-store" "/app/packages/theme-store"
+COPY \
+ --chown=1000:1000 \
+ --link \
+ "packages/utils" "/app/packages/utils"
+COPY \
+ --from=install \
+ --chown=1000:1000 \
+ --link \
+ "/app/node_modules" "/app/node_modules"
+COPY \
+ --from=install \
+ --chown=1000:1000 \
+ --link \
+ "/app/packages" "/app/packages"
+USER 1000:1000
+ENTRYPOINT ["deno", "task", "migrate"]
diff --git a/packages/db/dofigen.lock b/packages/db/dofigen.lock
new file mode 100644
index 000000000..49aa6e917
--- /dev/null
+++ b/packages/db/dofigen.lock
@@ -0,0 +1,159 @@
+effective: |
+ ignore:
+ - node_modules
+ builders:
+ install:
+ fromImage:
+ path: node
+ digest: sha256:6f7b03f7c2c8e2e784dcf9295400527b9b1270fd37b7e9a7285cf83b6951452d
+ label:
+ org.opencontainers.image.base.name: docker.io/node:24-slim
+ org.opencontainers.image.base.digest: sha256:6f7b03f7c2c8e2e784dcf9295400527b9b1270fd37b7e9a7285cf83b6951452d
+ org.opencontainers.image.stage: install
+ workdir: /app/
+ run:
+ - corepack enable pnpm
+ - pnpm install --prod --frozen-lockfile --filter=@openstatus/db... --verbose
+ cache:
+ - target: /root/.local/share/pnpm/store
+ bind:
+ - target: pnpm-workspace.yaml
+ source: pnpm-workspace.yaml
+ - target: pnpm-lock.yaml
+ source: pnpm-lock.yaml
+ - target: package.json
+ source: package.json
+ - target: packages/db/package.json
+ source: packages/db/package.json
+ - target: packages/assertions/package.json
+ source: packages/assertions/package.json
+ - target: packages/locales/package.json
+ source: packages/locales/package.json
+ - target: packages/regions/package.json
+ source: packages/regions/package.json
+ - target: packages/theme-store/package.json
+ source: packages/theme-store/package.json
+ - target: packages/utils/package.json
+ source: packages/utils/package.json
+ fromImage:
+ path: denoland/deno
+ digest: sha256:69a9f3033e3f381770452648b1cbf4ae96ea409f7ef24f30afeff3d380705f62
+ label:
+ org.opencontainers.image.vendor: OpenStatus
+ org.opencontainers.image.source: https://github.com/openstatusHQ/openstatus
+ org.opencontainers.image.description: One-shot database migration runner for OpenStatus
+ org.opencontainers.image.title: OpenStatus DB Migrate
+ io.dofigen.version: 2.8.0
+ org.opencontainers.image.base.digest: sha256:69a9f3033e3f381770452648b1cbf4ae96ea409f7ef24f30afeff3d380705f62
+ org.opencontainers.image.authors: OpenStatus Team
+ org.opencontainers.image.base.name: docker.io/denoland/deno:2.9.2
+ workdir: /app/packages/db
+ env:
+ DENO_DIR: /tmp/deno-dir
+ copy:
+ - paths:
+ - packages/db
+ target: /app/packages/db
+ - paths:
+ - packages/assertions
+ target: /app/packages/assertions
+ - paths:
+ - packages/locales
+ target: /app/packages/locales
+ - paths:
+ - packages/regions
+ target: /app/packages/regions
+ - paths:
+ - packages/theme-store
+ target: /app/packages/theme-store
+ - paths:
+ - packages/utils
+ target: /app/packages/utils
+ - fromBuilder: install
+ paths:
+ - /app/node_modules
+ target: /app/node_modules
+ - fromBuilder: install
+ paths:
+ - /app/packages
+ target: /app/packages
+ entrypoint:
+ - deno
+ - task
+ - migrate
+images:
+ docker.io:
+ denoland:
+ deno:
+ 2.9.2:
+ digest: sha256:69a9f3033e3f381770452648b1cbf4ae96ea409f7ef24f30afeff3d380705f62
+ library:
+ node:
+ 24-slim:
+ digest: sha256:6f7b03f7c2c8e2e784dcf9295400527b9b1270fd37b7e9a7285cf83b6951452d
+resources:
+ dofigen.yml:
+ hash: 3347644fa382f2f6faa53be252b2bfa2f0b65aaee345bc391b93fd11f57f7af8
+ content: |
+ ignore:
+ - node_modules
+ builders:
+ install:
+ fromImage: node:24-slim
+ workdir: /app/
+ labels:
+ org.opencontainers.image.stage: install
+ bind:
+ - pnpm-workspace.yaml
+ - pnpm-lock.yaml
+ - package.json
+ - packages/db/package.json
+ - packages/assertions/package.json
+ - packages/locales/package.json
+ - packages/regions/package.json
+ - packages/theme-store/package.json
+ - packages/utils/package.json
+ run:
+ - corepack enable pnpm
+ - pnpm install --prod --frozen-lockfile --filter=@openstatus/db... --verbose
+ cache:
+ - /root/.local/share/pnpm/store
+
+ # One-shot migration runner: drizzle's migrator reads drizzle/ from disk at
+ # runtime, so the image ships source + node_modules instead of a compiled binary.
+ fromImage: denoland/deno:2.9.2
+ workdir: /app/packages/db
+
+ labels:
+ org.opencontainers.image.title: OpenStatus DB Migrate
+ org.opencontainers.image.description: One-shot database migration runner for OpenStatus
+ org.opencontainers.image.source: https://github.com/openstatusHQ/openstatus
+ org.opencontainers.image.vendor: OpenStatus
+ org.opencontainers.image.authors: OpenStatus Team
+
+ # Workspace package sources ship too (not just their node_modules) so pnpm's
+ # @openstatus/* symlinks resolve and seed.mts can run via the same image.
+ copy:
+ - packages/db /app/packages/db
+ - packages/assertions /app/packages/assertions
+ - packages/locales /app/packages/locales
+ - packages/regions /app/packages/regions
+ - packages/theme-store /app/packages/theme-store
+ - packages/utils /app/packages/utils
+ - fromBuilder: install
+ source: /app/node_modules
+ target: /app/node_modules
+ - fromBuilder: install
+ source: /app/packages
+ target: /app/packages
+
+ # /deno-dir (image default) is root-owned; the runtime user needs a writable
+ # cache dir for the .mts transpile emit.
+ env:
+ DENO_DIR: /tmp/deno-dir
+
+ # deno task keeps package.json's migrate script the single source of truth.
+ entrypoint:
+ - deno
+ - task
+ - migrate
diff --git a/packages/db/dofigen.yml b/packages/db/dofigen.yml
new file mode 100644
index 000000000..ab3c1c10f
--- /dev/null
+++ b/packages/db/dofigen.yml
@@ -0,0 +1,62 @@
+ignore:
+ - node_modules
+builders:
+ install:
+ fromImage: node:24-slim
+ workdir: /app/
+ labels:
+ org.opencontainers.image.stage: install
+ bind:
+ - pnpm-workspace.yaml
+ - pnpm-lock.yaml
+ - package.json
+ - packages/db/package.json
+ - packages/assertions/package.json
+ - packages/locales/package.json
+ - packages/regions/package.json
+ - packages/theme-store/package.json
+ - packages/utils/package.json
+ run:
+ - corepack enable pnpm
+ - pnpm install --prod --frozen-lockfile --filter=@openstatus/db... --verbose
+ cache:
+ - /root/.local/share/pnpm/store
+
+# One-shot migration runner: drizzle's migrator reads drizzle/ from disk at
+# runtime, so the image ships source + node_modules instead of a compiled binary.
+fromImage: denoland/deno:2.9.2
+workdir: /app/packages/db
+
+labels:
+ org.opencontainers.image.title: OpenStatus DB Migrate
+ org.opencontainers.image.description: One-shot database migration runner for OpenStatus
+ org.opencontainers.image.source: https://github.com/openstatusHQ/openstatus
+ org.opencontainers.image.vendor: OpenStatus
+ org.opencontainers.image.authors: OpenStatus Team
+
+# Workspace package sources ship too (not just their node_modules) so pnpm's
+# @openstatus/* symlinks resolve and seed.mts can run via the same image.
+copy:
+ - packages/db /app/packages/db
+ - packages/assertions /app/packages/assertions
+ - packages/locales /app/packages/locales
+ - packages/regions /app/packages/regions
+ - packages/theme-store /app/packages/theme-store
+ - packages/utils /app/packages/utils
+ - fromBuilder: install
+ source: /app/node_modules
+ target: /app/node_modules
+ - fromBuilder: install
+ source: /app/packages
+ target: /app/packages
+
+# /deno-dir (image default) is root-owned; the runtime user needs a writable
+# cache dir for the .mts transpile emit.
+env:
+ DENO_DIR: /tmp/deno-dir
+
+# deno task keeps package.json's migrate script the single source of truth.
+entrypoint:
+ - deno
+ - task
+ - migrate