Files
wekan/snap-src/bin/wekan-database
T
Lauri Ojansivu 65bf215cbe Fix #6473: attachments missing after the MongoDB -> FerretDB migration.
- Migration importers: resolve the CollectionFS GridFS id from
  copies.<bucket>.key too (the REAL old-WeKan layout; only
  original.gridFsFileId / gridFsFileId / copies.gridfs.key were tried,
  none of which exist there) via a shared resolveCfsGridFsId() in
  releases/migrate-mongodb-to-ferretdb.mjs,
  snap-src/bin/migrate-mongo3-to-ferretdb.mjs and
  snap-src/bin/migrate-gridfs-to-fs.mjs. The modern importer now drives
  CollectionFS extraction from cfs_gridfs.<bucket>.files itself, so a
  missing/empty cfs.<bucket>.filerecord no longer silently skips every
  file; binaries without a filerecord are still extracted to disk, and
  filerecords whose binary cannot be located are reported on the
  dashboard instead of dropped.
- Meteor-Files phase: match versions.*.meta.gridFsFileId without a
  storage flag (WeKan's own getFileStrategy rule), handle every version
  (not just 'original'), and add a bucket-driven sweep of <bucket>.files
  by metadata.fileId so binaries are recovered even when the record's
  flags say nothing about GridFS. GridFS-flagged versions with no
  locatable binary are reported.
- mongo3 importer: copy the CollectionFS top-level boardId/cardId/
  listId/swimlaneId/userId into meta on the created records - an
  attachment without meta.cardId shows on no card.
- Admin Panel > Attachments: the Filesystem Storage paths were computed
  from process.env.WRITABLE_PATH IN THE BROWSER, so they always showed
  "/data". New admin-only getAttachmentStoragePaths method returns the
  real Snap-aware paths (shared models/lib/attachmentStoragePath.js),
  also used for the settings document default (was /data/attachments,
  actual Docker path is /data/files/attachments).
- Snap: `snap run wekan.database ferretdb` now says it does NOT migrate
  data, says when nothing was switched, and points at
  `snap run wekan.migrate` for re-running the full migration.
- Tests with negative cases: tests/migrationAttachmentExtraction.test.cjs
  (behavioral resolveCfsGridFsId from all three importers + wiring
  guards) and tests/attachmentStoragePath.test.cjs, wired into
  test:unit:node.
- Companion fix in wekan/FerretDB: accept documents with literal dotted
  field names like MongoDB 3.6+, so migrated documents containing them
  are no longer silently dropped.
- CHANGELOG.md: new Upcoming section with these changes.

If attachments are already missing after an earlier migration, run
`snap run wekan.migrate` - the source MongoDB data was never modified,
and the fixed importers re-create the attachment records and files.

Thanks to mueschel and xet7.
2026-07-17 01:43:53 +03:00

52 lines
2.7 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
# #6473: users ran `wekan.database ferretdb` expecting it to re-run the
# migration — it only SWITCHES databases. Say so, and point at the command
# that actually re-migrates, so "still no attachments" has a next step.
if [ "$(snapctl get database 2>/dev/null)" = "ferretdb" ]; then
echo "WeKan is already using FerretDB (SQLite); nothing switched."
else
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)."
fi
echo "Note: this command only selects the database, it does NOT migrate data."
echo "If data (for example attachments) is missing, re-run the full migration: snap run ${svc}.migrate"
;;
*)
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