mirror of
https://github.com/wekan/wekan.git
synced 2026-11-26 01:49:41 -05:00
For unattended upgrades at scale (6.09/MongoDB 3.2 -> 9.x/FerretDB across many servers), the "did the migration succeed?" test must not be fooled by a 0-byte stub file. - New shared helper snap-src/bin/ferretdb-has-data: exit 0 only if a *.sqlite file bigger than 0 bytes exists in files/db. Used by mongodb-control, ferretdb-control and wekan-control in place of the previous "*.sqlite exists" glob, so the DB decision is based on a real, non-empty FerretDB database. (Deliberately does NOT require the -wal file, which SQLite may checkpoint away when FerretDB is stopped - that would cause false negatives at startup.) - migration-control finish_success now verifies the non-empty SQLite database exists (and logs the WAL/shm sidecars) BEFORE switching the snap to FerretDB. If the importer returns success but wrote no data, it does not switch or set the done marker - MongoDB data is kept and the migration retries on the next start. Thanks to xet7.
23 lines
1.2 KiB
Bash
Executable File
23 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# ferretdb-has-data — exit 0 if the FerretDB (SQLite) database exists AND actually has data.
|
|
#
|
|
# "Has data" = there is a *.sqlite file BIGGER THAN 0 BYTES in the FerretDB SQLite directory
|
|
# (default $SNAP_COMMON/files/db). This — NOT the .migration-to-ferretdb-done marker, which is
|
|
# also written when the migration falls back with no data — is what the snap uses to decide
|
|
# whether to run FerretDB or MongoDB. A successful MongoDB -> FerretDB migration leaves a
|
|
# non-empty <db>.sqlite (plus its -wal / -shm sidecar files); a failed/empty migration leaves
|
|
# files/db empty or a 0-byte file.
|
|
#
|
|
# NOTE: we deliberately require only the .sqlite file and size > 0 here, NOT the -wal file:
|
|
# SQLite in WAL mode may checkpoint and remove -wal/-shm when the last connection closes, so a
|
|
# stopped FerretDB can legitimately have no -wal. The stronger "wal present too" check is done
|
|
# once, right after migration, in migration-control's finish_success (where FerretDB has just
|
|
# written the data and the WAL is present).
|
|
#
|
|
# Optional arg $1 overrides the directory to check.
|
|
DBDIR="${1:-${SNAP_COMMON:-/var/snap/${SNAP_INSTANCE_NAME:-${SNAP_NAME:-wekan}}/common}/files/db}"
|
|
for f in "$DBDIR"/*.sqlite; do
|
|
[ -f "$f" ] && [ -s "$f" ] && exit 0
|
|
done
|
|
exit 1
|