Here is the number one question I receive from PL/SQL developers, DBA’s and IT managers who are implementing a version control solution for their Oracle Database:

Developer 1 (or Team 1) works on Feature A (or issue A, bug A, project A). Developer 2 works on Feature B. Both developers make many changes to the PL/SQL code and many commits to the version control repository. We move to testing. Based on the test results, even more commits are made by both developers. Now at the last minute, due to some reason (a last minute bug, a tactical change in direction, a change in strategy etc…) we decide to ship Feature B only. How can we remove Feature A from the source code easily? How does version control help in such a situation?

There are multiple answers to this question. Below, I’ll go over two possible solutions for two potential setups:

If You Are Using One Shared Development Database

Let’s assume that our shared development database is called DEV. In other words, both Feature A and Feature B are being developed in the same code base. Let’s also assume our only test database is called TEST.

Finally, assume that DEV is managed by Gitora DEV and TEST is managed by Gitora TEST.

In this case, the commit history in Gitora DEV has changes both for Feature A and B in a random order and looks something like this:

There is no easy way to remove the commits for Feature B in this setup. If the team decides to deliver Feature A to production but postpone the delivery of Feature B here are the steps they should follow:

Go over the commit history in Gitora DEV and find the commits that are related to Feature A.

Comment out/revert back/change the edits made for Feature A. Git will help the developers to see what’s changed, added, deleted and what the previous versions of code objects looked like.

Commit these new changes to Gitora DEV.

At this point the commit history in Gitora DEV looks something like this:

And finally, the next steps are:

Pull the new version from DEV to TEST using Gitora TEST.

Run tests on the TEST database. If there are no errors, deliver the new version to production. If there are errors, go to the second step, rinse and repeat until the desired outcome is reached.

In such a setup Gitora provides the following benefits:

Gitora keeps track of all changes made to the PL/SQL code in DEV, automatically. Developer 2 does not have to remember which PL/SQL objects she modified and what she modified in those objects.

Moving the code between DEV and TEST is as easy as clicking a button or making a PL/SQL function call. The team does not need to manually prepare scripts.

The downside of this approach is that it involves manual work which is error prone. Developer 2 still has to manually go through the commit history and make the changes to the source code in DEV to disable/remove Feature A. With only one shared development database ( i.e. development environment), there is no feasible way to easily remove Feature A.

If You Are Using Multiple Development Databases

Now things get more interesting. Below is a simplified workflow that uses only two development databases. This setup enables the IT team to deliver only Feature B to deployment without manually editing PL/SQL code objects to remove Feature A. (Obviously, giving each developer her own development environment is ideal but I understand that this might not be possible on day one in many IT departments. With that said, the PDB feature in Oracle 12c makes giving each developer her own environment much easier than before.)

Here is our initial set up:

Developer 1 works in the database DEV1 and Developer 2 works in the database DEV2 i.e. both developers (teams) have their own private environment while they are developing their respective features.

Our only test database is called TEST.

DEV1 is managed by Gitora DEV1, DEV2 is managed by Gitora DEV2 and TEST is managed by Gitora TEST.

DEV1, DEV2 and TEST start with the same version of the code which is stored in the master branch of their respective Git repositories. (In other words, DEV1/master and DEV2/master are clones of TEST/master)

Developer 1:

Using Gitora on DEV1, create a new branch named featureA (DEV1/featureA). Switch DEV1 to use this new branch.

Write code in DEV1

Test code in DEV1

Commit code changes to the DEV1/featureA (using Gitora DEV1). Go back to step 2 as many times as needed.

As an example, the Git history in Gitora DEV1 looks like this:

Developer 2:

Using Gitora DEV2, create new branch named featureB (DEV2/featureB). Switch DEV2 to use this new branch.

Write code in DEV2

Test code in DEV2

Commit code changes to the repository to DEV2/featureB (using Gitora DEV2). Go back to step 2 as many times as needed.

