Alan McCloud
Alan McCloud

Reputation: 641

Database migrations in Grails

Suppose I have a database containing 3 tables in a grails application: User Activity Friend

User table table has one to many relation to Activity and Friend tables so in User table I have:

static hasMany = [activies: Activity, friends: Friend]

and in Friend and Activity I have:

static belongsTo User.

Application is deployed and lets says thousands of customers have registered. Now changes are made in the database: Table Activity is dropped. A table Journal is created which is on the many sides of the User table. The User table has a new column added and this column cannot be null. An old column in Friend table is deleted that was also defined as not null.

So given above scenario and assume using MySQL what needs to be done to make above changes without deleting existing customers data and safely add the new table to existing customers?

Ruby on Rails comes with ActiveRecord for database migrations. Does Grails comes with something like this out of the box?

Currently in development when I run my grails application after adding a new not null column to a table, I get column cannot be null exception thrown unless I delete that table in the database before running grails application which would recreate the table if not exists. Obviously once the application is deployed I will not have the luxury to delete the table.

Upvotes: 2

Views: 361

Answers (1)

Kaleb Brasee
Kaleb Brasee

Reputation: 51945

Unfortunately, the current version of Grails doesn't come with database migration. However, there is a plugin for Liquibase which makes migrations possible.

The next version of Grails (1.4, planned for Q1 2011) will supposedly contain a built-in migration tool, which I am very much looking forward to.

Note: I haven't used the Liquibase plugin, so I don't have any firsthand experience with it. I have seen numerous blog posts describing its use, however, and I'm probably going to use it in my next Grails project if 1.4 isn't out by then.

Upvotes: 2

Related Questions