Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liquibase add comment to table

Tags:

liquibase

I'm currently trying to add comment on tables in liquibase 3.1.1

What I want to do is ALTER TABLE t1 COMMENT = 'New table comment';

I didn't find any help in the documentation of liquibase about this case, there is only help for adding comments on columns.

I am currently thinking of creating a customChange or doing the change by myself with SQL statements but as we are going to migrate from MySQL to Oracle I would like to avoid this solution (or use it in last resort).

Has anyone found another solution for this problem ?

like image 734
Inox Avatar asked Nov 24 '16 09:11

Inox


1 Answers

COMMENT ON TABLE is absolutely helpful in this case. See example I provided below along with some tips and pitfalls about editing tables using liqubase.

Continuing the response above, I'd like to pay attention on tag <preConditions> here. It's critical when dealing with tables to ask liqubase whether the certain table exists at the moment you try to edit one. Here's some example of this behavior:

<changeSet id="your_table_id" author="author_name" dbms="postgresql">
        <preConditions onFail="MARK_RAN">
            <tableExists tableName="table_name" schemaName="schema_name"/>
        </preConditions>
        <sql>
            COMMENT ON TABLE schema_name.table_name is 'YOUR_COMMENT_ON_TABLE';
        </sql>
 </changeSet>

In case dealing with columns (editing, adding, deleting) ALSO consider asking liqubase the similar way of the existing or absence of the specific column(s):

<preConditions onFail="MARK_RAN">
    <not>
         <columnExists tableName="table_name" schemaName="schema_name" 
             columnName="column_name"/>
    </not>
</preConditions>
<sql>
...
</sql>

The example above checks if column NOT present in table and then executes some SQL script.

like image 85
Roman Gorbatenko Avatar answered Nov 07 '22 11:11

Roman Gorbatenko