The Git commit history in Gitora DEV2 looks like this:

Moving Code Between Databases

At any point in time, if Developer 1 or Developer 2 decides to send code to TEST (for example, for integration testing purposes..), they follow the steps below.

Please note that in real world development, the workflows described below can be performed simultaneously in DEV1 and DEV2, in no particular order, any number of times until both features are ready to be deployed to production.

The steps below are merely a simplified example of how this workflow can take place.

Developer 1:

In our example , we assume that Developer 1 is the first developer sending her commits to TEST.

Using Gitora DEV1, merge DEV1/featureA to DEV1/master. (DEV1/featureA –> DEV1/master) In our workflow, as a general rule merges to the master branch are performed in the development database repositories not in the TEST database.)

After the merge, commit history in Gitora DEV1 looks like this:

Pull master branch from Gitora DEV1 to Gitora TEST. (DEV1/master –> TEST/master). A “Pull” is simply a two step process of fetching a branch from a remote Git repository and then merging it to another local branch. In our example Gitora TEST fetches DEV1/master from Gitora DEV1 and merges it to TEST/master which we simply show as DEV1/master –> TEST/master.

After the pull, commit history of both TEST and DEV1 looks like this:

Developer 2:

Pull master branch from Gitora TEST to the master branch in Gitora DEV2. (TEST/master –> DEV2/master). (In our example, this is necessary, because TEST/master has received new commits from DEV1/master.) After the pull, the commit history looks like this: (Remember, previously we pulled commits from DEV1/master to TEST/master and we also made commits to DEV2/featureB)

Using Gitora DEV2, merge DEV2/featureB to DEV2/master. (DEV2/featureB –> DEV2/master) After the merge, the commit history looks like this:

Using Gitora TEST, pull master branch from Gitora DEV2 to Gitora TEST. (DEV2/master –> TEST/master). After the pull, the commit history looks like this:

In other words, in its final state, the source code in the TEST database is a merge of Feature A and B where the commits in TEST/master branch are in a random order. In our example, the full commit history of DEV1, DEV2 and TEST repositories look like this:

Note that at all times, DEV1/featureA only contains the code for Feature A. Similarly, DEV2/featureB only contains the code for Feature B.

This workflow enables the IT team to exclude Feature A from the next deployment using Git commands at any point in time before going production.

To achieve this in our example, follow the steps below using Gitora:

Revert DEV2/master back to its initial state where no code for Feature B has been committed yet. (This uses the Git reset command.)

Merge DEV2/featureB to DEV2/master. (DEV2/featureB –> DEV2/master)

Reset TEST/master to its original state.

Finally, pull master branch of DEV2 to the master branch of TEST. (DEV2/master –> TEST/master)

After these steps are completed, the TEST database only contains code changes related to Feature B. We can use Gitora to extract a DDL script which contains only the changes made between the initial and final state of TEST/master and use this script to deploy Feature B.

You can also watch the video tutorial for this workflow below: (The only difference is that in the video the TEST database is called PREPROD.)

Gitora helps developers execute this workflow with a point&click GUI and PL/SQL API’s. Specifically:

Gitora keeps track of all changes made to the PL/SQL code in DEV1, DEV2 and TEST automatically.

Gitora updates the source code in the Oracle Database automatically when the executed Git command changes the files in the working directory.

Therefore:

Developers don’t have to remember which PL/SQL objects they modified and what they modified in those objects.

Moving the code between DEV1, DEV2 and TEST is as easy as clicking a button or making an PL/SQL function call. The team does not need to manually prepare scripts. Gitora can either generate the scripts or update the databases automatically.

Crucially, Gitora enables Developer 1 and Developer 2 switch between code branches automatically. (For example if the DEV1 database switches from featureA branch to the master branch, Gitora automatically updates the code in the DEV1 database to reflect this change.)

Download Gitora now and try this workflow in your environment.

Yalim K. Gerger

Founder