Clj-Liquibase /

Filename Size Date modified Message
92 B
2.9 KB
3.6 KB
4.2 KB

-- markdown --

Clj-Liquibase v0.3

Clj-Liquibase is a simple Clojure wrapper around the Liquibase library for carrying out relational database change management and migrations.

Supported actions:

  • update
  • tag
  • rollback
  • generate SQL for actions
  • generate DB doc
  • database diff


Maven/Leiningen dependency details are here:

Examples for usage can be found in the tutorial below:


You will need Maven 2 to build from sources. Execute the following:

$ mvn clean package  # packages up a JAR in "target" dir
$ mvn install        # to install to your local Maven repo
$ mvn clojure:gendoc # generate Clojure API documentation


Copyright (C) 2011 Shantanu Kumar (kumar[dot]shantanu[at]gmail[dot]com)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


You can use Clj-Liquibase after including its namespace in your project:

(use 'org.bituf.clj-liquibase)
(use 'org.bituf.clj-liquibase.change)


Create a new project and include the following dependencies:

[org.bituf/clj-dbcp "0.5"]
[org.bituf/oss-jdbc "0.5"]
[org.bituf/clj-liquibase "0.3"]

To use Clj-Liquibase you need to include the required namespace in your application and define a changelog.

;; filename: fooapp/src/fooapp/dbchange.clj
(ns fooapp.dbchange
    [org.bituf.clj-liquibase :as lb]
    [org.bituf.clj-liquibase.change :as ch]))

(def ct-change1 (ch/create-table :sample-table1
                  [[:id     :int          :null false :pk true :autoinc true]
                   [:name   [:varchar 40] :null false]
                   [:gender [:char 1]     :null false]]))

(def changeset-1 ["id=1" "author=shantanu" [ct-change1]])

(lb/defchangelog changelog [changeset-1])

After defining the changelog, you need to apply the changes (see below).

;; filename: fooapp/src/fooapp/dbmigrate.clj
(ns fooapp.dbmigrate
    [fooapp.dbchange         :as dbch]
    [org.bituf.clj-dbcp      :as dbcp]
    [org.bituf.clj-dbspec    :as spec]
    [org.bituf.clj-liquibase :as lb]))

;; define datasource for supported database using Clj-DBCP
(def ds (dbcp/mysql-datasource "localhost" "dbname" "user" "pass"))

(defn do-lb-action "Wrap f using DBSpec middleware and execute it"
  (let [g (spec/wrap-dbspec (spec/make-dbspec ds)
            (lb/wrap-lb-init f))]

(defn do-update "Invoke this function to update the database"
  (do-lb-action #(lb/update dbch/changelog)))

Once you are done with these, you can invoke fooapp.dbmigrate/do-update to carry out the changes.


Please check The Bitumen Framework Handbook