I am relatively new to SpringBoot (2.4.2), Hibernate (5.4.27) and Flyway (7.1.1) and I'll give my best to describe the problem as exact as I can. I have an entity address annotated like this:
@Entity
@Table(
name = "address",
indexes = [Index(columnList = "zip, city", name = "zip_city_index")]
)
data class Address( ... )
The config of hibernate and flyway looks like this:
jpa:
hibernate:
ddl-auto: validate
show-sql: true
properties:
hibernate:
hbm2ddl.auto: validate
jdbc.lob.non_contextual_creation: true
flyway:
enabled: true
The SQL scripts are created manually and are migrated via flyway. I am using a Postgres to store the data. If there is a mismatch between the DB and my entity-model (e.g column names, types etc) Schema-Validation fails and I am aware of something is wrong and can fix this.
This works for all my cases except for the index I want to create. Hibernate does not validate the existence of this index. I forgot to add the corresponding CREATE INDEX migration, but Hibernate did not care at all. If i use hbm2ddl.auto = update it creates the index but as I want only a validation, this is not the way to go for me.
I looked at a lot of documentation, but I couldn't find a way to enforce the validation/existance of an index.
Should it even be possible to validate this? Is there maybe another/better way to go?
Thank you in advance.