I am using Spring-Boot 1.2.1, and Liquibase to create both H2 (testing) and PostgreSQL (QA & Production) databases. I have a couple of tables that I want to seed when the db is created. However, despite trying both dataLoad and sqlFile, nothing is getting inserted. My sql file is just a bunch of insert statements such as:
INSERT INTO state (Name, Code) VALUES('Alabama','AL');
INSERT INTO state (Name, Code) VALUES('Alaska','AK');
Here is my relevant changelog-master.xml:
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-3.3.xsd"
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
...
<changeSet id="3" author="me">
<createTable tableName="STATE">
<column name="code" type="VARCHAR(10)">
<constraints primaryKey="true"/>
</column>
<column name="name" type="VARCHAR(100)"/>
</createTable>
<sqlFile dbms="h2, PostgreSQL"
encoding="utf8"
endDelimiter="\nGO"
path="src/main/resources/db/changelog/data/states.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="true"/>
</changeSet>
Here is my project structure:
When I startup my spring-boot app, I can see that the State table is created, but it has zero rows in it. I also tried taking the out of changeset 3 and using this:
<changeSet id="4" author="me">
<loadData file="data/state.csv" tablename="STATE" schemaName="edentalmanager" relativeToChangelogFile="true">
<column name="name" type="VARCHAR(100)"/>
<column name="code" type="VARCHAR(10)"/>
</loadData>
</changeSet>
The csv file is basically:
Alabama,AL
Alaska,AK
...
I dont' see any messages in the console logs that Liquibase is trying to create or insert the data into the table. Nor do I get any exceptions or error messages.
UPDATE: If I copy off the state.sql as /resources/data.sql then spring-boot picks up the file and executes the sql just fine. Unfortunately, this means every time I startup, it will try and insert those values again, causing startup exceptions (duplicate key violations) But, rather than rely on a single file, I would prefer Liquibase to execute them as part of the changeset as data needs change.
src/main/resources/db/changelog/data/states.sql
can't work when you pack your application to JAR/WAR. ideally if liquibase could read files from classpath but can't find it in documentatino – sodik