`I have already running project and trying to introduce liquibase in middle of project. This is spring boot maven based project.
I am following steps.
1.liquibase.properties
url=jdbc:postgresql://localhost:5432/cc
username=postgres
password=deadline123
driver=org.postgresql.Driver
outputChangeLogFile=src/main/resources/db/changelog/db.changelog-master.yaml
runOnChange=true
referenceUrl=jdbc:postgresql://localhost:5432/cc
referenceUsername=postgres
referencePassword=deadline123
changelogFile=src/main/resources/db/changelog/db.changelog-master.yaml
diffChangeLogFile=src/main/resources/diff.yaml
- Run command to generate changelog for current DB state
mvn liquibase:generateChangeLog - Then run command to sync changelog and create entry in DB
mvn liquibase:changelogSync - Starting my application but it's throwing error relation already exist. I can't figure out why liquibase is executing already executed changeset? I am using liquibase 4.6.3
CodePudding user response:
Liquibase doesn't compare changes against your actual tables, it only keeps track of what changesets have already been executed (it creates another table for that called databasechangelog).
That being said, you have to make sure liquibase executes your changesets with a precondition that says 'if anything fails, mark it as executed'. It can be achieved like so:
<preconditions onFail="MARK_RAN">
<not>
<tableExists tableName="person"/>
</not>
</preconditions>
This example as well as much more information could be found on https://www.liquibase.com/blog/adding-liquibase-on-an-existing-project
CodePudding user response:
Issue was with file path src/main/resources/db/changelog/db.changelog-master.yaml
liquibase:changelogSync adds file path as above in log sync and liquibae on start actually takes classpath classpath:/db/changelog/db.changelog-master.yaml
