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

Note: Place your jar file in the Liquibase/lib install directory.

  • Ensure that you have ASE 12.0+ version.
  • Set select into database option.
  • 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 dropAll.

Tutorial

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

  1. Create a new project folder and name it LiquibaseSybase.
  2. In your LiquibaseSybase folder, create a new text file and name it liquibase.properties.
  3. Edit the liquibase.properties file to add the following properties:
changeLogFile: 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 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. 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"
          xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
          http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.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 department create table changeset as follows:
<?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"
       xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
              http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
           <changeSet id="1" author="bob">
             <createTable tableName="department">
                <column name="id" type="int">
                     <constraints primaryKey="true" nullable="false"/>
                </column>
                <column name="name" type="varchar(50)">
                      <constraints nullable="false"/>
                </column>
                <column name="active" type="boolean" defaultValueBoolean="true"/>
                </createTable>
             </changeSet>
</databaseChangeLog>

Note: The preceding changeset is XML format. The corresponding SQL statement looks like the following:

--liquibase formatted sql

--changeset bob:1
CREATE TABLE "DEPARTMENT" ("ID" INTEGER, "NAME" STRING, "ACTIVE" BOOLEAN);
  1. Open the command prompt, navigate to the LiquibaseSybase directory, and then run the following command:
liquibase update
  1. From a database UI Tool, check your database changes. You will see a new department; table added to the database. For example:
SELECT * FROM "dbo"."department";
ID Name Active

NULL

NULL

NULL

Also, you will see two more tables:

DATABASECHANGELOG tracking table. This table keeps a record of all the changesets that were deployed. This way, next time when you deploy again, the changesets in the changelog will be compared with the DATABASECHANGELOG tracking table and only the new changesets that were not found in the DATABASECHANGELOG will be deployed. You will see that a new row was created in that table with the changeset information we have just deployed. For example:

ID Author Filename Dateexecuted Orderexecuted Exectype MDSum

1

bob

dbchangelog.xml

date&time

1

EXECUTED

checksumvalue

DATABASECHANGELOGLOCK tracking table. This table is used internally by Liquibase to manage access to the changelog table during deployment.