我正在尝试使用此站点作为参考来熟悉Grails 数据库迁移插件。尝试添加具有非空约束的属性时遇到问题。我以与站点上显示的相同方式对脚本进行建模(添加列,为现有记录设置默认值,然后向列添加不可为空的约束):
databaseChangeLog = {
changeSet(author: "Ryan (generated)", id: "1340893788251-1") {
addColumn(tableName: "game") {
column(name: "genre", type: "varchar(255)")
}
grailsChange{
change{
sql.executeUpdate("UPDATE game SET genre = 'Other'")
}
}
addNotNullConstraint(tableName: "game", columnName: "genre")
}
}
当我尝试更新我的数据库时,它会默默地失败。因此,我将这三个更改拆分为三个不同的 groovy 脚本来追踪问题。
第一个文件(添加列)工作正常:
databaseChangeLog = {
changeSet(author: "Ryan (generated)", id: "1340893788251-1") {
addColumn(tableName: "game") {
column(name: "genre", type: "varchar(255)")
}
}
}
第二个文件(为现有记录分配默认值)工作正常:
databaseChangeLog = {
changeSet(author: "Ryan (generated)", id: "defaultValue") {
grailsChange{
change{
sql.executeUpdate("UPDATE game SET genre = 'Other'")
}
}
}
}
第三个文件(添加非空约束)静默失败:
databaseChangeLog = {
changeSet(author: "Ryan (generated)", id: "notNull") {
addNotNullConstraint(tableName: "game", columnName: "genre")
}
}
The log file only shows this in relation to the plugin:
2012-06-28 10:17:11,694 [main] INFO liquibase - Successfully acquired change log lock
2012-06-28 10:17:11,972 [main] INFO liquibase - Reading fromDATABASECHANGELOG
2012-06-28 10:17:11,980 [main] INFO liquibase - Reading fromDATABASECHANGELOG
2012-06-28 10:17:12,009 [main] INFO liquibase - Successfully released change log lock
If I check the databasechangelog table I can see that the script has not been executed. The console gave me this:
| Starting dbm-update for database root @ jdbc:mysql://localhost/migration
but there is no
| Finished dbm-update
like I see with the successful updates.
NOTE: It may be important to note that the site I am using as a reference is using version 1.0, I am using version 1.1. I am having a hard time finding tutorials or examples of this plugin at all, harder still to find info for the most recent version (released a month ago).
Can anyone pinpoint where I'm going wrong with the not null constraint?