Jeff Benton
Jeff Benton

Reputation: 146

liquibase is not creating unsigned columns

My Environment:

database change log 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>

Using the updateSql command, I see the following sql being generated

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));

My goal is that the columns would be SMALLINT UNSIGNED. Is there something that I am doing wrong?

Upvotes: 6

Views: 4004

Answers (2)

Mark Chesney
Mark Chesney

Reputation: 1152

I implemented CORE-2300 Unsigned Int / Bigint cannot be created that fixes this issue. It has been merged to the master branch. If you can use a -SNAPSHOT version based on master then you could get the fix before the 3.4.0 release, which I suspect will be in the next few months.

If you're using Maven:

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

Or download it from the build server:

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

liquibase-3.4.0-SNAPSHOT-bin.zip

Or if you want to use 3.3.x you could create your own 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

Then update your POM:

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

or use the resultant distribution zip file.

Upvotes: 1

Jakob Pinggera
Jakob Pinggera

Reputation: 1

I had the same problem. It seems to be a bug in the current implementation of liquibase, which seems to get fixed with 3.4.0 (cf. https://liquibase.jira.com/browse/CORE-2300). I tried to implement the commits attached to the issue (https://github.com/liquibase/liquibase/commit/5bf8fc591477587c3f61c876e91011d0b8a6d362) on 3.3.2. This resolves the unsigned problem, but creating columns with auto increment of the unsigned types failed.

In the end, I used version 3.0.7, which seems to be last one without this issue. Works flawless so far.

Upvotes: 0

Related Questions