Search in sources :

Example 1 with AtherysDatabaseMigrationEvent

use of com.atherys.core.event.AtherysDatabaseMigrationEvent in project AtherysCore by Atherys-Horizons.

the class DatabaseMigrator method migrate.

public void migrate() {
    logger.info("Beginning database migration...");
    String vendor = config.HIBERNATE.get(JPAConfig.URL_KEY).split(":")[1];
    AtherysDatabaseMigrationEvent event = new AtherysDatabaseMigrationEvent();
    Sponge.getEventManager().post(event);
    event.getPluginIds().forEach(pluginId -> {
        String location = String.format("classpath:db/migration/%s/%s", pluginId, vendor);
        logger.info("Migrating " + location);
        FluentConfiguration cfg = new FluentConfiguration().dataSource(config.HIBERNATE.get(JPAConfig.URL_KEY), config.HIBERNATE.get(JPAConfig.USERNAME_KEY), config.HIBERNATE.get(JPAConfig.PASSWORD_KEY)).schemas(pluginId).table("flyway_schema_history_" + pluginId).locations(location);
        new Flyway(cfg).migrate();
    });
    logger.info("Database migration complete.");
}
Also used : FluentConfiguration(org.flywaydb.core.api.configuration.FluentConfiguration) Flyway(org.flywaydb.core.Flyway) AtherysDatabaseMigrationEvent(com.atherys.core.event.AtherysDatabaseMigrationEvent)

Aggregations

AtherysDatabaseMigrationEvent (com.atherys.core.event.AtherysDatabaseMigrationEvent)1 Flyway (org.flywaydb.core.Flyway)1 FluentConfiguration (org.flywaydb.core.api.configuration.FluentConfiguration)1