6.7 The auto-migration framework

OwnSona’s schema evolves through a Java-class-based auto-migration framework that runs at servlet startup.

6.7.1 Components

Migration interface

A single apply(Connection db) method, plus version() (target version) and name() (for logs).

MigrationRegistry

A static ordered list of Migration instances plus CURRENT_DB_VERSION. The two must stay in lockstep; the framework fails fast at startup otherwise.

DbMigrator

Runs at MCPServer.<clinit> via runOnStartup(). Creates a db_version bookkeeping table on first run, finds the gap between the database’s current version and CURRENT_DB_VERSION, applies each missing migration in a separate transaction, recording the new version after each success.

Migration002AddRecordVersion, ...

One class per applied change. Once shipped, a migration is permanent — never edit a deployed one; write a new migration that fixes or supersedes it.

6.7.2 Invariants