Categories
database-schema java mysql spring-boot

Spring Boot schema.sql – drop db schema on restart

Hi I’m using Spring Boot version 1.5.9.

When using Spring Boot to initialize schema.sql for mysql database, it works all fine and the database schema is getting created successfully. But on restart of the application this schema.sql script is executing again and the application fails to start because the tables already exist.

I tried spring.jpa.hibernate.ddl-auto=create-drop option in application.properties but it does not have any effect (probably because it only works for Hibernate entities which I’m not using)

Is there a way to have Spring Boot to re-create schema from schema.sql every time on restart if the database is not in-memory one?

GitHub:
https://github.com/itisha/spring-batch-demo/tree/database-input