3

im building a Spring Boot web app with MySQL and till now i used the

spring.jpa.hibernate.ddl-auto=create-drop

in my properties file, and now i want to move to production and i cant use this line anymore because as u all know its saving the data on the memory and the worst thing its destroying all the data and create a new table every deploy.

for dev purposes its wonderful but what i need to do next cause i want it to behave exactly as i was on the ddl-auto but to persistently save the data and most inportantly never to drop the data.

P.S. the hibernate.ddl-auto has nothig to do with the JPA Repository? cause i use Crud Repository alot and i need this to continue working with Crud Repository, will it?

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
Aharon
  • 81
  • 8
  • Possible duplicate of [Hibernate hbm2ddl.auto possible values and what they do?](http://stackoverflow.com/questions/438146/hibernate-hbm2ddl-auto-possible-values-and-what-they-do) – Mike Nakis Apr 28 '17 at 08:39
  • 1
    no i already saw that question its not what i asked – Aharon Apr 28 '17 at 09:13

2 Answers2

1

the best thing to do, according to me, is:

  • use the option spring.jpa.hibernate.ddl-auto=create-drop to create the DB schema and the default data (if any) in development environment
  • export the created DB schema in a normal DDL
  • give the DDL to DBAs to check if any improvement must be done (e.g. add some indexes, review some FK etc..)
  • adapt JPA models after DBAs review
  • give the final DDL to the "production DBAs" in order to create the final correct schema in production environment too

Regarding to your question:

the hibernate.ddl-auto has nothig to do with the JPA Repository? cause i use Crud Repository alot and i need this to continue working with Crud Repository, will it?

You can of course use the crud repository; this option will not influence your business logic

I hope it's useful

Angelo

Angelo Immediata
  • 6,635
  • 4
  • 33
  • 65
  • thanks alot for answering , i understood what u saying, nut i dont know how to do that... were can i find th ddl schema? how give the DBAs? how to adapt the models? and the last line how do i give the final DDL to the "production DBAs" ? – Aharon Apr 28 '17 at 07:17
  • @Aharon You will create the environment DB schema on a DB (e.g. MySQL o PostgreSQL); by using any DB client (or by command line) you can connect to the development DB and use the export DB option; once you exported the schema you have the DDL (it's a common .sql file); you can then give this file to the DBAs to check for any improvement or to the production DBAs (the DBAs responsible for the production environment) in order to let them to create the DB – Angelo Immediata Apr 28 '17 at 07:21
  • last thing.. the extracted schema is a normal .sql file and not needed to modifay unless the SQL client tells me to? – Aharon Apr 28 '17 at 07:39
  • It's a normal .sql file; you should give this file to DBAs so that they can create the schema and check if any improvements are needed. If no improvement is needed the sql can be left as it is – Angelo Immediata Apr 28 '17 at 07:52
0

You don't want to be sending DDLs around. You will end up trying to invent version control system for your scripts, by naming them specifically or putting them in folders, you will struggle communicating with DBAs, scripts breaking..

You want your database definition code to be a part of your code base so you can put it under version control (yes, git).

Try to use Liquibase for this. It will help you do automatic updates of the schema, data, everything db related, and it knows how to migrate your app's db, lets say, from 1.1 to 1.2 but also from 1.1 to 1.6. There are also other db migration tools like Flyway, you can look them up and play around.

veljkost
  • 1,748
  • 21
  • 25
  • yes you right now that i think about it i cant update th DB... i can use for the first time DDL and then use the Liquibase? cause i dont know hot to use this for now and its looks not that eazy(i will be glad if u can share a good TUT or youtuve video that explain the Liquibase for my purposes!!!) – Aharon Apr 28 '17 at 09:20
  • It is true that you have to put some additional effort to start using it, but it pays off. Start with docs on their site, like: http://www.liquibase.org/documentation/existing_project.html and expand from there. There's a lot examples and tuts out there. Like with everything else, you can try with some small project to get a feel. – veljkost Apr 28 '17 at 11:08
  • Hey mate can u please help me somehow I can't configure liquibase in my project can I contact u somehow for help? – Aharon May 15 '17 at 15:18