Sitemap

Dolt — Using SQL Database like Git

4 min readMar 7, 2021

--

For today I review about fundamental of Git again because I forgot some content like Merge vs Rebase, Git workflow, Worktree, etc. Suddenly I found keyword Git for Data, so I’d know what is difference with Git, so I learn and write in this blog.

What is Dolt?

Dolt is opensource SQL database. You can run base command like Git for manage your data, create new branch, checkout to it, insert new data, commit them, get log information, and diff changed data. They have private and public repository on Dolthub.

Get NB’s stories in your inbox

Join Medium for free to get updates from this writer.

In my opinion, it’s so familiar with Git, but doesn’t exactly the same, because it focus on the data. It’s work well with Public Data Source.

Use Case

  • For QA / tester, initial data set for test with SQL database in each branch such as data-set-for-integration-test, data-set-for-end-to-end-test. Switch branch into it when you need to test in difference data set.
  • For infrastrucutre, snapshot data with specific table. Export and import them when need, and track changed data by log time, commit hash.
  • For your teammate, you can share the data in your local machine with your team. Pull it in their machine, and merge your data with their data.

Dolt = Version Control of Data System

Press enter or click to view image in full size
Dolt Command in CLI
Press enter or click to view image in full size
When run command: dolt log

My Example

Create new database and table.

  • Database name: dolt_example
  • Table name: User (ID int)
Dolt Schema Show

Create new branch name

  • master
  • add-new-user
Dolt Example Branch

Insert new data into user table that data come from difference branch and merge them into master branch.

Press enter or click to view image in full size
Dolt SQL SELECT from user table

Insert new data (id = {6, 7, 8}) into user table and try to run data diff. You can run checkout for discard changes data if need.

Press enter or click to view image in full size
Dolt get status in master branch and diff user table

Run snapshot data into dolt database with mysql compatible server. the database can CRUD from other process.

Press enter or click to view image in full size
Dolt run mysql compatible server

Insert data (id = 9) from other process via mysql compatible server, and data change immediately.

Dolt diff after insert data from other process

Commit new data change for backup into data revision

Press enter or click to view image in full size

Export to sql command file for make sure data that should be backup

Dolt export table user into sql command file

Import data from SQL command file. They force to do with dolt sql command

Press enter or click to view image in full size

So I read file and send into stdin with pipe

Dolt import table

Remove table user and import from sql command and checkout from revision HEAD for move to before remove table

Press enter or click to view image in full size
Dolt remove table and checkout to revision HEAD

This tool is very useful when you use to the right work, also concept of Git is very nice, and show me that we can adapt it with other problem solver, and make our working life easier. Thanks my reader. See you next blog. :)

Reference

--

--