fix(config-init): make config seeding idempotent via version marker
Closes #175 (closed)
Summary
config/init-configs.shnow writes/target/.pgai-configs-versionafter each successful copy and short-circuits on subsequent runs when the marker matches the image's/VERSION.- Stops
docker compose upfrom silently reseeding thepostgres_ai_configsvolume on every restart, which was wiping production-side edits topgwatch{,-prometheus}/metrics.yml(e.g. thecalls >= 3filter cherry-picked from !220 (closed)). - Adds
tests/compliance_vectors/test_init_configs.py(committed first per TDD) covering empty target, matching marker (skip + preserve user edit), mismatched marker, and missing marker on a non-empty target.
Test plan
-
python3 -m pytest tests/compliance_vectors/test_init_configs.py -vpasses (4 passed) against the patched script. - Same suite fails (4 failed) against current
main— confirms the test actually exercises the bug (TDD red, then green). -
shellcheck config/init-configs.shclean. - Manual: on a 0.14.0+1 monitoring VM, edit
pgwatch-prometheus/metrics.yml, rundocker compose -f docker-compose.yml -p monitoring up -d sink-prometheus, confirm the edit survives andconfig-initlogsConfigs already initialized at version <v>; skipping.. - Manual: bump configs image to a newer version on the same volume, run compose, confirm the edit is overwritten and the marker file contents update to the new version.
Migration / breaking changes
Operators who upgrade the postgres-ai-configs image while keeping the same postgres_ai_configs volume and want to pull in the new image defaults must either:
- delete the marker before bringing the stack up, e.g.
docker exec config-init rm /target/.pgai-configs-version(or remove the file directly from the host volume mount), or - recreate the volume (
docker compose down -vand back up first if you have local edits worth keeping).
The script will then reseed the volume and write the new version marker. This is documented in a comment block inside init-configs.sh.