我将如何为grails数据库迁移插件编写一个changelog.groovy,如果一系列ID尚不存在行,该插件会将行插入表中?例如。
cool_stuff表具有
id | some_other_id |
cool_stuff表中填充了数据。给定一系列cool_stuff id,即1-2000,我想:
最佳答案
所以,你想喜欢吗?
table of "cool_stuff"
FROM:
id | some_other_id
----|---------------
1 | 2
2 | 1
3 | 2
4 | 1
TO:
id | some_other_id
----|---------------
1 | 2
2 | 1
3 | 2
4 | 1
2 | 2
4 | 2
这是正确的吗??
我想跟随我。
databaseChangeLog = {
changeSet(author: "koji", id: "123456789") {
grailsChange {
change {
CoolStuff.list().findAll {
it.someOtherId != 2
}.each{
// save new instance
new CoolStuf(id: it.id, someOtherId:2).save(flush:true)
}
}
}
}
}