https://github.com/rads/migrate
A minimal migration library in pure Clojure.
https://github.com/rads/migrate
Last synced: 5 months ago
JSON representation
A minimal migration library in pure Clojure.
- Host: GitHub
- URL: https://github.com/rads/migrate
- Owner: rads
- License: mit
- Created: 2025-02-28T08:28:39.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-05-26T09:33:21.000Z (8 months ago)
- Last Synced: 2025-06-30T09:42:53.617Z (7 months ago)
- Language: Clojure
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rads.migrate
[](https://clojars.org/io.github.rads/migrate)
A minimal migration library in pure Clojure.
## Features
- Zero dependencies.
- Supports any storage backend with defaults for next.jdbc.
- All migration events are logged.
- Migrations are sequences of maps.
- Each migration map has the following keys:
- `:id` (required) - A unique ID.
- `:migrate` (required) - A function to run the migration.
- `:rollback` (optional) - A function to rollback the migration.
## Usage
```clojure
(require '[next.jdbc :as jdbc]
'[rads.migrate :as migrate]
'[rads.migrate.next-jdbc :as migrate-next-jdbc])
(defn migrations [{:keys [print-fn]}]
[{:id :seed
:migrate (fn [_] (print-fn "Seeding"))
:rollback (fn [_] (print-fn "Rolling back seed"))}
{:id :alter
:migrate (fn [_] (print-fn "Altering"))
:rollback (fn [_] (print-fn "Rolling back alter"))}])
(defn migration-config [opts]
{:storage (migrate-next-jdbc/storage opts)
:migrations (migrations opts)})
(comment
(def config
(migration-config
{:ds (jdbc/get-datasource "jdbc:sqlite:app.db")
:print-fn println}))
;; Migrate to the latest migration
(migrate/migrate! config)
;; Rollback to the previous migration
(migrate/rollback! config)
;; Get last migration event
(migrate/get-last-event config))
```
## License
Copyright © 2025 Radford Smith
rads.migrate is distributed under the [MIT License](LICENSE).