Skip to content

Configuration: Introduced moves into empty places, section and file merges, and deletion of emptied directories - #18

Merged
whereareiam merged 1 commit into
devfrom
feature/config-operations
Oct 12, 2026
Merged

whereareiam merged 1 commit into
devfrom
feature/config-operations

Conversation

@whereareiam

Copy link
Copy Markdown
Owner

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

ConfigContext could 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. ConfigContext also 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 ConfigContext operations. 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 _version stays 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 _version that 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, .strata and 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 separate delete-directory list. 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).
  • Published locally as 3.2.0-local-1d9eaf5.

Release notes

  • The title follows Area: Description with a listed area
  • The title describes the effect in the past tense, for example Database: Fixed ...
  • Exactly one label: feature, change, bug, dependencies, or skip-changelog
  • bug only for a bug that shipped in a release; a fix for a bug that only existed on dev is skip-changelog
  • major added when applications must change their code or migrations on upgrade (not needed: additive)
  • Upgrade steps added to .github/release-notes.md, if applications need them (none needed)

Checks

  • Tests added or updated
  • README updated for changed usage

🤖 Generated with Claude Code

…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>
@whereareiam whereareiam added the feature Something new for users or developers label Oct 12, 2026
@whereareiam
whereareiam merged commit 5e818ab into dev Oct 12, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Something new for users or developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant