====== LiquiBase Command Line ====== LiquiBase can be run from the command line by running **liquibase [options] [command]** (optionally, replace the liquibase command with java -jar ). The command line migrator works well when you want to do migrations on demand, but don't have Ant or Maven available such as on servers. The command line migrator also gives you more control over the process than the [[Servlet Listener]], [[Ant]], or [[Maven]] do, allowing you to run maintenance commands like outputting SQL and listing/releasing database changelog locks. The command line migrator also allows you to * [[rollback|perform rollback operations and generate rollback scripts]] * [[diff|generate "diff"s]] * [[generating changelogs|generate creation scripts from existing databases]] * [[dbdoc|generate database change documentation]] If you run the command line migrator without any arguments, you will get a help message listing these available parameters: ===== Database Update Commands ===== ^ update | Updates database to current version | ^ updateCount | Applies the next change sets | ^ updateSQL | Writes SQL to update database to current version to STDOUT | ^ updateCountSQL | Writes SQL to apply the next change sets to STDOUT | ===== Database Rollback Commands ===== ^ rollback | Rolls back the database to the state it was in when the tag was applied | ^ rollbackToDate | Rolls back the database to the state it was in at the given date/time | ^ rollbackCount | Rolls back the last change sets | ^ rollbackSQL | Writes SQL to roll back the database to the state it was in when the tag was applied to STDOUT | ^ rollbackToDateSQL | Writes SQL to roll back the database to the state it was in at the given date/time version to STDOUT | ^ rollbackCountSQL | Writes SQL to roll back the last change sets to STDOUT | ^ futureRollbackSQL | Writes SQL to roll back the database to the current state after the changes in the changeslog have been applied | ^ generateChangeLog | generateChangeLog of the database to standard out | ===== Diff Commands ===== ^ diff [diff parameters] | Writes description of differences to standard out | ^ diffChangeLog [diff parameters] | Writes Change Log XML to update the base database to the target database to standard out | ===== Documentation Commands ===== ^ dbDoc | Generates Javadoc-like documentation based on current database and change log | ===== Maintenance Commands ===== ^ tag | 'Tags' the current database state for future rollback | ^ status | Outputs count (list if --verbose) of unrun change sets | ^ validate | Checks the changelog for errors | ^ changelogSync | Mark all changes as executed in the database | ^ changelogSyncSQL | Writes SQL to mark all changes as executed in the database to STDOUT | ^ markNextChangeSetRan | Mark the next change set as executed in the database | ^ listLocks | Lists who currently has locks on the database changelog | ^ releaseLocks | Releases all locks on the database changelog | ^ dropAll | Drops all database objects owned by the user | ===== Required Parameters ===== ^ --changeLogFile= | The changelog file to use | ^ --username= | Database username | ^ --password= | Database password | ^ --url= | Database URL | ^ --driver= | Database driver class name | ===== Optional Parameters ===== ^ --classpath= | Classpath containing migration files and JDBC Driver. | ^ --contexts= | ChangeSet contexts to execute | ^ --defaultSchemaName= | Specifies the default schema to use for managed database objects and for LiquiBase control tables | ^ --databaseClassName= | Specifies a custom [[http://www.liquibase.org/api/liquibase/database/Database.html|Database]] implementation to use | ^ --defaultsFile= | File containing default option values (default: ./liquibase.properties) | ^ --includeSystemClasspath= | Include the system classpath in the LiquiBase classpath (default: true) | ^ --promptForNonLocalDatabase= | Prompt if non-localhost databases (default: false) | ^ --currentDateTimeFunction= | Overrides current date time function used in SQL. Useful for unsupported databases | ^ --logLevel= | Execution log level (finest, finer, fine, info, warning, severe) | ^ --help | Output command line parameter help | ===== Required Diff Parameters ===== ^ --baseUsername= | Base Database username | ^ --basePassword= | Base Database password | ^ --baseUrl= | Base Database URL | ===== Optional Diff Parameters ===== ^ --baseDriver= | Base Database driver class name | ===== Change Log Properties ===== ^ -D= | Pass a name/value pair for [[changelog parameters|substitution of ${} blocks]] in the change log(s) | ===== Using a liquibase.properties file ===== If you do not want to always specify options on the command line, you can create a properties file that contains default values. By default, LiquiBase will look for a file called "liquibase.properties" in the current working directory, but you can specify an alternate location with the --defaultsFile flag. If you have specify an option in a properties file and specify the same option on the command line, the value on the command line will override the properties file value. ===== Examples ===== ==== Standard Migrator Run ==== java -jar liquibase.jar \ --driver=oracle.jdbc.OracleDriver \ --classpath=\path\to\classes:jdbcdriver.jar \ --changeLogFile=com/example/db.changelog.xml \ --url="jdbc:oracle:thin:@localhost:1521:oracle" \ --username=scott \ --password=tiger \ update ==== Run Migrator pulling changelogs from a .WAR file ==== java -jar liquibase.jar \ --driver=oracle.jdbc.OracleDriver \ --classpath=website.war \ --changeLogFile=com/example/db.changelog.xml \ --url=jdbc:oracle:thin:@localhost:1521:oracle \ --username=scott \ --password=tiger \ update ==== Run Migrator pulling changelogs from an .EAR file ==== java -jar liquibase.jar \ --driver=oracle.jdbc.OracleDriver \ --classpath=application.ear \ --changeLogFile=com/example/db.changelog.xml \ --url=jdbc:oracle:thin:@localhost:1521:oracle \ --username=scott \ --password=tiger ==== Don't execute changesets, save SQL to /tmp/script.sql ==== java -jar liquibase.jar \ --driver=oracle.jdbc.OracleDriver \ --classpath=jdbcdriver.jar \ --url=jdbc:oracle:thin:@localhost:1521:oracle \ --username=scott \ --password=tiger \ updateSQL > /tmp/script.sql ==== List locks on the database change log ==== java -jar liquibase.jar \ --driver=oracle.jdbc.OracleDriver \ --classpath=jdbcdriver.jar \ --url=jdbc:oracle:thin:@localhost:1521:oracle \ --username=scott \ --password=tiger \ listLocks ==== Runs LiquiBase using defaults from ./liquibase.properties ==== java -jar liquibase.jar update #liquibase.properties driver: oracle.jdbc.OracleDriver classpath: jdbcdriver.jar url: jdbc:oracle:thin:@localhost:1521:oracle username: scott password: tiger