Parameters can be passed via commandline or using properties file
Important
Using the CLI to enter command-line arguments will always override the properties stored in the Liquibase properties file.
liquibase <command name> --helpurl=jdbc:postgresql://localhost:5432/DEVDB
username=<name>
password=<password>
changelog-file=yourchangelog.xml
log-level=FINE
| Level | Description |
|---|---|
| SEVERE (highest level) | Serious failures that may prevent program execution. |
| WARNING | Potential problems for program execution. |
| INFO | Informational messages. Complete list of the command operation. |
| FINE (lowest level) | Tracing information on the program execution and minor failures. Helpful in resolving errors. |
| OFF (default) | Hides all log messages. |
liquibase --changelog-file=yourchangelog.xml update-sqlWhen running the update command, Liquibase reads the changesets in the changelog file in sequential order and then compares the unique identifiers of id, author, and path to the changelog to the values stored in the DATABASECHANGELOG table. If the unique identifiers do not exist, Liquibase will apply the changeset to the database.
liquibase --changelog-file=yourchangelog.xml updateThere are a few variations of this command. some notable ones are
- update-count
- update-to-tag
To verify the sql generated by liquibase add sql to the command <command>-sql like
- update-sql
- update-count-sql
- update-to-tag-sql
The history command will list the time the database was updated and the list of executed changesets with their associated deploymentId. The output can also be used to determine which Liquibase commands need to run.
liquibase history
liquibase --outputFile=history.txt historyThe status command is usually run with the --verbose command attribute which lists undeployed changesets along with the path to the changeset, author, and id.
liquibase status --verboseThe tag command can be run to mark the last row inserted in the DATABASECHANGELOG table
liquibase tag release-1.0.1To add tag to the changelog refer tagDatabase
When changes are rolled back, the row associated with that change is deleted from the DATABASECHANGELOG table.
liquibase rollback-to-date <date in YYYY-MM-DD or YYYY-MM-DD'T'HH:MM:SS>
# To validate sql
liquibase rollback-to-date-sql 2025-01-25liquibase rollback-count 5
# To validate sql
liquibase rollback-count-sql 5liquibase rollback <tagname>To add a custom rollback refer Custom rollback statements
ex
<changeSet author="liquibaseuser" id="2">
<dropTable tableName="person"/>
<rollback>
<createTable catalogName="department"
remarks="A String"
schemaName="public"
tableName="person">
<column name="address" type="varchar(255)"/>
</createTable>
</rollback>
</changeSet>Refer update-testing-rollback command
see changes made to DB. They need extra parameters referenceUsername, referencePassword, referenceURL
you can also filter using --diffTypes=<catalogs,tables,functions,views,columns,indexes,foreignkeys>
compare 2 databases or database to snapshot
compare 2 databases and generate changelog file
liquibase --changelog-file=file_name.sql --username=<USERNAME> --password=<PASSWORD>
--referenceUsername=<USERNAME> --referencePassword=<PASSWORD> diff-changelog- Snapshots are great for keeping a record of the current database state but snapshots cannot be used to repopulate a database.
- To record a database state in a format that will allow for re-creating that state, use the generate-changelog command.
Used to capture the current state of the database.
liquibase --output-file=yourSnapshot.json snapshot --snapshotFormat=jsonUsed to create a changelog file that describes how to re-create the current state of the database.
liquibase --changelog-file=newgeneratedchangelog.xml generate-changelog