Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Clojure wrapper for Liquibase for database change management and migration
Clojure Java
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
doc Small formatting fix
java-src/clj_liquibase Update to Liquibase 3.0, RawSqlChange Implementation
src/clj_liquibase Fix Liquibase doc URLs
test/clj_liquibase implement 'sql-file' change type
.gitignore Ignoring the REPL history.
CHANGES.md
README.md bump version to 0.5.2; add Clojure 1.6 to tests
project.clj bump version to 0.5.2; add Clojure 1.6 to tests

README.md

clj-liquibase

Clj-Liquibase is a Clojure wrapper for Liquibase for database change management and migration.

Supported actions:

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

Usage

On Clojars: https://clojars.org/clj-liquibase

Leiningen dependency: [clj-liquibase "0.5.2"]

Quickstart

Create a new project e.g. fooapp using Leiningen and include the following dependencies in project.clj:

[clj-dbcp      "0.8.1"]  ; to create connection-pooling DataSource
[clj-liquibase "0.5.2"]  ; for this library
[oss-jdbc      "0.8.0"]  ; for Open Source JDBC drivers

Create a Clojure source file for managing the DB schema. Include the required namespaces define the change, changeset and changelog objects:

(ns fooapp.dbschema
  (:require
    [clj-dbcp.core        :as cp]
    [clj-liquibase.change :as ch]
    [clj-liquibase.cli    :as cli])
  (:use
    [clj-liquibase.core :only (defchangelog)]))

;; define the changes, changesets and the changelog

(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]]))

; recommended: one change per changeset
(def changeset-1 ["id=1" "author=shantanu" [ct-change1]])


; you can add more changesets later to the changelog
(defchangelog app-changelog "fooapp" [changeset-1])


;; keep the DataSource handy and invoke the CLI

(def ds (cp/make-datasource :mysql {:host "localhost" :database "people"
                                    :user "dbuser"    :password "s3cr3t"}))

(defn -main
  [& [cmd & args]]
  (apply cli/entry cmd {:datasource ds :changelog  app-changelog}
         args))

After defining the changelog, you need to apply the changes:

lein run -m fooapp.dbschema help
lein run -m fooapp.dbschema update

Documentation

For more documentation please refer the file doc/intro.md in this repo.

Contributors

License

Copyright © 2012-2014 Shantanu Kumar and contributors

Distributed under the Eclipse Public License, the same as Clojure.

Something went wrong with that request. Please try again.