How do I manage an offline database?
If you cannot run Liquibase directly against a database, you can still ensure your database is kept up to date with the commands below.
Running in offline mode only supportsupdate-sql
,rollback-sql
,tag
, andtag-exists
. It does not support directupdate
,diff
, or preconditions, as there is nothing to actually update or state to check.
update-sql
The most common way to update offline databases is to use the update-sql
functionality against a backup or test database.
The update-sql
command reads a database's DATABASECHANGELOG table and outputs the SQL that would run as part of the upgrade. This SQL includes inserts into the DATABASECHANGELOG table and can be ran against any database to both upgrade it and keep its history correct.
It is important that the database you generate the SQL from is the same as the database(s) you plan to run the SQL against.
Unless you have preconditions in your changelog file, the update-sql
process only reads the DATABASECHANGELOG table to determine what changesets to run. Therefore if, for example, you have a production database that you cannot run Liquibase against directly and it may be different than your test databases, you can copy or restore just the DATABASECHANGELOG table from the production database into a database you can run update-sql
against. Then run the generated SQL against the actual production database.
An offline database is connected by using a URL syntax of offline:DATABASE_TYPE?param1=value1&aparam2=value2
.
Available parameters
Attribute | Description |
| Specify the file acting as the DATABASECHANGELOG table. Defaults to |
| Specify the database version to ensure generated SQL matches target database version. Example: 5.4.2 or 12.1.0.3 |
| Specify "product name" seen by the JDBC driver. |
| Specify the connection catalog |
| Specify if the database is case sensitive or not |
| If set to |
Examples
offline:oracle
offline:mssql?changelog-file=/src/changelog.csv
offline:mysql?version=5.4.21&changelog-file=/src/changelog.csv