sql

Eugen 2023-06-14T19:16:23.348569Z

hi, what do you use for SQL migrations? currently using migratus and I think it could use a feature to list ALL migration id's . wdyt? cc @yogthos > I think it would be very useful to have a way to list the migration ids that migratus knows about (maybe with file path?) > Migrations up / down can use the ID's but to my knowledge there is no easy way to print them. > I'm using clj-migratus, but I think this should be part of core and exposed in clj-migratus.

2023-06-20T11:01:39.320609Z

https://gist.github.com/geraldodev/f4cc25376331ebd37d2eb8a4d3ccf8a9 Mybatis migrations with babashka

Andrei Stan 2023-08-22T15:06:10.114549Z

Hello, i have added API support to display more informations about migrations If you guys have some time to look at: https://github.com/yogthos/migratus/issues/240#issuecomment-1688354449 Thanks.

igrishaev 2023-06-14T19:18:56.683619Z

You can just find/grep the resources/migrations directory (locally)

igrishaev 2023-06-14T19:20:59.681849Z

Aside from Migratus, I used Ragtime as well. It’s a great library and it might be used with nosql DBs, e.g Cassandra

Eugen 2023-06-14T19:24:15.845939Z

I know, but that would not give me the migrations that migratus discovers / considers

seancorfield 2023-06-14T19:25:45.685099Z

Go create an issue on the repo. Having some options to list all / applicable migrations without applying them sounds useful.

Eugen 2023-06-14T19:28:48.814249Z

there is option to see pending migrations but not all

Eugen 2023-06-14T19:29:22.152219Z

I was going to create the issue but decided to have a discussion first, get some consensus

seancorfield 2023-06-14T19:32:56.867049Z

I can definitely see value in a migrations library being able to produce a list of all possible migrations, indicating which have been applied an which haven't (if the system is able to track on a per-migration basis whether it has been applied or not). Our hand-rolled system at work is "linear" (it has a monotonically-increased "version" number and just tracks the highest version applied) and if I was starting over again, I'd use Migratus and I would love the "report" feature that provided more information, especially if it could list the date a migration was applied, etc.

Eugen 2023-06-14T19:34:15.792429Z

nice feedback. I will add it to the issue

Eugen 2023-06-14T19:34:58.209029Z

https://github.com/yogthos/migratus/issues/240

👍🏻 1
dharrigan 2023-06-14T19:59:22.446329Z

