https://github.com/daaku/pgmig
Database migrations for PostgreSQL on Clojure using next.jdbc.
https://github.com/daaku/pgmig
clojure database-migrations postgresql
Last synced: 6 months ago
JSON representation
Database migrations for PostgreSQL on Clojure using next.jdbc.
- Host: GitHub
- URL: https://github.com/daaku/pgmig
- Owner: daaku
- License: mit
- Created: 2020-08-16T06:20:56.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-10-28T12:42:50.000Z (over 4 years ago)
- Last Synced: 2025-07-25T09:00:58.636Z (6 months ago)
- Topics: clojure, database-migrations, postgresql
- Language: Clojure
- Homepage: https://cljdoc.org/d/daaku/pgmig
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
pgmig
=====
Database migrations for
[next.jdbc](https://github.com/seancorfield/next-jdbc) and
[PostgreSQL](https://www.postgresql.org/).
[](https://cljdoc.org/d/daaku/pgmig/CURRENT)
[](https://clojars.org/daaku/pgmig)
[](https://github.com/daaku/pgmig/actions?query=workflow%3Abuild)
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.
1. Will run everything in a single transaction, so all pending
migrations are run, or nothing.
1. Expects you to never delete or rename a migration.
1. Expects you to not put a new migration between two existing ones.
1. Expects file names and contents to be UTF-8.
1. There are no rollbacks - just write a new migration.
To use it:
```clojure
(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))
```