Reputation: 386
I've got a git repository having such arborescence :
Files inside "data" are usually JSON files that are updated after some users actions on front side. When a file has been updated, I would like to commit & push it to have an history.
Is it a good idea to use git as a "database", in the same git repo than source code ? Maybe it would be cleaner to create a dedicated repo just for the data ?
I thought about this solution because my JSON files are small and not updated frequently. I think I would spend more time creating a database with MariaDB than just saving my data in a file. Also I need a historic, and I must have that files on 2 places (in case the main server crashes). The JSON files are independent and do not share the same data structure.
Upvotes: 1
Views: 1177
Reputation: 36
To answer your question : If you want to go with this method. i think it would be better to create a repo just for the 'data'. To reduce risk of conflicts when you are working on it while in production.
Then i don't think it is the best method:
There are some cons using this method:
If you plan to have a lot of commit by second, it is not the fastest way to do so, since git need to write the files to disk before doing the commit. If you work with many sub folder instead, you could maximize this limited commit by second. The reason is that when you create a commit, you have to copy the tree, make the change and then save the tree.
It can be problematic if users are allowed to read and write at the same time as it can cause conflicts. This can be fix by locking write/read in certain situation.
I read this article ( https://www.kenneth-truyers.net/2016/10/13/git-nosql-database/ ), wich show how to use git as a NoSql database, showing a lot of pros and cons and explain a lot of things about it. There is a lot of cons, and a lot of solution for those cons. But it seems out of the way to fix those, why not using a technology that do not require all these work around in the first place.
although i never used git that way, the fact that you need a lot of work around and setup for this, i think it is best to use a database rather than using git as a database. And for tracking your data, you could use a table, store the action, the information of the object, the date and time and the user who modified it, and then you have an history
Upvotes: 1