I am adding a field using the migrations plugin:
databaseChangeLog = {
changeSet(author: "me", id: "add publish_date") {
addColumn(tableName: "book") {
column(name: "publish_date", type: "timestamp") {
constraints(nullable: "true")
}
}
}
}
I would also like to update publish_date
for some Book
s. One way of doing it is by using sql.execute("UPDATE book SET publish_date = ____ WHERE year = 2012")
but this doesn't seem very database agnostic... and I'd like it to be.
I'm thinking that using Book
domain in the migration would ensure that the migration works for different databases. Can anyone comment if this is sane/possible?
changeSet(author: "me", id: "add publish_date") {
grailsChange {
change {
Book.findAllByYear(2012).each { book ->
book.publishDate = _____
book.save()
}
}
}
}
What are the options if you wanted to keep the migrations database agnostic?