Skip to content

Small migration package to run database queries when app starts

License

Notifications You must be signed in to change notification settings

deadkrolik/startup-migrator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Non deployment migration package

Introduction

When you write small golang application and don't need to have any deployment procedure you may also need to have specific database structure before run your application. This package is created to fit this need. You just describe sql-statements in the code and then run execution only once - before main code starts.

Code Samples

Here is a simple code:

package main

import (
	startupMigrator "github.com/deadkrolik/startup-migrator"
)

func loadMigrations() {
	dsn := "root:root@/test?charset=utf8"
	migrator, err := startupMigrator.GetMigrator("migrations", startupMigrator.GetEngineMysql(dsn))
	if err != nil {
		panic(err)
	}
	err = migrator.Run([]string{
		"CREATE TABLE test1 (id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY)",
		"CREATE TABLE test2 (id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY)",
	})
	if err != nil {
		panic(err)
	}
}

Installation

Run this command:

go get -u github.com/deadkrolik/startup-migrator

About

Small migration package to run database queries when app starts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages