Class ConfigMigrator.Builder

java.lang.Object
net.blockhost.commons.config.migration.ConfigMigrator.Builder
Enclosing class:
ConfigMigrator

public static final class ConfigMigrator.Builder extends Object
Builder for creating ConfigMigrator instances.
  • Method Details

    • register

      public ConfigMigrator.Builder register(Migration migration)
      Registers a migration.
      Parameters:
      migration - the migration to register
      Returns:
      this builder
    • registerAll

      public ConfigMigrator.Builder registerAll(Migration... migrations)
      Registers multiple migrations.
      Parameters:
      migrations - the migrations to register
      Returns:
      this builder
    • envPrefix

      public ConfigMigrator.Builder envPrefix(String prefix)

      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 var MYPLUGIN_DATABASE_HOST would override the database.host config field.

      Resolved values are never written back to disk.

      Parameters:
      prefix - the environment variable prefix (e.g. "MYPLUGIN_")
      Returns:
      this builder
    • strictMode

      public ConfigMigrator.Builder strictMode(boolean strict)

      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

      public ConfigMigrator.Builder createBackups(boolean createBackups)
      Enables or disables backup creation.
      Parameters:
      createBackups - true to create backups before migration
      Returns:
      this builder
    • backupSuffix

      public ConfigMigrator.Builder backupSuffix(String suffix)
      Sets the backup file suffix.
      Parameters:
      suffix - the suffix to append to backup files (default: ".bak")
      Returns:
      this builder
    • useTimestampedBackups

      public ConfigMigrator.Builder useTimestampedBackups(boolean timestamped)

      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

      public ConfigMigrator.Builder beforeMigration(Consumer<Migration> callback)
      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

      public ConfigMigrator build()
      Builds the ConfigMigrator.
      Returns:
      the configured migrator