Liking cljdoc? Tell your friends :D

pgmig

Database migrations for next.jdbc and PostgreSQL.

Documentation Clojars Build

Documentation: https://cljdoc.org/d/daaku/pgmig

Usage

Make a directory that contains your migrations. You can put this in your resources directory and load it from your jar if that makes sense. The library will run thru all the files in sorted order. The suggested naming convention is 000_first.sql, 001_second.sql and so on.

The library:

  1. Will create a table named pgmig_migrate to manage the migration state.
  2. Will run everything in a single transaction, so all pending migrations are run, or nothing.
  3. Expects you to never delete or rename a migration.
  4. Expects you to not put a new migration between two existing ones.
  5. Expects file names and contents to be UTF-8.
  6. There are no rollbacks - just write a new migration.

To use it:

(ns myapp
  (:require [clojure.java.io :as io]
            [daaku.pgmig :as pgmig]))

(def db-spec {:dbtype "postgres" :dbname "myapp"})

(def migrations
  (delay (pgmig/migrations-from-dir (io/resource "myapp/migrations"))))

(defn start []
  (pgmig/migrate db-spec @migrations))

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close