使用 Liquibase 创建 Oracle 序列

Creating Oracle sequences with Liquibase

我想为我在 Oracle 上工作的 table 的主 ID 创建一个自动递增的数字序列。

使用 Liquibase,我可以看到 Add Auto Increment 中的 Oracle 不支持该列的 autoincrement。那么我该如何为特定的 table.

添加排序呢?

以下是我目前拥有的。

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

Oracle 12c 支持自动递增。所以你要么需要让 Liquibase 为它提供支持,要么只创建 table(s) "natively",也许使用 sqlplus

中的脚本