Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

The Definitive Guide to Database Version Control — Part 5

DZone's Guide to

The Definitive Guide to Database Version Control — Part 5

We are now going through the most popular methods being used for creating software and the shortfalls of each. We will then reveal the correct way to practice database version control in order to maximize value and eliminate risk to the organization.

· Database Zone
Free Resource

Learn how to move from MongoDB to Couchbase Server for consistent high performance in distributed environments at any scale.

This is part five of a seven part series on database version control. In part one, two, three, and four, we reviewed how the methods for creating software evolved into Agile and DevOps, what separates the database from application code and the challenges that must be addressed when managing database changes.

We are now going through the most popular methods being used and the shortfalls of each. We will then reveal the correct way to practice database version control in order to maximize value and eliminate risk to the organization.

Another approach that is commonly used is to generate the database change script automatically by comparing the source environment (development) to the target environment (test, UAT, Production, etc.). This saves the developers and DBAs time because they don’t have to manually maintain the script, if it is a create script or an alter script for the release. Scripts can be generated when needed, and refer to the current structure of the target environment.

Let’s review the challenges and see if this approach overcomes them:

✔   Ensures all database code is covered – most compare & sync tools know how to handle the different database objects, but only a few have the functionality to handle the compare & sync of the reference data.

X   Ensures the version control repository can act as the single source of truth – simple compare & sync does not utilize the version control repository when performing the compare and generating the merge script.

✔   Ensures the deployment script being executed is aware of the environment status when the script is executing – the best practice is to generate the script just before executing it, so it will refer the current environment status.

X   Ensures the deployment script handles conflicts and merges them – simple compare & sync tools compare A to B (source to target). Based on the simple table at the left, the tool then generates a script to “upgrade” the target to match the source.

Without knowing the nature of the change, the wrong script can be generated. For example, there is an index in the target that was created from a different branch or critical fix. If this index does not exist in the source environment, what should the tool do? Drop the index? If there is an index in development, but not in production, was it added in development? Dropped in production? Using such a solution requires deep knowledge of each change to make sure they are handled properly.

X   Generates deployment scripts for only relevant changes – the compare & sync tools compare the entire schema and show the differences. They are not aware of the reason behind the changes, as this information is stored in the ALM, CMS, or version control repository, which is external to the compare & sync tool. You might get a lot of background noise, making it difficult to determine what you actually need to deal with.

✔   Ensures the deployment script is aware of the database dependencies – compare & sync tools are aware of database dependencies and generate the relevant DDLs, DCLs, and DMLs in the correct order. Not all compare & sync tools support generating a script that contains objects from several schemas.

Bottom line: compare & sync tools satisfy some of the must-have requirements, but fail to deal with others. Scripts must be manually reviewed, and cannot be trusted in an automated process.

In part six of the series, we will review the only fully automated method for managing the database, which involves utilizing a Database Enforced Change Management solution.

Want to deliver a whole new level of customer experience? Learn how to make your move from MongoDB to Couchbase Server.

Topics:
database ,version control ,script ,series

Published at DZone with permission of Yaniv Yehuda, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}