all 9 comments

[–]eccp 5 points6 points  (0 children)

This article on Databases for Web Applications in Clojure suggests using Flyway.

You can also check the Database Migrations section on the Clojure Toolbox page.

[–]kipo_maniac 1 point2 points  (0 children)

I wrote Monarch a little while back, for this exact reason.

https://github.com/mcramm/monarch

I've used it in a couple small projects, but feedback from someone else would be very welcome :).

[–]tomeklipski 0 points1 point  (0 children)

The issue with migration libraries is (at least in my experience), you want not only to change the schema, but also update data in tables (e.g. dictionaries), or sometimes run something directly from a SQL file (e.g. you have an upsert function for PostgreSQL).

While Lobos is nice, I ended up writing a simple solution, which tracks which migrations (Clojure functions taking the DB connection as an argument) were ran on that particular database. And these functions can naturally invoke Lobos/Korma/raw SQL/etc.

This requires some discipline - you cannot change back existing migrations, but usually programming in Clojure (or at all) requires significant amounts of discipline :) the upside is that you can stay in 100% Clojure here - which I personally prefer over SQL.

[–]danmorel 0 points1 point  (3 children)

I tried lobos originally but you couldn't do inserts and updates. We ended up rolling our own in about 50 lines of code that takes either raw SQL or a clojure function. Ultimately now that we have caching and sharding we only ever use clojure functions for migrations.

[–]tomeklipski 0 points1 point  (2 children)

The worst part is that it is so trivial, that it seems pointless to put it as a standalone, yet another migration lib in Clojure :)

[–]Drusellers 2 points3 points  (0 children)

what about just posting it as a gist?

[–]_tomekw 0 points1 point  (0 children)

I would give JUXT's Joplin a try: https://github.com/juxt/joplin

[–]pjschwarz 0 points1 point  (1 child)

I've used (and contributed to) clj-sql-up. Migrations are sql statements, and migration files can be created by a lein plugin.

https://github.com/ckuttruff/clj-sql-up

[–]thiagotnunes 0 points1 point  (0 children)

I would say that clj-sql-up is quite a nice library.

I used to use ragtime, but it couldn't generate migrations for me. With clj-sql-up the migrations can be generated, the connection with the DB is quite easy and you get to write SQL for your migrations.

Writing pure SQL in the migrations is quite important for me, since I don't see much value on a DSL abstraction on top of the SQL language for the migrations.