Database structure and source control - best practice

前端 未结 10 1767
轻奢々
轻奢々 2020-12-07 10:22

Background

I came from several years working in a company where all the database objects were stored in source control, one file per object. We had

10条回答
  •  旧巷少年郎
    2020-12-07 10:57

    I am not very familiar with RedGate toolkit, but if it is any similar to dbGhost, there must be a utility that allows you to script the database objects to the files one per object. In this case I would suggest following:

    • add a daily (or part of a build) job to reverse-engineer the DEV database into the directory structure
    • then compare it to what you have in repository (by means of simple diff), and basically FAIL the build job and report the diff if any. This will indicate that the structure of the DEV database has changed and is not reflected in the source control,
    • which will indicate to the developer to add the changes to the source control (even use the reported .diff file for this)

    If you many DEV databases (one per user or development branch) and it is too cumbersome, then probably a better combination would be to do such task on the STAGE (TEST just before release) version of the database, at which point you would store the PROD schema in the repository and would update it from the STAGE only during the pre-release testing phase, where you will ensure that your schema changes are also in the repository.

    This way developers can still work in the usual way: change the schema on the DEV database first, and hopefully you get the balance between the flexibility and one truth you would like.

    In my team we add change to VCS as soon as we change the DEV database, but we still do have such task to compare the schema between different databases (DEV, STAGE and PROD). Basically, we follow what I once answered in How should you build your database from source control?.

提交回复
热议问题