Class SchemaMigrations

java.lang.Object
dev.agenor.adapters.persistence.SchemaMigrations

public final class SchemaMigrations extends Object
Internal Flyway runner shared by the directory and HITL schema managers. Not public API — not to be referenced from outside this module.

Each schema records itself in a history table of its own, so the directory, the HITL queue and an application's own migrations can share one database. Up to 0.37.0 both schemas used Flyway's default table, both have a V1, and whichever migrated second failed validation.

The baseline is chosen from the schema's own tables, not from whether the database is empty. baselineOnMigrate at Flyway's default version 1 skips V1 on any database that holds some other table, which left agenor_agents missing with no error. So, when the history table does not exist yet:

  • the marker table exists → baseline 1: a database migrated by 0.37.0 or earlier, whose history is in the default table. Only V1 existed then, so it is at V1 at most, and any later version still runs;
  • otherwise → baseline 0, and V1 runs whatever else the database holds.
Once the history table exists the baseline plays no part.

The migrations live under db/agenor/. Up to 0.37.0 they were under db/migration/, which Spring Boot's Flyway scans recursively by default, so an application with Flyway of its own found Agenor's V1s next to its own and failed with "more than one migration with version 1". A caller still passing an old location is moved to the new one with a warning, until 1.0.0.

Since:
0.38.0
  • Method Details

    • migrate

      public static int migrate(DataSource dataSource, String location, String historyTable, String markerTable)
      Applies the pending migrations at location, recording them in historyTable.
      Parameters:
      dataSource - the database to migrate
      location - the Flyway location holding this schema's migrations
      historyTable - this schema's own history table
      markerTable - a table V1 creates, whose presence means V1 has run
      Returns:
      the number of migrations executed