Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create partitioned table with liquibase

Can I create partitioned table like:

CREATE TABLE person(
    id INT NOT NULL,
    NAME VARCHAR(30),
    borned TIMESTAMP)
PARTITION BY RANGE (UNIX_TIMESTAMP(borned)) (
    PARTITION p0 VALUES LESS THAN (UNIX_TIMESTAMP('2000-01-01 00:00:00')),
    PARTITION p1 VALUES LESS THAN (MAXVALUE));

using liquibase tags? I mean not with custom <sql> but with <createTable>

like image 214
Vova Yatsyk Avatar asked Jan 07 '23 09:01

Vova Yatsyk


1 Answers

Since 1.9: You can use modifySql to append to the createTable output

<changeSet author="StackOverflow" id="C0FE77AA-5517-11E7-8CAD-224C16886A7C">
    <createTable tableName="test">
        <column name="id" type="INT">
            <constraints nullable="false"/>
        </column>
        <column name="NAME" type="VARCHAR(30)"/>
        <column name="borned" type="TIMESTAMP"/>
    </createTable>
    <modifySql dbms="postgresql">
        <append value=" PARTITION BY RANGE (UNIX_TIMESTAMP(borned)) (
PARTITION p0 VALUES LESS THAN (UNIX_TIMESTAMP('2000-01-01 00:00:00')),
PARTITION p1 VALUES LESS THAN (MAXVALUE))"/>
    </modifySql>
</changeSet>

Liquibase outputs the following SQL (according to the updateSql goal):

CREATE TABLE db.test (id INT NOT NULL, NAME VARCHAR(30) NULL, borned timestamp NULL) PARTITION BY RANGE (UNIX_TIMESTAMP(borned)) (     PARTITION p0 VALUES LESS THAN (UNIX_TIMESTAMP('2000-01-01 00:00:00')),     PARTITION p1 VALUES LESS THAN (MAXVALUE));
like image 134
Birchlabs Avatar answered Feb 27 '23 06:02

Birchlabs