Repository navigation
Configuration: Introduced moves into empty places, section and file merges, and deletion of emptied directories - #18
Merged
Conversation
…les, delete emptied directories ConfigContext gains the operations a migration needs on a directory that earlier builds left values in more than one place, each a no-op when there is nothing to do: - moveIfAbsent: moves a value only into an empty place; a value already at the new place stays and the moved one is dropped - moveSection: merges a section into another value by value, down through the sections both hold, and removes the emptied source and the sections above it; an empty pointer names the whole document, whose _version stays - moveFile: merges a whole file into another the same way, without its _version, and deletes it - removeIfEmpty: removes an empty section and the ones above it it empties - removeVersion: takes a meaningless _version out of a file - deleteDirectoryIfEmpty: deletes a directory once only empty directories are left in it, counting the migration's own changes The commit journal records the deleted directories as a list of its own, replayed after the file deletions, deepest first; a directory that is no longer empty or already gone is left alone, and a journal without the list replays as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Config migrations get the operations needed to bring along a directory where earlier builds left values in more than one place, so an application no longer has to write its own merge helpers on top of
ConfigContext. Identica's configuration migration (whereareiam/Identica#196) is the first user.Cause
ConfigContextcould only move a value and overwrite whatever was at the target. It couldn't move into empty places only, merge sections or files, prune emptied sections, or delete directories.ConfigContextalso could not handle a directory at all: it would have tried to read it as a document, and the commit journal only knew about files.Fix
New
ConfigContextoperations. Each does nothing when there is nothing to do, so a migration built from them can run safely on a directory that is already past it:moveIfAbsent(file, pointer, targetFile, targetPointer): moves a value only into an empty place. If the target already holds a value, that value is kept and the moved one is dropped.moveSection(file, pointer, targetFile, targetPointer): merges a section into another one value by value, going down through sections both sides hold. Values the target already holds are kept. The emptied source and the sections above it that it leaves empty are removed. An empty pointer names the whole document; its_versionstays where it is. Overlapping sections of the same file are rejected.moveFile(file, targetFile): merges a whole file the same way, without its_version, and deletes it. If the target is missing, it is created.removeIfEmpty(file, pointer): removes an empty section and the sections above it that it leaves empty. The document itself always stays, so an empty pointer does nothing.removeVersion(file): takes out a_versionthat has no meaning in that file. The Javadoc warns never to call it on another stream's version file.deleteDirectoryIfEmpty(directory): deletes a directory once only empty directories are left in it, counting the migration's own staged deletions and writes. It returns false and leaves the directory when anything else is in it. The root,.strataand paths outside the directory are rejected.Escaping a key for a pointer stays with Jackson (
JsonPointer.appendProperty), as the README now explains.Journal:
CommitJournal.commit(changes, directories)records directory deletions in a separatedelete-directorylist. On replay they run after the file deletions, deepest first. A directory that is no longer empty or is already gone is skipped, so recovery cannot get stuck. A journal left by 3.1 or earlier, without the list, replays as before. A file move is one write plus one deletion in the same commit, so it was already all-or-nothing and backed up.Tests
ConfigContextTest: every new operation, run for both YAML and JSON (@EnumSource). Covers moving into empty and occupied places, deep merges, emptied sources, a target holding a non-section, a document's_version, files moved into new and existing files, pruning, stale versions, directories with staged deletions and writes, nested empty directories, rejected paths, and Jackson pointer escaping.CommitJournalTest: directory deletions after file deletions; directories no longer empty or already gone; crash recovery after the commit took effect; recovery interrupted halfway through deleting directories; journals without a directory list.ConfiguraTargetTest: a migration that moves a file out of a directory and deletes it, end to end with backup and version; recovery of an interrupted commit with a directory deletion.Verification
./gradlew clean build -PintegrationTests=true --no-build-cache: BUILD SUCCESSFUL, 192 tests, 0 failures (adapter-configura 70; container tests against PostgreSQL, MariaDB and MySQL included).3.2.0-local-1d9eaf5.Release notes
Area: Descriptionwith a listed areaDatabase: Fixed ...feature,change,bug,dependencies, orskip-changelogbugonly for a bug that shipped in a release; a fix for a bug that only existed ondevisskip-changelogmajoradded when applications must change their code or migrations on upgrade (not needed: additive).github/release-notes.md, if applications need them (none needed)Checks
🤖 Generated with Claude Code