From 2e3762afe120d7aae703de0cf92d3d34d02a2d62 Mon Sep 17 00:00:00 2001 From: Isaias Tavares Date: Thu, 5 Nov 2026 01:15:21 -0300 Subject: [PATCH] feat(db): run TREK on PostgreSQL TREK runs on PostgreSQL when TREK_DB_URL is set, and on SQLite as before otherwise: an engine port under src/db/engine, the dialect helpers under src/db/dialect, a Postgres baseline for the migrations up to the cut, pg_dump/pg_restore backups, a probe of every repository method against a real server and a Postgres test lane in CI. --- .github/workflows/test.yml | 130 ++- CLAUDE.md | 5 +- Dockerfile | 12 +- README.md | 4 + charts/README.md | 1 + charts/trek/templates/deployment.yaml | 21 +- charts/trek/templates/secret.yaml | 6 + charts/trek/values.yaml | 24 +- docker-compose.postgres.yml | 87 ++ package-lock.json | 20 +- server/.env.example | 7 +- server/CLAUDE.md | 16 +- server/assets/postgres/baseline.json | 338 +++++++ server/assets/postgres/baseline.sql | 825 ++++++++++++++++++ server/package.json | 6 +- server/scripts/dialect-baseline.json | 3 - server/scripts/dialect-lint.mjs | 11 +- server/scripts/engine-dispatch-baseline.json | 3 + server/scripts/engine-dispatch-ratchet.mjs | 50 ++ server/scripts/generate-pg-baseline.ts | 229 +++++ server/scripts/pg-probe-baseline.json | 21 +- server/scripts/pg-probe.ts | 11 +- server/scripts/pg-probe/arg-samples.ts | 23 +- server/scripts/pg-probe/baseline.ts | 18 +- server/scripts/pg-probe/engines.ts | 7 +- server/scripts/pg-probe/helper-cases.ts | 13 + server/scripts/pg-probe/report.ts | 14 +- server/scripts/pg-probe/schema.ts | 106 --- server/scripts/size-baseline.json | 6 +- server/scripts/test-new-service-baseline.json | 1 - server/src/app-config/db-settings.ts | 14 + server/src/app-config/derive.ts | 17 + server/src/app-config/env.schema.ts | 14 + server/src/app-config/env.ts | 22 +- server/src/app-config/index.ts | 1 + server/src/db/dialect/catalog.ts | 37 + server/src/db/dialect/sql-functions.ts | 11 + server/src/db/email-case-index.ts | 19 +- server/src/db/engine/engine.ts | 49 ++ server/src/db/engine/index.ts | 58 ++ server/src/db/engine/postgres/baseline.ts | 93 ++ server/src/db/engine/postgres/clear-schema.ts | 41 + server/src/db/engine/postgres/pg-process.ts | 119 +++ server/src/db/engine/postgres/pg-tools.ts | 206 +++++ .../src/db/engine/postgres/postgres-driver.ts | 67 ++ .../src/db/engine/postgres/postgres-engine.ts | 90 ++ .../db/engine/postgres/postgres-triggers.ts | 32 + .../src/db/engine/postgres/restore-safety.ts | 50 ++ .../src/db/engine/postgres/schema-adjust.ts | 109 +++ .../db/engine/postgres/schema-bootstrap.ts | 185 ++++ server/src/db/engine/postgres/sql-split.ts | 59 ++ server/src/db/engine/postgres/ssl.ts | 42 + server/src/db/engine/redact-url.ts | 17 + server/src/db/engine/sqlite/sqlite-engine.ts | 61 ++ .../db/engine/sqlite/sqlite-maintenance.ts | 49 ++ server/src/db/migration-utils.ts | 32 +- server/src/db/orm.ts | 50 +- server/src/db/pre-migrate-snapshot.ts | 15 +- .../DayAccommodations.repository.ts | 9 +- .../repositories/GoogleApiUsage.repository.ts | 4 +- .../db/repositories/MaintenanceRepository.ts | 103 +-- .../src/db/repositories/Places.repository.ts | 16 +- .../ReservationDayPositions.repository.ts | 16 +- .../repositories/Reservations.repository.ts | 31 +- .../RouteUsageDaily.repository.ts | 10 +- .../src/db/repositories/Trips.repository.ts | 4 +- .../_shared/reservation-accommodation.ts | 22 + .../_shared/reservation-joined-query.ts | 12 +- server/src/db/standalone-orm.ts | 32 + server/src/index.ts | 2 + server/src/mikro-orm.config.ts | 42 +- .../src/nest/assistant/assistant.service.ts | 59 +- server/src/nest/backup/backup.impl.ts | 14 +- server/src/nest/backup/boot-restore.ts | 48 +- .../src/nest/backup/database-backup.module.ts | 24 +- server/src/nest/backup/database-swap.ts | 58 ++ .../nest/backup/postgres-database-backup.ts | 127 +++ .../src/nest/backup/sqlite-database-backup.ts | 111 +-- server/src/nest/common/describe-error.ts | 2 + .../database/database-backup.interface.ts | 22 +- .../nest/database/database-engine.module.ts | 30 + .../database/database-lifecycle.module.ts | 3 +- .../database/database-lifecycle.service.ts | 64 +- .../src/nest/database/maintenance.module.ts | 17 +- server/src/nest/database/orm.module.ts | 10 +- server/src/nest/database/unit-of-work.ts | 19 +- server/src/nest/places/places.helpers.ts | 17 + server/src/nest/places/places.service.ts | 16 +- server/tests/build-schema-snapshot.ts | 5 +- server/tests/e2e/assistant.e2e.test.ts | 27 + server/tests/helpers/fake-pg-tools.ts | 124 +++ server/tests/helpers/legacy-upgrade-suite.ts | 2 +- server/tests/helpers/test-addons.ts | 3 +- server/tests/helpers/test-uow.ts | 3 +- server/tests/integration/mcp.test.ts | 3 +- .../tests/integration/oauth-authorize.test.ts | 3 +- server/tests/integration/oauth.test.ts | 3 +- server/tests/integration/places.test.ts | 17 + .../plugins/boot-registry-order.test.ts | 7 +- .../plugin-runtime.task2-conversion.test.ts | 11 +- .../plugins/plugin-scheduler-sweep.test.ts | 3 +- .../integration/plugins/registry.test.ts | 3 +- server/tests/postgres/build-template.ts | 36 + server/tests/postgres/databases.ts | 37 + server/tests/postgres/global-setup.ts | 60 ++ server/tests/postgres/schema-parity.test.ts | 133 +++ server/tests/postgres/semantics.test.ts | 66 ++ server/tests/postgres/setup.ts | 44 + server/tests/unit/app-config/derive.test.ts | 28 + server/tests/unit/app-config/validate.test.ts | 37 + server/tests/unit/auto-backup.test.ts | 4 +- server/tests/unit/db/connection.test.ts | 15 +- server/tests/unit/db/dialect/catalog.test.ts | 85 ++ .../db/dialect/sql-functions.postgres.test.ts | 4 + server/tests/unit/db/engine/engine.test.ts | 133 +++ .../unit/db/engine/postgres/baseline.test.ts | 170 ++++ .../unit/db/engine/postgres/pg-tools.test.ts | 260 ++++++ .../engine/postgres/postgres-driver.test.ts | 47 + .../engine/postgres/schema-adjust.test.ts} | 52 +- .../engine/postgres/schema-bootstrap.test.ts | 267 ++++++ .../engine/sqlite/sqlite-maintenance.test.ts | 109 +++ .../unit/db/pre-migrate-snapshot.test.ts | 2 +- .../AssignmentParticipants.repository.test.ts | 3 +- .../DayAssignments.repository.test.ts | 3 +- .../InviteTokens.repository.test.ts | 3 +- .../MaintenanceRepository.test.ts | 86 +- .../repositories/McpTokens.repository.test.ts | 5 +- .../OauthClients.repository.test.ts | 3 +- .../OauthConsents.repository.test.ts | 3 +- .../OauthTokens.repository.test.ts | 3 +- .../PasswordResetTokens.repository.test.ts | 7 +- .../db/repositories/Places.repository.test.ts | 12 +- ...ReservationDayPositions.repository.test.ts | 34 +- .../db/repositories/Tags.repository.test.ts | 3 +- .../db/repositories/Tours.repository.test.ts | 5 +- .../db/repositories/Trips.repository.test.ts | 3 +- .../WebauthnCredentials.repository.test.ts | 3 +- .../identity-map-writeback.test.ts | 3 +- .../db/repositories/trek-repository.test.ts | 3 +- .../unit/db/restore-migrates-forward.test.ts | 4 +- .../tests/unit/db/transaction-yield.test.ts | 3 +- .../tests/unit/demo/demo-reset-path.test.ts | 6 +- .../restricted-syntax-selectors.test.ts | 2 +- .../tests/unit/nest-rpc/plugin-guards.test.ts | 3 +- server/tests/unit/nest/addons.service.test.ts | 3 +- server/tests/unit/nest/backup.impl.test.ts | 8 +- .../unit/nest/backup/database-swap.test.ts | 85 ++ server/tests/unit/nest/boot-restore.test.ts | 65 ++ .../database/database-engine.module.test.ts | 29 + .../database-lifecycle.service.test.ts | 52 +- .../nest/database/unit-of-work.d5.test.ts | 3 +- .../unit/nest/database/unit-of-work.test.ts | 3 +- server/tests/unit/nest/oauth.service.test.ts | 5 +- .../nest/postgres-database-backup.test.ts | 172 ++++ .../unit/nest/sqlite-database-backup.test.ts | 26 +- server/tests/unit/plugins/discovery.test.ts | 3 +- .../unit/plugins/plugin-oauth.service.test.ts | 3 +- .../plugin-runtime.boot-no-orm.test.ts | 3 +- .../unit/plugins/request-context.test.ts | 3 +- .../unit/plugins/settings-isolation.test.ts | 3 +- .../tests/unit/scripts/dialect-lint.test.ts | 2 + .../scripts/engine-dispatch-ratchet.test.ts | 88 ++ .../unit/scripts/pg-probe/arg-samples.test.ts | 27 +- .../unit/scripts/pg-probe/baseline.test.ts | 10 +- .../unit/scripts/pg-probe/report.test.ts | 30 +- server/tsconfig.scripts.json | 2 +- server/vitest.config.ts | 4 +- server/vitest.pg.config.ts | 62 ++ wiki/Backups.md | 10 +- wiki/Database-Postgres.md | 149 ++++ wiki/Environment-Variables.md | 9 +- wiki/Install-Docker-Compose.md | 17 +- wiki/Install-Helm.md | 29 +- wiki/Troubleshooting.md | 56 ++ wiki/Updating.md | 19 +- wiki/_Sidebar.md | 1 + 176 files changed, 6728 insertions(+), 777 deletions(-) create mode 100644 docker-compose.postgres.yml create mode 100644 server/assets/postgres/baseline.json create mode 100644 server/assets/postgres/baseline.sql create mode 100644 server/scripts/engine-dispatch-baseline.json create mode 100644 server/scripts/engine-dispatch-ratchet.mjs create mode 100644 server/scripts/generate-pg-baseline.ts delete mode 100644 server/scripts/pg-probe/schema.ts create mode 100644 server/src/app-config/db-settings.ts create mode 100644 server/src/db/dialect/catalog.ts create mode 100644 server/src/db/engine/engine.ts create mode 100644 server/src/db/engine/index.ts create mode 100644 server/src/db/engine/postgres/baseline.ts create mode 100644 server/src/db/engine/postgres/clear-schema.ts create mode 100644 server/src/db/engine/postgres/pg-process.ts create mode 100644 server/src/db/engine/postgres/pg-tools.ts create mode 100644 server/src/db/engine/postgres/postgres-driver.ts create mode 100644 server/src/db/engine/postgres/postgres-engine.ts create mode 100644 server/src/db/engine/postgres/postgres-triggers.ts create mode 100644 server/src/db/engine/postgres/restore-safety.ts create mode 100644 server/src/db/engine/postgres/schema-adjust.ts create mode 100644 server/src/db/engine/postgres/schema-bootstrap.ts create mode 100644 server/src/db/engine/postgres/sql-split.ts create mode 100644 server/src/db/engine/postgres/ssl.ts create mode 100644 server/src/db/engine/redact-url.ts create mode 100644 server/src/db/engine/sqlite/sqlite-engine.ts create mode 100644 server/src/db/engine/sqlite/sqlite-maintenance.ts create mode 100644 server/src/db/repositories/_shared/reservation-accommodation.ts create mode 100644 server/src/db/standalone-orm.ts create mode 100644 server/src/nest/backup/database-swap.ts create mode 100644 server/src/nest/backup/postgres-database-backup.ts create mode 100644 server/src/nest/common/describe-error.ts create mode 100644 server/src/nest/database/database-engine.module.ts create mode 100644 server/tests/helpers/fake-pg-tools.ts create mode 100644 server/tests/postgres/build-template.ts create mode 100644 server/tests/postgres/databases.ts create mode 100644 server/tests/postgres/global-setup.ts create mode 100644 server/tests/postgres/schema-parity.test.ts create mode 100644 server/tests/postgres/semantics.test.ts create mode 100644 server/tests/postgres/setup.ts create mode 100644 server/tests/unit/db/dialect/catalog.test.ts create mode 100644 server/tests/unit/db/engine/engine.test.ts create mode 100644 server/tests/unit/db/engine/postgres/baseline.test.ts create mode 100644 server/tests/unit/db/engine/postgres/pg-tools.test.ts create mode 100644 server/tests/unit/db/engine/postgres/postgres-driver.test.ts rename server/tests/unit/{scripts/pg-probe/schema.test.ts => db/engine/postgres/schema-adjust.test.ts} (53%) create mode 100644 server/tests/unit/db/engine/postgres/schema-bootstrap.test.ts create mode 100644 server/tests/unit/db/engine/sqlite/sqlite-maintenance.test.ts create mode 100644 server/tests/unit/nest/backup/database-swap.test.ts create mode 100644 server/tests/unit/nest/database/database-engine.module.test.ts create mode 100644 server/tests/unit/nest/postgres-database-backup.test.ts create mode 100644 server/tests/unit/scripts/engine-dispatch-ratchet.test.ts create mode 100644 server/vitest.pg.config.ts create mode 100644 wiki/Database-Postgres.md diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 546a08743..33f54c7d8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,6 +32,8 @@ permissions: # Server: S3 Contract (MinIO) # the storage driver against MinIO # Server: Postgres Probe the repository SQL against Postgres +# Server: Postgres Tests the suites that boot the app, plus PARITY-PG and +# the write lock, on Postgres (vitest.pg.config.ts) # Client: Types & Checks typecheck and the strict ratchet; then the page # pattern and the source ratchets (RTL, size, # Prettier, layers, offline path, duplication, @@ -44,7 +46,7 @@ permissions: # Client: Bundle the production build, one chunk per map engine # Client: End-to-End the app in Chromium and WebKit # Plugin SDK: Types & Coverage -# Repo: Docker Image builds the image and boots it until ready +# Repo: Docker Image builds the image and boots it until ready, on SQLite and on Postgres # Repo: Helm Chart & Compose # Repo: Sonar Scan SonarCloud analysis, not required # ci-ok the one required check (below) @@ -65,9 +67,9 @@ permissions: # test jobs feeds the scan. # - Job count: GitHub runs at most 20 jobs of the organisation at once and # does not say in which order it starts queued ones. A code change starts -# the 14 shards and about a dozen other jobs; seven of those (parity, the -# SDK, the bundle, S3, Postgres, shared coverage, the chart) are done in -# a minute or two, so what queues at the start waits about that long. The +# the 14 shards and about a dozen other jobs; eight of those (parity, the +# SDK, the bundle, S3, the Postgres probe and tests, shared coverage, the +# chart) are done in a few minutes, so what queues at the start waits about that long. The # jobs that run for minutes (shards, gates, e2e, the image) must not # outnumber the 20 slots, or one of them waits for another to finish and # the run grows by a whole job: a layout with six gate jobs did exactly @@ -282,6 +284,13 @@ jobs: # migration that changes a column regenerates it in the same change. run: cd server && npm run check:db-types + - name: Postgres baseline matches the entities + # server/assets/postgres/ is the schema a fresh Postgres database starts + # from, generated from the entities by gen:pg-baseline. Until a migration + # lands after its cut it must match them exactly; after, it is frozen + # and only its list of migrations is checked. + run: cd server && npm run check:pg-baseline + server-lint-checks: name: 'Server: Lint & Checks' needs: changes @@ -367,6 +376,12 @@ jobs: # so the code stays portable to a second engine. run: cd server && npm run lint:dialect + - name: Engine checks may only shrink + # isSqlite(/isPostgres( and platform instanceof outside src/db/dialect/ + # and src/db/engine/ are held to scripts/engine-dispatch-baseline.json, + # so what differs between engines stays in those two places. + run: cd server && npm run lint:engine-dispatch + - name: Writes outside a transaction # A method that writes twice does it inside one uow.transactional. # Today's exceptions sit in scripts/tx-writes-baseline.json and may @@ -805,6 +820,50 @@ jobs: if-no-files-found: ignore retention-days: 14 + # The Postgres lane: every suite that boots the app through buildApp() on the + # real database module, each file on its own copy of one migrated template, + # plus the Postgres-only suites (PARITY-PG, the write lock). The lane fails, + # never skips, without TREK_TEST_DB_URL. + server-postgres-tests: + name: 'Server: Postgres Tests' + runs-on: ubuntu-24.04 + timeout-minutes: 15 + needs: changes + if: needs.changes.outputs.code == 'true' + services: + postgres: + image: postgres:17 + env: + POSTGRES_PASSWORD: lane + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready -U postgres" + --health-interval 5s + --health-timeout 5s + --health-retries 20 + steps: + - uses: actions/checkout@v6 + with: + persist-credentials: false + + - uses: actions/setup-node@v6 + with: + node-version-file: .nvmrc + cache: npm + cache-dependency-path: package-lock.json + + - name: Install dependencies + run: npm ci + + - name: Build shared + run: npm run build --workspace=shared + + - name: Run the Postgres lane + env: + TREK_TEST_DB_URL: postgres://postgres:lane@127.0.0.1:5432/postgres + run: npm run test:pg --workspace=server + # The server suite in seven slices. vitest.shard.config.ts is vitest.config.ts # without the thresholds and the coverage reports: a slice's blob carries # its coverage to server-coverage, which checks the whole. fail-fast is off, @@ -1208,10 +1267,72 @@ jobs: docker logs trek-ci 2>&1 | grep 'SIGTERM received' >/dev/null \ || { echo "::error::the server never saw SIGTERM"; exit 1; } + # The same image on a Postgres database (TREK_DB_URL): an empty database + # gets the baseline schema, the admin is seeded, and the server answers + # ready. The database runs beside it on a private network, never exposed. + - name: Start the container on Postgres + run: | + set -euo pipefail + docker network create trek-ci-pg + docker run -d --name trek-ci-db --network trek-ci-pg \ + -e POSTGRES_PASSWORD=ci -e POSTGRES_DB=trek postgres:17 + for _ in $(seq 1 30); do + docker exec trek-ci-db pg_isready -U postgres -d trek >/dev/null 2>&1 && break + sleep 2 + done + docker exec trek-ci-db pg_isready -U postgres -d trek \ + || { echo "::error::Postgres did not accept connections within 60 seconds."; exit 1; } + mkdir -p "$RUNNER_TEMP/trek-pg/data" "$RUNNER_TEMP/trek-pg/uploads" + docker run -d --name trek-ci-on-pg --network trek-ci-pg -p 127.0.0.1:3001:3000 \ + --read-only --tmpfs /tmp:noexec,nosuid,size=128m \ + --security-opt no-new-privileges:true \ + --cap-drop ALL --cap-add CHOWN --cap-add SETUID --cap-add SETGID --cap-add KILL \ + -v "$RUNNER_TEMP/trek-pg/data:/app/data" \ + -v "$RUNNER_TEMP/trek-pg/uploads:/app/uploads" \ + -e ENCRYPTION_KEY="$(openssl rand -hex 32)" \ + -e TREK_DB_URL=postgres://postgres:ci@trek-ci-db:5432/trek \ + trek:ci + + # Twice: the first start creates the schema in the empty database, the + # restart finds it migrated and must start without touching it. + - name: Wait until the server on Postgres is ready, then again after a restart + run: | + wait_ready() { + for _ in $(seq 1 90); do + if [ "$(docker inspect -f '{{.State.Running}}' trek-ci-on-pg)" != "true" ]; then + echo "::error::The container on Postgres exited before it became ready." + exit 1 + fi + if curl -sf http://127.0.0.1:3001/api/health/ready; then + echo + return 0 + fi + sleep 2 + done + echo "::error::/api/health/ready on Postgres did not answer within 180 seconds." + exit 1 + } + wait_ready + docker restart -t 30 trek-ci-on-pg >/dev/null + wait_ready + + - name: Stop the container on Postgres gracefully + run: | + set -euo pipefail + docker stop -t 30 trek-ci-on-pg >/dev/null + code="$(docker inspect -f '{{.State.ExitCode}}' trek-ci-on-pg)" + [ "$code" = "0" ] || { echo "::error::docker stop ended with exit code $code, not a graceful shutdown"; exit 1; } + - name: Container log if: always() run: docker logs trek-ci 2>&1 || true + - name: Container log on Postgres + if: always() + run: | + docker logs trek-ci-on-pg 2>&1 || true + docker logs trek-ci-db 2>&1 | tail -50 || true + # The Helm chart and the compose files are what self-hosters deploy from, # and before this job only a release ever touched them. The chart is linted, # rendered with the defaults and with each secret and persistence mode, and @@ -1332,6 +1453,7 @@ jobs: - client-e2e - s3-contract - postgres-probe + - server-postgres-tests - server-tests - server-coverage - client-tests diff --git a/CLAUDE.md b/CLAUDE.md index 8b6cf1a0a..41cb44163 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -31,6 +31,7 @@ Tests: npm run test # all workspaces npm run test --workspace=server # vitest run (server); also test:unit / test:integration / test:ws npm run test:e2e # server e2e (boots Nest against a temp SQLite) +npm run test:pg --workspace=server # the Postgres lane (vitest.pg.config.ts; needs TREK_TEST_DB_URL, e.g. postgres://postgres:trek@127.0.0.1:55432/postgres) npm run test:cov # coverage (lcov) for all four packages incl. plugin-sdk cd client && npm run test # client vitest run cd client && npm run e2e # Playwright (CI runs the public and app projects; the screenshot and help-media ones are local) @@ -51,7 +52,9 @@ cd client && npm run lint:skips # no .only; skipped tests may cd client && npm run lint:i18n-keys # every key the client names exists in en; unused en keys may only shrink (CI gate) cd server && npm run lint:boundaries # no new import cycles or cross-domain reach-ins (CI gate) cd server && npm run lint:dialect # SQLite-only SQL spellings may only shrink (CI gate; rules in server/CLAUDE.md) +cd server && npm run lint:engine-dispatch # engine checks outside src/db/dialect/ and src/db/engine/ may only shrink (CI gate) cd server && npm run probe:pg # dialect helpers + the repository statements it reaches against Postgres (CI job; needs TREK_PG_PROBE_URL) +cd server && npm run check:pg-baseline # the Postgres baseline in server/assets/postgres/ matches the entities and the migrations (CI gate) cd server && npm run lint:tx # no new method writing twice outside one transaction (CI gate) cd server && npm run lint:test-sql # raw SQL fixtures in tests/ may only shrink; seed through tests/helpers/factories (CI gate) cd server && npm run lint:test-mocks # vi.mock of config, realtime and db modules in tests/ may only shrink (CI gate) @@ -134,7 +137,7 @@ These principles come out of a full-repo audit and shape all new code: ## Quality gates in CI -`.github/workflows/test.yml` runs, per package: typecheck (server also `typecheck:tests`, client also the strict-mode ratchet `lint:strict`), lint (client and server through `lint:warnings`, which also holds the warning count per rule), `lint:pages`, `lint:rtl`, `lint:size` (client and server), the server's `lint:strict`, `lint:boundaries`, `lint:tx`, `lint:dialect`, `lint:test-sql`, `lint:test-mocks`, `lint:test-new-service`, `lint:query-api`, `lint:mcp-zod`, `lint:service-http` and `lint:response-contracts`, the client's and server's `lint:format`, `lint:layers`, `lint:offline`, `lint:dup`, `lint:pairs`, `lint:skips`, `lint:i18n-keys` and `theme:lint`, shared's `contracts:open`, the repo-wide `lint:knip` (in server-lint-checks), `check:plugin-facts`, `i18n:parity:strict` (with the untranslated-strings ratchet), the S3 contract suite, the Postgres probe (`postgres-probe`: every dialect helper on SQLite and Postgres, and the statements every repository method reaches with sample arguments against a Postgres service; the SQL errors per method and the list of methods it cannot measure are held to a baseline that only shrinks and fails while it is still unmeasured; see `server/CLAUDE.md`), the browser end-to-end flows (Chromium and WebKit), a client build with `check:gl-split`, coverage for all four packages, then a SonarCloud scan. It also builds the Docker image and boots it until `/api/health/ready` answers (`docker-image`), and lints and renders the Helm chart against the Kubernetes schemas and runs `docker compose config` on every compose file (`deploy-manifests`). `lint-prettier.yml` additionally runs `lint` + `lint:format` on `shared/`, both check-only. `plugin-sdk` has no lint script and is outside the eslint gates. **Not in CI**: the screenshot and help-media Playwright projects; run them locally. There are no git hooks; nothing runs before a commit except you. Other workflows build Docker images, scan them, and publish `trek-plugin-sdk` on `plugin-sdk-v*` tags. +`.github/workflows/test.yml` runs, per package: typecheck (server also `typecheck:tests`, client also the strict-mode ratchet `lint:strict`), lint (client and server through `lint:warnings`, which also holds the warning count per rule), `lint:pages`, `lint:rtl`, `lint:size` (client and server), the server's `lint:strict`, `lint:boundaries`, `lint:tx`, `lint:dialect`, `lint:engine-dispatch`, `lint:test-sql`, `lint:test-mocks`, `lint:test-new-service`, `lint:query-api`, `lint:mcp-zod`, `lint:service-http` and `lint:response-contracts`, the client's and server's `lint:format`, `lint:layers`, `lint:offline`, `lint:dup`, `lint:pairs`, `lint:skips`, `lint:i18n-keys` and `theme:lint`, shared's `contracts:open`, the repo-wide `lint:knip` (in server-lint-checks), `check:plugin-facts`, `i18n:parity:strict` (with the untranslated-strings ratchet), the S3 contract suite, the Postgres probe (`postgres-probe`: every dialect helper on SQLite and Postgres, and the statements every repository method reaches with sample arguments against a Postgres service; the SQL errors per method and the list of methods it cannot measure are held to a baseline that only shrinks and fails while it is still unmeasured; see `server/CLAUDE.md`), the Postgres lane (`server-postgres-tests`: the suites that boot the app, PARITY-PG and the write lock on a Postgres service), the browser end-to-end flows (Chromium and WebKit), a client build with `check:gl-split`, coverage for all four packages, then a SonarCloud scan. It also builds the Docker image and boots it until `/api/health/ready` answers (`docker-image`), and lints and renders the Helm chart against the Kubernetes schemas and runs `docker compose config` on every compose file (`deploy-manifests`). `lint-prettier.yml` additionally runs `lint` + `lint:format` on `shared/`, both check-only. `plugin-sdk` has no lint script and is outside the eslint gates. **Not in CI**: the screenshot and help-media Playwright projects; run them locally. There are no git hooks; nothing runs before a commit except you. Other workflows build Docker images, scan them, and publish `trek-plugin-sdk` on `plugin-sdk-v*` tags. - **Job names read "package: what"** (`Server: Types`, `Client: Tests 3/7`), and the list at the top of `test.yml` says what each job holds. A new job follows the scheme and joins that list, and the job-count note there says when a long job needs a slot freed first. - **Tests run beside the gates, in shards.** The client and server suites run in slices on parallel runners (`client-tests`, `server-tests`, through each package's `vitest.shard.config.ts`), and `client-coverage`/`server-coverage` merge their blob reports and check the thresholds against the whole. A red slice is usually a failing test, a red merge job usually a threshold. diff --git a/Dockerfile b/Dockerfile index f1c462e28..e6ab8b731 100644 --- a/Dockerfile +++ b/Dockerfile @@ -72,10 +72,15 @@ COPY server/package.json ./server/ # package, and a telemetry ping. # The upgrade takes the Debian security fixes the base image was built before # (zlib, 11/2026, failed the image scan until node:24-trixie-slim caught up). +# +# postgresql-client-17 (Debian 13's own) brings pg_dump and pg_restore to +# /usr/lib/postgresql/17/bin, which back up an install on Postgres +# (TREK_DB_URL). pg_dump refuses a server newer than itself, so it stays at the +# newest major TREK supports. RUN apt-get update && \ apt-get upgrade -y --no-install-recommends && \ apt-get install -y --no-install-recommends tzdata dumb-init wget ca-certificates \ - libkitinerary-bin libsqlite3-0 && \ + libkitinerary-bin libsqlite3-0 postgresql-client-17 && \ npm ci --workspace=server --omit=dev --ignore-scripts && \ { ln -sf "$(find /usr/lib -name kitinerary-extractor -type f | head -1)" /usr/local/bin/kitinerary-extractor || true; } && \ rm -rf /var/lib/apt/lists/* /usr/local/lib/node_modules/npm /usr/local/bin/npm /usr/local/bin/npx && \ @@ -94,8 +99,9 @@ ENV KITINERARY_EXTRACTOR_PATH=/usr/local/bin/kitinerary-extractor COPY --chown=node:node --from=server-builder /app/server/dist ./server/dist # Runtime data assets read from server/assets at runtime: airports.json (flight -# transport search) and atlas/*.geojson.gz + atlas/admin1/*.geojson.gz (Atlas -# country/region map). The build +# transport search), atlas/*.geojson.gz + atlas/admin1/*.geojson.gz (Atlas +# country/region map) and postgres/baseline.* (the schema a fresh Postgres +# database starts from). The build # only emits dist, so these must be copied explicitly or the features silently # degrade to empty in the image. COPY --chown=node:node --from=server-builder /app/server/assets ./server/assets diff --git a/README.md b/README.md index 22b711357..7d90c3a1d 100644 --- a/README.md +++ b/README.md @@ -321,6 +321,10 @@ docker compose up -d See [Install with Docker Compose](https://github.com/liketrek/TREK/wiki/Install-Docker-Compose) for the full walkthrough. +TREK stores its data in SQLite by default. Set `TREK_DB_URL` to run it on a PostgreSQL 14 to 17 database instead. The +[`docker-compose.postgres.yml`](docker-compose.postgres.yml) example starts one beside TREK, and the +[Postgres guide](https://github.com/liketrek/TREK/wiki/Database-Postgres) covers the requirements and the backups. +

