org.dbmaintain.util.DbMaintainException: Following irregular script updates were detected — решение проблемы


Tagged , , ,

При накатывании миграции через dbmaintain может возникнуть ошибка:

Exception in thread "main" org.dbmaintain.util.DbMaintainException: Following irregular script updates were detected:
.... Тут перечислены скрипт(ы) .....
Because of this, dbmaintain can't perform the update. To solve this problem, you can do one of the following:
  1: Revert the irregular updates and use regular script updates instead
  2: Enable the fromScratch option so that the database is recreated from scratch (all data will be lost)
  3: Perform the updates manually on the database and invoke the markDatabaseAsUpToDate operation (error prone)

Причина в том, что скрипт миграции уже содержится в таблице проведенных миграций и его контрольная сумма не совпадает с тем, что лежит на диске. Т.е. файл был изменен.

Решение. Смотрим в конфиге dbmaintain название таблицы куда пишутся все проведенные миграции в параметре dbMaintainer.executedScriptsTableName. Допустим это таблица migrations. Заходим в базу приложения, находим эту таблицу и ищем нужную нам запись

db=# select * from migrations where file_name like '%название_файла_из_ошибки%';

Видим запись, берем поле checksum и удаляем эту запись.

db=# delete from migrations where checksum='794fe145f2ad4f254e8ae187fd0ef1d5';

Далее как обычно проводим миграции

$ ./dbmaintain.sh updateDatabase -config MyConfig.properties

В моем случае эта миграция вообще была бесполезной. Поэтому перед тем как запустить обновление я зафейкал миграцию

./dbmaintain.sh markErrorScriptPerformed scripts/incremental/4/002_@some_script.sql -config MyConfig.properties

Share:

No comments

RSS / trackback

Respond