2015-01-08 35 views
3

我的环境:liquibase不产生无符号列

  • 的java:1.8.0_20,64位
  • liquibase:3.3.1
  • MySQL的:34年5月5日
  • MySQL的连接器:mysql-连接器的Java-5.1.34-bin.jar
  • MySQL驱动:com.mysql.jdbc.Driver
  • MySQL连接字符串:JDBC:MySQL的://本地主机/ MY_DB
  • MySQL用户:根用户
  • 操作系统:Windows 7 64

数据库更改日志XML

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" 
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd"> 

<changeSet author="jbenton" id="create my_test_tbl table"> 
    <sql> SET storage_engine=MYISAM; </sql> 
    <createTable tableName="my_test_tbl"> 
     <column autoIncrement="true" name="my_test_tbl_id" type="INT UNSIGNED"> 
      <constraints primaryKey="true"/> 
     </column> 
     <column defaultValueNumeric="0" name="col_smallint" type="SMALLINT"> 
      <constraints nullable="false"/> 
     </column> 
     <column defaultValueNumeric="0" name="col_smallint_unsigned" type="SMALLINT UNSIGNED"/> 
     <column defaultValueNumeric="0" name="col_smallint_unsigned_not_null" type="SMALLINT UNSIGNED"> 
      <constraints nullable="false"/> 
     </column> 
    </createTable> 
</changeSet> 
</databaseChangeLog> 

使用updateSql命令,我看到以下SQL产生

CREATE TABLE my_db.my_test_tbl (
    my_test_tbl_id INT AUTO_INCREMENT NOT NULL, 
    col_smallint SMALLINT DEFAULT 0 NOT NULL, 
    col_smallint_unsigned SMALLINT DEFAULT 0 NULL, 
    col_smallint_unsigned_not_null SMALLINT DEFAULT 0 NOT NULL, 
    CONSTRAINT PK_MY_TEST_TBL PRIMARY KEY (my_test_tbl_id)); 

我的目标是列将是SMALLINT UNSIGNED。有什么我做错了吗?

+0

对不起,我真的不明白这里有什么可能是错的。查看源代码,我可以在['SmallIntType.java'](https://github.com/liquibase/liquibase/blob/master/liquibase-core/src/)上看到一个注释'/ always smallint, main/java/liquibase/datatype/core/SmallIntType.java)类。我不监督整个代码,因此不能肯定地说这是否真的表明该类型的其他参数(如“unsigned”)被省略。也许你可以在liquibase-github上提交一个bug /增强? – Jens

+1

我会提交一个错误。我只是想确保没有什么明显的我错过了。我已经看到了几个似乎已经为其他人工作的stackoverflow的例子。请注意,该id是一个int,我将其定义为'int unsigned',并以普通的旧int结尾。在3.3.2版本中,类型为“BIGINT UNSIGNED”的类型为' –

+0

',即使对于其也创建了'BIGINT(20)'未unsigned –

回答

0

我有同样的问题。这似乎是目前liquibase实施中的一个错误,似乎在3.4.0中得到修复(参见https://liquibase.jira.com/browse/CORE-2300)。我试图在3.3.2中实现附于问题(https://github.com/liquibase/liquibase/commit/5bf8fc591477587c3f61c876e91011d0b8a6d362)的提交。这解决了未签名的问题,但创建无符号类型自动增量的列失败。

最后,我使用了版本3.0.7,这似乎是没有这个问题的最后一个。迄今为止工作完美无瑕。

1

我实施了CORE-2300 Unsigned Int/Bigint cannot be created修复了这个问题。它已被合并到主分支。如果你可以使用基于master的-SNAPSHOT版本,那么你可以在3.4.0发布之前得到修复,我怀疑这个修复会在未来几个月内发布。

如果你使用的是Maven:

<dependency> 
    <groupId>org.liquibase</groupId> 
    <artifactId>liquibase-core</artifactId> 
    <version>3.4.0-SNAPSHOT</version> 
</dependency> 

还是从构建服务器下载:

https://liquibase.jira.com/builds/browse/CORE-LB-90/artifact

liquibase-3.4.0-SNAPSHOT-bin.zip

或者,如果你想使用3.3.x你可以创建你自己的3.3.4-SNAPSHOT

$ git clone https://github.com/liquibase/liquibase.git 
$ cd liquibase 
$ git checkout 3.3.x 
$ git cherry-pick 5bf8fc591477587c3f61c876e91011d0b8a6d362 
$ git status 
$ # resolve the merge conflicts 
$ vi liquibase-core/src/main/java/liquibase/datatype/core/*IntType.java 
$ git add '*.java' 
$ git cherry-pick --continue 
$ mvn clean verify 

然后更新您的POM:

<dependency> 
    <groupId>org.liquibase</groupId> 
    <artifactId>liquibase-core</artifactId> 
    <version>3.3.4-SNAPSHOT</version> 
</dependency> 

或使用所产生的分配zip文件。