Transactional DDL workflow for MySQL

前端 未结 2 1308
野的像风
野的像风 2021-02-18 20:31

I was a little surprised to discover that DDL statements (alter table, create index etc) implicitly commit the current transaction in MySQL. Coming fr

2条回答
  •  死守一世寂寞
    2021-02-18 21:09

    One possibility is doing DDL changes in a non-destructive-manner, which would include:

    • split logic in DDL/DCL (+1 to reverse all) and DML
    • run only the DDL/DCL script adding columns, new tables, ..
    • depending on result:
      • on success, apply the DML changes,
      • on fail, apply reverse DDL/DCL script removing the stuff you wanted to add in second step (obviously with some errors "does not exist" depending on how far step 1 got)
    • remove what is not needed anymore, drop old columns/tables

提交回复
热议问题