Grails Database Reverse Engineering Plugin

Posted by: Burt Beckwith on 2010-11-09 11:21:00.0

Support for database migrations and reverse engineering are two related features that we've scheduled for Grails 1.4/2.0 (see the roadmap wiki page for the others). The migration support will be based on Liquibase and there's already a plugin for that so I started looking at reverse engineering first.

Work progressed faster than I expected (thanks to the features of the Hibernate Tools library and all of the time I spent digging into its internals for the App Info plugin) and it didn't depend on any new features in 1.4 (not yet anyway) so I released the plugin yesterday so users can started using it now. Install it the usual way:

grails install-plugin reverse-engineer

and refer to the documentation for configuration options.

I tested this with MySQL and Oracle, and other databases that Hibernate supports should work too. There's a tutorial in the documentation that uses MySQL, and you can use the Chinook database to test with Oracle. I used these settings (in grails-app/conf/Config.groovy) for the Chinook database:

grails.plugin.reveng.packageName = 'com.codeplex.chinookdatabase'
grails.plugin.reveng.defaultSchema = 'CHINOOK'
grails.plugin.reveng.manyToManyBelongsTos = [PLAYLISTTRACK: 'PLAYLIST']

and these datasource settings (in grails-app/conf/DataSource.groovy)

dataSource {
   url = 'jdbc:oracle:thin:@localhost:1521:orcl'
   driverClassName = 'oracle.jdbc.driver.OracleDriver'
   username = 'chinook'
   password = 'p4ssw0rd'
   dialect = org.hibernate.dialect.Oracle10gDialect
}

Try it out and report any issues on the Grails user mailing list or in JIRA under the 'Grails-Reverse-Engineer' component.


One related thing I wanted to point out is that the work to replace HSQLDB with H2 is mostly complete (JIRA issue here). I'm a big fan of H2 and one of its coolest features is its embedded web-based console (which works with any database that has a JDBC driver). This is now enabled by default in the development environment and can be enabled in other environments. Accessing data in your development database will be very convenient in 1.4 - just open http://localhost:8080/appname/dbconsole in a browser (JIRA issue here).

Share


be the first to rate this blog

About Burt Beckwith

Burt Beckwith

Burt Beckwith is a Java and Groovy developer with over ten years of experience in a variety of industries including biotech, travel, e-learning, social networking, and financial services. For the past three years he's been working with Grails and Groovy full-time. Along the way he's created over fifteen Grails plugins and made significant contributions to several others. He was the technical editor for Grails in Action.

More About Burt »

NFJS, the Magazine

2010-11-01 00:00:00.0 Issue Now Available
  • Engineering and Ethics
    by Neal Ford
  • Encryption and the JVM: A Perfect Match for a Necessary Technology
    by Matthew McCullough
  • Language Workbenches
    by Peter Bell
  • Test Doubles with Mockito
    by James Carr
  • On Becoming a Certified Gemologist
    by Raju Gandhi
Learn More »