From 8c1cfcfc112398c5fc8f9c5c5de4dcdab9d6151f Mon Sep 17 00:00:00 2001 From: Sajeyks Date: Mon, 5 Oct 2026 22:59:58 +0300 Subject: [PATCH] Add a script to restore the snapshot into the compose stack --- legacy-snapshot/README.md | 15 +++++++++++++++ legacy-snapshot/restore.sh | 14 ++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 legacy-snapshot/README.md create mode 100644 legacy-snapshot/restore.sh diff --git a/legacy-snapshot/README.md b/legacy-snapshot/README.md new file mode 100644 index 00000000..22722bec --- /dev/null +++ b/legacy-snapshot/README.md @@ -0,0 +1,15 @@ +# Old-version database snapshot + +`django-1.9.sql.gz` is a dump of the sample database made on the original +Django 1.9 stack (no real or personal data). It stands in for an old +production database: after each upgrade step, restore it and let the new +version migrate it. + +```sh +sh legacy-snapshot/restore.sh +docker compose exec web python smoke_test.py # after the site answers (~1.5 min) +``` + +It holds the sample sites and pages from `seed_dummy_data` plus what +`seed_extra.py` adds: blog posts, contact messages, hosting plans and +supporters. Real production rows are the one thing it cannot cover. diff --git a/legacy-snapshot/restore.sh b/legacy-snapshot/restore.sh new file mode 100644 index 00000000..3e7068c5 --- /dev/null +++ b/legacy-snapshot/restore.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# Replaces the database of the running compose stack with the Django 1.9 +# snapshot, then restarts the app (its start-up runs "migrate"). +# Use it to check that an upgraded version can migrate old data: +# sh legacy-snapshot/restore.sh +set -e +cd "$(dirname "$0")/.." +docker compose stop web celery +docker compose exec -T db psql -U app -d postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'app' AND pid <> pg_backend_pid()" > /dev/null +docker compose exec -T db psql -U app -d postgres -c "DROP DATABASE IF EXISTS app" +docker compose exec -T db psql -U app -d postgres -c "CREATE DATABASE app OWNER app" +gunzip -c legacy-snapshot/django-1.9.sql.gz | docker compose exec -T db psql -U app -d app -q -v ON_ERROR_STOP=1 > /dev/null +docker compose up -d web celery +echo "Restored. The site answers after about 1.5 minutes; then run: docker compose exec web python smoke_test.py"