Interface PluginMigration

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface PluginMigration
Interface for plugin database migrations.

Plugins can define migrations to update their database schema over time. Migrations run in order based on version numbers and only run once.

Example:

@OnEnable
public void onEnable(PluginContext context) {
    PluginDatabaseManager db = context.getDatabaseManager();

    // Migration to version 1: Initial schema
    db.migrate(1, manager -> {
        manager.createTable(TableSchema.builder("users")
            .column("name", ColumnType.STRING, 100, false)
            .build());
    });

    // Migration to version 2: Add email column
    db.migrate(2, manager -> {
        // Use raw ALTER TABLE via migration helper
        manager.addColumn("users", "email", ColumnType.STRING, 255, true);
    });

    // Migration to version 3: Add index
    db.migrate(3, manager -> {
        manager.createIndex("users", false, "email");
    });
}

  • Method Details

    • migrate

      void migrate(PluginMigration.MigrationHelper migrationHelper) throws Exception
      Execute the migration.

      This method is called within a database transaction. If an exception is thrown, the migration is rolled back.

      Parameters:
      migrationHelper - helper for migration operations
      Throws:
      Exception - if migration fails