2

Continuous Delivery

I am building an application with a MySQL DB for relational storage. The application is being designed for continuous delivery, to this end, the application DB must be upgraded in-place.

Basic Approaches

1. Application -> Transactional Statements -> DB -> Table View (Schema Version) -> Table

A single DB is used for all application versions. The latest schema version defines the real table structure, previous schema versions are supported through table views that simulate the previous schema.

2. Application -> Transactional Statements -> DB (Schema Version) -> Table

When a new schema is released, the DB is duplicated and schema changes are applied to the new DB. Transactions on the old DB after starting the process are tracked and applied to the new DB.

When the upgrade is complete (and all application deployments have switched to the new schema), the old DB is dumped.

Option 1 is Preferred

Option 2 is technically simple because there is no requirement to modify the schema of an active DB. However, if the DB grows to a substantial size, then the resource consumption will become substantial; for this reason, there are practical limitations to the size of application that this approach could support.

As such, option 1 preferred, but it presents the problem of applying transactional DDL statements.

Transactional DDL Statement Strategy

How can I modify both the DB Table and the corresponding Table View without risking data corruption or an interruption in the application's ability to access the DB?

My current thought is to approach the changes as follows:

  1. Apply creations and additions
    1. create new tables
    2. create new columns
  2. Apply column renaming
    1. Lock table view (and, by extension, the base tables)
    2. Rename column
    3. Modify table view to use the new target column name
    4. Unlock table view
  3. Apply table renaming
    1. Lock table view (and, by extension, the base tables)
    2. Rename base table
    3. Modify table view to use new base table name
    4. Unlock table view

From there, the new schema table views would be created so that the same strategy could be used when the next schema change is deployed.

Note: any deleted columns or tables would be preserved during the transition but would be renamed to append _deprecate or some other identifying suffix

Questions

It is my understanding that transactional DDL statements are impossible in MySQL as the statements will trigger implicit commits. Is this correct?

Will the option 1 approach I describe above work?

Specifically, I have two concerns:

  1. Table Lock causing disruption for the application. Is the only concern here that a single table lock lasts so long that waiting connections timeout? If so, this should be manageable by testing the duration of each table lock during the application staging.

  2. Rollback I obviously do not have automatic rollbacks with this arrangement. However, all I need is for any modification to the base table to be mirrored with a change to the table view. Is it possible to apply changes to both the base table and the table view in a single transaction? If not, I will just have to test very thoroughly before deploying schema changes.

1 Answer 1

0

MySQL doesn't support transactional DDL and probably never will.

You could use a different database though.

You could use liquibase and handle your rollbacks manually.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.