【问题标题】:liquibase is not creating unsigned columnsliquibase 没有创建无符号列
【发布时间】:2015-03-07 04:46:35
【问题描述】:

我的环境:

  • 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用户
  • 操作系统: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。是不是我做错了什么?

【问题讨论】:

  • 抱歉,我真的不知道这里有什么问题。查看源代码,我可以在 SmallIntType.java 类上看到评论 /always smallint regardless of parameters passed。我不监督整个代码,因此不能确定这是否真的表明该类型的其他参数(如“无符号”)被遗漏了。也许您可以为此在 liquibase-github 上提交错误/增强功能?
  • 我会提交一个错误。我只是想确保我没有遗漏任何明显的东西。我在 stackoverflow 上看到了几个例子,似乎这对其他人有用。请注意,id 是一个 int,我将其定义为“int unsigned”,它最终是一个普通的旧 int。
  • 在 3.3.2 版中 type="BIGINT UNSIGNED" 即使它也只是创建了 BIGINT(20) 而不是未签名
  • 有些人说 UNSIGNED 不是 SQL 标准。所以可能不支持 liquibase。

标签: mysql liquibase


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    我实现了解决此问题的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 文件。

    【讨论】:

      猜你喜欢
      • 2020-09-26
      • 1970-01-01
      • 2017-07-29
      • 1970-01-01
      • 2018-08-09
      • 2014-05-30
      • 2022-11-24
      • 2022-01-13
      • 1970-01-01
      相关资源
      最近更新 更多