Question

I am trying to achieve the following:

  1. we have a mysql DB where we don't want to use foreign keys in the DB level and use MyISAM engine in most of our tables for performance reasons.

  2. we would like to be able to create a "skeleton" of the DB with foreign keys in order to be able to generate propel or jooq files by reverse engineering the DB.

I am trying to use context="fk" for things that I only need for the 2nd point. Here's my changelog.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
    http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
    <changeSet author="gavriel" id="1398956739320-1">
        <createTable tableName="A">
            <column autoIncrement="true" name="Id" type="INT(10)">
                <constraints primaryKey="true"/>
            </column>
        </createTable>
    <modifySql dbms="mysql">
        <append value=" Engine MyISAM"/>
    </modifySql>
    </changeSet>
    <changeSet author="gavriel" id="1398956739320-4">
        <createTable tableName="B">
            <column autoIncrement="true" name="Id" type="INT(10)">
                <constraints primaryKey="true"/>
            </column>
            <column name="AId" type="INT(10)">
                <constraints nullable="false"/>
            </column>
        </createTable>
    <modifySql dbms="mysql" context="!fk">
        <append value=" Engine MyISAM"/>
    </modifySql>
    <modifySql dbms="mysql" context="fk">
        <append value=" Engine InnoDB"/>
    </modifySql>
    </changeSet>
</databaseChangeLog>

When I run

liquibase --contexts=fk updateSQL

then I see (as expected) that table B has 'Engine InnoDB':

CREATE TABLE innovid_studio_jooq.B (Id INT(10) AUTO_INCREMENT NOT NULL, AId INT(10) NOT NULL, CONSTRAINT PK_B PRIMARY KEY (Id)) Engine InnoDB;

However when I run liquibase without context or with any random (non existant) context, then neither 'Engine MyISAM' nor 'Engine InnoDB' is appended to the sql:

CREATE TABLE innovid_studio_jooq.B (Id INT(10) AUTO_INCREMENT NOT NULL, AId INT(10) NOT NULL, CONSTRAINT PK_B PRIMARY KEY (Id));

Why? Shouldn't 'Engine MyISAM' be appended because it's context is "!fk"?

Was it helpful?

Solution

The logical operators for contexts (i.e. the context="!fk") are only available in the 3.2 beta releases (which you would have to build yourself from source), as far as I know. The documentation has gotten a little bit ahead of the code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top