MySql as Infrastructure as Code using standard tools can be unsafe

The delivery of your MySql Database as Infrastructure as Code can be a challenge. Moreover, it can be also unsafe for your data! Why?

Most standard tools designed to run Db scripts (including EF migrations) rely on Db transactions. Any script failure during the release pipeline rollbacks the Db into a previous state.

The problem is that this will not work out well for MySql (as well for Oracle Db), because of its implicit commit caused by DDL statements. One failing script can put your Db into an intermediate state. This state is not recognized by such a standard script running tool. Rerunning of your release pipeline will cause that the tool will try to execute migration scripts again. But applying the same change scripts twice is not a safe operation for your data! Are your developers providing Db scripts aware of it?

As the solution for this problem, check out my extension of the open-source tool yuniql with the implementation of enhanced flow for MySql. The flow is documented here. The tool can be easily integrated into your release pipeline and can safely run new DB version scripts.

The delivery of infrastructure as code for Microsoft SQL Server or PostgreSQL can be easier, as their transactions fully support the rollback, regardless of whether DDL statement was used.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.