🔥 1 day streak
343 words

What’s wrong with clojure database migrations?

Once upon a time there lived a few grumpy old web devs who were programming clojure on top of relational databases. They had to change their schema over time and they decided that SQL was enough, that they didn’t need the COMPLEXITY of clojure migrations so they wrote their SQL files and wrapped “up” and “down” migrations in libraries like ragtime and migratus. Writing down migrations with plain old SQL is so simple it’s great! Just run the migrations from the code, and keep track, it’s simple, soooo simple. The simplicity is almost painful.

The reason that rails, laravel, phoenix and others have migrations in the same language as the framework is that it’s easier. It’s easier to not switch contexts, it’s easier to type less stuff, no more down migrations, the framework does it for you, it’s also easier to do things to your database when you’re writing actual code instead of SQL. There are a ton of benefits to rails-like migrations that wrap SQL DDL syntax! There must be an insane mismatch between what people want and what clojure people want.

I did find one library that has done this before, migratus’ create-table but no one seems to have gone full on rails copy mode yet, UNTIL NOW BABY 👶 That’s right, coast on clojure is getting easy (not simple) migrations. Check it

(ns db.migrations.create-table-todo
  (:require [coast.migrations :refer :all]))

(defn change []
  (create-table :todo
    (text :name)
    (timestamp :finished-at)

That’s a pretty sweet copy of ruby on rails’ migrations and I think it’s an upgrade to what I was doing before with the edn migrations, I may have been the only one on the planet that understood what the heck I was talking about with that EDN stuff. Hopefully this makes coast so easy to develop with that you can make a new web app every day in 2019, wouldn’t that be something? 12 startups/ 12 months -> 24 hr startup -> 365 startups / 365 days. Now THAT is rapid web development.