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?
recently moved stuff to flyway as well. it seems to work for the basic needs.
I've also read a bit about sqitch - I'd be interfacing with postgres primarily
I've seen at least one person using Flyway from Clojure but it doesn't seem very common.
https://github.com/yogthos/migratus and https://github.com/weavejester/ragtime -- 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).
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 https://github.com/weavejester/ragtime/wiki/SQL-Migrations#sql).
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 https://github.com/weavejester/ragtime/wiki/Concepts#strategies). 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).
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.