Helm (Kubernetes)

diff --git a/charts/README.md b/charts/README.md index 62060538b..48726dcb5 100644 --- a/charts/README.md +++ b/charts/README.md @@ -46,6 +46,7 @@ See `values.yaml` for more options. - Both PVCs are `ReadWriteOnce`. Set `persistence.data.accessModes` and/or `persistence.uploads.accessModes` to override, for example `[ReadWriteMany]` so a backup pod can mount the volume. On the data volume such a pod may only read: SQLite corrupts `travel.db` when a second process writes it over a network filesystem. - To use your own PVCs, set `persistence.data.existingClaim` and/or `persistence.uploads.existingClaim`. The other values for that volume (size, storageClassName, accessModes, annotations) are then ignored. - With `persistence.enabled: false`, the data and uploads volumes use an `emptyDir` — storage is ephemeral and lost on pod restart. Intended for testing only. +- `database.url` runs TREK on a PostgreSQL database instead of the SQLite file. The chart writes it into its Secret as `TREK_DB_URL`; `database.existingSecret` and `database.existingSecretKey` read it from a Secret you manage. Leave both empty for SQLite. Keep `replicas: 1` either way. See the wiki page `Database-Postgres`. - `JWT_SECRET` is managed entirely by the server — auto-generated into the data PVC on first start and rotatable via the admin panel (Settings → Danger Zone). No Helm configuration needed. - `ENCRYPTION_KEY` encrypts stored secrets (API keys, MFA, SMTP, OIDC) at rest. Recommended: set via `secretEnv.ENCRYPTION_KEY` or `existingSecret`. If left empty, the server falls back automatically: existing installs use `data/.jwt_secret` (no action needed on upgrade); fresh installs auto-generate a key persisted to the data PVC. - Liveness and readiness probes are configurable under `probes`. Overrides are merged over the defaults, so `--set probes.liveness.initialDelaySeconds=60` keeps the `httpGet` handler. When switching to `exec` or `tcpSocket`, clear `httpGet` in the same override. Set `probes.liveness: null` to remove a probe. diff --git a/charts/trek/templates/deployment.yaml b/charts/trek/templates/deployment.yaml index 7e426593f..fe844e908 100644 --- a/charts/trek/templates/deployment.yaml +++ b/charts/trek/templates/deployment.yaml @@ -1,3 +1,6 @@ +{{- if and .Values.database.url (not .Values.database.existingSecret) .Values.existingSecret }} +{{- fail "database.url is written into the chart's own Secret, which existingSecret replaces. Put TREK_DB_URL in your Secret and set database.existingSecret instead." }} +{{- end }} apiVersion: apps/v1 kind: Deployment metadata: @@ -5,11 +8,13 @@ metadata: labels: app: {{ include "trek.name" . }} spec: + # One replica. Its rate limits, pending codes, permission cache and WebSocket + # connections live in the process's memory, so a second pod would not share them. That + # holds with database.url (PostgreSQL) too; see updateStrategy in values.yaml. replicas: 1 - # TREK is a single-writer SQLite app on a ReadWriteOnce PVC, so the default - # RollingUpdate would start a second pod holding the same volume before the old one - # exits — a Multi-Attach deadlock, or two processes on one travel.db. Recreate tears - # the old pod down first. Keep it, see updateStrategy in values.yaml. + # The default RollingUpdate would start a second pod on the same ReadWriteOnce PVC + # before the old one exits: a Multi-Attach deadlock, or two processes on one travel.db. + # Recreate tears the old pod down first. Keep it, see updateStrategy in values.yaml. strategy: type: {{ .Values.updateStrategy | default "Recreate" }} selector: @@ -61,6 +66,14 @@ spec: name: {{ default (printf "%s-secret" (include "trek.fullname" .)) .Values.existingSecret }} key: {{ .Values.existingSecretKey | default "ENCRYPTION_KEY" }} optional: true + {{- if or .Values.database.url .Values.database.existingSecret }} + # Required when set: a missing key stops the pod rather than starting it on SQLite. + - name: TREK_DB_URL + valueFrom: + secretKeyRef: + name: {{ default (printf "%s-secret" (include "trek.fullname" .)) .Values.database.existingSecret }} + key: {{ if .Values.database.existingSecret }}{{ .Values.database.existingSecretKey | default "TREK_DB_URL" }}{{ else }}TREK_DB_URL{{ end }} + {{- end }} - name: ADMIN_EMAIL valueFrom: secretKeyRef: diff --git a/charts/trek/templates/secret.yaml b/charts/trek/templates/secret.yaml index eacc4da4e..f9c1440e2 100644 --- a/charts/trek/templates/secret.yaml +++ b/charts/trek/templates/secret.yaml @@ -8,6 +8,9 @@ metadata: type: Opaque data: {{ .Values.existingSecretKey | default "ENCRYPTION_KEY" }}: {{ .Values.secretEnv.ENCRYPTION_KEY | b64enc | quote }} + {{- if .Values.database.url }} + TREK_DB_URL: {{ .Values.database.url | b64enc | quote }} + {{- end }} {{- if .Values.secretEnv.ADMIN_EMAIL }} ADMIN_EMAIL: {{ .Values.secretEnv.ADMIN_EMAIL | b64enc | quote }} {{- end }} @@ -65,6 +68,9 @@ stringData: {{- else }} {{ .Values.existingSecretKey | default "ENCRYPTION_KEY" }}: {{ randAlphaNum 32 | quote }} {{- end }} + {{- if .Values.database.url }} + TREK_DB_URL: {{ .Values.database.url | quote }} + {{- end }} {{- if .Values.secretEnv.ADMIN_EMAIL }} ADMIN_EMAIL: {{ .Values.secretEnv.ADMIN_EMAIL | quote }} {{- end }} diff --git a/charts/trek/values.yaml b/charts/trek/values.yaml index 648058884..6abe14f01 100644 --- a/charts/trek/values.yaml +++ b/charts/trek/values.yaml @@ -4,10 +4,13 @@ image: # tag: latest pullPolicy: IfNotPresent -# Deployment update strategy. Keep Recreate: TREK is a single-writer SQLite app, and -# during a RollingUpdate the new pod migrates the database while the old one still -# writes to it. A ReadWriteMany volume does not make that safe; SQLite's WAL needs both -# processes on one host, which network filesystems do not provide. +# Deployment update strategy. Keep Recreate. The new pod migrates the database when it +# starts, and during a RollingUpdate it would do that while the old pod still writes to +# it. Recreate stops the old pod first. On SQLite two processes on one travel.db are +# unsafe, and a ReadWriteOnce volume cannot be attached to both pods at once. +# With database.url the database is PostgreSQL, but the reason for one replica stays: TREK +# keeps rate limits, pending codes, the permission cache and WebSocket connections in +# memory, so a second pod would not share them. Postgres does not make more replicas safe. updateStrategy: Recreate # Pod-level security context. fsGroup gives the node user (uid/gid 1000) group access @@ -178,6 +181,19 @@ env: # address is sent unless you set one here. +# Database. Empty (the default) keeps TREK on its SQLite file in the data volume. Set url to +# run TREK on a PostgreSQL database instead (see the wiki page Database-Postgres). The URL +# carries the password, so it is never a plain env value: with url, the chart writes it into +# its own Secret as TREK_DB_URL; with existingSecret, TREK reads TREK_DB_URL from that Secret +# under existingSecretKey and the chart writes nothing. existingSecret wins over url. The +# variable is required when either is set: a missing Secret key stops the pod instead of +# starting it on SQLite. +# url: "postgres://trek:@postgres.example.internal:5432/trek?sslmode=require" +database: + url: "" + existingSecret: "" + existingSecretKey: TREK_DB_URL + # Secret environment variables stored in a Kubernetes Secret. # JWT_SECRET is managed entirely by the server (auto-generated into the data PVC, # rotatable via the admin panel) — it is not configured here. diff --git a/docker-compose.postgres.yml b/docker-compose.postgres.yml new file mode 100644 index 000000000..dc5aaa17f --- /dev/null +++ b/docker-compose.postgres.yml @@ -0,0 +1,87 @@ +# TREK on a Postgres database instead of the SQLite file. See the wiki page +# Database-Postgres for what this changes, the requirements and the backups. +# +# Set the database password in a .env file beside this file (or in the +# shell) before the first start: +# POSTGRES_PASSWORD= +# The password goes into TREK_DB_URL below, so keep it to URL-safe characters +# or percent-encode it. Without POSTGRES_PASSWORD the postgres image refuses to +# initialize its database, and TREK does not start. +services: + db: + image: postgres:17 + container_name: trek-db + restart: unless-stopped + environment: + - POSTGRES_DB=${POSTGRES_DB:-trek} + - POSTGRES_USER=${POSTGRES_USER:-trek} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-} + security_opt: + - no-new-privileges:true + # No ports are published: only the trek service on the compose network reaches the database. + volumes: + - trek-pgdata:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 10s + logging: + driver: json-file + options: + max-size: 10m + max-file: "3" + + app: + image: mauriceboe/trek:latest + container_name: trek + depends_on: + db: + condition: service_healthy + read_only: true + security_opt: + - no-new-privileges:true + cap_drop: + - ALL + cap_add: + - CHOWN + - SETUID + - SETGID + # dumb-init runs as root and forwards SIGTERM to node, which runs as the + # node user; signalling another user's process needs KILL. See docker-compose.yml. + - KILL + tmpfs: + - /tmp:noexec,nosuid,size=128m + ports: + - "3000:3000" + environment: + - NODE_ENV=production + - PORT=3000 + - ENCRYPTION_KEY=${ENCRYPTION_KEY:-} # Recommended. Generate with: openssl rand -hex 32. + - TZ=${TZ:-UTC} + - LOG_LEVEL=${LOG_LEVEL:-info} + - ALLOWED_ORIGINS=${ALLOWED_ORIGINS:-} + # The database URL. Its host is the service name above; sslmode=disable is + # right on the compose network. Use sslmode=verify-full with sslrootcert= + # for a database reached over a network you do not control. + - TREK_DB_URL=postgres://${POSTGRES_USER:-trek}:${POSTGRES_PASSWORD:-}@db:5432/${POSTGRES_DB:-trek}?sslmode=disable + # Scale-out is not supported: keep one trek container (see Database-Postgres). + volumes: + - ./data:/app/data + - ./uploads:/app/uploads + restart: unless-stopped + logging: + driver: json-file + options: + max-size: 10m + max-file: "3" + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://localhost:$${PORT:-3000}/api/health || exit 1"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 15s + +volumes: + trek-pgdata: diff --git a/package-lock.json b/package-lock.json index 75e0dd845..0921101ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5684,7 +5684,6 @@ "version": "7.2.8", "resolved": "https://registry.npmjs.org/@mikro-orm/postgresql/-/postgresql-7.2.8.tgz", "integrity": "sha512-spAGvR8xfXGK0+mwsAsN3Kt5cg2Ge3DgXT3rNOeA7IxaBXpl+NMwXu5cSWes4jHlhWKJ4jzXyTo6xH+we9fbNA==", - "dev": true, "license": "MIT", "dependencies": { "@mikro-orm/sql": "7.2.8", @@ -19855,7 +19854,6 @@ "version": "8.23.1", "resolved": "https://registry.npmjs.org/pg/-/pg-8.23.1.tgz", "integrity": "sha512-aL96AHANtWjPLDOLqnhx+ngp9+UK7ETEU8VJrDCGvsSSi/mGLcWYsS6Herg7lmaBJe4uwrfqsa7gTEFaSizDoQ==", - "dev": true, "license": "MIT", "dependencies": { "pg-connection-string": "^2.14.1", @@ -19883,7 +19881,6 @@ "version": "1.4.1", "resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.4.1.tgz", "integrity": "sha512-6PQbsFWZcp9EmJEwy5cGQ2La+AMWpP46lgbb8X+U/XsHIUweYDNCpeuKck5RxL2MdVFi7krbbEi5nX4Zh7JhrQ==", - "dev": true, "license": "MIT", "optional": true }, @@ -19891,14 +19888,12 @@ "version": "2.14.1", "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.14.1.tgz", "integrity": "sha512-qR3kGNPBLpCNtz0evbKA0Y/MRFXwSSdT+pTJvYp/bXTcReZbvX1kzF0IyTc1QnxqF7AZbOeBhNL8R5mYQZV/MA==", - "dev": true, "license": "MIT" }, "node_modules/pg-cursor": { "version": "2.22.1", "resolved": "https://registry.npmjs.org/pg-cursor/-/pg-cursor-2.22.1.tgz", "integrity": "sha512-X10ldv3wwBONQkOSwgWEbaEITMGLd92V2Zd+xsFPhDt3nhhU3hpAT08SERBChnIFmomczLax6lKXLJrHPPXfxA==", - "dev": true, "license": "MIT", "peerDependencies": { "pg": "^8" @@ -19908,7 +19903,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz", "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==", - "dev": true, "license": "ISC", "engines": { "node": ">=4.0.0" @@ -19918,7 +19912,6 @@ "version": "3.14.0", "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.14.0.tgz", "integrity": "sha512-gKtPkFdQPU3DksooVLi9LsjZxrsBUZIpa+7aVx+LV5pNh0KzP4Zleud2po+ConrxbuXGBJ6Hfer6hdgpIBpBaw==", - "dev": true, "license": "MIT", "peerDependencies": { "pg": ">=8.0" @@ -19928,14 +19921,12 @@ "version": "1.16.1", "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.16.1.tgz", "integrity": "sha512-p9VOFMiHB/ZbJATetbg+99PxssTVSQRnyuPSQ67mN1+1KBOjZaZ83ZQzltnxPhJwSsC3nwVjJ10DVJlerbFzLg==", - "dev": true, "license": "MIT" }, "node_modules/pg-types": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz", "integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==", - "dev": true, "license": "MIT", "dependencies": { "pg-int8": "1.0.1", @@ -19952,7 +19943,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz", "integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==", - "dev": true, "license": "MIT", "engines": { "node": ">=4" @@ -19962,7 +19952,6 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz", "integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==", - "dev": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -19972,7 +19961,6 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz", "integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==", - "dev": true, "license": "MIT", "dependencies": { "xtend": "^4.0.0" @@ -19985,7 +19973,6 @@ "version": "1.0.5", "resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz", "integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==", - "dev": true, "license": "MIT", "dependencies": { "split2": "^4.1.0" @@ -20355,7 +20342,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-3.0.4.tgz", "integrity": "sha512-nAUSGfSDGOaOAEGwqsRY27GPOea7CNipJPOA7lPbdEpx5Kg3qzdP0AaWC5MlhTWV9s4hFX39nomVZ+C4tnGOJQ==", - "dev": true, "license": "MIT", "engines": { "node": ">=12" @@ -20365,7 +20351,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.1.tgz", "integrity": "sha512-5+5HqXnsZPE65IJZSMkZtURARZelel2oXUEO8rH83VS/hxH5vv1uHquPg5wZs8yMAfdv971IU+kcPUczi7NVBQ==", - "dev": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -20375,7 +20360,6 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-2.1.0.tgz", "integrity": "sha512-K7Juri8gtgXVcDfZttFKVmhglp7epKb1K4pgrkLxehjqkrgPhfG6OO8LHLkfaqkbpjNRnra018XwAr1yQFWGcA==", - "dev": true, "license": "MIT", "engines": { "node": ">=12" @@ -20385,7 +20369,6 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-4.1.0.tgz", "integrity": "sha512-nJLACcOHi2iyRuMJeW6CuIA0Dc0i1YEpRr26XDyHAfxPjYUJOFxwZjmOc5oFFctTTh/OlRAMlnlXEJvr170fJg==", - "dev": true, "license": "MIT", "engines": { "node": ">=12" @@ -25724,7 +25707,6 @@ "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", - "dev": true, "license": "MIT", "engines": { "node": ">=0.4" @@ -25933,6 +25915,7 @@ "@mikro-orm/core": "^7.2.7", "@mikro-orm/migrations": "^7.2.7", "@mikro-orm/nestjs": "^7.1.0", + "@mikro-orm/postgresql": "^7.2.7", "@mikro-orm/seeder": "^7.2.7", "@mikro-orm/sql": "^7.2.1", "@mikro-orm/sqlite": "^7.2.7", @@ -25987,7 +25970,6 @@ "@aws-lite/s3-types": "^0.2.8", "@eslint/js": "^10.0.1", "@mikro-orm/entity-generator": "^7.2.7", - "@mikro-orm/postgresql": "^7.2.7", "@nestjs/testing": "^11.2.5", "@swc/core": "^1.16.22", "@trivago/prettier-plugin-sort-imports": "^6.0.2", diff --git a/server/.env.example b/server/.env.example index e0bf2fcbe..b9549bece 100644 --- a/server/.env.example +++ b/server/.env.example @@ -47,13 +47,16 @@ DEMO_MODE=false # Demo mode: resets data hourly # DEMO_ADMIN_EMAIL=admin@trek.app # Email of that seeded demo admin. (default: admin@trek.app) # DEMO_ADMIN_PASS=admin12345 # Initial password of that seeded demo admin. Change it on a public demo. (default: admin12345) -# RESTORE_FROM_BACKUP=/app/data/backup.zip # Restore this backup on the first start, before any setup. Ignored once a database exists. +# RESTORE_FROM_BACKUP=/app/data/backup.zip # Restore this backup on the first start, before any setup. Ignored once a database exists (on Postgres: once the database holds a table). # FILE_UPLOAD_LIMIT_MB=50 # Max size (MB) of a file uploaded to a trip, a booking or a note. Videos keep their own 500 MB cap. Raise your reverse proxy's upload limit too. # BACKUP_MAX_DECOMPRESSED_MB=5120 # Max size (MB) a restore archive may unpack to, on both restore paths: the zip-bomb guard. Raise it if a large backup is refused with "Backup exceeds the maximum decompressed size". (default: 5120) # BACKUP_UPLOAD_LIMIT_MB=500 # Max size (MB) of a backup archive you can upload when restoring. Raise it if your backup exceeds 500 MB. If you sit behind a reverse proxy, raise its upload limit too (e.g. nginx client_max_body_size). +# TREK_DB_URL=postgres://trek:password@db:5432/trek # Run on a Postgres database instead of the SQLite file in data/. TREK creates its schema in an empty database and refuses one holding tables it did not create. sslmode=disable, require, verify-ca or verify-full (the last three always verify the certificate; sslrootcert= names the CA file). Cannot be combined with TREK_DB_FILE, TREK_DB_JOURNAL_MODE or TREK_DB_SYNCHRONOUS. +# TREK_DB_PG_BIN_DIR=/usr/lib/postgresql/17/bin # The directory holding pg_dump, pg_restore and psql, which back up and restore a Postgres database. Unset, TREK looks in /usr/lib/postgresql/<17..14>/bin, /usr/local/bin and /usr/bin (the Docker image installs the version 17 tools, which cannot dump a newer server). Unused on SQLite. +# TREK_DB_POOL_MAX=10 # Most connections TREK opens to the Postgres database (1 to 100). Unused on SQLite. (default: 10) # TREK_DB_JOURNAL_MODE=WAL # SQLite journal mode (DELETE, TRUNCATE, PERSIST, MEMORY, WAL, OFF). WAL is fastest and the right choice on local disk. Set DELETE if the data directory lives on network storage (Azure App Service, an SMB/NFS volume on a NAS) — WAL coordinates writers through a shared-memory file that those filesystems do not implement reliably. The mode is stored inside the database file, so it survives a restart; changing this applies on the next boot. -# TREK_DB_PRE_MIGRATE_SNAPSHOT=true # Copy the database to data/pre-migrate--