A database migration tool written in Golang
./GoMigrate -o=create -n=my-new-migration-file(If you're using the executable file)go run ./ -o=create -n=my-new-migration-file(If you cloned this repo and are running it inside the project folder)
- Download the GoMigrate executable file in this repo and add it in your project folder.
- If you would like to build the executable file yourself, clone this repo and run
go build -o=GoMigratethen copy and paste the created executable file in your project folder. - Setup the following environment variables in your project. You can reference the sample.env file.
DB_USER=your_database_usernameDB_PASSWORD=your_database_passwordDB_NAME=your_database_nameDB_HOST=your_database_host_nameDB_PORT=your_database_portMIGRATION_FOLDER_PATH=folder_to_store_all_migrationsMIGRATION_TEMPLATE_NAME=your_migration_template_nameplease use the templates/migration-template.go filePLUGIN_FOLDER_PATH=folder_to_store_all_migration_pluginsTEMPLATE_FOLDER_PATH=folder_where_the_migration_template_is_stored
- -o: (Required) To set the operation to perform. Values that can be parsed are:
c or createto create a new migration filer or runto run a migration file or run all migration filesu or undoto undo migration file(s)
- -n: To set the name of the file
- Run
./GoMigrate -o=create -n=my-new-migration-file. A new go file will be created inside the migrations folder - Open the newly created migration file to edit the queries
- Run
./GoMigrate -o=run -n=my-migration-fileto migrate a single file - Run
./GoMigrate -o=runto migrate all files
- Run
./GoMigrate -o=undo -n=my-migration-fileto undo up to a specific migration file - Run
./GoMigrate -o=undoto undo all migrations