How to automate migration (schema and data) for PHP/MySQL application

前端 未结 11 2274
鱼传尺愫
鱼传尺愫 2020-12-12 15:32

I have an application in PHP/MySQL. I am searching for an automated way upgrading database behind the application. I don\'t need to have the compatibility with older version

11条回答
  •  半阙折子戏
    2020-12-12 15:43

    Similar to gnarf's suggestion I would run with the following:

    • For every change to the schema create an SQL file that when run will take you from the old version to the new version (this could be one file per major version or lots of smaller changes).
    • Create a separate file listing each of the SQL file names in the order they must be applied in (oldest at the top, newest at the bottom)
    • Create a simple "versioning" table (all it needs is a single VARCHAR column) in your database

    Now you need to write a simple script that works in the following way:

    • Query the versioning table for the name of the last SQL update file applied
    • If there are newer SQL alteration files to be run execute them in sequence
    • record the name of the newest SQL file applied

    I hope that makes sense

提交回复
热议问题