Grails数据库迁移属性是不可知的 [英] Grails database-migration with property to be db agnostic

查看:159
本文介绍了Grails数据库迁移属性是不可知的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Grails-database迁移插件中有没有一种方法可以定义迁移文件中的属性,以便能够定义数据库不可知的迁移,就像Liquibase中可能的那样?



我试过:

  databaseChangeLog = {
property([name:boolean.type,value: (1),dbms:mysql])
property([name:boolean.type,value:number(1,0),dbms:oracle])
...
}

在colum定义中使用它:

  changeSet(author:me,id:121112341-1){
createTable(tableName:test_table){
...
列(名称:my_column,类型:$ {boolean.type})
...
}
}

但这不起作用...

解决在Groovy文件中$ {boolean.type}是一个GString,所以Groovy试图解析属性变量布尔值的类型。您需要使用单引号,这样Groovy才会将字符串保留下来,并让Liquibase执行特定于dbms的替换操作:

  my_column,输入:'$ {boolean.type}')


Is there a way in the Grails-database migration plugin to define properties in migration files to be able to define database agnostic migration, like it is possible in Liquibase?

I tried with:

databaseChangeLog = {
property([name:"boolean.type", value:"bit(1)",dbms:"mysql" ])
property([name:"boolean.type", value:"number(1,0)", dbms:"oracle"])
...
} 

an using it in the colum definition:

changeSet(author: "me", id: "121112341-1") {
createTable(tableName: "test_table") {
...
column(name: "my_column", type: "${boolean.type}")
...
}
}

but that does not work...

解决方案

In a Groovy file "${boolean.type}" is a GString, so Groovy is attempting to resolve the property type of the variable boolean. You need to use single quotes so Groovy leaves the string alone and lets Liquibase do the dbms-specific replacement:

column(name: "my_column", type: '${boolean.type}')

这篇关于Grails数据库迁移属性是不可知的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