Using Liquibase with Apache Derby

Apache Derby is an open-source relational database implemented entirely in Java and available under the Apache License, Version 2.0.

Note: For more information, see the Apache Derby page.

Supported Versions

  • 10.14
  • 10.15

Note: The supported versions are the versions that were tested with Liquibase Test Harness.

Prerequisites

Before using Liquibase and Apache Derby, ensure you have completed the following:

Driver Information

Apache Derby is based on the Java, JDBC, and SQL standards. To use Liquibase and Apache Derby, you need to have Java and JDBC. For the JDBC driver:

  1. Ensure you downloaded the Derby client JDBC jar driver file. To download it, go to the Apache Derby: Downloads page. You can also find the Apache Derby driver in the derbytools.jar file by going to the Apache Derby Tools Maven repository.
  2. Place the derbytools.jar file in the liquibase/lib directory.

Note: If you put the derbytools.jar file in any other directory, specify the path to it in the liquibase.properties file: classpath:../path_to_drivers/derbytools.jar. For more information, see Creating and configuring a liquibase.properties file.

If you use Maven, you also need to download the Apache Derby driver jar file and put the driver in a location that your Maven build can access. Configure the Maven pom.xml file to use the local copy of the driver jar file. For example:

<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbytools</artifactId>
<version>10.15.2.0</version>
</dependency>

Testing Your Connection

For Liquibase and Apache Derby to work, you need to:

  1. Ensure your Apache Derby database is configured. As an option, you can run the sysinfo command to check the output of Derby system information. For more details, see the Install Software documentation.
  2. Specify the database URL in your liquibase.properties file:
  3. url: jdbc:derby://localhost:1527/MYDATABASE;create=true

    Note: If you created MYDATABASE, use create=false or remove create=true from URL.

    Tip: If you already have a Liquibase Pro key and want to apply it to your project, add the following property to your liquibase.properties file: liquibaseProLicenseKey: <paste license key>.

  1. Create a text file called changelog (.xml, .sql, .json, or .yaml) in your project directory and add a changeset.
  1. Run the status command to see whether the connection is successful. Specify the name of the changelog you created in place of changelog.xml. Also, to run Liquibase commands, you need to specify your username and password in the liquibase.properties file or on the command line. However, the username and password attributes are not required for connections and systems which use alternate means of authentication.
  2. liquibase --username=test --password=test --changeLogFile=changelog.xml status

    Note: Alternatively, you can add the changeLogFile attribute to your liquibase.properties file.

  1. Run your first update with the Liquibase update command, which will make changes to your database. You can also run the updateSQL command if you want to inspect the SQL before running the update command.
  2. liquibase --changeLogFile=changelog.xml updateSQL
    liquibase --changeLogFile=changelog.xml update

After your first update, you will see a new table along with the DATABASECHANGELOG and DATABASECHANGELOGLOCK tables added to the database:

  • DATABASECHANGELOG table. This table keeps a record of all the changesets that were deployed. When you deploy, the changesets in the changelog are compared with the DATABASECHANGELOG tracking table, and only the new changesets that were not found in the DATABASECHANGELOG will be deployed.
  • DATABASECHANGELOGLOCK table. This table is used internally by Liquibase to manage access to the DATABASECHANGELOG table during deployment and ensure only one instance of Liquibase is updating the database at a time, whether that is creating, updating or deleting changes.

Troubleshooting issues on the macOS

If your Derby Server is not running or you are not using the embedded driver, use the following commands on the Mac to start the Derby Server:

export DERBY_HOME=<location_of the unzipped directory_for_derby>

Example: export DERBY_HOME=/Users/myname/Downloads/db-derby-10.15.2.0-bin

export JAVA_HOME=<path_to_your_JRE>

Note: Use the actual installed location of the JRE in place of <path_to_your_JRE> since Apache Derby will expect a bin directory as a subfolder. For example, export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home

java -jar $DERBY_HOME/lib/derbynet.jar start -h 0.0.0.0

Supported Change Types

Change Type Supported
addColumn Supported
addDefaultValue Supported
addForeignKeyConstraint Supported
addLookupTable Not Supported
addNotNullConstraint Supported
addPrimaryKey Supported
addUniqueConstraint Supported
alterSequence Not Supported
createFunction Not Supported
createIndex Supported
createPackage Not Supported
createPackageBody Not Supported
createProcedure Supported
createSequence Supported
createTable Supported
createView Supported
delete Supported
dropColumn Supported
dropDefaultValue Supported
dropForeignKeyConstraint Supported
dropIndex Supported
dropNotNullConstraint Supported
dropPrimaryKey Supported
dropProcedure Supported
dropSequence Supported
dropTable Supported
dropUniqueConstraint Supported
dropView Supported
renameColumn Supported
renameTable Supported
renameView Not Supported
sql Supported

Related Links