Branching and merging

DB Version Control helps you use branches to develop your database.

Let's say you are working on a database which is currently in version 1 and your last migration script is V1__2020.01.01_100000__SmallChange.sql.

Now you decide to branch database for a new feature, you make changes to the database and script them out as V2 script, for example, V2__2020.02.02_140000__BranchedChange.sql.

Let's say you are still working on other changes in V2 but there is a bug fix needed in V1 and you make a change with migration script V1__2020.02.05_090000__BugFix.sql.

In the same way branching and merging is done for source code files, you would have to update your V2 branch with this bug fix. Once you are happy, you merge back changes to the master branch.

In which order should the migration scripts be applied?

If only date/time is used, the scripts would be applied in the following order:

  1. V1__2020.01.01_100000__SmallChange.sql
  2. V2__2020.02.02_140000__BranchedChange.sql
  3. V1__2020.02.05_090000__BugFix.sql

However, the correct order is:

  1. V1__2020.01.01_100000__SmallChange.sql
  2. V1__2020.02.05_090000__BugFix.sql
  3. V2__2020.02.02_140000__BranchedChange.sql

To support such scenarios, {version} number is used.