Fork me on GitHub

This might be the wrong forum - but how are folks managing database migrations these days? I want to create some tables, some constraints, have the sql that created these tables live under source control, and also track changes to these tables with additional scripts that can be applied on top of the previous. Is flyway popular/simple/ok/not wildly confusing?


I've also read a bit about sqitch - I'd be interfacing with postgres primarily


We built our own migration tool in Clojure (because, reasons) but most folks use Ragtime or Migratus @radicalmatt


I use flyway at work for a multi-tenant SaaS sw. Flyway takes a list of schemas to run the (same) migrations on, which simplifies adding tenants. We use a schema per tenant. It also has Java migrations that you can of course call Clojure from.


The automatic schema addition is convenient. I have a test fixture that first deletes the "test" tenant's schema and then runs migrations on it, creating a new one. It's an easy way to keep the test database clean.


recently moved stuff to flyway as well. it seems to work for the basic needs.


I've seen at least one person using Flyway from Clojure but it doesn't seem very common.

seancorfield01:08:45 and -- if I were to pick one of those, it would be Migratus, since the sequential migration numbers in Ragtime can be problematic (Migratus' README explains why).

thanks2 3

Humm, as far as I know, sequential migration numbers are only needed in Ragtime if you want to split a SQL migration in several files so each file has only one SQL sentence (according to But if you use the --;; marker to separate SQL sentences, you can have them in a single file. In this case, the name of the file doesn't need to include sequential migration numbers. Files just need to end in .up.sql and .down.sql, but the "prefix" can be whatever you like, as long as they sort lexicographically in the order you need. That is, you could use timestamps as migration ids, like you do in Migratus. Am I wrong?


I'd have to dig into how Ragtime records which migrations have been applied and which haven't, but it is relying on conventions, whereas Migratus records all the actual migrations applied I believe (so you don't have problems if you create migrations on branches that don't get merged until later). I haven't used either, so I'm basing my comments on other people's discussions about running into that problem (with Ragtime specifically and sequential migrations in general). Migratus has a utility to create the migration files for you so you don't have to manually figure out the right name.


Oh, now I see what you meant! You were talking about the order of the recorded migrations that are already applied. And not about how to order the files with the new migrations that you want to apply. In that case, Ragtime imposes what you called "sequential migration numbers" by default, using the so-called "raise-error migration strategy" (See But you can choose between several strategies. I think ragtime.strategy/apply-new is almost the same as what you say Migratus does.


(our bespoke system at work uses sequential numbers, so I know that pain well, and it had its origins in pre-Clojure days for our company, so I just converted it to Clojure rather than switch completely to an existing one).