This issue was something similar that our team encountered and tried a couple of attempts to use sql-based flyway migration initially
Due to the complexity of storing the blob with using SQL statements, we moved to use spring JDBC templates in a java-based migration script. https://flywaydb.org/documentation/concepts/migrations#java-based-migrations
In regards to your question, we would need to create a separate folder called db.migration within your src/main/java folder in order for flyway to pick up the java based migration and run it sequentially according to the version numbers provided in the name.
src
main
java
com.example.package
db.migration
- V3__insert_table_data.java
resources
db.migration
- V2__init.sql
Sample implementation for using spring jdbc templates and reading of image files from machine. This assumes images are checked in together with source code
public class V3__insert_table_data extends BaseJavaMigration {
public void migrate(Context context) {
var image = getImageFromFile("filename.svg");
var insertStatement = "INSERT INTO table_name VALUES ('id1', '" + image + "')";
new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), true))
.execute(insertStatement);
}
}
//helper method to retrieve images from file system
private String getImageFromFile(String fileName) throws IOException {
try(FileInputStream image = new FileInputStream("pathToImage/" + fileName)){
var bytes = logo.readAllBytes();
// You might want to Base64 encode the image to prevent any sql grammar insertion error happening
var encodedBytes = Base64.getEncoder().encode(bytes);
return new String(encodedBytes);
}
}