Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails: Generate SQL CREATE TABLE statements from domain classes

Tags:

mysql

grails

Grails can automatically create database tables (e.g. in MySQL) based on domain classes.

During debugging, is there a command that will simply print out the SQL statement that would be executed against the database to create the table, based on a domain class?

That is, instead of having Grails actually trying to create the table and generate potential errors (yes, that may include the CREATE TABLE statement).

I would find it useful sometimes to have Grails tell me what SQL CREATE TABLE statement it thinks a domain class maps to.

like image 435
metajungle Avatar asked Dec 11 '25 23:12

metajungle


1 Answers

Use the schema-export command for this.

If you're using Grails 3 you'll need to add the plugin as a classpath dependency in buildscript.dependencies. This is done for you in recent Grails 3 versions but in an earlier release you just need to add it yourself:

buildscript {
   ...
   dependencies {        
      ...
      classpath "org.grails.plugins:hibernate:4.3.10.5"
   }
}
like image 98
Burt Beckwith Avatar answered Dec 13 '25 15:12

Burt Beckwith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!