How to avoid automatic schema modification when working with legacy databases using Grails?

When changing a domain model, Grails automatically modifies the schema (including index / foreign key updates). This is usually normal, but when working with legacy databases, I would like to completely disable all table changes.

How do I prevent Grails from changing the table structure (including indexes and foreign key constraints)?

Here's how I set up the display now:

class ClassName { String string1 String string2 AnotherClass anotherClass static mapping = { version(false) table("legacy_table") string1(column: "some_legacy_field_1") string2(column: "some_legacy_field_2") anotherClass(column: "another_class_id", nullable: true, ignoreNotFound: true) } } 
+4
source share
2 answers

dataSource dataSource has a dbCreate property that can be set to validate to verify that the schema matches the domain model without changing it in any way.

More details here: http://grails.org/doc/latest/guide/3.%20Configuration.html#3.3%20The%20DataSource

+9
source

As mentioned earlier, the dbCreate property is the one you use to specify how the database will change each time changes are made to domain classes. I would suggest removing this entire property, as Bert suggested, so Hibernate does not control how the database is updated, as this can cause certain conflicts depending on the changes you make to the domain classes.

How can I manage database changes in our project using database migration, I recommend using Liquibase , there is a plugin for Grails that works great, it is easy to use and provides great flexibility.

+2
source

Source: https://habr.com/ru/post/1333860/


All Articles