mirror of
https://github.com/wekan/wekan.git
synced 2026-11-26 01:49:41 -05:00
d1be2d2131714d023a22a6ffc0a94de651dc7f4e
3
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
898643eea9 |
Build the universal change history, and put undo on top of it
Phase 1 of docs/Features/Reports/History/History.md §10, plus the write half of phase 2. Ctrl+Z is no longer a position-only feature. THE STORE. models/changeHistory.js is the append-only collection of §4: one row per change, carrying every container id it sits inside (boardId, swimlaneId, listId, cardId) so a container scope is a plain equality rather than a join the database cannot do - which is what makes a swimlane's history include its lists' and cards' rows. It imports NO other model, deliberately. Its predecessor imports Cards, Lists, Swimlanes, Checklists and ChecklistItems so its undo() can write to them, and that is precisely why models/cards.js could not import it, guarded on an assumed global instead, and recorded nothing for years. A collection that entities must import cannot import entities. Applying a change back to a document therefore lives in server/models/changeHistory.js, which nothing imports and which may import anything. THE RULES ARE PURE. models/lib/changeHistoryQuery.js holds the scope-to-selector translation, the search and the selection normalisation, with no Meteor and no database, because that is where this feature is either right or quietly wrong: a scope that resolves to the wrong id column shows one board's history under another board's menu, and a selection that does not normalise its input restores the wrong rows. Both are silent. 17 tests, including that an unknown or half-given scope is REFUSED rather than widened into a selector that matches everything. UNDO IS NOW THE WHOLE HISTORY. changeHistory.undoLast/redoLast replace the position-only methods; the keyboard bindings and the tested pickUndo/pickRedo rule are unchanged. One rule covers every change type instead of a case per action: undo applies previousContent, redo applies newContent. Restores go through the same setters an ordinary edit uses, so validation, hooks and Activities still run, and each restore is itself recorded twice - once attributed to whoever made the change being restored, once to whoever pressed Restore (§8.3). RECORDED SO FAR: card description edits (§10.2's first content group - the previous text is read BEFORE the write, since after it the old value is gone), card moves, list moves, and list soft-delete/restore, which is what makes "undo a deleted list" work. changeHistory is in the snap's MERGE_COLLECTIONS, as §9a.4 requires the moment the collection exists: a history row written on the copy that is not served is work that would otherwise be stranded in a database nobody opens. NOT BUILT: every UI in §7, §7a and §8 - the popup, the table, the contributor avatars, the Restore button, the "History" menu items - and recording for the remaining groups of §3. The methods those screens need exist and are tested; nothing calls them yet. Both docs now say which half is which, because the last time this document claimed more than the code did, the gap survived for months. Thanks to xet7 ! |
||
|
|
bb76e7bf10 |
Snap: remove the database setting. There is one answer, and it is FerretDB.
`snap set wekan database=mongodb|ferretdb` is gone, and so is `snap run wekan.database`. WeKan runs on FerretDB on every platform; MongoDB is in the amd64/arm64 snaps to be READ while a migration is owed. A setting could say something the data did not support, and every way it could was a report: set to mongodb it kept a site on the database the snap migrates away from, for good, because nothing ever set it back - including instances a failed migration or a wrong staleness guess had put there; set to ferretdb with no FerretDB present it would have served an empty site, so the guard against that had to exist anyway; and each script carried its own copy of "which database is this, then". snap-src/bin/database-role replaces it. One helper, asked by wekan-control, mongodb-control, ferretdb-control, migration-pending, attachment-repair and the configure hook, answering from the data: a FerretDB with something in it and a migration that has finished means ferretdb, MongoDB data with the migration still owed means mongodb. An interrupted migration is told from a finished one by the importer's checkpoint, so a partial FerretDB resumes and a finished one whose marker went missing is not migrated over again (#6585). An empty FerretDB beside a MongoDB full of boards is never served. The explanatory page is no longer a dead end: when this snap cannot read the MongoDB files but a FerretDB copy is there, the copy is served - older beats unreadable - and the page says the snap keeps trying rather than giving a command to type. A snap that still has the old setting is told once that it is ignored, and it is unset. docs/Platforms/FOSS/Container/Snap/Migration-to-FerretDB.md is the design in one page: all text data to SQLite, CollectionFS and Meteor-Files attachments to the filesystem, the card History with it, which MongoDB versions can be read, when it runs, what happens when it fails, and how two copies are reconciled. The Admin Panel, Snap and CPU-platform docs point there instead of documenting a setting that no longer exists. Nine guards updated; each says in it which decision changed and why. Thanks to xet7 ! |
||
|
|
40ff8151ea |
Snap: pick the database that holds the work, and merge the other one into its history.
An email report, on an instance being served the older of its two copies: "some users are unable to log in (error: 'user not found'), and boards created after mid-July appear to be missing." That is what serving a copy looks like from the outside - the accounts and boards made after the copy was taken simply are not there. Until now the snap handled that by telling the admin to sort it out. #6583 taught it not to switch on a guess, so when both MongoDB and the migrated FerretDB have been written to since the migration it printed the two `snap set wekan database=...` commands and stayed where it was. That message is in `snap logs`; most people never see it, and their site meanwhile shows the wrong copy. A file timestamp cannot answer "which copy holds the work" - an mtime says when a file was touched, and starting a database touches its files. But both copies can be READ, so ask them. bin/db-eval.mjs gains an `evidence` command (per-collection counts, plus the newest timestamp any document carries) and bin/database-choose.mjs decides from the two answers: one holds everything the other holds, and is not older -> serve it, nothing to merge; both hold work the other does not, and one is clearly newer -> serve the newer one and copy across what only exists in the other; too close to call, or nothing readable -> change NOTHING and keep the existing message, because that case is a decision about somebody's work. "Clearly newer" is a margin, not a tie-break: six hours by default, so the writes the migration itself makes on both sides cannot decide anything. WHY THE MERGE IS SAFE, and it is WeKan's own design that makes it safe: the history is APPEND-ONLY (docs/Features/Reports/History/History.md, which gains a section 9a on exactly this). Activities, comments and the coming changeHistory rows are never rewritten in place, so they can only be ADDED to. bin/database- merge-missing.mjs therefore inserts every document whose _id is ABSENT from the chosen database and does nothing else: * a document that IS there is never overwritten - a card edited on both sides keeps the version in the copy being served, which is the newer one; * nothing is deleted, on either side; * the copy that was not chosen stays on disk, so `snap set wekan database=<the other one>` is still the way back - now a choice rather than a repair; * the work done on the copy that is not being served becomes readable in the served copy's card History instead of sitting in a database nobody opens. For the reported symptoms that means the missing users and boards are inserted rather than left behind: a user who could not log in exists again, with their own _id, and their boards with them. A three-way merge - reconciling two edits of one field - is not attempted and will not be from a script. Where the evidence cannot separate the copies, the snap still says so and hands the decision to a person. WEKAN_AUTOPICK=false turns the whole thing off, `database-autopick --dry-run` shows what it would do, and AUTOPICK_MERGE_LIMIT bounds how much it copies. tests/snapDatabaseAutopick.test.cjs covers the decision (both superset directions, the both-diverged case, one side empty or unreadable, too-close, no timestamps, and a BIGGER but older copy that must not win on size) and runs the merge against an in-memory pair of databases: what is missing is inserted, what exists is not overwritten, nothing is deleted on either side, --dry-run writes nothing, a limit is not an error, and the merge script contains no update or delete operation at all. tests/ferretdbMigrationStale.test.cjs keeps its rule - no switch on a guess - with the assertion updated to match what changed: this branch may not choose from the timestamps it has, it delegates to the one thing that can choose, and when even that cannot tell the copies apart the admin still gets both commands. Verified by running both suites and the whole node suite (381 suites, 0 failed). The snap itself cannot be built or refreshed in this sandbox, so the orchestration that starts each database on a temporary port is verified from the code and from the shapes migration-control already uses, not from a running snap. Thanks to xet7 ! |