Integrant methods for running database migrations using Ragtime.
To install, add the following to your project :dependencies
:
[duct/migrator.ragtime "0.2.2"]
This library provides the :duct.migrator/ragtime
Integrant key,
which takes four options:
{:duct.migrator/ragtime
{:database #ig/ref :duct.database/sql
:logger #ig/ref :duct/logger
:strategy :rebase
:migrations [#ig/ref :foo.migration/create-foo-table]}}
The :database
key should be a SQL database compatible with the Duct
database.sql library. For example:
{:duct.database.sql/hikaricp
{:jdbc-url "jdbc:sqlite:db/foo.sqlite"}}
The :logger
key should be a logger compatible with the Duct
logger library:
{:duct.logger.timbre/println {}
:duct.logger/timbre
{:level :info
:appender #ig/ref :duct.logger.timbre/println}}
The :strategy
is either :apply-new
, :raise-error
or
:rebase
. These correspond to the ragtime strategies with the
same names.
The :migrations
key is a vector of migrations. The easiest way to
create these is to use a composite key that is derived from
:duct.migrator.ragtime/sql
.
{[:duct.migrator.ragtime/sql :foo.migration/create-foo-table]
{:up ["CREATE TABLE foo (id int);"]
:down ["DROP TABLE foo;"]}}
Migrations built in this way expect an :up
and a :down
key that
contain vectors of SQL, either as strings, or URLs to resources on the
classpath.
Resources can be specified in the edn configuration file using the
#duct/resource
tag. For example:
{[:duct.migrator.ragtime/sql :foo.migration/create-foo-table]
{:up [#duct/resource "migrations/foo-up.sql"]
:down [#duct/resource "migrations/foo-down.sql"]}}
The associated SQL files can then be placed in resources/migrations
.
Copyright © 2018 James Reeves
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close