Spring boot offers the great option to load initial data into the database on startup using data.sql. The problem is, I have a table where the column is unique and spring tries to executes the sqls on every startup and fails if the data already present. Now the question is, what is the proper way to handle such cases, is there any way to tell spring when to execute and when not to execute the data.sql file. Thanks
You have couple of options:
spring.datasource.initialize=false
spring.datasource.continue-on-error=true
Second option would let your Spring Boot app to start normally by ignoring any exceptions arising from script execution.
If both of the above options doesn't suit your requirement, as Darren Forsythe mentioned in comments, Consider data migration tools like Flyway or Liquibase. Spring boot provides great support for both tools. Check this out.