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.

How to Install Golang Migrate on Windows?

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.

Similar Reads

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....

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:...

Contact Us