mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 22:57:32 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 39d2196a14 |
@@ -35,7 +35,7 @@ permissions:
|
||||
# Server tests i/10 one slice of the server suite, with coverage
|
||||
# Server coverage merges the slices, checks the per-domain
|
||||
# thresholds, uploads lcov
|
||||
# Server Postgres 14 i/3, Server Postgres 18 i/3
|
||||
# Server Postgres 14 i/3, Server Postgres 19 i/3
|
||||
# per supported major, in three slices: the probe
|
||||
# (the repository SQL against Postgres, first slice
|
||||
# only), then a slice of the lane (every suite that
|
||||
@@ -55,7 +55,7 @@ permissions:
|
||||
# Client e2e i/2 one slice of the browser flows in Chromium and
|
||||
# WebKit, in the Playwright container
|
||||
# Docker and Helm builds the image and boots it until ready, on
|
||||
# SQLite and on Postgres 18; lints and renders the
|
||||
# SQLite and on Postgres 19; lints and renders the
|
||||
# Helm chart and checks the compose files
|
||||
# Sonar SonarCloud analysis, not required
|
||||
# ci-ok the one required check (below)
|
||||
@@ -639,7 +639,7 @@ jobs:
|
||||
retention-days: 1
|
||||
|
||||
# TREK on Postgres, once per supported major: the oldest (14) and the newest
|
||||
# (18). Both steps run against the same service, the probe on an empty
|
||||
# (19). Both steps run against the same service, the probe on an empty
|
||||
# database of its own, the lane on databases it creates and drops.
|
||||
#
|
||||
# The probe (server/scripts/pg-probe.ts): against an empty Postgres it
|
||||
@@ -696,7 +696,7 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
postgres: [14, 18]
|
||||
postgres: [14, 19]
|
||||
shard: [1, 2, 3]
|
||||
services:
|
||||
postgres:
|
||||
@@ -757,14 +757,14 @@ jobs:
|
||||
if-no-files-found: ignore
|
||||
retention-days: 14
|
||||
|
||||
# The image ships the 18 client tools, which write settings a 14 server
|
||||
# The image ships the 19 client tools, which write settings a 14 server
|
||||
# does not know; the backup round trip runs with the same tools here.
|
||||
- name: Install the PostgreSQL 18 client tools
|
||||
- name: Install the PostgreSQL 19 client tools
|
||||
run: |
|
||||
set -euo pipefail
|
||||
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y >/dev/null
|
||||
sudo apt-get install -y --no-install-recommends postgresql-client-18 >/dev/null
|
||||
/usr/lib/postgresql/18/bin/pg_restore --version
|
||||
sudo apt-get install -y --no-install-recommends postgresql-client-19 >/dev/null
|
||||
/usr/lib/postgresql/19/bin/pg_restore --version
|
||||
|
||||
- name: Run the Postgres lane
|
||||
if: ${{ !cancelled() }}
|
||||
@@ -1347,7 +1347,7 @@ jobs:
|
||||
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:18
|
||||
-e POSTGRES_PASSWORD=ci -e POSTGRES_DB=trek postgres:19
|
||||
for _ in $(seq 1 30); do
|
||||
docker exec trek-ci-db pg_isready -U postgres -d trek >/dev/null 2>&1 && break
|
||||
sleep 2
|
||||
|
||||
@@ -137,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: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`), `check:plugin-facts`, `i18n:parity:strict` (with the untranslated-strings ratchet), the S3 contract suite, TREK on Postgres (`server-postgres`, once per supported major, 14 and 18, each in three slices: first the Postgres probe (in the first slice), every dialect helper on SQLite and Postgres and the statements every repository method reaches with sample arguments, its SQL errors per method and the methods it cannot measure held to a baseline that only shrinks and fails while it is still unmeasured; then the Postgres lane, every suite that boots the app on the real database module, found by `server/tests/postgres/lane.ts` rather than listed, plus PARITY-PG and the write lock; see `server/CLAUDE.md`), the browser end-to-end flows (Chromium and WebKit, in the Playwright container, in two slices), 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, on SQLite and on Postgres 18, and lints and renders the Helm chart against the Kubernetes schemas and runs `docker compose config` on every compose file (both in `docker`, each part when its area changed). `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`), `check:plugin-facts`, `i18n:parity:strict` (with the untranslated-strings ratchet), the S3 contract suite, TREK on Postgres (`server-postgres`, once per supported major, 14 and 19, each in three slices: first the Postgres probe (in the first slice), every dialect helper on SQLite and Postgres and the statements every repository method reaches with sample arguments, its SQL errors per method and the methods it cannot measure held to a baseline that only shrinks and fails while it is still unmeasured; then the Postgres lane, every suite that boots the app on the real database module, found by `server/tests/postgres/lane.ts` rather than listed, plus PARITY-PG and the write lock; see `server/CLAUDE.md`), the browser end-to-end flows (Chromium and WebKit, in the Playwright container, in two slices), 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, on SQLite and on Postgres 19, and lints and renders the Helm chart against the Kubernetes schemas and runs `docker compose config` on every compose file (both in `docker`, each part when its area changed). `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 "<Area> <what>[ <variant>][ i/n]"** (`Server tests 3/10`, `Server Postgres 14 2/3`, `Docker and Helm`): the area first, one of Changes, Shared, Server, Client, Docker or Sonar, then lower case, with no colon, no parentheses and no middle dot, and a slice only at the end, so the checks list sorts by area. The workflow is named `CI`, so a check reads `CI / Server tests 3/10`. Job ids are the names in kebab-case (`server-tests`), the jobs stand in `test.yml` in area order, and the list at the top of `test.yml` says what each job holds. A new job follows the scheme and joins that list; `scripts/ci/workflow-jobs.test.mjs` fails on a name outside it. `ci-ok`, `lint` and `check-target` keep their names: the ruleset requires them by name.
|
||||
- **What the folded jobs hold.** `Shared tests` is the plugin SDK's typecheck and coverage, run before the root install so the SDK resolves only its own dependencies, then i18n parity and shared's coverage. `Client types` is the typecheck and the strict ratchet; `Client checks` the source ratchets, then the production build with `check:gl-split`. `Docker and Helm` builds and boots the image when the image area changed and checks the chart and compose files when the deploy area changed. Inside a folded job each group of steps runs after a failure in another, so one red check shows every gate that failed; the step names say which.
|
||||
|
||||
+17
-9
@@ -73,22 +73,30 @@ COPY server/package.json ./server/
|
||||
# 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-18 brings pg_dump, pg_restore and psql to
|
||||
# /usr/lib/postgresql/18/bin, which back up and restore an install on Postgres
|
||||
# postgresql-client-19 brings pg_dump, pg_restore and psql to
|
||||
# /usr/lib/postgresql/19/bin, which back up and restore an install on Postgres
|
||||
# (TREK_DB_URL). A client handles every server up to its own major and refuses
|
||||
# a newer one, so the image carries the newest major TREK supports (14 to 18).
|
||||
# a newer one, so the image carries the newest major TREK supports (14 to 19).
|
||||
# Debian 13 ships 17 only, so it comes from the PostgreSQL project's apt
|
||||
# repository (PGDG): the `18` component lists that major's packages and no
|
||||
# other, and the repository's signing key (fingerprint B97B 0AFC AA1A 47F0 44F2
|
||||
# 44A0 7FCC 7D46 ACCC 4CF8) is kept beside the entrypoint instead of fetched at
|
||||
# build time. Raise both together when TREK supports a newer major.
|
||||
# repository (PGDG): its `main` component carries every major the project
|
||||
# supports, and the package name pins the one installed. The per-major
|
||||
# components can trail a new release, so the image does not rely on them. The
|
||||
# repository's signing key (fingerprint B97B 0AFC AA1A 47F0 44F2 44A0 7FCC 7D46
|
||||
# ACCC 4CF8) is kept beside the entrypoint instead of fetched at build time.
|
||||
# Raise the package together with SUPPORTED_SERVER_MAJORS in
|
||||
# server/src/db/engine/postgres/server-checks.ts.
|
||||
# Earlier images carried the version 18 tools, and installs that set
|
||||
# TREK_DB_PG_BIN_DIR=/usr/lib/postgresql/18/bin (the old .env.example value)
|
||||
# would lose backups and the pre-migrate snapshot after updating, so that path
|
||||
# stays as a link to the 19 tools, which handle every supported server.
|
||||
COPY server/scripts/pgdg-apt-key.asc /etc/apt/keyrings/pgdg.asc
|
||||
RUN echo 'deb [signed-by=/etc/apt/keyrings/pgdg.asc] http://apt.postgresql.org/pub/repos/apt trixie-pgdg main 18' \
|
||||
RUN echo 'deb [signed-by=/etc/apt/keyrings/pgdg.asc] http://apt.postgresql.org/pub/repos/apt trixie-pgdg main' \
|
||||
> /etc/apt/sources.list.d/pgdg.list && \
|
||||
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 postgresql-client-18 && \
|
||||
libkitinerary-bin libsqlite3-0 postgresql-client-19 && \
|
||||
mkdir -p /usr/lib/postgresql/18 && ln -s /usr/lib/postgresql/19/bin /usr/lib/postgresql/18/bin && \
|
||||
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 && \
|
||||
|
||||
@@ -288,7 +288,7 @@ 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 18 database instead. The
|
||||
TREK stores its data in SQLite by default. Set `TREK_DB_URL` to run it on a PostgreSQL 14 to 19 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, the backups and
|
||||
how to move an existing SQLite install to Postgres with the command TREK ships for it.
|
||||
|
||||
@@ -190,7 +190,7 @@ env:
|
||||
# starting it on SQLite. The role in the URL owns TREK's database and must not be a superuser
|
||||
# (nor a member of one, nor hold a right that reaches the server's files or programs): a
|
||||
# restore runs the backup's SQL as that role and refuses one that could reach the database host. The wiki page shows the
|
||||
# SQL that creates such a role. PostgreSQL 14 to 18 is supported.
|
||||
# SQL that creates such a role. PostgreSQL 14 to 19 is supported.
|
||||
# url: "postgres://trek:<password>@postgres.example.internal:5432/trek?sslmode=require"
|
||||
database:
|
||||
url: ""
|
||||
|
||||
@@ -21,11 +21,12 @@
|
||||
# superuser trek; the wiki page Database-Postgres ("Moving a compose install
|
||||
# off the superuser") shows how to move it to this layout.
|
||||
#
|
||||
# The database runs PostgreSQL 18. TREK supports 14 to 18: to run 14 to 17,
|
||||
# change the image tag and mount the volume at /var/lib/postgresql/data
|
||||
# instead, where those images keep their data (the 18 image refuses that
|
||||
# path). An existing database stays on the major it was created with: when
|
||||
# you update this file, keep your image tag and volume path. Moving to
|
||||
# The database runs PostgreSQL 18. TREK supports 14 to 19: a new database
|
||||
# may run postgres:19 on the same volume path. To run 14 to 17, change the
|
||||
# image tag and mount the volume at /var/lib/postgresql/data instead, where
|
||||
# those images keep their data (the 18 and 19 images refuse that path). An
|
||||
# existing database stays on the major it was created with: when you update
|
||||
# this file, keep your image tag and volume path. Moving to
|
||||
# another major needs pg_upgrade, or a dump and restore (a TREK backup
|
||||
# restored into a new, empty database of the same or a newer major), never
|
||||
# just a new image tag.
|
||||
@@ -46,7 +47,7 @@ services:
|
||||
- no-new-privileges:true
|
||||
# No ports are published: only the trek service on the compose network reaches the database.
|
||||
volumes:
|
||||
# The path the postgres:18 image expects. Images 14 to 17 need
|
||||
# The path the postgres:18 and :19 images expect. Images 14 to 17 need
|
||||
# /var/lib/postgresql/data here (see the top of this file).
|
||||
- trek-pgdata:/var/lib/postgresql
|
||||
healthcheck:
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ DEMO_MODE=false # Demo mode: resets data hourly
|
||||
# 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). For a server that asks for a client certificate, sslcert= and sslkey= name the certificate and its key file, both together and only with a verifying sslmode. A Unix socket: postgresql://trek@localhost/trek?host=/var/run/postgresql (a host= or port= parameter takes the place of the URL's own, as in libpq). Cannot be combined with TREK_DB_FILE, TREK_DB_JOURNAL_MODE or TREK_DB_SYNCHRONOUS.
|
||||
# TREK_DB_PG_BIN_DIR=/usr/lib/postgresql/18/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/<18..14>/bin, newest first, then /usr/local/bin and /usr/bin (the Docker image installs the version 18 tools, which work with every supported server; tools older than the server are refused). Unused on SQLite.
|
||||
# TREK_DB_PG_BIN_DIR=/usr/lib/postgresql/19/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/<19..14>/bin, newest first, then /usr/local/bin and /usr/bin (the Docker image installs the version 19 tools, which work with every supported server; tools older than the server are refused). 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-<schema>-<time>.db (a .pgdump made with pg_dump on Postgres) before a startup migrates it, so the previous image can run on the copy again. A copy that cannot be written stops the startup; false migrates without one.
|
||||
|
||||
+3
-3
File diff suppressed because one or more lines are too long
@@ -14,12 +14,13 @@ export type PgTool = 'pg_dump' | 'pg_restore' | 'psql';
|
||||
|
||||
/**
|
||||
* Where the client tools are looked for when `TREK_DB_PG_BIN_DIR` is unset:
|
||||
* Debian's versioned directories newest first (the Docker image installs 18),
|
||||
* Debian's versioned directories newest first (the Docker image installs 19),
|
||||
* then the usual prefixes. Newest first because a client dumps and restores
|
||||
* every server up to its own major version and refuses a newer one. Never
|
||||
* PATH: a binary is run by its absolute path.
|
||||
*/
|
||||
const DEFAULT_BIN_DIRS = [
|
||||
'/usr/lib/postgresql/19/bin',
|
||||
'/usr/lib/postgresql/18/bin',
|
||||
'/usr/lib/postgresql/17/bin',
|
||||
'/usr/lib/postgresql/16/bin',
|
||||
|
||||
@@ -38,7 +38,7 @@ import path from 'node:path';
|
||||
*
|
||||
* Which names are functions of `pg_catalog` is read from
|
||||
* `assets/postgres/catalog-functions.txt`: every function name of every
|
||||
* supported major (14 to 18; the boot refuses any other server). The Postgres
|
||||
* supported major (14 to 19; the boot refuses any other server). The Postgres
|
||||
* lane compares it with `pg_proc` on the server it runs on and fails on a
|
||||
* name missing there (PGPLUG-021), so a new major cannot add a function a
|
||||
* plugin may call without someone deciding whether it belongs here.
|
||||
|
||||
@@ -8,8 +8,8 @@ import { run } from './pg-process';
|
||||
* psql then refuses every meta-command until the matching `\unrestrict`.
|
||||
*
|
||||
* RESTRICT_SINCE holds, per major, the first minor that carries the fix, for
|
||||
* every major TREK supports (14 to 18; 18 has it from 18.0). Every major after
|
||||
* the last one listed has it from its first release.
|
||||
* the majors TREK supports from 14 to 18 (18 has it from 18.0). Every major after
|
||||
* the last one listed (19 and later) has it from its first release.
|
||||
*/
|
||||
const RESTRICT_SINCE: Readonly<Partial<Record<number, number>>> = { 14: 19, 15: 14, 16: 10, 17: 6, 18: 0 };
|
||||
const LAST_MAJOR_WITHOUT_IT = Math.max(...Object.keys(RESTRICT_SINCE).map(Number));
|
||||
@@ -46,6 +46,6 @@ export async function refuseToolsWithoutRestrict(binDir: string | undefined): Pr
|
||||
if (stale < 0) return;
|
||||
throw new Error(
|
||||
`${tools[stale]} is too old to restore safely (${versions[stale].trim()}): it must be at least ${minimumVersionsText()} ` +
|
||||
'(the Docker image has 18). Upgrade the PostgreSQL client tools or point TREK_DB_PG_BIN_DIR at newer ones.',
|
||||
'(the Docker image has 19). Upgrade the PostgreSQL client tools or point TREK_DB_PG_BIN_DIR at newer ones.',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { REFUSAL } from '../../legacy-baseline';
|
||||
*/
|
||||
|
||||
/** The PostgreSQL majors TREK supports and CI runs: the oldest and the newest. */
|
||||
const SUPPORTED_SERVER_MAJORS = { oldest: 14, newest: 18 } as const;
|
||||
const SUPPORTED_SERVER_MAJORS = { oldest: 14, newest: 19 } as const;
|
||||
|
||||
/**
|
||||
* The `pg_catalog` functions that read, list or write files on the database
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
* (tests/unit/nest-rpc/rpc-row-id-params.test.ts) for plugin RPC params.
|
||||
*
|
||||
* It boots the app on the real database module, so it runs in the SQLite
|
||||
* suite and in the Postgres lane on 14 and 18.
|
||||
* suite and in the Postgres lane on 14 and 19.
|
||||
*/
|
||||
import { buildApp } from '../../src/bootstrap';
|
||||
import { Addons } from '../../src/db/entities/Addons.entity';
|
||||
|
||||
@@ -59,6 +59,21 @@ describe('pg-tools', () => {
|
||||
expect(resolvePgTool('psql', bin)).toBeNull();
|
||||
});
|
||||
|
||||
it('PGTOOLS-024: without a configured directory, the newest supported major is looked in first, then the older ones', () => {
|
||||
const access = vi.spyOn(fs, 'accessSync').mockImplementation(() => {
|
||||
throw new Error('not installed');
|
||||
});
|
||||
try {
|
||||
expect(resolvePgTool('pg_dump', undefined)).toBeNull();
|
||||
const looked = access.mock.calls.map(([candidate]) => String(candidate));
|
||||
expect(looked.slice(0, 6)).toEqual(
|
||||
[19, 18, 17, 16, 15, 14].map((major) => path.join(`/usr/lib/postgresql/${major}/bin`, 'pg_dump')),
|
||||
);
|
||||
} finally {
|
||||
access.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it('PGTOOLS-002: the connection goes in the libpq environment, the password decoded and never an argument', () => {
|
||||
expect(pgConnectionEnv(URL_WITH_SECRET)).toEqual({
|
||||
PGHOST: 'db.example',
|
||||
|
||||
@@ -239,17 +239,17 @@ describe('bootstrapPostgresSchema', () => {
|
||||
|
||||
it.each([
|
||||
{ id: 'PGBOOT-020a', version: '130016', major: 13 },
|
||||
{ id: 'PGBOOT-020b', version: '190000', major: 19 },
|
||||
])('$id: a server outside 14 to 18 is refused before anything is read or written', async ({ version, major }) => {
|
||||
{ id: 'PGBOOT-020b', version: '200000', major: 20 },
|
||||
])('$id: a server outside 14 to 19 is refused before anything is read or written', async ({ version, major }) => {
|
||||
const { orm, db } = fakeOrm({ executed: [], pending: [M1, M2], tables: [], server: { version } });
|
||||
await expect(bootstrapPostgresSchema(orm, deps())).rejects.toThrow(
|
||||
`Refusing to boot: the Postgres server is version ${major}; TREK supports PostgreSQL 14 to 18.`,
|
||||
`Refusing to boot: the Postgres server is version ${major}; TREK supports PostgreSQL 14 to 19.`,
|
||||
);
|
||||
expect(db.sql).toEqual([]);
|
||||
expect(db.ensureTable).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each(['140019', '180001'])(
|
||||
it.each(['140019', '190001'])(
|
||||
'PGBOOT-021: the oldest and the newest supported servers boot (%s)',
|
||||
async (version) => {
|
||||
const { orm, db } = fakeOrm({ executed: [], pending: [M1, M2], tables: [], server: { version } });
|
||||
|
||||
@@ -110,3 +110,14 @@ describe('entrypoint script', () => {
|
||||
expect(source).not.toMatch(/^\s*exec gosu/m);
|
||||
});
|
||||
});
|
||||
|
||||
// Earlier images carried the version 18 client tools, and the old .env.example
|
||||
// suggested TREK_DB_PG_BIN_DIR=/usr/lib/postgresql/18/bin. resolvePgTool looks
|
||||
// only in a configured directory, so without the link such an install loses its
|
||||
// backups and the mandatory pre-migrate snapshot after updating the image.
|
||||
describe('postgres client tools in the image', () => {
|
||||
it('installs the version 19 client and keeps the version 18 directory as a link to it', () => {
|
||||
expect(dockerfile).toMatch(/\bpostgresql-client-19\b/);
|
||||
expect(dockerfile).toContain('ln -s /usr/lib/postgresql/19/bin /usr/lib/postgresql/18/bin');
|
||||
});
|
||||
});
|
||||
|
||||
+16
-15
@@ -2,7 +2,7 @@
|
||||
|
||||
By default TREK keeps all data in one SQLite file, `travel.db`, in the data directory. Setting `TREK_DB_URL` runs TREK on a PostgreSQL database instead. Without that variable nothing changes, and every page of this wiki that describes `travel.db` still applies to an install on SQLite.
|
||||
|
||||
> **Status:** Postgres support is new. On every pull request, CI runs the server test suites that start the app against PostgreSQL 14 and 18, the oldest and newest supported versions. It has also been checked by hand end to end against PostgreSQL 17 in Docker (first boot, sign-in, trips, backup and restore, the copy before a migration, `RESTORE_FROM_BACKUP`). The same checks have been run against a Supabase project over its direct connection; see [Supabase](#supabase) and the [Manual verification checklist](#manual-verification-checklist) below.
|
||||
> **Status:** Postgres support is new. On every pull request, CI runs the server test suites that start the app against PostgreSQL 14 and 19, the oldest and newest supported versions. It has also been checked by hand end to end against PostgreSQL 17 in Docker (first boot, sign-in, trips, backup and restore, the copy before a migration, `RESTORE_FROM_BACKUP`). The same checks have been run against a Supabase project over its direct connection; see [Supabase](#supabase) and the [Manual verification checklist](#manual-verification-checklist) below.
|
||||
|
||||
## When to use it
|
||||
|
||||
@@ -12,11 +12,11 @@ Postgres does not make TREK scale out. TREK still runs as one process. See [Limi
|
||||
|
||||
## Requirements
|
||||
|
||||
- **PostgreSQL 14 to 18.** TREK refuses to start on any other server version, before it writes anything.
|
||||
- **PostgreSQL 14 to 19.** TREK refuses to start on any other server version, before it writes anything.
|
||||
- **An empty database dedicated to TREK.** TREK creates its schema in an empty database. It refuses a database that holds tables it did not create, and a restore replaces everything in the schema it loads into. Do not share the database with another application.
|
||||
- **A role that is not a superuser,** which owns the database or can create objects in its schema. A backup archive is a SQL script run by this role during a restore, so a role with fewer privileges limits what a crafted archive can do. A restore refuses a role that could reach the database server from SQL (a superuser, a member of a superuser role, a role that holds `pg_execute_server_program`, `pg_read_server_files` or `pg_write_server_files` or may run a server file function such as `lo_export` or `pg_read_file`, from PostgreSQL 15 on a role granted ALTER SYSTEM or a superuser-only setting, and on PostgreSQL 14 and 15 a role with CREATEROLE or a member of one), and TREK warns about such a role when it starts. See [A role that is not a superuser](#a-role-that-is-not-a-superuser).
|
||||
- **ICU support in the server.** The schema creates the collation `nocase` with `provider = icu`, so the server must be built with ICU. The official `postgres` images include it.
|
||||
- **PostgreSQL client tools** (`pg_dump`, `pg_restore`, `psql`) for backups, restores and the copy TREK takes before a migration. The Docker image installs the version 18 client, which works with every supported server. A client works with servers up to its own major version, so a client outside the image must be at least as new as the server; TREK refuses an older one with a message that names both versions. See [Configuration](#configuration).
|
||||
- **PostgreSQL client tools** (`pg_dump`, `pg_restore`, `psql`) for backups, restores and the copy TREK takes before a migration. The Docker image installs the version 19 client, which works with every supported server. A client works with servers up to its own major version, so a client outside the image must be at least as new as the server; TREK refuses an older one with a message that names both versions. See [Configuration](#configuration).
|
||||
- **Client tool versions that carry the CVE-2025-8714 fix.** A restore refuses `pg_restore` or `psql` older than 18.0, 17.6, 16.10, 15.14 or 14.19.
|
||||
|
||||
## Configuration
|
||||
@@ -63,13 +63,14 @@ The key file must satisfy libpq's rule, or `pg_dump`, `pg_restore` and `psql` re
|
||||
|
||||
TREK runs the tools by their absolute path. It does not search `PATH`. When `TREK_DB_PG_BIN_DIR` is unset, TREK looks in these directories, in order, and uses the first one that holds the tool:
|
||||
|
||||
1. `/usr/lib/postgresql/18/bin`
|
||||
2. `/usr/lib/postgresql/17/bin`
|
||||
3. `/usr/lib/postgresql/16/bin`
|
||||
4. `/usr/lib/postgresql/15/bin`
|
||||
5. `/usr/lib/postgresql/14/bin`
|
||||
6. `/usr/local/bin`
|
||||
7. `/usr/bin`
|
||||
1. `/usr/lib/postgresql/19/bin`
|
||||
2. `/usr/lib/postgresql/18/bin`
|
||||
3. `/usr/lib/postgresql/17/bin`
|
||||
4. `/usr/lib/postgresql/16/bin`
|
||||
5. `/usr/lib/postgresql/15/bin`
|
||||
6. `/usr/lib/postgresql/14/bin`
|
||||
7. `/usr/local/bin`
|
||||
8. `/usr/bin`
|
||||
|
||||
The newest version comes first, because a client works with every server up to its own major version and refuses a newer one.
|
||||
|
||||
@@ -85,16 +86,16 @@ If that first start fails because a password is missing, the database is already
|
||||
|
||||
#### Postgres versions and the volume path
|
||||
|
||||
The file uses PostgreSQL 18, the newest version TREK supports, which matches the client tools in the TREK image. The `postgres` image keeps its data in a different place before and from version 18, so the volume is mounted at another path:
|
||||
The file uses PostgreSQL 18. TREK supports up to 19 and the client tools in the TREK image are version 19, so a new database may also run `postgres:19`, on the same volume path. The `postgres` image keeps its data in a different place before and from version 18, so the volume is mounted at another path:
|
||||
|
||||
| Image | Volume mounted at |
|
||||
|---|---|
|
||||
| `postgres:18` | `/var/lib/postgresql` |
|
||||
| `postgres:18`, `postgres:19` | `/var/lib/postgresql` |
|
||||
| `postgres:14` to `postgres:17` | `/var/lib/postgresql/data` |
|
||||
|
||||
To run 14 to 17, change both the image tag and the volume path in the `db` service. The 18 image refuses a volume at `/var/lib/postgresql/data`, and a 14 to 17 image with its volume one level up would keep the data in an anonymous volume, which `docker compose down` leaves behind, so the next start comes up on an empty database.
|
||||
To run 14 to 17, change both the image tag and the volume path in the `db` service. The 18 and 19 images refuse a volume at `/var/lib/postgresql/data`, and a 14 to 17 image with its volume one level up would keep the data in an anonymous volume, which `docker compose down` leaves behind, so the next start comes up on an empty database.
|
||||
|
||||
A database stays on the major version it was created with. When you update `docker-compose.postgres.yml`, keep the image tag and the volume path of your existing database. A new image tag on the old volume does not bring the data along: the 18 image refuses a volume that holds an older database, and an older image does not find the data of a newer one. To move a database to another major, use `pg_upgrade`, or dump and restore it: take a backup under **Admin > Backup** and download it, start the new major on a new, empty volume, and restore the backup there, on the first start with `RESTORE_FROM_BACKUP` (see [Backups and restore](#backups-and-restore)) or under **Admin > Backup**. TREK's backups restore into the same or a newer major; TREK refuses a backup from a newer major than the server it restores into.
|
||||
A database stays on the major version it was created with. When you update `docker-compose.postgres.yml`, keep the image tag and the volume path of your existing database. A new image tag on the old volume does not bring the data along: the 18 or 19 image refuses a volume that holds an older database, and an older image does not find the data of a newer one. To move a database to another major, use `pg_upgrade`, or dump and restore it: take a backup under **Admin > Backup** and download it, start the new major on a new, empty volume, and restore the backup there, on the first start with `RESTORE_FROM_BACKUP` (see [Backups and restore](#backups-and-restore)) or under **Admin > Backup**. TREK's backups restore into the same or a newer major; TREK refuses a backup from a newer major than the server it restores into.
|
||||
|
||||
### A role that is not a superuser
|
||||
|
||||
@@ -266,7 +267,7 @@ A plugin with the `db:own` permission keeps its own database. On SQLite that is
|
||||
- **Moving from SQLite goes one way.** The [move command](#moving-an-existing-install-to-postgres) copies a SQLite install into an empty Postgres database. The way back is to start TREK on the untouched SQLite file again; nothing copies Postgres data back into SQLite.
|
||||
- **No more than one TREK replica.** TREK keeps state in memory: rate limits, pending one-time codes, the permission cache and the WebSocket connections. Each process has its own copy, so two replicas would disagree with each other. Keep `replicas: 1` in the Helm chart and one `trek` container. Postgres does not change that.
|
||||
- **Two processes booting on one database at once are not coordinated.** Start one process for the first boot and for each upgrade, then continue with one.
|
||||
- **PostgreSQL 14 to 18 only.** A newer server is refused until a TREK release supports it, because the image's client tools would not be able to back it up.
|
||||
- **PostgreSQL 14 to 19 only.** A newer server is refused until a TREK release supports it, because the image's client tools would not be able to back it up.
|
||||
- **One TREK instance per database.** Plugin data schemas are named after the plugin alone (see [Plugin data](#plugin-data)), and a restore drops the plugin schemas the role owns. Give each instance its own database.
|
||||
- **Writes are serialized.** TREK takes a database-wide advisory lock for each write transaction, as the SQLite engine does with its single writer. Heavy concurrent writes wait on that lock.
|
||||
|
||||
|
||||
@@ -507,9 +507,9 @@ through environment variables. `TREK_PLACE_PHOTO_DIR` below is unaffected.
|
||||
| `BACKUP_UPLOAD_LIMIT_MB` | Maximum **compressed** size (in MB) of a restore-backup archive that may be uploaded. Raise it if your backups (which include the `uploads/` directory) exceed the default. Non-positive or invalid values abort startup. | `500` |
|
||||
| `RESTORE_FROM_BACKUP` | Path to a backup ZIP to restore on the **first** start, before any setup. Only acts while no database exists; afterwards it is ignored with a warning. A backup that fails the restore checks stops the start. See [Backups](Backups#restoring-on-a-new-install-before-setup). | none |
|
||||
| `BACKUP_MAX_DECOMPRESSED_MB` | Maximum **decompressed** size (in MB) of a restore-backup archive — the zip-bomb guard. Independent of `BACKUP_UPLOAD_LIMIT_MB` and enforced on both restore paths, so a restore that fits the upload cap can still be refused with `Backup exceeds the maximum decompressed size.` Raise both when restoring a very large instance. | `5120` (5 GB) |
|
||||
| `TREK_DB_URL` | Run TREK on a PostgreSQL database instead of the SQLite file: `postgres://user:password@host:5432/database` (or `postgresql://`). Needs PostgreSQL 14 to 18, an empty database of its own and a role that is not a superuser. Percent-encode special characters in the password. See [Database: Postgres](Database-Postgres). | unset (SQLite) |
|
||||
| `TREK_DB_URL` | Run TREK on a PostgreSQL database instead of the SQLite file: `postgres://user:password@host:5432/database` (or `postgresql://`). Needs PostgreSQL 14 to 19, an empty database of its own and a role that is not a superuser. Percent-encode special characters in the password. See [Database: Postgres](Database-Postgres). | unset (SQLite) |
|
||||
| `TREK_DB_POOL_MAX` | Most connections TREK opens to the PostgreSQL database, from 1 to 100. Unused on SQLite. | `10` |
|
||||
| `TREK_DB_PG_BIN_DIR` | Directory holding `pg_dump`, `pg_restore` and `psql`, which back up and restore a PostgreSQL database. Unset, TREK looks in `/usr/lib/postgresql/18` to `14` (`bin`), newest first, then `/usr/local/bin` and `/usr/bin`. Unused on SQLite. See [Database: Postgres](Database-Postgres#where-the-client-tools-are-found). | unset |
|
||||
| `TREK_DB_PG_BIN_DIR` | Directory holding `pg_dump`, `pg_restore` and `psql`, which back up and restore a PostgreSQL database. Unset, TREK looks in `/usr/lib/postgresql/19` to `14` (`bin`), newest first, then `/usr/local/bin` and `/usr/bin`. Unused on SQLite. See [Database: Postgres](Database-Postgres#where-the-client-tools-are-found). | unset |
|
||||
| `TREK_DB_FILE` | Explicit path of the SQLite database file. Unset, TREK uses `travel.db` in the data directory. Not used with `TREK_DB_URL`. | unset |
|
||||
| `TREK_DB_JOURNAL_MODE` | SQLite [journal mode](https://sqlite.org/pragma.html#pragma_journal_mode): `DELETE`, `TRUNCATE`, `PERSIST`, `MEMORY`, `WAL` or `OFF`. Set `DELETE` when the data directory lives on network storage — see below. Values SQLite doesn't know log a warning and fall back. | `WAL` |
|
||||
| `TREK_DB_PRE_MIGRATE_SNAPSHOT` | Copy the database to `pre-migrate-<schema>-<time>.db` next to it before a startup applies pending migrations, so the previous image can be started on that copy again. On PostgreSQL the copy is a `pg_dump` file, `pre-migrate-<schema>-<time>.pgdump`, and needs the client tools (see `TREK_DB_PG_BIN_DIR`). If the copy cannot be written the startup refuses rather than migrate without one. Set `false` only to get past that when you cannot free space and have a backup of your own. See [Updating](Updating#database-migrations). | `true` |
|
||||
|
||||
@@ -120,7 +120,7 @@ See [Reverse-Proxy](Reverse-Proxy) for complete proxy configuration examples.
|
||||
|
||||
[`docker-compose.postgres.yml`](https://github.com/liketrek/TREK/blob/main/docker-compose.postgres.yml) runs TREK beside a `postgres:18` service instead of the SQLite file. Its `db` service keeps the database in a named volume and publishes no port, and the `app` service (container `trek`) waits for the database's health check before it starts. The `app` service sets only a few environment variables; add the others you need (`APP_URL`, `FORCE_HTTPS`, OIDC, SMTP and so on) as in `docker-compose.yml`. It needs Docker Compose 2.23.1 or newer (`docker compose version`); an older one refuses the file with `Additional property content is not allowed`.
|
||||
|
||||
The volume path depends on the Postgres major version: `postgres:18` keeps its data under `/var/lib/postgresql`, the images for 14 to 17 under `/var/lib/postgresql/data`. Change the image tag and the volume path together, and only for a new database. A database stays on the major it was created with, so when you update the compose file later, keep your image tag and volume path; moving to another major needs `pg_upgrade` or a backup and restore, never just a new tag. See [Database: Postgres](Database-Postgres#postgres-versions-and-the-volume-path).
|
||||
The volume path depends on the Postgres major version: `postgres:18` and `postgres:19` keep their data under `/var/lib/postgresql`, the images for 14 to 17 under `/var/lib/postgresql/data`. Change the image tag and the volume path together, and only for a new database. A database stays on the major it was created with, so when you update the compose file later, keep your image tag and volume path; moving to another major needs `pg_upgrade` or a backup and restore, never just a new tag. See [Database: Postgres](Database-Postgres#postgres-versions-and-the-volume-path).
|
||||
|
||||
Add two passwords to the `.env` file beside the compose file, together with `COMPOSE_FILE`, then start it:
|
||||
|
||||
|
||||
@@ -672,23 +672,23 @@ See [Notifications](Notifications#web-push) for the details.
|
||||
|
||||
## Postgres: "pg_dump was not found" when backing up or restoring
|
||||
|
||||
**Cause:** The backup, restore or pre-migration copy runs `pg_dump`, `pg_restore` or `psql` by its absolute path. None of them is in the directories TREK searches (`/usr/lib/postgresql/18` down to `14`, `/usr/local/bin`, `/usr/bin`), and `PATH` is not searched.
|
||||
**Cause:** The backup, restore or pre-migration copy runs `pg_dump`, `pg_restore` or `psql` by its absolute path. None of them is in the directories TREK searches (`/usr/lib/postgresql/19` down to `14`, `/usr/local/bin`, `/usr/bin`), and `PATH` is not searched.
|
||||
|
||||
**Fix:** Install the `postgresql-client` package, or set `TREK_DB_PG_BIN_DIR` to the directory that holds the three tools. The Docker image already includes the version 18 client. See [Database-Postgres](Database-Postgres#where-the-client-tools-are-found).
|
||||
**Fix:** Install the `postgresql-client` package, or set `TREK_DB_PG_BIN_DIR` to the directory that holds the three tools. The Docker image already includes the version 19 client in `/usr/lib/postgresql/19/bin`; it keeps `/usr/lib/postgresql/18/bin` as a link to it, so a `TREK_DB_PG_BIN_DIR` copied from an older `.env.example` still works. On your own image, unset the variable or point it at the directory the installed client uses. See [Database-Postgres](Database-Postgres#where-the-client-tools-are-found).
|
||||
|
||||
---
|
||||
|
||||
## Postgres: a backup or restore fails with "server version mismatch" or a version error
|
||||
|
||||
**Cause:** Three different problems produce messages about versions. A client tool works with servers up to its own major version, so TREK refuses a backup or restore with tools older than the server (`pg_dump is version 17, older than the PostgreSQL 18 server`). A restore also refuses a `pg_restore` or `psql` older than 18.0, 17.6, 16.10, 15.14 or 14.19, because those versions cannot restore a dump safely (CVE-2025-8714). And a client older than 16 cannot use the system's certificate authorities, so with `sslmode` set and no `sslrootcert` it is refused too. Each error names the version it found.
|
||||
**Cause:** Three different problems produce messages about versions. A client tool works with servers up to its own major version, so TREK refuses a backup or restore with tools older than the server (`pg_dump is version 18, older than the PostgreSQL 19 server`). A restore also refuses a `pg_restore` or `psql` older than 18.0, 17.6, 16.10, 15.14 or 14.19, because those versions cannot restore a dump safely (CVE-2025-8714). And a client older than 16 cannot use the system's certificate authorities, so with `sslmode` set and no `sslrootcert` it is refused too. Each error names the version it found.
|
||||
|
||||
**Fix:** Use the Docker image's tools, which are version 18 and work with every supported server (14 to 18), or point `TREK_DB_PG_BIN_DIR` at client tools at least as new as the server. For the certificate message, add `sslrootcert=<CA file>` to `TREK_DB_URL` or use newer tools.
|
||||
**Fix:** Use the Docker image's tools, which are version 19 and work with every supported server (14 to 19), or point `TREK_DB_PG_BIN_DIR` at client tools at least as new as the server. For the certificate message, add `sslrootcert=<CA file>` to `TREK_DB_URL` or use newer tools.
|
||||
|
||||
---
|
||||
|
||||
## Postgres: TREK refuses to start because of the server version
|
||||
|
||||
**Cause:** TREK supports PostgreSQL 14 to 18 and refuses any other server before it writes anything (`the Postgres server is version 19; TREK supports PostgreSQL 14 to 18`).
|
||||
**Cause:** TREK supports PostgreSQL 14 to 19 and refuses any other server before it writes anything (`the Postgres server is version 20; TREK supports PostgreSQL 14 to 19`).
|
||||
|
||||
**Fix:** Run TREK on a server of a supported version. A newer major is supported once a TREK release ships client tools for it.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user