Reputation: 1892
I'm new to Jhipster, I have created a monolithic application and I would like to know how could I automatically create entity in my H2 database when my application start in dev ?
I've seen some csv file in /resources/config/liquibase that seems to create the users and the authorities but I don't know how to create other entities with it
Upvotes: 2
Views: 4705
Reputation: 840
What worked for me:
Edit the "added_entity" xml in your config/liquidbase/changelog (example:20180606131920_added_entity_Product.xml) and add after the createTable tag:
<loadData encoding="UTF-8"
file="config/liquibase/product.csv"
separator=";"
tableName="product">
</loadData>
and of cource create a product.csv at the specified location
Upvotes: 0
Reputation: 830
You can create a new Liquibase ChangeSet that uses the ext:LoadData element. Within this element you need to specify each column you want to populate.
<changeSet author="Joe Bloggs" id="42">
<ext:loadData identityInsertEnabled="true" commentLineStartsWith="#"
encoding="UTF-8"
file="config/liquibase/changelog/data/foo.csv"
quotchar="""
separator=","
tableName="FOO">
<column name="bar" type="STRING"/>
<column name="baz" type="STRING"/>
</ext:loadData>
</changeSet>
Then in your foo.csv file you can add your values (the first row is headers, subsequent rows are the data):
"bar","baz"
"bar1","baz1"
"bar2","baz2"
"bar3","baz3"
Upvotes: 6