1
votes

I have a springboot project with liquibase installed and some changeSet. In developpement to be simpler I used loadData to load data from my csv files. Now I'm deploying it in production but I would like to create the table without the data.

<changeSet id="00000000000001" author="jhipster">
    <createTable tableName="jhi_user">
        <column name="id" type="bigint" autoIncrement="${autoIncrement}">
            <constraints primaryKey="true" nullable="false"/>
        </column>
        [...]
    <loadData encoding="UTF-8"
              file="config/liquibase/users.csv"
              separator=";"
              tableName="jhi_user">
        <column name="activated" type="boolean"/>
        <column name="created_date" type="timestamp"/>
    </loadData>
</changeSet>

Is it possible to load data depending on the context ?

1

1 Answers

2
votes

In jhipster liquibase configuration, there are PROD and DEV contexts.

Use

<changeSet id="00000000000001" author="jhipster" context="DEV" >

To only play this changeset in dev You can use multiple changeSet to choose your loaddata context. The standard generated unit tests use PROD to prepare the database.

for example in your file : 22220000000000 will be only in DEV, 22210000000000 will be in DEV + PROD

<changeSet id="22220000000000" author="Korrident" context="DEV">
    <loadData encoding="UTF-8"
              file="config/liquibase/DEV_boards.csv"
              separator=";"
              tableName="board">
    </loadData>
    <loadData encoding="UTF-8"
              file="config/liquibase/DEV_game_managements.csv"
              separator=";"
              tableName="game_management">
    </loadData>
</changeSet>


<changeSet id="22210000000000" author="Korrident" >
    <loadData encoding="UTF-8"
              file="config/liquibase/DEV_PROD_players.csv"
              separator=";"
              tableName="player">
    </loadData>
</changeSet>

Official liquibase doc : https://www.liquibase.org/documentation/contexts.html