Files
wekan/docs/Features/Admin-Panel/Problems/Migrations.md
T
Lauri Ojansivu c66af0e134 Docs: Admin Panel / Problems (Files to Performance): what each feature is, how to use it, how its numbers are calculated, how it works, and its commits.
File status, Filesystem integrity, Impersonation Report, Instrumentation,
Large boards, Login problems, Migrations, Offices, Password length and
Performance now each say what the feature is, where to read more, how to use
it, how its numbers are calculated, how it is implemented, and link the
commits that built it.

Corrected from the code: the file status scan limits are 100,000 records per
collection and 250,000 versions, not 20,000; the snap's FerretDB default is
OpLog with polling as the fallback, not polling only; the Password length
table has 25 rows a page.

Thanks to xet7 !
2026-11-22 17:59:12 +02:00

9.4 KiB
Raw Blame History

Admin Panel → Problems: database text-data migration

Status: Implemented · Owner: xet7 · Related: server/methods/migrateTextDatabase.js, server/lib/repairBoardData.js, server/lib/systemStatus.js, models/textMigrationStatus.js, client/components/settings/attachments.js, client/components/settings/migrationProgress.*.

What it is

WeKan can migrate its text data (everything except attachments and avatars, which stay on the filesystem) between MongoDB and FerretDB v1 (SQLite) in either direction, from Admin Panel → Attachments. Both databases speak the MongoDB wire protocol, so the same driver copies collection by collection, upserting by _id (idempotent — re-running is safe). Its progress is visible on Problems, and this page also explains the FerretDB CPU problem that is the usual reason to look at it.

Read more

How to use it

Migrate the text data

  1. Sign in as a site administrator and open Admin Panel → Attachments → Database migration.
  2. Press Migrate text data to FerretDB v1 (SQLite) or Migrate text data to MongoDB, and confirm.
  3. Watch the blue progress dashboard, or the phase line under the buttons (Phase, the collection being copied and how far it is). You may close the page: the migration keeps running on the server.
  4. After it finishes, point MONGO_URL at the other database and restart.

On the snap there is nothing to point: WeKan runs on FerretDB and the snap migrates itself, with no setting to choose — see Migration-to-FerretDB.md. A Sandstorm grain has only its own FerretDB SQLite database, so the migration is refused there.

See whether a migration or repair is running

  • Admin Panel → Problems → Summary → Status lists it under "In progress".
  • snap run wekan.problems migrations prints it as text (see Snap.md).

Check and set the FerretDB reactivity mode

snap get wekan wekan-ferretdb-oplog     # true (OpLog) or false (polling)
snap set wekan wekan-ferretdb-oplog=false
snap restart wekan.wekan wekan.ferretdb

Admin Panel → Version → Reactivity mode shows which is live (polling vs oplog).

How the numbers are calculated

From server/methods/migrateTextDatabase.js and client/components/settings/attachments.js:

  • Batch size: documents are copied 200 at a time (BATCH), as one bulkWrite of replaceOne upserts; a batch that fails is retried one document at a time, and the documents the target refuses are counted in failed and per collection in failedByCollection. The run succeeds only when that count is 0; otherwise it ends in the error phase with the counts per collection and the first failure.
  • Collections: every collection except the file collections (attachments, avatars, the cfs.* and cfs_gridfs.* ones) and system.*. collectionsDone / collectionsTotal counts them; collDone / collTotal counts the documents of the current one (countDocuments).
  • Overall progress on the dashboard: the repair phase is the first 40 % (boards done / boards total × 40), the copy the last 60 % (40 + collections done / collections total × 60), each rounded.
  • Saved progress: the status is written to text_migration_status at each phase change, per collection, and every 25 boards during the repair.
  • Polling: the page asks for the status every 2 seconds while it runs.
  • Target addresses: WEKAN_FERRETDB_URL (default mongodb://127.0.0.1:27018/wekan) for FerretDB, WEKAN_MONGODB_URL (default mongodb://127.0.0.1:27019/wekan) for MongoDB.

How it works in WeKan

Phases

  1. Repairing — the shared board data-repairs (see Repairs.md) run on the live database first, so the copy carries clean data into the target.
  2. Migrating — every non-file collection is copied in batches to the other database.

Runs server-side. The migration runs as a background operation on the server. It does not depend on the admin staying on the page — if you close the Attachments page the migration keeps running to completion. The progress you see is just a view of it. migrateTextDatabase(direction) and migrateTextDatabaseStatus are admin-only methods; a second start while one runs is refused (already-running).

Progress dashboard. The migration drives the same blue, Product-name-branded progress dashboard as the board repairs (mounted app-wide, client/components/settings/migrationProgress.js). The dashboard is fed from the migration status poll, so the two phases above appear as two steps.

Visible without a browser. The migration and the startup repair persist their progress to the text_migration_status collection (models/textMigrationStatus.js). That means a separate process can see whether a migration/repair is running, through server/lib/systemStatus.js. This is why an in-memory-only progress object was not enough: a CLI or the Problems page in another session could not read it.

Why you might migrate. If the ferretdb process is pegged near 200% CPU for a long time (pages take minutes, All Boards counts stay 0, raw i18n keys appear), the FerretDB v1 (SQLite) backend is saturated under WeKan's load. First check that a migration or repair is not simply still running (snap run wekan.problems), then the reactivity mode below. On the snap there is no longer a way to move back to MongoDB: WeKan runs on FerretDB (Migration-to-FerretDB.md).

FerretDB reactivity mode (polling vs OpLog). FerretDB v1 has no real replica-set OpLog; WeKan can either poll it (poll-and-diff) or tail a simulated OpLog. The snap default was polling only from v10.16, because an OpLog tail then kept FerretDB CPU pinned: the ferretdb process pegging ~2 cores for a long time while the WeKan node process is nearly idle is the signature of an OpLog tail, where Meteor holds a tailable cursor on local.oplog.rs and FerretDB re-scans it server-side.

The snap default is now OpLog again (DEFAULT_WEKAN_FERRETDB_OPLOG="true" in snap-src/bin/config), named write-notified FerretDB OpLog reactivity in the commit that enabled it. Opting into OpLog is also cheaper on the FerretDB side than it was: the {ts: {$gt}} tail filter is pushed down to SQL and the OpLog's Timestamp is indexed, so an idle tail is an index range scan instead of a whole-collection re-decode on every poll. Polling stays as the fallback. Two guards make wekan-ferretdb-oplog=false truly polling only:

  • wekan-control clears MONGO_OPLOG_URL in polling mode, so node never tails.
  • ferretdb-control enables the replica set / OpLog only when wekan-ferretdb-oplog=true; in polling mode FerretDB runs standalone, so no OpLog is maintained and nothing can spin on tailing it.

So if you see the pegged-ferretdb / idle-node pattern, force polling with the commands under How to use it.

Tests: tests/ferretdbMigrationStale.test.cjs, tests/ferretdbOplogGating.test.cjs, tests/boardRepair.test.cjs, tests/problemsStatus.test.cjs and tests/sandstormSlim.test.cjs.

Commits