Skip to content

Latest commit

 

History

History

HibernateSpringBootFlywayMySQLQuick

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

How To Migrate Schema Using Flyway In MySQL With Database Created Via createDatabaseIfNotExist

Note: For production don't rely on hibernate.ddl-auto to create your schema. Remove (disable) hibernate.ddl-auto or set it to validate and rely on Flyway or Liquibase.

Description: This application is an example of migrating a MySQL schema when the database exists (is created before migration via MySQL specific, createDatabaseIfNotExist=true). In this example, the names of the table specified in CREATE TABLE queries are the same as the names of the entities, therefore, there is no need to use @Table(name="...").

Key points:
- for Maven, in pom.xml, add the Flyway dependency
- remove (disable) spring.jpa.hibernate.ddl-auto
- in application.properties, set the JDBC URL as follows: jdbc:mysql://localhost:3306/bookstoredb?createDatabaseIfNotExist=true
- each SQL file containing the schema update add it in classpath:db/migration
- each SQL file name it as V1.1__Description.sql, V1.2__Description.sql, ...


You may like to try as well: