nilgun
nilgun

Reputation: 10629

Should I be worried about creating idempotent migrations while using Flyway?

I have been reading a blog post about Flyway, called Lessons Learned Using Flyway DB with Distributed Version Control. One of the author's suggestions is to create idempotent migrations.

Quoting from the article:

In a perfect world, each migration will only be run once against each database.

In a perfect world, that is.

In actuality, there will be cases where you’ll need to re-run migrations against the same database. Often this will be due to a failed migration somewhere along the line, causing you to have to retrace your steps of successful migrations before to get the database back in a working state. When this happens, it’s incredibly helpful for the migration to be written in an idempotent manner.

Assuming I am using a database that supports DDL transactions, should I be worried about idempotency while creating these migration sqls?

Upvotes: 4

Views: 1842

Answers (1)

Axel Fontaine
Axel Fontaine

Reputation: 35167

In general no, especially when you have a database that supports DDL transactions.

Versioned migrations are designed to run exactly once and can, but don't have to be idempotent (virtually no benefit).

Repeatable migrations on the other hand have to be idempotent as they'll be run over and over again.

Flyway let's you very easily recreate your database from scratch, and that's the approach you should favor when experimenting.

Upvotes: 6

Related Questions