Code-based Migrations with Migratus in Clojure

Migratus is a wonderful migration tool for Clojure. You can use it on its own, or if you have a Luminus project, it is already included.

There are a few areas that could use some extra tutorials, though. One of them is code-based migrations. Especially, examples on how to modify the database would be nice.

Here’s a quick explanation of how to modify the database with a code-based migration in Migratus.

First, create an *.edn file in the folder with the regular migrations. It takes the same format as other migrations, so you can really just change the extension of one of your created migrations to ‘.edn’ and change the contents.

Continue reading “Code-based Migrations with Migratus in Clojure”

Clojure Migratus: “Migration reserved by another instance”

Migratus is a great migration tool for Clojure enterprise projects. Migrations allow you to do and undo changes to a database very quickly. The best use case for Migratus is update of a database for your enterprise project or setting up a new database for a development environment. Setting up the database can be on a production server or your local development environment.

Eventually one of your migrations is going to have an SQL exception. Normally, SQL exceptions aren’t a big deal. You just fix it, and run the migration again. However, Migration gets into an :ignore state and gives you an exception reading …

… and then refuses to run another migration no matter what you do.

The fix is to go into your ‘schema_migrations’ table in your database and remove the row that has an id of -1.

That’s really a simple fix for your favorite Clojure migration tool.