Skip to content

conskit/ck.migrations

Repository files navigation

ck.migrations Build Status Dependencies Status Clojars Project

Database Migration module for conskit

Installation

Add the dependency in the clojars badge above in your project.clj.

FlywayDb support

Add the classifier "flyway" and the org.flywaydb/flyway-core library.

Usage

Add the following to your bootstrap.cfg:

ck.migrations/migrations

Add the following to your config.conf

database: {
  classname:   "org.h2.Driver"
  subprotocol: "h2:file"
  subname:     "./demo"
  user:        "sa"
  password:    ""
  prefix: "" # the prefix to use for migration file names (default for flyway is 'V')
}

Add the dependency in your serivice and call the migrate! method in the init phase.

(defservice
  my-service
  [[:CKMigration migrate!]]
  (init [this context]
    ...
    (migrate! :flyway :database)
  ...)

migrate! is called with a provider (:flyway) and the config key for where it should find the database settings (:database)

Add your migrations to the the code or, in the case of Flywaydb, add the sql needed for the migrations to your resources/db/migration folder.

Now when your service is initialized it will migrate the database.

Alternatives

If Flywaydb is not your cup of tea you can always implement your own provider by providing a method that extends the ck.migrations/migrate!* multimethod

(defmethod migrate!* :my-special-provider
  [{:keys [config]}]
  ;; logic
  )
  
;; Within service init
(migrate! :my-special-provider :database)

where config here is the configuration with the database and possibly other settings i.e. basically anything under the key specified (see flyway/ck/migrations/flyway.clj for an example).

License

Copyright © 2018 Jason Murphy

Distributed under the Apache License, Version 2.0.

About

Database Migration module for conskit

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published