The SequenceTable extension allows databases that do not support sequences to natively create "sequence tables". Sequence tables can be used by Hibernate for its SequenceStyleGenerator functionality or used directly through SQL.

Current Version


The current version is available from https://github.com/liquibase/liquibase-sequencetable/wiki 


Legacy Version (Liquibase 2.0)

Purpose

The main purpose of the genericSequence extension is to be able to use Hibernate’s SequenceStyleGenerator as a database-independent way of creating IDs for tables.

For more details please read the according section in the user guide, which might be found at 5.1.5. Enhanced identifier generators

Right now the extension supports

How it works

Depending on the used database the extension checks if sequences are supported or not. In the first case a sequence is used in the other case a table.

Usage

You can use this extension as a child element in your changeSets.

Example:

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

  <changeSet id="create_data_language" author="michael">
    <ext:createGenericSequence sequenceName="SQ_DATA_LANGUAGE" incrementBy="1" startValue="10000"/>

    <createTable tableName="DATA_LANGUAGE" remarks="This table stores the data language definitions.">
      <column name="ID" type="NUMBER(10)">
        <constraints primaryKeyName="PK_DATA_LANGUAGE" primaryKey="true"/>
      </column>
      <column name="ISO_CODE" type="VARCHAR(10)" >
        <constraints nullable="false" unique="true"/>
      </column>
    </createTable>
  </changeSet>
</databaseChangeLog>

XSD:

<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.liquibase.org/xml/ns/dbchangelog-ext"
  xmlns="http://www.liquibase.org/xml/ns/dbchangelog-ext"
  elementFormDefault="qualified">

  <xsd:element name="createGenericSequence">
    <xsd:complexType>
      <xsd:attribute name="schemaName" type="xsd:string"/>
      <xsd:attribute name="sequenceName" type="xsd:string" use="required"/>
      <xsd:attribute name="startValue" type="xsd:integer" default="1"/>
      <xsd:attribute name="minValue" type="xsd:integer"/>
      <xsd:attribute name="maxValue" type="xsd:integer"/>
      <xsd:attribute name="incrementBy" type="xsd:integer" default="1"/>
      <xsd:attribute name="forceTableUse" type="xsd:boolean" default="false"/>
      <xsd:attribute name="tableValueColumnName" type="xsd:string" default="next_val" />
      <xsd:attribute name="tableValueColumnSize" type="xsd:integer" default="10" />
    </xsd:complexType>
  </xsd:element>

  <xsd:element name="dropGenericSequence">
    <xsd:complexType>
      <xsd:attribute name="schemaName" type="xsd:string" />
      <xsd:attribute name="sequenceName" type="xsd:string" use="required"/>
      <xsd:attribute name="forceTableUse" type="xsd:boolean" default="false"/>
    </xsd:complexType>
  </xsd:element>

</xsd:schema>

Files