Skip to content

Instantly share code, notes, and snippets.

@sagrawal31
Last active May 9, 2019 10:43
Show Gist options
  • Save sagrawal31/2b11f4507cc170fd9ead78c2277132e5 to your computer and use it in GitHub Desktop.
Save sagrawal31/2b11f4507cc170fd9ead78c2277132e5 to your computer and use it in GitHub Desktop.
import liquibase.statement.core.UpdateStatement
databaseChangeLog = {
// Some other changeSets
changeSet(author: "Shashank (generated)", id: "1381499382647-13") {
addColumn(tableName: "ufile") {
column(name: "file_group", type: "varchar(255)") {
constraints(nullable: "false")
}
}
}
changeSet(author: 'Shashank Agrawal', id: 'file-uploader-10112013-1') {
grailsChange {
change {
def statements = []
// Example 1: Updating file_group column with some value based on where clause
statements << new UpdateStatement('my_database_name', 'ufile')
.addNewColumnValue('file_group', "customerLogo")
.setWhereClause(" id < 8")
statements << new UpdateStatement('my_database_name', 'ufile')
.addNewColumnValue('file_group', "blogLogo")
.setWhereClause(" id in (13,14)")
statements << new UpdateStatement('my_database_name', 'ufile')
.addNewColumnValue('type', "LOCAL")
statements << new UpdateStatement('my_database_name', 'ufile')
.addNewColumnValue('date_created', new Date())
sqlStatements(statements) // Executing all statements at once
confirm 'Initializing default value' // Optional method call to display message
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment