hertzbeat icon indicating copy to clipboard operation
hertzbeat copied to clipboard

[BUG] manager cannot start again after V181 migration fails (flyway records failed migration)

Open orangeCatDeveloper opened this issue 3 months ago • 0 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Current Behavior

On a fresh MySQL/PostgreSQL database, Hibernate ddl-auto creates the hzb_sop_schedule table from the entity before Flyway runs (Flyway is deliberately delayed until after entityManagerFactory). V181__update_column.sql then executes a bare CREATE TABLE hzb_sop_schedule, which fails with "Table 'hzb_sop_schedule' already exists". Flyway records this failure in flyway_schema_history, and from then on every restart aborts during validation:

FlywayValidateException: Validate failed: Migrations have failed validation
Detected failed migration to version 181 (update column)

The instance can never start again until someone manually deletes the failed row from flyway_schema_history.

Expected Behavior

The V181 migration should tolerate objects already created by Hibernate (CREATE TABLE IF NOT EXISTS / CREATE INDEX IF NOT EXISTS), and a previously recorded failed migration should not permanently prevent startup — Flyway history can be repaired automatically and the (now idempotent) migration retried.

Steps To Reproduce

  1. Point the manager at an empty MySQL (or PostgreSQL) database with spring.flyway.enabled=true (default startup config)
  2. First boot: Hibernate creates hzb_sop_schedule; Flyway's V181 CREATE TABLE collides and the failure is recorded in flyway_schema_history
  3. Restart the manager
  4. Startup aborts with Validate failed ... Detected failed migration to version 181 — and keeps failing on every restart

Environment

HertzBeat version(s): master (also reproduced against 1.8.0 schema with MySQL 8 and PostgreSQL 15)

Debug logs

No response

Anything else?

No response

orangeCatDeveloper avatar Aug 17 '26 07:08 orangeCatDeveloper