feat(config): add explicit configuration schema migrations - #763
Open
ajulaybeeb wants to merge 1 commit into
Open
feat(config): add explicit configuration schema migrations#763ajulaybeeb wants to merge 1 commit into
ajulaybeeb wants to merge 1 commit into
Conversation
Implement structured, versioned schema migrations for StarForge configuration files (~/.starforge/config.toml). Core changes: - ConfigMigrationError enum: Provides structured, actionable errors for future schema versions (FromFuture), unrecognised versions (UnknownVersion), step failures (StepFailed), and backup I/O failures (BackupFailed). - MigrationReport struct: Captures from_version, to_version, steps_applied, and backup_path for auditing and testing. - ConfigMigrationStep registry: Replaces ad-hoc string matching with a versioned step pipeline (MIGRATION_STEPS) that executes sequential migrations (e.g. v0 -> v1) in ascending order. - Pre-migration backup policy: Writes a timestamped backup (config.backup.v<version>.<timestamp>.toml) prior to running any migration step, aborting safely if backup creation fails. - run_config_migrations() entry point: Exposes detailed migration execution and reporting while preserving backward compatibility with migrate_config(). Tests & Documentation: - tests/config_migrations.rs: Added 8 integration tests covering primary flow (v0 -> v1 step execution), boundary cases (already-current no-op, backup path formatting, empty vs explicit v0), and failure paths (future versions requiring binary upgrade, unknown version strings). - README.md & DEVELOPER_GUIDE.md: Documented migration pipeline, backup/rollback procedure, error resolution table, and guide for adding future schema steps. Closes Nanle-code#660
|
@ajulaybeeb Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Collaborator
|
@ajulaybeeb Please make sure to fix CI issues, very important!!! |
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
~/.starforge/config.toml)ConfigMigrationStepandMIGRATION_STEPS) that applies sequential schema upgrades in ascending orderConfigMigrationError) and execution auditing (MigrationReport)config.backup.v<version>.<timestamp>.toml) that abort safely prior to applying migration steps if backup writing failstests/config_migrations.rs) and updateREADME.mdandDEVELOPER_GUIDE.mdwith schema migration documentationWhy
Issue #660 requires older configuration files to be upgraded predictably with automatic backups and actionable error messages. Previously,
migrate_configperformed flatmatchlogic on string versions without a formal step registry, structured error types, execution reports, or comprehensive automated tests for edge cases (such as future config versions written by newer binaries or corrupted version strings).Implementation
src/utils/config.rsCURRENT_CONFIG_VERSION: Const ("1") specifying the latest supported schema versionConfigMigrationError: Enum providing actionable error variants:FromFuture { found, latest }: Instructs user to upgradestarforgewhen attempting to load a config from a newer binaryUnknownVersion { found }: Reports unrecognised/corrupted schema version stringsStepFailed { from, to, reason }: Reports failures during step executionBackupFailed { version, reason }: Reports backup file I/O failuresMigrationReport: Struct recordingfrom_version,to_version,steps_appliedlist, andbackup_pathMIGRATION_STEPS: Registry ofConfigMigrationStepentries defining sequential version transforms (e.g.v0→v1)run_config_migrations(): Primary entry point that validates version hierarchy, writes a pre-migration backup, executes step sequences in order, and returns(Config, MigrationReport)migrate_config(): Preserved as a backward-compatible wrapper returningResult<Config>tests/config_migrations.rs(new, 8 tests)test_migration_from_empty_version_to_v1: Primary flow verifying v0 → v1 migration step executiontest_migration_from_explicit_v0_to_v1: Normalizing explicit"0"version stringtest_migration_already_current_is_noop: Verifying already-current config executes no steps and writes no backuptest_migrate_config_convenience_wrapper: Exercising high-levelmigrate_confighelpertest_migration_backup_path_encodes_source_version: Validating backup path naming structuretest_migration_from_future_version_errors: Failure path confirmingFromFutureerror with upgrade instructionstest_migration_unknown_version_errors: Failure path confirmingUnknownVersionerror for invalid version stringstest_migration_non_numeric_version_not_silently_upgraded: Failure path ensuring non-numeric string versions are rejectedDocumentation
README.md: Added Configuration schema migrations section detailing migration pipeline, timestamped backups, recovery steps, error resolution matrix, and developer instructions for adding schema versionsDEVELOPER_GUIDE.md: Added architecture overview, backup policy, step addition workflow, and test execution instructionsTesting
Ran automated integration suite: