public List < MetadataInfo > ensureMetadata ( final MigratoryOption [ ] options ) throws MigratoryException { if ( migratoryContext . getDbSupport ( ) . tableExists ( migratoryConfig . getMetadataTableName ( ) ) ) { return null ; } if ( migratoryConfig . isReadOnly ( ) ) { throw new MigratoryException ( Reason . IS_READONLY ) ; } // Table does not exist. The way we get one, is that we run a special migration for the internal metadata schema final MigrationPlanner migrationPlanner = new MigrationPlanner ( new MigrationManager ( migratoryContext , METADATA_MIGRATION_NAME ) , 0 , Integer . MAX_VALUE ) ; migrationPlanner . plan ( ) ; if ( migrationPlanner . getDirection ( ) != MigrationDirection . FORWARD ) { throw new MigratoryException ( Reason . INTERNAL , "Migration planner could not plan a migration for the metadata table!" ) ; } final DbMigrator migrator = new DbMigrator ( migratoryContext , migrationPlanner ) ; try { lock ( METADATA_MIGRATION_NAME ) ; final List < MigrationResult > results = migrator . migrate ( options ) ; return commit ( results ) ; } catch ( MigratoryException e ) { rollback ( ) ; throw e ; } catch ( RuntimeException e ) { rollback ( ) ; throw e ; } }
Make sure that the metadata exists . If it does not exist create the metadata table from scratch and register its creation .