liquibase不会创建无符号列

时间:2015-01-08 22:38:57

标签: mysql liquibase

我的环境:

  • java:1.8.0_20,64位
  • liquibase:3.3.1
  • mysql:5.5.34
  • mysql连接器:mysql-connector-java-5.1.34-bin.jar
  • mysql驱动程序:com.mysql.jdbc.Driver
  • mysql连接字符串:jdbc:mysql:// localhost / my_db
  • mysql用户:root用户
  • os: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。有什么我做错了吗?

2 个答案:

答案 0 :(得分: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文件。

答案 1 :(得分: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,似乎是没有此问题的最后一个版本。到目前为止工作完美无瑕。

相关问题