How to code a simple versioning system?

后端 未结 13 669
广开言路
广开言路 2021-01-30 11:27

I want to do a simple versioning system but i don\'t have ideas on how to structure my datas, and my code.

Here is a short example:

  1. User logs in
  2. U
13条回答
  •  攒了一身酷
    2021-01-30 12:19

    I recently built a simple versioning system for some static data entities. The requirement was to have an 'Active' version and 0 or 1 'pending' versions.

    In the end, my versioned entity had the following attributes relevant to versioning.

    VersionNumber (int/long) ActiveVersionFlag (boolean)

    Where:-

    • only 1 entity can be ActiveVersionFlag = 'Y'
    • only 1 entity can be Version number > the 'Active' version (i.e. the 'pending' version)

    The kind of operations I allowed were

    Clone current version.

    • Fail if there is already a version > the Versionnumber of the 'Active' version
    • Copy all of the data to the new version
    • increment the version number by one

    Activate Pending Version

    • Fail if the specified version is not the 'Active' version + 1
    • find the 'Active' version and set its ActiveVersionFlag to 'N'
    • set the ActiveVersionFlag of the 'pending' version to 'Y'

    Delete Pending Version

    • Delete the Pending Entity

    This was reasonably successfull and my users now clone and activate all the time :)

    Michael

提交回复
热议问题