Created
May 9, 2019 10:43
-
-
Save sagrawal31/41faf9d9892be4eeaa3b66e91d2330d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import liquibase.statement.core.InsertStatement | |
databaseChangeLog = { | |
changeSet(author: "Shashank Agrawal", id: "my-custom-unique-id-for-each-changeSet-11212013-1") { | |
grailsChange { | |
change { | |
def statements = [] | |
// Iterating through each row in table. | |
sql.eachRow('select * from old_table_name') { | |
def insertStatement = new InsertStatement("my_database_name", "new_table_name") | |
.addColumnValue("id", it.id) | |
.addColumnValue("version", 0) | |
.addColumnValue("date_created", it.date_created) | |
.addColumnValue("last_updated", new Date()) | |
.addColumnValue("some_other_field", it.id) | |
.addColumnValue("user_id", 0) | |
statements.add(insertStatement) | |
} | |
sqlStatements(statements) // Executing every statement at one shot | |
confirm 'Adding records to new table' // Optional line. Just for message. | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment