-1

How can I "sync" my db server (MySQL) with my hibernate tables without the hibernate.hbm2ddl.auto = update property? Before using MySQL databases I was using H2 and I could use Liquibase to "merge" two different database so I only had to host an empty database with the tables somewhere and then check for potential update but how can I do it with MySQL as it is a server? Is there a better way to do it?

Thanks

Nicolas Sagala Beaucage
  • 1,229
  • 1
  • 11
  • 23
  • You can use liquibase with MySQL too. It may not be an embedded database, but it's still a database. Liquibase doesn't care. – Kayaman Sep 05 '17 at 20:06
  • Yes but what should I compare? Before I had a mv.db file for H2 I could easily drop somewhere and download it within my code. Now I have a MySQL Server. I can't really copy it – Nicolas Sagala Beaucage Sep 05 '17 at 20:08
  • I'm not sure I understand. Why would you download it in your code? What prevents you from copying a MySQL database? – Kayaman Sep 05 '17 at 20:11
  • My logic with my H2 database was to drop a clean copy of my tables into a ftp. When the user launch my app it downloads the clean db and I do a diff from liquibase from the ftp version and the local one so I could update the columns like nothing. Now I wonder can I still do that for a MySQL Server? Because I can't copy the mysql database into a ftp and do the same logic? – Nicolas Sagala Beaucage Sep 05 '17 at 20:14
  • Do you mean the application is a stand-alone program, and all users are expected to have their own server running? If so, you'd probably want to think of a better strategy for DDL updates. Writing proper liquibase update scripts for example, instead of performing a merge. – Kayaman Sep 05 '17 at 20:19
  • So I should generate a changeset for each version? – Nicolas Sagala Beaucage Sep 05 '17 at 20:25
  • That would be a lot better approach, yes. – Kayaman Sep 05 '17 at 20:26

1 Answers1

1

Instead of doing a compare-and-merge, a better and more standard approach is to provide Liquibase changesets for any changes in the database.

This also allows you to check that the database is in proper condition before updating (and possibly breaking things), and updates will be executed sequentially instead of just directly modifying the database from point A to point Z. This allows you also to change the data from one format to another if necessary.

You can also execute the changesets programmatically, so you don't need to put big database dumps anywhere, just the small changeset files.

Kayaman
  • 72,141
  • 5
  • 83
  • 121