ninjaframework / ninja

Ninja is a full stack web framework for Java. Rock solid, fast and super productive.
http://www.ninjaframework.org
Apache License 2.0
1.91k stars 521 forks source link

How to generate db script based on model #710

Open liudianpeng opened 3 years ago

liudianpeng commented 3 years ago

How to generate db script based on model Create table

raphaelbauer commented 3 years ago

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

raphaelbauer commented 3 years ago

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.

xabolcs commented 1 year ago

(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.