Hacker News new | ask | show | jobs
by dewey 811 days ago
We have been using https://www.red-gate.com/products/flyway/ with Postgres (via CloudSQL) for at least 8 years and are happy with it.

Now that I looked at the website to share the link, I would probably be scared away because it looks very enterprise and corporate but it works well and it's just a Docker container built in CI and I don't have to interact with it.

1 comments

I've used Flyway and it works great, can also recommend Alembic from the Python world - https://alembic.sqlalchemy.org/en/latest/
Flyway and Alembic are imperative, not declarative.

Imperative tools express schema changes as a filesystem of incremental "migrations", whereas declarative tools use a filesystem of CREATE statements and can generate DDL diffs to transition between states.

The declarative flow has a lot of benefits [1]. It is much closer to how source code is typically managed/reviewed/deployed, which is especially important for stored procedures [2].

However, using a purely declarative flow (as opposed to using a declarative tool just to auto-generate incremental migrations, which are then run from another tool) isn't necessarily advisable in Postgres, since Postgres supports DDL in transactions. So there's potentially multiple paths/orderings to reach any given desired state, as well as the ability to mix schema changes with data changes in one transaction. This means in Postgres there's often manual editing of the auto-generated incremental change, whereas in other DBs with fewer features this isn't necessary.

Disclosure: I'm the author of Skeema, mentioned in the GP comment.

[1] https://www.skeema.io/blog/2019/01/18/declarative/

[2] https://www.skeema.io/blog/2023/10/24/stored-proc-deployment...

Yeah, I was talking more in general as to what parent said suggesting good, battle-tested migration tools like Flyway. Declarative/imperative wasn't the focus.