Class ConfigMigrator.Builder
java.lang.Object
net.blockhost.commons.config.migration.ConfigMigrator.Builder
- Enclosing class:
ConfigMigrator
Builder for creating
ConfigMigrator instances.-
Method Summary
Modifier and TypeMethodDescriptionSets a callback to be invoked after each successful migration.backupSuffix(String suffix) Sets the backup file suffix.beforeMigration(Consumer<Migration> callback) Sets a callback to be invoked before each migration.build()Builds the ConfigMigrator.createBackups(boolean createBackups) Enables or disables backup creation.Sets the environment variable prefix for config value resolution.onError(Consumer<MigrationException> callback) Sets a callback to be invoked when a migration fails.Registers a migration.registerAll(Migration... migrations) Registers multiple migrations.strictMode(boolean strict) Enables or disables strict mode.useTimestampedBackups(boolean timestamped) Enables timestamped backups.
-
Method Details
-
register
Registers a migration.- Parameters:
migration- the migration to register- Returns:
- this builder
-
registerAll
Registers multiple migrations.- Parameters:
migrations- the migrations to register- Returns:
- this builder
-
envPrefix
Sets the environment variable prefix for config value resolution.
When set, environment variables starting with this prefix can override configuration values. For example, with prefix
"MYPLUGIN_", the env varMYPLUGIN_DATABASE_HOSTwould override thedatabase.hostconfig field.Resolved values are never written back to disk.
- Parameters:
prefix- the environment variable prefix (e.g."MYPLUGIN_")- Returns:
- this builder
-
strictMode
Enables or disables strict mode.
In strict mode (default), migration fails if any step is missing.
- Parameters:
strict- true for strict mode- Returns:
- this builder
-
createBackups
Enables or disables backup creation.- Parameters:
createBackups- true to create backups before migration- Returns:
- this builder
-
backupSuffix
Sets the backup file suffix.- Parameters:
suffix- the suffix to append to backup files (default: ".bak")- Returns:
- this builder
-
useTimestampedBackups
Enables timestamped backups.
When enabled, backup files include a timestamp in the filename, preventing overwrites of previous backups.
- Parameters:
timestamped- true for timestamped backups- Returns:
- this builder
-
beforeMigration
Sets a callback to be invoked before each migration.- Parameters:
callback- the callback- Returns:
- this builder
-
afterMigration
Sets a callback to be invoked after each successful migration.- Parameters:
callback- the callback- Returns:
- this builder
-
onError
Sets a callback to be invoked when a migration fails.- Parameters:
callback- the callback- Returns:
- this builder
-
build
-