Files
wekan/snap-src/bin/wekan-database
T
Lauri Ojansivu 7d271413bf Snap: make database setting authoritative + wekan.database command + no-downtime on failure
Problem: the control scripts force-switched to FerretDB whenever a *.sqlite file existed, so
`snap set wekan database=mongodb` did not stick and a failed migration caused downtime with no
way to keep WeKan running on MongoDB while fixing it.

- The `database` snap setting is now AUTHORITATIVE. Removed the "FerretDB SQLite present ->
  force ferretdb / disable mongodb" overrides from wekan-control, ferretdb-control and
  mongodb-control. wekan-control keeps only the safety guard (never start an EMPTY FerretDB
  while MongoDB has data).

- New `snap run wekan.database mongodb|ferretdb` command (bin/wekan-database): switch which
  database WeKan runs on. `mongodb` also pauses auto-migration (migrate=off) so it does not
  switch back; `ferretdb` requires a non-empty SQLite first.

- Auto-migration can be paused: migration-pending now also returns "not pending" when
  `snap get migrate` == off. A migration that FAILS now runs fail_and_run_mongodb: delete the
  partial SQLite, set migrate=off, and exec mongodb-control so WeKan keeps working on MongoDB
  (no downtime, no retry loop). fall_back_to_mongodb likewise sets migrate=off instead of the
  done marker. `snap run wekan.migrate` re-enables migrate and retries.

- finish_success now restarts wekan.wekan so it reconnects to FerretDB after a successful
  migration instead of waiting for the now-stopped MongoDB.

Registered the `database` app in snapcraft.yaml and snapcraft-core26.yaml (also added the
previously-missing migrate/maintenance apps to core26).

Thanks to xet7.
2026-07-15 08:58:36 +03:00

43 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
# wekan-database — choose which database WeKan runs on.
# snap run wekan.database mongodb -> run WeKan on MongoDB (and pause auto-migration)
# snap run wekan.database ferretdb -> run WeKan on FerretDB (migrated SQLite)
# snap run wekan.database -> show the current selection
#
# The `database` snap setting is authoritative (see wekan-control); this sets it and flips the
# services so WeKan actually runs on the chosen database. Use `mongodb` to keep WeKan working on
# MongoDB while a FerretDB migration is being fixed — this also pauses auto-migration
# (migrate=off) so the next start does not switch back to a half-migrated FerretDB. Re-run the
# migration any time with `snap run wekan.migrate`.
set -u
svc="${SNAP_INSTANCE_NAME:-${SNAP_NAME:-wekan}}"
case "${1:-}" in
mongodb)
snapctl set database=mongodb 2>/dev/null || true
snapctl set migrate=off 2>/dev/null || true
snapctl stop --disable "${svc}.ferretdb" 2>/dev/null || true
snapctl start --enable "${svc}.mongodb" 2>/dev/null || true
snapctl restart "${svc}.wekan" 2>/dev/null || true
echo "WeKan now uses MongoDB. Auto-migration is PAUSED (migrate=off) so it will not switch back."
echo "When you want to migrate to FerretDB again: snap run ${svc}.migrate"
;;
ferretdb)
if ! bash "$SNAP/bin/ferretdb-has-data"; then
echo "No FerretDB (SQLite) database found in ${SNAP_COMMON}/files/db — nothing to run on FerretDB yet."
echo "Migrate first: snap run ${svc}.migrate (then: snap run ${svc}.database ferretdb)"
exit 1
fi
snapctl set database=ferretdb 2>/dev/null || true
snapctl stop --disable "${svc}.mongodb" 2>/dev/null || true
snapctl start --enable "${svc}.ferretdb" 2>/dev/null || true
snapctl restart "${svc}.wekan" 2>/dev/null || true
echo "WeKan now uses FerretDB (SQLite)."
;;
*)
echo "Current database: $(snapctl get database 2>/dev/null || true)"
echo "Auto-migration: $([ "$(snapctl get migrate 2>/dev/null)" = off ] && echo 'off (paused)' || echo 'on')"
echo "Usage: snap run ${svc}.database mongodb|ferretdb"
;;
esac