I use FlywayDB (https://flywaydb.org/) - been using it for years, from java, to kotlin and now on Clojure

dharrigan 2023-06-14T19:59:29.610309Z

works a treat.

Eugen 2023-06-14T20:10:30.565299Z

I've also used flyway (also has a cli). On the project I joined they are using migratus though. flyway seems more polished, but it's been around for longer and also has some financial backing behind

yogthos 2023-06-14T23:34:19.602509Z

having an option to list all migrations would make sense, and should be pretty quick to add, effectively would just be a matter of factoring out the parts of find-migration-files and find-migration-resources that find the migrations, and exposing that as list-migrations or something

yogthos 2023-06-14T23:34:32.714149Z

the relevant namespace is here https://github.com/yogthos/migratus/blob/master/src/migratus/migrations.clj#L77

Andrei Stan 2023-06-21T10:01:10.445309Z

hi, i have added some design ideas on adding list options for migratus https://github.com/yogthos/migratus/issues/240#issuecomment-1600540973

Andrei Stan 2023-07-12T11:11:04.073199Z

Hello, i have made a PR with some work in progress https://github.com/yogthos/migratus/pull/244 If you have the time to give me some input, it will help me a lot. Thanks.

Eugen 2023-06-15T07:26:26.055509Z

thanks. I'll add your notes to the issue. Also, I think it makes sense to list the migrations applied in DB as well as local migration files

yogthos 2023-06-15T11:35:01.949949Z

agreed, might be good to return a map with all the available migrations as well as the ones applied, the second bit will have to be read from the migrations table

Eugen 2023-06-15T13:28:41.145939Z

cc @andrei.stan

slipset 2023-06-14T19:59:29.733599Z

On the topic of tools for migrations. So, first perhaps unpopular opinion, it’s hard (in general) to write down migrations. At ardoq we write them, but we have yet to actually roll back a migration. In general, we roll forward. Secondly we see two (or perhaps even three) types of migrations that we do. One is creating new or adjusting old tables, adding constraints and those kinds of things. These are normally fast, and are nice if run early in the boostrapping of the app. Then we have data migrations which can be expressed in the language of the database, These will typically touch customer data, and can be longer running. It’s no fun to wait for these when starting up the app. Thirdly we have the kind of data migrations that for various reasons are hard to express in the language of the database, so it’s more convenient to write a clojure fn for them. These can also be timeconsuming to run. And, we don’t need support for umpteen different databases, we currently have two, aiming for one. So, where am I going with this. I guess I’m sortof wanting a migration tool which basically only has ups, and its only job is to record the running of a fn in a table somewhere so that we run the fn once an only once. Does anything as simple as that exist? Or should I write it myself, or isn’t it that simple.

isak 2023-06-14T20:17:41.443129Z

Not sure if that exists. But it is also extremely simple, I would just do it yourself. (I have done so multiple times)

isak 2023-06-14T20:20:26.340599Z

In our case we don't do the extremely slow migrations that way, those have to happen while the application is running (background jobs)

slipset 2023-06-14T20:32:32.747639Z

Yah, makes sense to do it as a background job.

respatialized 2023-06-14T20:43:40.291809Z

I think there have been some efforts recently to create more "declarative" migration tools that try to avoid the "apply every migration that's ever happened to reproduce a database" workflow that seems to create a lot of hassle https://atlasgo.io/getting-started#declarative-migrations

respatialized 2023-06-14T20:44:55.043599Z

I have no idea if this translates into lower operational overhead or reduced processing time while migrations are running, but in theory an approach like this might help eliminate unnecessary steps in the migration process

isak 2023-06-14T20:50:07.831519Z

Sounds like it would be nice for development. But I think the general approach is to just periodically take a snapshot of your schema (Sql DDL), then archive the migrations that have been run to result in that schema (or have insert statements for them).

seancorfield 2023-06-14T21:24:48.346489Z

@slipset We rolled our own up-only SQL migration code. We also have a separate notion of "data migrations" which are either integrated into batch jobs -- if they're going to be ongoing for a while or more -- or done "manually". In all cases, the migrations are bundled into JAR files and deployed as part of our normal staging/production process. The up SQL migrations are applied automatically as part of that deployment (and so we make sure up migrations are always non-breaking/backward compatible). The "batch" data migrations happen automatically too by virtue of automated deployment/restarts and or existing cron jobs (that they are added to). The "manual" migrations are run as needed by an engineer using an automatically deployed artifact java -jar the.jar ticket#1 ticket#2 ticket#3 where the (Jira) ticket numbers correspond to specific data migrations that need running. Those data migrations usually need to run for dev/test/CI we add them to a list of "local automated" migrations that run as part of DB setup.

igrishaev 2023-06-15T06:50:32.090819Z

There are two different approaches for migrations: 1) you write up & down migrations, and 2) you write only up. The problem with 2) is, should you mess up on prod, you've got to rollback asap and that's where 1) benefits because you already have a down part. With 2), you have to write it which takes time.

Eugen 2023-06-15T07:59:42.126109Z

@igrishaev: sometimes migrations change data and that part is not so easy to undo. Even if you save the old data, if the table is large enough and the system is running, you might get into a situation where you can't rollback. Not without some manual intervention. I trie to avoid these kinds of migrations of course.

Eugen 2023-06-15T07:59:56.585389Z

aslo a snapshotting feature does not sound that bad 🙂