I’d like to use the Grails feature for creating/updating database tables on a limited basis. Specifically, I’d like Grails to manage some tables, but not all.
Is there a way to limit the tables managed by Grails or is it an all or nothing proposition?
In general it’s all or nothing since Grails uses Hibernate’s HBM2DDL functionality. But you can intercept the process using a custom configuration subclass. Here’s an example that extends GrailsAnnotationConfiguration and overrides all three SQL generation methods:
You don’t need to override all three, e.g. you could let creates go through but remove updates.
This gets registered in grails-app/conf/DataSource.groovy:
Note that the class has to be written in Java because of an issue with private methods in the base class clashing with methods that Groovy adds to all groovy classes.