Litetree: Branchable SQLite Engine

Author: Shazin Sadakath


Relational Databases are the central source of truth in almost all of the applications that run nowadays. For this reason Relational Database are built on the ACID (Atomic, Consistent, Independent, Durable) principles. These provide very reliable and non corrupted data read and writes to applications. But during an upgrade or release of a new version of an application with database changes things can quickly go into chaotic mode.

This is because a feature we are introducing in a new version of the application may require to remove an existing column or alter the datatype of an existing column. The repercussions of this kind of change will only be visible during production and sometimes can bring down the entire application down.

Litetree solves this by providing branchable database engine for SQLite database similar to popular version control systems like Git!

It works by associating each database transaction to a commit id which is an incrementing number. For example consider an empty abc database. Executing the following command will keep it state commit id 1.

CREATE TABLE person(id INT, name VARCHAR(100))

Executing the following insert will change the state to commit id 2.

INSERT INTO person(id, name) VALUES(1, 'Shazin')

Executing another insert will change the state to commit id 3.

INSERT INTO person(id, name) VALUES(2, 'Shahim')

So now the database state can be visualized as following:

A new branch can be created with only the first insert (commit id 2) by using following command:

PRAGMA new_branch=develop at master.2

The above command will create the new branch from master's commit id 2 and will change to that branch. Any further commands will execute on this branch.

INSERT INTO person(id, name) VALUES(3, 'Shuhail')

Now the database will look the following:

 

For more information read the github page.



Tags: SQLite Litetree Branching Git Version
Views: 329
Register for more exciting articles

Comments

Please login or register to post a comment.


There are currently no comments.