我尝试运行“dbm-db-doc”脚本。似乎脚本无法正常工作,因为它已在已执行的更改日志上失败。这是改变:
<script src="https://code.createjs.com/easeljs-0.8.1.min.js"></script>
<canvas id="canvas" width=100 height=100 style="background-color:whitesmoke"></canvas>
在数据库中,此更改日志已标记为“已执行”
但是在运行脚本时,似乎脚本想要执行该更改日志并因为“product.prepares_for_exam_id”列已被删除而失败。
完整错误:
changeSet(author: "Bernardo (generated)", id: "1436991688243-1") {
addColumn(tableName: "prepares_for_exam") {
column(name: "exam_id", type: "bigint")
}
grailsChange {
change {
sql.execute("UPDATE prepares_for_exam JOIN product ON prepares_for_exam.id = product.prepares_for_exam_id SET prepares_for_exam.exam_id = product.id")
}
rollback {
}
}
addNotNullConstraint(columnDataType: "bigint", tableName: "prepares_for_exam", columnName: "exam_id")
}
changeSet(author: "Bernardo (generated)", id: "1436991688243-32") {
dropColumn(columnName: "prepares_for_exam_id", tableName: "product")
}
所以我的问题是:
“dbm-db-doc”-script中是否有错误或者我是否因为变更集搞砸了什么?
答案 0 :(得分:2)
我正在回答我自己的问题,因为我发现了溶剂:
似乎迁移插件每次都在执行“grailsChange”部分,虽然changeSet已经执行了(我不知道为什么......答案欢迎!)
sollution不使用“grailsChange”并改为使用普通的“sql”命令。这是溶剂:
changeSet(author: "Bernardo (generated)", id: "1436991688243-1") {
addColumn(tableName: "prepares_for_exam") {
column(name: "exam_id", type: "bigint")
}
sql(""" UPDATE prepares_for_exam JOIN product ON prepares_for_exam.id = product.prepares_for_exam_id SET prepares_for_exam.exam_id = product.id """ )
addNotNullConstraint(columnDataType: "bigint", tableName: "prepares_for_exam", columnName: "exam_id")
}