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:
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 schema in a single database
- If you are using multiple development schemas in a single database (or at least if you are open to the idea.)
If You Are Using One Shared Development Schema
Let’s assume that our development database is called DEV and the shared development schema in DEV is called HR. In other words, both Feature A and Feature B are being developed in the same code base. Let’s also assume that there is no other database for testing. We test in DEV in the schema called HR_TEST.
Assume that HR and HR_TEST schemas are managed by two Gitora single schema repos (SSR) repos named HR_REPO and HR_TEST_REPO, respectively.
In this case, the commit history in HR_REPO 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 HR_REPO 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 HR_REPO.
At this point the commit history in HR_REPO looks something like this:
And finally, the next steps are:
- Pull the new version from HR_REPO to HR_TEST_REPO using Gitora.
- Run tests on the HR_TEST schema. 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 the HR schema, 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 HR and HR_TEST schemas is as easy as clicking a button. 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 the HR schema to disable/remove Feature A. With only one shared development database ( i.e. development environment), there is no easy way to remove Feature A.
If You Are Using Multiple Development Schemas
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.
Here is our initial set up:
- Developer 1 works in the schema HR_DEV1 schema and Developer 2 works in the HR_DEV2 schema i.e. both developers (teams) have their own private schemas while they are developing their respective features.
- Our only test schema is in the same database and is called HR_TEST.
- HR_DEV1 is schema managed by Gitora single schema repo DEV1, HR_DEV2 is managed by Gitora SSR DEV2 and the HR_TEST is managed by Gitora SSR TEST.
- DEV1, DEV2 and TEST repos start with the same version of the code which is stored in their master branch.(In other words, DEV1/master and DEV2/master are clones of TEST/master)
Obviously, all Git operations mentioned below are executed using Gitora. Gitora takes care of updating the database code after a Git command is executed.
- Using Gitora, create a new branch named featureA (DEV1/featureA). Switch DEV1 to use this new branch.
- Write code in DEV1.
- Commit code changes to the DEV1/featureA (using Gitora). Go back to step 2 as many times as needed.
As an example, the commit history of DEV1 looks like this:
- Create new branch named featureB (DEV2/featureB). Switch DEV2 to use this new branch.
- Write code in DEV2.
- Commit code changes to the repository to DEV2/featureB (using Gitora). Go back to step 2 as many times as needed.
The Git commit history in Gitora DEV2 looks like this:
Moving Code Between Schemas
At any point in time, if Developer 1 or Developer 2 decides to send code to the HR_TEST schema (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 repos, 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 takes place.
- In our example , we assume that Developer 1 is the first developer sending her commits to the HR_TEST schema.
- Merge DEV1/featureA to DEV1/master. (DEV1/featureA –> DEV1/master)
After the merge, commit history in DEV1 looks like this:
- Pull master branch from DEV1 to 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 a local branch. In our example TEST fetches DEV1/master from the DEV1 repo 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:
Now it is time for Developer 2 to send her changes to the HR_TEST schema. She does the following steps:
- Pull master branch from the TEST repo to the master branch in 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)
- Merge DEV2/featureB to DEV2/master. (DEV2/featureB –> DEV2/master) After the merge, the commit history looks like this:
- Pull master branch from the DEV2 repo to the TEST repo. (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 HR_TEST schema (and in the TEST repo) is a merge of Feature A and B. 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.
Removing Feature A from the Deployment
This workflow enables the IT team to exclude Feature A from the next version of the software at any point in time before deploying it to the production environment.
To exclude Feature A from the deployment in the example above, follow the steps below:
- 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 HR_TEST schema only contains code changes related to Feature B. We can use Gitora to extract a DDL script from HR_TEST which contains only the changes made between the initial and final state of TEST/master and use this script to deploy Feature B to the production environment.
Gitora helps developers execute this workflow with a point&click GUI:
- Gitora keeps track of all changes made to the PL/SQL code in HR_DEV1, HR_DEV2 and HR_TEST schemas automatically.
- Gitora updates the source code in the Oracle Database automatically when the executed Git command changes the files in a Git working directory.
- Developers don’t have to remember which PL/SQL objects they modified and what they modified in those objects.
- Moving the code between HR_DEV1, HR_DEV2 and HR_TEST is as easy as clicking a button. 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 to switch between code branches automatically. (For example if the DEV1 repo switches its active branch from featureA to the master branch, Gitora automatically updates the code in the HR_DEV1 schema to reflect this change.)
Download Gitora now and try this workflow in your environment.