How to Install Golang Migrate on Windows?
Last Updated :
31 Oct, 2022
Golang (also called Go language) is an open-source procedural language. It is designed by Robert Griesemer, Rob Pike, and Ken Thompson at Google. It was developed in 2007 and publicly announced in 2009. Golang is widely used in Google and many other open-source projects. Have a look at this article for more information about Golang Programming Language.
Golang Migrate
Golang Migrate is a Golang package that is used for handling database migrations. Golang database migrations are imported as libraries or used as CLI. Golang migrates reads migrations from the sources like (Filesystem, io/fs, GitHub, Google cloud storage, etc…) and applies them to the databases like (PGX, Redshift, MongoDB, MySQL, etc…). Databases don’t have self-thinking capacities as humans. If it’s incomplete or incorrect, it fails.
File Name Format
A migration is represented in 2 separate migration files, one is migrate up file, and another is migrate down file from sources like (Filesystem, io/fs, GitHub, etc…). Migrate up file migrate “up” from the previous version to the specified version.
{version}_{filename}.up.{extension}
Migrate down the file to migrate back “down” to the previous version.
{version}_{filename}.down.{extension}
The title of each migration is only for readability. The library doesn’t check the extension of the migration files. Use the appropriate format for the database (ex: .mongodb for MongoDB). Golang migrate CLI is a simple wrapper around the library; it doesn’t have any config search paths, config files, or magic ENV var injections, and it also has one of the best features ctrl + c (SIGINT). It is handled very efficiently.
Example:
$ migrate -source file://path/to/migrations -database postgres://localhost:8000/database up 5
If you want to run the first 5 migrations of your database and want to stop in the middle, send ctrl + c (SIGINT) the CLI will gracefully stop at a safe point.
Send SIGKILL for an immediate halt.
Installing Golang Migrate
Let’s install Golang Migrate now, but before that, make sure that you have GO installed on your PC. Check if you had GO installed on your PC. Run the following command in cmd to check that:
$ go version
If that shows an error or the go command is not recognized as internal or external, it means you don’t have GO installed on your PC. Also, if your version of GO is less than 1.15, follow this GFG article and install the latest version of GO: Install GO. Let’s start the process of installing GOLANG MIGRATE now,
Method 1: (Using Scoop)
Scoop is A command-line installer for Windows; this makes the installation of programs easy and fast. If you had installed it early, then jump to step 2. Else, don’t worry, it’s just 1 step process,
Step 1: Install Scoop: Open the Windows power shell on your PC, and run the following command to install SCOOP.
$ irm get.scoop.sh | iex
This shows that Scoop is installed successfully on your PC.
Step 2: Install Migrate: Open the Windows power shell on your PC, and run the following command to install MIGRATE.
$ scoop install migrate
Now you are all set to use MIGRATE for your database migrations.
Method 2: (Using Go Toolchain)
If you have git installed already on your PC, then proceed to Step 2. Else, follow the process in Step 1.
Step 1: Install GIT: If you don’t have git installed but Scoop installed on your PC, proceed to Step 1.2 or else follow Step 1.1.
- Install Scoop first following Method 1, Step 1.
- Open Windows PowerShell, using the following command to install git.
$ scoop install git
Step 2: Open Windows Powershell and run the following commands,
$ go get -u -d github.com/golang-migrate/migrate/cmd/migrate
While running the below command, go through your PC, find the path where it is located and run the command. It may be in a different drive or directory, so carefully check all possible directories with names related to GO. You can see the example from my commands. Use the ls command wherever it is necessary.
$ cd src/github.com/golang-migrate/migrate/cmd/migrate
Step 3: After running the above commands, run the following commands,
$ git checkout v4.15.2
We are using v4.15.2 here because it is the latest version.
$ go install
Check by running,
$ migrate -version
It should give output as v4.15.2.
Now you are all set to use MIGRATE for your database migrations.
Similar Reads
How to Install Golang Mockery on Windows?
Mockery is a Golang plugin that is used to perform unit tests since it has the ability to easily generate mocks for Golang interfaces using the stretch/testify/mock package. This article covers four different ways of installing and getting started with Golang mockery. These include: Installing throu
2 min read
How to Install Golang Migrate on Ubuntu?
Schema migration is an important activity when dealing with databases that we frequently have to perform during the application's life cycle to adapt to new business needs. Golang migrate is a tool which helps in this operation. Installing Golang Migrate on Ubuntu Step 1: Open the terminal for execu
1 min read
How to Install Go on Windows?
Prerequisite: Introduction to Go Programming Language Before, we start with the process of Installing Golang on our System. We must have first-hand knowledge of What the Go Language is and what it actually does? Go is an open-source and statically typed programming language developed in 2007 by Robe
3 min read
How to Install GNU Octave on Windows?
Octave is free and open source software. It features high level programming language and used for numerical computation with an interactive environment. It also features mathematics-oriented syntax with built-in plotting and visualization tools and also provides Octave syntax to solve problems every
3 min read
How to Install Git on Windows Command Line?
Git is an open-source and free, decentralized version control system designed to handle projects of all sizes with speed and efficiency. Basically, it is a software tracking application that is commonly used to monitor projects across several teams. The best way of downloading and installing Git on
3 min read
How to Install Geopandas on Windows?
Geopandas is a Python library used to add geographical data to pandas as an object. In this article, we will look into the process of installing Geopandas on a windows machine. Pre-requisites: The only thing that you need for installing Numpy on Windows are: Python PIP or Conda (depending upon user
2 min read
How to Install Nmap on Windows?
Nmap is computer software that is used to scan networks. It was developed by Gordon Lyon. It is written in C, C++, Python, and Lua. Its initial release was in 1997, and its stable release was in 2021. Its latest version is 7.92. It is free software used for security purposes of networks. It can be r
3 min read
How to Install Julia on Windows ?
Julia is a programming language used for statistical computations and data analysis. Julia is a combination of super-fast execution speed of C and flexible code writing of Python. Working with Julia is considered to be super fun and super easy among the Computer scientists and Software Engineers, be
3 min read
How to Install Krita on Windows?
Krita is a free and open-source raster graphics editor designed primarily for digital painting and 2D animation. It runs on Windows, macOS, Linux, Android, and Chrome OS. It is developed by Krita foundations. It is written in C++ using Qt. It is released on 21 June 2005. The size of the software is
3 min read
How to Download & Install NLTK on Windows?
NLTK is Natural Language Tool Kit. It is used to build python programming. It helps to work with human languages data. It gives a very easy user interface. It supports classification, steaming, tagging, etc. Installing NLTK on Windows using PIP: In windows, we first have to install the python curren
1 min read