ninja icon indicating copy to clipboard operation
ninja copied to clipboard

How to generate db script based on model

Open liudianpeng opened this issue 3 years ago • 3 comments

How to generate db script based on model Create table

liudianpeng avatar Mar 23 '21 09:03 liudianpeng

You could either use something like JPA or ebean (https://github.com/ninjaframework/ninja-ebean) to that end.

raphaelbauer avatar Mar 31 '21 19:03 raphaelbauer

Or maybe I got it wrong and you mean the DDL? Then you could use JPA/Hibernate which support that.

But to be honest - I always do this via flyway manually. It's much better and you'll need migrations anyway in reality.

raphaelbauer avatar Mar 31 '21 19:03 raphaelbauer

(Sorry for necroposting.)

If you choose Ebean, then it could help you to create the whole database (CREATE ALL) with ebean-ddl-generator. Please note that since Ebean 12.7.1 (see ebean-orm/ebean#2162) it's not included in ebean but in ebean-test only.

Ebean could also help with migrations: not just generating them but also running them:

Ebean can generate the migrations for us by performing a diff on the model and then generating database platform specific DDL for the change.

Ebean can also run the migrations (similar to FlywayDb). It is recommended to use Ebean's built in migration runner rather than FlywayDb or LiquiBase.

xabolcs avatar Dec 31 '22 08:12 xabolcs