0

For the database schema management with spring data/hibernate, setting spring.jpa.hibernate.ddl-auto option doesn't look like a cleaner approach.

Bcoz

1) We are forced to put the credentials of a user that has permission to create and delete in the application.properties.

2) In production, relaying on spring.jpa.hibernate.ddl-auto option could lead to dataloss, if not managed carefully.

So what is the best way out there to handle the database schema management automatically in a spring boot/spring data app?

Any pointers would help.

Thanks

Minisha
  • 2,117
  • 2
  • 25
  • 56
  • Do you investigate the Flyway or Liquibase or something else for the database schema changes tracking? – Max Peng Jul 27 '18 at 06:54
  • Yeah, I am looking for something that automatically generate the sql based on model taking the difference on the database also. In flyway we have to write the sql. Is there a way to fully automate this? – Minisha Jul 27 '18 at 10:05
  • Like from model -> sql -> then flyway – Minisha Jul 27 '18 at 10:07

2 Answers2

0

If you want to track each change state of database then you can use flyway

See this link how to maintain database versioning in spring-boot

GolamMazid Sajib
  • 8,698
  • 6
  • 21
  • 39
0

In production, you should ideally set spring.jpa.hibernate.ddl-auto property as none so that no schema changes are allowed.

For the database schema management with spring data/hibernate, I would suggest you go for Liquibase, it basically is an open source database-independent library for tracking, managing and applying database schema changes.

Every change to Schema is added as a changeset using property file in Liquibase , this is for the new changes.

In order to migrate the existing database structure into Liquibase, it provides you with commands to automatically generate Changesets by reading the current database.

So using this you can generate database schema, add constraints, load data.

More info at : https://www.liquibase.org/ , Why and when Liquibase?

Jayesh Mulwani
  • 655
  • 6
  • 19