Reputation: 1902
I have data.sql file in my spring boot project, which contains initial data for the db. When the system starts for the first time, those records should be generated in the db, afterwards it should be ignored if that is already in db. That was my goal, and so I included liqubase in my project. But, it is not behaving as I expected, spring tries to execute the sql on every startup and fails if the data is present. Can this be done with liqubase and if yes, what config should I look for specifically?
Upvotes: 1
Views: 57
Reputation: 2984
data.sql
will run every time, no matter you have liquibase or not. You can do 2 things here.
Move your sql inserts from data.sql
to liquibase
changeset upgrade. How?
Write your sql inserts in data.sql
in such way that they ignore if entry is already present.
like if you have:-
INSERT INTO users (id, name) VALUES (1005201,'dave')
you can change it to :-
INSERT IGNORE INTO users (id, name) VALUES (1005201,'dave')
Upvotes: 3