Using Liquibase with Sybase Enterprise

The purpose of this document is to guide you through the process of creating a new Liquibase project with Sybase Enterprise. In this tutorial, you will learn how to generate an example project and follow the instructions to apply concepts associated with creating new Liquibase projects with Sybase Enterprise.

Prerequisites

Before using Liquibase with your database, ensure you have:

  • Downloaded the JDBC jar driver file. JTDS is the recommended driver. Place your jar file in the liquibase/lib install directory or in any other known directory so you can locate it easily.
  • Selected the ASE 12.0+ version.
  • Set theselect into database option.

Note: Take into account that rollbacks will not work on failures as Sybase does not support transactions for DDL. Additionally, foreign keys cannot be dropped, which can break the rollback or drop-all.

Tutorial

To create a Liquibase project with Sybase Enterprise, perform the following steps:

  1. Add the following properties to the Liquibase properties file:
changelog-file: dbchangelog.xml
url: jdbc:jtds:sybase://localhost:5432/MYDATABASE
username: user1
password: password
driver: net.sourceforge.jtds.jdbc.Driver
classpath: ../../Liquibase/lib/jtds-1.3.1.jar

Note: Specifying your password, take into account that Liquibase supports only the following special characters: ~ # $ % * ( ) - _ + [ ] { } . ?. Unsupported special characters are as follows: @ & / : < > " ' ` | ^ ! = , \ <spaces>.

If you placed the jar file in the liquibase/lib install directory, do not specify the classpath property in the Liquibase properties file. Otherwise, specify the driver path as shown in the preceding example.

To apply a Liquibase Pro key to your project, add the following property to the Liquibase properties file:

liquibaseProLicenseKey: <paste license key>
  1. In your LiquibaseSybase folder, create a new text file and name it dbchangelog.xml. The changelog files contain a sequence of changesets, each of which makes small changes to the structure of your database.

Note: Instead of creating an empty changelog file, you can use an existing database to generate a changelog. In this tutorial, you will manually add a single change. To add this change, open the XML file and update the changelog file with the following code snippet:

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
	xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
	xmlns:pro="http://www.liquibase.org/xml/ns/pro"
	xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
		http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd
		http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
		http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.9.xsd">
</databaseChangeLog>
  1. Add a changeset to the changelog. The changesets are uniquely identified by author and id. Liquibase attempts to execute each changeset in a transaction that is committed at the end. In the dbchangelog.xml file, add a new createTable changeset as follows:
  1. Navigate to your project folder in the CLI and run the Liquibase status command to see whether the connection is successful. You can pass arguments in the CLI or keep them in the Liquibase properties file.
  2. liquibase --username=test --password=test --changelog-file=<changelog.xml> status
  3. Run your first update with the update command, which makes changes to your database. You can also run the update-sql command to inspect the SQL before running the update command.
  4. liquibase --changelog-file=<changelog.xml> update-sql
    liquibase --changelog-file=<changelog.xml> update

From a database UI tool, ensure that your database contains the table you added along with the DATABASECHANGELOG table and DATABASECHANGELOGLOCK table.