Martin
Martin

Reputation: 9369

How to use Databases concurrently with Git (or à la Git)

We currently use JSON files to store data required to configure a system. We use Git as versioning system.

We populate these JSON's manually from time to time: we use to concurrently modify the text, for example, by adding new elements in arrays and by committing the changes to Git. Also because JSON's are in plain text, Git makes it easy for us to rebase, create or review any merge requests before approving the commits.

However, we are essentially using these JSONs as database for all our configurations. We think it's not the best option. For example, there are plenty of integrity constraints between the (elements in the) structures defined in these JSON's which are not evident and cannot be enforced in any way. As you can imagine, it's easy to forget, violate or break things when you add new elements.

These structures and relationship between them could be easily modelled in terms of tables, primary and foreign keys, for example. For this reason, we think we might get some advantages with using a real a relational database, but we strongly want to achieve the following goals:

  1. it must still be possible to automatically produce JSON's from the DB instance (to configure the system)
  2. we want to integrate Git with the concurrent use of the DB somehow - or ideally speaking, we would like to have the possibility to easily create branches of instances, create merge requests, let others review differences differences between branches and finally approve them.

Do you know any good strategy or have any advices for the above requirements? Is there any specific tool for the above questions (especially question 2)? Has this kind of problems ever been faced with some technologies? Any suggestion to make the whole development flow safer and easy will be strongly appreciated.

Upvotes: 1

Views: 49

Answers (1)

CL.
CL.

Reputation: 180210

Just store the database as plain text:

$ sqlite3 config.db .dump > config.db.sql
$ cat config.db.sql
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE Users(name primary key);
INSERT INTO "Users" VALUES('me');
INSERT INTO "Users" VALUES('you');
INSERT INTO "Users" VALUES('somebody');
CREATE TABLE Config(name, value, user references Users(name));
INSERT INTO "Config" VALUES('EnableBugs',0,NULL);
INSERT INTO "Config" VALUES('EnableBugs',1,'you');
INSERT INTO "Config" VALUES('BackgroundColor','#000000','me');
INSERT INTO "Config" VALUES('BackgroundColor','#ffffff','somebody');
INSERT INTO "Config" VALUES('BackgroundColor','#808080','you');
COMMIT;

Upvotes: 1

Related Questions