utils

package
v0.0.0-...-3568023 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2016 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const MigrationTemplate = `` /* 412-byte string literal not displayed */

MigrationTemplate is the template for the generation of the migrations.

Variables

View Source
var DownFlagsTemplate = template.Must(template.New("up.main.template").Parse(`
package main

import (
	"log"
	transporter "github.com/wawandco/transporter/core"
)

func main() {
	databaseURL := "{{.DatabaseURL}}"
	databaseDriver := "{{.DatabaseDriver}}"
	
	log.Println("| Running Migrations Down")
	db, err := transporter.DBConnectionWith( databaseURL, databaseDriver )

	if err != nil {
		log.Println("Could not init database connection:", err)
		return
	}

	defer db.Close()
	transporter.RunOneMigrationDown(db)
}
`))

UpTemplate is the template for the Main when cmd.Up runs.

View Source
var DownTemplate = template.Must(template.New("down.main.template").Parse(`
package main

import (
	"log"
	"path/filepath"
	transporter "github.com/wawandco/transporter/core"
	"io/ioutil"
)

func main() {
	log.Println("| Running Migrations Down on [{{.Environment}}] environment")
	dat, _ := ioutil.ReadFile(filepath.Join("{{.TempDir}}","config.yml"))
	db, err := transporter.DBConnection(dat, "{{.Environment}}")

	if err != nil {
		log.Println("Could not init database connection:", err)
		return
	}

	defer db.Close()
	transporter.RunOneMigrationDown(db)
}
`))

DownTemplate is the template for the main.go file when running Down cmd.

View Source
var UpFlagsTemplate = template.Must(template.New("up.flags.template").Parse(`
package main

import (
	"log"
	transporter "github.com/wawandco/transporter/core"
)

func main() {
	databaseURL := "{{.DatabaseURL}}"
	databaseDriver := "{{.DatabaseDriver}}"
	
	log.Println("| Running Migrations UP")
	db, err := transporter.DBConnectionWith( databaseURL, databaseDriver )

	if err != nil {
		log.Println("Could not init database connection:", err)
		return
	}

	defer db.Close()
	transporter.RunAllMigrationsUp(db)
}
`))
View Source
var UpTemplate = template.Must(template.New("up.main.template").Parse(`
package main

import (
	"log"
	"path/filepath"
	transporter "github.com/wawandco/transporter/core"
	"io/ioutil"
)

func main() {
	log.Println("| Running Migrations UP on [{{.Environment}}] environment")
	dat, _ := ioutil.ReadFile(filepath.Join("{{.TempDir}}","config.yml"))
	db, err := transporter.DBConnection(dat, "{{.Environment}}")

	if err != nil {
		log.Println("Could not init database connection:", err)
		return
	}

	defer db.Close()
	transporter.RunAllMigrationsUp(db)
}
`))

UpTemplate is the template for the Main when cmd.Up runs.

Functions

func BuildTestConfigFile

func BuildTestConfigFile(base, driver string)

func BuildTestingConnection

func BuildTestingConnection(driver string) (*sql.DB, error)

func ClearTestMigrations

func ClearTestMigrations()

func ClearTestTables

func ClearTestTables(driver string)

func CopyMigrationFilesTo

func CopyMigrationFilesTo(tempFolder string) []string

CopyMigrationFilesTo copies the migration files into a specific folder, this is useful to run the Up and Down commands.

func GenerateMigrationFile

func GenerateMigrationFile(mig TestMigration)

func GenerateMigrationFiles

func GenerateMigrationFiles(migs []TestMigration)

func ReplaceInFile

func ReplaceInFile(file, base, replacement string)

ReplaceInFile Replaces a text inside a file, this is usefull to replace the migrations package for the main when copying the sources to run Up and Down.

func SetupTestingFolders

func SetupTestingFolders(driver string)

func WriteTemplateToFile

func WriteTemplateToFile(path string, t *template.Template, data interface{}) (string, error)

WriteTemplateToFile writes a template result to a file.

Types

type TestConfig

type TestConfig map[string]map[string]string

type TestMigration

type TestMigration struct {
	Identifier  int64
	UpCommand   string
	DownCommand string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL