Skip to content

Latest commit

 

History

History
121 lines (90 loc) · 6.7 KB

README.md

File metadata and controls

121 lines (90 loc) · 6.7 KB

Lightweight anonymized dev database

A small (~110 MB dump, ~320 MB once restored), anonymized and consistent extract of the production database, for development. It keeps the edge cases (see below) and the public transport data (stopareas), so nothing has to be requested from Navitia.

Using it

The dump is restored by an image on first start (PostgreSQL 18 + PostGIS):

cp c2corg-dev-pg96.dump scripts/dev-database/c2corg-dev.dump   # or pass --build-arg DUMP=...
docker build -t c2corg-dev-db scripts/dev-database
docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=test c2corg-dev-db

Database c2corg, user www-data (password www-data) or postgres. It is already at the latest alembic revision of the code at the time it was built.

The matching Elasticsearch, with the index already built from this database, is the image ghcr.io/c2corg/c2corg-dev-es (same tag, always published together with the database; its data is in /esdata). To build the index yourself instead, run these commands in this order (without the first one, Elasticsearch creates the index on its own without the search sub-fields, and the search silently returns nothing):

initialize_c2corg_api_es development.ini    # creates the index and its mappings
fill_es_index development.ini               # about 5 minutes, 44,000 documents

es_index_fingerprint check development.ini tells whether an index was built by the indexing code of your checkout (see below).

Everything (PostgreSQL, Elasticsearch, Redis, the API) fits in about 1.5 GB of memory (ES_HEAP_SIZE=512m is enough for Elasticsearch).

Accounts (password c2c for all): moderator, user, blocked, unvalidated. Logging in works without a forum; the API only logs Could not request nonce when it cannot reach Discourse.

Public transport: the stop areas come from the dump and are served by /waypoints/{id}/stopareas.

Tracks: there are no GPX files. The tracks of routes and outings (about a quarter of them have one) are geometries with elevation, and they are simplified (tolerance of 10 m, see 20-shrink.sql) to keep the dump small. Synchronized activities (Strava, Garmin...) are removed.

What is kept

Kept Why
All areas, articles, books, maps, coverages, xreports few of them, referenced everywhere
All waypoints and routes of the zones in 01-setup.sql, their recent outings (+ a sample of older ones) realistic content, several langs and countries
A corpus of edge cases outside of the zones (10-select.sql, rule edge:*) every quality level, protected / redirected documents, longest texts, many langs, no geometry, odd titles...
What these documents need (closure): main waypoints, parents, redirect targets, images (max 6 per document), authors referential integrity
Last version of each document; the last 30 versions for the edge cases and a sample the archives tables are huge (some pages have more than a thousand versions of a long text)
Only the users with a public profile see below
Stop areas of the kept waypoints public transport

The zones and the sampling parameters are at the top of 01-setup.sql. The reason why each document is kept is stored in devdb.keep_doc.reason during the build.

Accounts

Only the accounts with a public profile (about 4 % of the accounts) are used. What is linked to the other accounts is left out: their profile, the outings and reports they took part in (unless a public user also did), and their name in the histories, which is replaced by a single Former member account. The documents themselves are kept, as they are public content.

The name displayed everywhere (users.name) is kept for these public accounts, as it is on the site, unless it looks like a real identity (an email, or Firstname Lastname): then it becomes User <id>. About a quarter of the accounts are then switched to private, to exercise the private profiles.

Personal data is removed by ../anonymize-database/anonymize-data.sql, then 60-verify.sql fails the build if anything is left (emails, passwords, tokens, free texts, profiles...). Its blocking checks must be extended whenever a table with personal data is added.

Building it

From a production dump (custom format, as made by the nightly backup: extract c2corg.YYYY-MM-DD.dump from the tar). It runs in a throwaway container, nothing is installed on the host:

scripts/dev-database/run-in-docker.sh 96 /path/to/c2corg.2026-07-19.dump ./out   # PostgreSQL 9.6
scripts/dev-database/run-in-docker.sh 18 /path/to/c2corg.2026-07-19.dump ./out   # PostgreSQL 18

Needs about 10 GB of disk and 4 GB of memory (MEM= to change it), and takes around an hour: most of it is restoring the full dump. The same SQL runs on both versions.

Prefer the 96 build as long as older PostgreSQL versions must be supported: its dump can be restored by 9.6 and by 18, whereas a dump made by a PostgreSQL 18 server can only be restored by 18.

The production dump contains personal data and must not leave the machine that builds the extract, nor be committed (*.dump is ignored). Only the resulting dump is meant to be shared, after the checks passed.

Publishing

scripts/dev-database/publish.sh c2corg-dev-pg96.dump 2026-07-19

It builds the database image, restores it in a throwaway container and runs 60-verify.sql (nothing is pushed if personal data is left). It then fills an Elasticsearch from that database with the indexing code of the checkout it is run from (a few minutes, about 1.5 GB of memory more), builds the Elasticsearch image from it and checks it. After a confirmation, both images are pushed with the same tag and latest to ghcr.io/c2corg/c2corg-dev-db and ghcr.io/c2corg/c2corg-dev-es (IMAGE= and ES_IMAGE= to change them, DRY_RUN=1 to stop before the push). A package created by a push is private; making it public is done in its settings on GitHub.

Publishing both images in one run keeps the index in step with the database. The index also has to follow the code: fill_es_index and the mappings change with the API. The image therefore stores a fingerprint of the indexing code (c2corg_api/search, c2corg_api/scripts/es; see c2corg_api/scripts/es/fingerprint.py), and the dev container setup compares it with the one of the checkout: if they differ, it rebuilds the index from the database instead of keeping a stale one. Publish again from a recent checkout when the indexing code changed, to avoid that rebuild.

Attribution

The names of the users and the authors of the images are replaced by pseudonyms, but the identifiers of the documents are kept: every document can be traced back to its page on the site, where its history and its authors are listed. Image files are not part of the dump, only their rows.