Eboshi is a lightweight Clojure library for managing SQL migrations stored as EDN files and executing them against a relational database. The project provides a migration-runner protocol and a MySQL implementation using next.jdbc.
{:name "1600000000000-create-users"
:up ["create table if not exists users (id int auto_increment primary key, name varchar(255));"]
:down ["drop table if exists users;"]}
:name field is used to track applied migrations.MigrationRunner protocol declares two operations:
find-last-migration-name — returns the last applied migration name (maybe String)execute! — apply or revert a migration and return the migration mapsrc/eboshi/services/migrations.clj — high-level migration helpers (create, up!, down!, sync!)src/eboshi/protocols/migration_runner.clj — s/defprotocol for migration runners (Schema is used for runtime validation)src/eboshi/infra/mysql_migration_runner.clj — MySQL runner implementation using next.jdbctest/... — unit and integration tests. Integration tests use Testcontainers' MySQLContainer and require Docker.Create a database spec for a local MySQL instance (ensure MySQL driver is in your deps):
;; URL string form
(def db-spec "jdbc:mysql://localhost:3306/eboshi?useSSL=false&serverTimezone=UTC&user=root&password=secret")
;; or map form
(def db-spec {:jdbcUrl "jdbc:mysql://localhost:3306/eboshi?useSSL=false&serverTimezone=UTC"
:user "root"
:password "secret"})
Create and use the MySQL migration runner:
(require '[eboshi.infra.mysql-migration-runner :as mysql-runner]
'[eboshi.services.migrations :as migrations])
(def runner (mysql-runner/make-mysql-migration-runner db-spec))
(def config {:migrations-dir "/path/to/migrations"})
;; write a migration (helper provided by the library)
(migrations/create config "add-users")
;; apply next pending migration
(migrations/up! config runner)
;; apply all pending migrations
(migrations/sync! config runner)
;; revert last migration
(migrations/down! config runner)
The project includes unit and integration tests. Integration tests use Testcontainers and require Docker to be available.
Using Leiningen:
lein test
If you run only unit tests or want to skip integration tests, use your usual tooling/aliases as configured in the project.
eboshi.protocols.migration-runner/MigrationRunner protocol.test/.See LICENSE in the project root.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |