1

Im wanting to create an auto incrementing number sequence for the primary id of the tables Im working with on Oracle.

With Liquibase I can see that autoincrement for the column is not supported for Oracle in Add Auto Increment. So how can I go about adding a sequencing for a particular table.

Below is what I currently have.

<databaseChangeLog
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">

    <property name="now" value="now()" dbms="mysql,h2"/>
    <property name="now" value="current_timestamp" dbms="postgresql"/>
    <property name="now" value="sysdate" dbms="oracle"/>
    <property name="now" value="GETDATE()" dbms="mssql"/>

    <property name="autoIncrement" value="true" dbms="mysql,h2,postgresql,mssql"/>

    <property name="floatType" value="float4" dbms="postgresql, h2"/>
    <property name="floatType" value="float" dbms="mysql, oracle, mssql"/>

    <changeSet id="20170122022905-1" author="test">
        <createTable tableName="certificate_metadata">
            <column name="id" type="bigint" autoIncrement="${autoIncrement}">
                <constraints primaryKey="true" nullable="false"/>
            </column>

            <column name="org_id" type="bigint">
                <constraints unique="true" nullable="false"/>
            </column>

            <column name="certificate_id" type="uuid">
                <constraints nullable="false"/>
            </column>

            <column name="type" type="varchar(30)">
                <constraints nullable="false"/>
            </column>

            <column name="expiry_date" type="timestamp">
                <constraints nullable="true"/>
            </column>

            <column name="created_date" type="timestamp">
                <constraints nullable="true"/>
            </column>

            <column name="updated_date" type="timestamp">
                <constraints nullable="true"/>
            </column>
        </createTable>
        <dropDefaultValue tableName="certificate_metadata" columnName="created_date" columnDataType="datetime"/>
        <dropDefaultValue tableName="certificate_metadata" columnName="updated_date" columnDataType="datetime"/>
    </changeSet>
</databaseChangeLog>
nixgadget
  • 6,983
  • 16
  • 70
  • 103

1 Answers1

4

Oracle 12c does support Auto Increment. So you either need to have Liquibase provide support for it, or just create the table(s) "natively", perhaps using a script in sqlplus

BobC
  • 4,208
  • 1
  • 12
  • 15
  • Liqubase supports this since 3.4.0: https://stackoverflow.com/questions/57151627/is-auto-increment-supported-in-oracle-using-liquibase/64206737#64206737 – Vadzim Oct 05 '20 at 10:20