Custom Groovy changes using Grails db-migration plugin (Part II)

Shashank Agrawal
WizPanda
Published in
1 min readMay 10, 2019

Check out Part I.

In my previous post for Custom Groovy Changes In Grails DbMigration, you have seen a various example of writing custom changes for your migrations. Here are some more cases with an example:

Case 1: Changing a field’s data type

Case 2: Custom Id generation to auto increment id generation.

By default, Grails add an id field to domain class which is marked to auto increment. But Grails also provide configuration to generate custom ids (see here). When changing the id generator from custom id generator to an autoincrement field (default of grails), the migration plugin does not generate the changeset and it has to be manually added.

Case 3: Deleting records

Case 4: Adding unique constraint

Case 5: Adding a foreign key

db-migration plugin generates both a changeset for adding a column and an index for a foreign key but MySql creates an index by default for a Foreign Key. Which makes the second changeset generated by DB migration for creating an index useless. You will have to remove the generated code which adds the index on foreign keys for the migration to run error free.

Want to see your amazing idea in action? Or want to join us? Connect us at https://www.wizpanda.com/

--

--

Shashank Agrawal
WizPanda

Serial Entrepreneur | Founder / CTO @ Cooee® — AI-driven Personalised Notifications platform for Better Customer Engagement. bit.ly/shashanka