Legacy Wiki.js push to new DB and instant rollback
When you push database changes to production with push-to-prod.sh, the script no longer overwrites the live production database. Instead it:
- Creates a new database on the prod Postgres instance (e.g.
wiki_20260217_143022). - Restores your local dump into that new database. The current prod database (e.g.
wiki) is left unchanged. - Switch (optional): You then point the old Wiki.js app at the new database. If something goes wrong, rollback is instant by pointing back at the previous database.
Push flow
From dev/wikijs:
./scripts/push-to-prod.sh # DB only: creates new DB, restores; prints how to switch
./scripts/push-to-prod.sh --data # Same + sync wiki data volume (if PROD_WIKI_VOLUME set)
./scripts/push-to-prod.sh --switch # Same + auto-switch Wiki.js to new DB (requires PROD_COMPOSE_DIR)
- Without
--switch: The script prints the new database name and instructions. On the server, setDB_NAME=<new_db_name>where Wiki.js gets its env (e.g..envin the compose dir), then recreate the wiki container so it picks up the newDB_NAME. - With
--switch: IfPROD_COMPOSE_DIRis set in.env, the script SSHs to prod, updates.envwithDB_NAME=<new_db_name>, and runsdocker-compose up -d wiki --force-recreate(ordocker compose). You need SSH and write access to that directory.
Rollback
If the new database causes issues:
- On the server, set
DB_NAMEback to the previous database (e.g.wikior the last known-good name likewiki_20260214_120000). - Recreate the wiki container so it uses the updated env, e.g.:
Wiki.js will connect to the old database again; no data restore needed.cd $COMPOSE_DIR && docker-compose up -d wiki --force-recreate
Cleanup (optional)
Old databases remain on the prod Postgres instance until you drop them. To free space after you are satisfied with a push:
# On the server, connect to Postgres and list databases
docker exec -it db psql -U postgres -c '\l'
# Drop an old database (only when you no longer need it for rollback)
docker exec db psql -U postgres -c 'DROP DATABASE wiki_20260201_100000;'
Requirements
- Create DB: The script uses the
postgressuperuser to runCREATE DATABASEon the server. Thewiki(orPROD_DB_USER) user is set as owner so restore works as that user. - PROD_COMPOSE_DIR: Only needed for
--switch. If unset, follow the printed instructions to switch and rollback manually.
Related
- wikijs-local-dev.md — local dev setup and pull/push overview.
dev/wikijs/scripts/push-to-prod.sh— script implementation.