DoltHUb Version Control Git for Database

Nowadays database versioning is an important part of development.  To manage the projects and work parallel with a number of developers, the database version control system is safe to deploy projects live.

Dolthub database git

To version control, numbers of software are available in the market but we mostly used DOLTHUB that we are using mostly.

Below you will get a list of command prompt commands to execute a number of processes. These processes you can set with the docker and make the automated processes as you want to perform.

DOLTHUB Commands and Actions

  • First, you need to install the dolthub msi file for windows system and then open command prompt to run below command:
$ dolt init

This command will initialize the dolthub on your working folder to perform actions.

  • If you get username and email error than use below command
$ dolt --config  --add user.name victor

$ dolt --config --add user.email victor@gexp.com
  • Now again run dolt init command and it will give you success message on your board.
  • Now make database as origin with below command:
$ dolt remote add origin victorusernameofdolt/databasename
  • To push data into repository use below command:
$ dolt push origin master
  • You can make directory using below command to connect folder:
$ mkdir dolthub
$ cd dolthub
  • Add table into dolt database (perform SQL)
$ dolt sql -q “create table populations ( state varchar(14), population int, primary key (state) )”
  • To add changes use below adds command:
$ dolt add .
  • Now use commit for add changes using below command:
$ dolt commit –m “database changes has been added”
  • To show table use below command:
$ dolt sql -q "show tables"
  • To insert records into table use below command:
$ dolt sql -q "insert into populations (state, population) values ('Delaware', 59096), ('Maryland', 319728), ('Tennessee', 35691), ('Virginia', 691937), ('Connecticut', 237946), ('Massachusetts', 378787), ('South Carolina', 249073), ('New Hampshire', 141885), ('New York', 340120), ('New Jersey', 184139), ('North Carolina', 393751), ('Maine', 96540), ('Rhode Island', 68825)"
  • To select the value by name from table use below command:
$ dolt sql -q "select * from populations where state = 'New York'"
  • Now you need to find out changes you have done and this will be find by below command:
$ dolt diff
  • If you want to see commit log then you need to use below command to find the log of your changes and commit:
$ dolt log
  • To import the data you can use below two commands, one for import data into existing table (-u) and another one for create new table and then import (-c).
$ dolt table import -c -pk=state populations data.csv

$ dolt table import -u -pk=state populations data.csv
  • To switch the branch use below command:
$ dolt checkout –b login

$ dolt checkout master
  • To merge the login branch into master branch you need to checkout with master branch and then use below command:
$ dolt merge login
  • Now before using remote dolthub you need to login with dolthub account using below command otherwise it will give you permission error:
$ dolt login
  • To work with remote server you need to use below command to connect and make origin repository.
$ dolt remote add origin myname/myRepo

$ dolt remote add origin https://doltremoteapi.dolthub.com/yournamedoltuhub/databasename
  • TO push the current database into the origin server you can use below command:
$ dolt push origin yournamedoltuhub/databasename 
$ dolt push origin master 
  • If you are getting “common ancestor” error pushing the data from local to dolthub then use below command to solve the issue:
$ dolt push -f origin master
  • To start sql server you need to use the below command:
$ dolt sql-server
  • To remove current origin, you need to use below command:
$ dolt remote remove origin

Hope this guide will help you to manage the database of your project and allow multiple users to manage work on it to complete on time. The database versioning allows helping you to revert the changes of the database immediately that is not belong to you and save you from hack codes.

We are looking into a more tutorial that will work for you to increase your business or jobs growth. To get more recent updates join us on the telegram channel or more social network channels.

Stay in touch. Ask Questions.
Lean on us for help, strategies and expertise.

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe CodeMeta To Learn Next Level Programming Knowledge

X