I am building a Spring Boot application which has several long texts in it's entities.
To ensure I can handle my database migrations well I included Flyway. In production I'm using a MySQL database, for local testing I want to implement the default h2 database.
An entity might have the following property
@Column(columnDefinition = "TEXT")
val startText: String?
For my MySQL database, this works fine and looks like this in my flyway schema:
start_text TEXT,
When I now start my tests with the default h2 in-memory database in Spring, I receive the following error:
Schema-validation: wrong column type encountered in column [start_text] in table [t_table]; found [clob (Types#CLOB)], but expecting [text (Types#VARCHAR)]
I understand that h2 does not support the MySQL specific type TEXT
but actually I have no clue how to fix this.
Any help is appreciated.
Thank you.
I found a workaround for this. In my application.yaml I have the following:
spring:
flyway:
placeholders:
text-datatype: 'TEXT' #defines a placeholder that is available in flyway
In my application.yaml in my test folder I have the following
spring:
flyway:
placeholders:
text-datatype: 'VARCHAR(255)'
Now I can use the placeholder in my Flyway scripts and it works fine:
start_text ${text-datatype}