Files
wekan/snap-src/bin/migration-pending
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

21 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
# Exit 0 if a one-time MongoDB -> FerretDB v1 migration is pending for this snap,
# else exit 1. "Pending" = existing MongoDB (WiredTiger) data is present in
# $SNAP_COMMON, the migration has not completed yet, and the tools to do it
# (ferretdb binary, bundled node, the migrator script) are all available.
MARKER="$SNAP_COMMON/.migration-to-ferretdb-done"
DBPATH="$SNAP_COMMON"
[ -f "$MARKER" ] && exit 1
# Admin can pause auto-migration so WeKan keeps running on MongoDB while a migration is being
# fixed: `snap set wekan migrate=off` (or `snap run wekan.database mongodb`). A migration that
# FAILS also sets migrate=off automatically so it does not loop and cause downtime. Re-enable
# and retry with `snap run wekan.migrate`.
[ "$(snapctl get migrate 2>/dev/null)" = "off" ] && exit 1
[ -x "$SNAP/ferretdb" ] || exit 1
[ -x "$SNAP/bin/node" ] || exit 1
[ -f "$SNAP/bin/migrate-mongodb-to-ferretdb.mjs" ] || exit 1
if [ -f "$DBPATH/WiredTiger" ] || ls "$DBPATH"/collection-*.wt >/dev/null 2>&1; then
exit 0
fi
exit 1