Documentation ¶
Index ¶
- Constants
- Variables
- func BuildTestConfigFile(base, driver string)
- func BuildTestingConnection(driver string) (*sql.DB, error)
- func ClearTestMigrations()
- func ClearTestTables(driver string)
- func CopyMigrationFilesTo(tempFolder string) []string
- func GenerateMigrationFile(mig TestMigration)
- func GenerateMigrationFiles(migs []TestMigration)
- func ReplaceInFile(file, base, replacement string)
- func SetupTestingFolders(driver string)
- func WriteTemplateToFile(path string, t *template.Template, data interface{}) (string, error)
- type TestConfig
- type TestMigration
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 ClearTestMigrations ¶
func ClearTestMigrations()
func ClearTestTables ¶
func ClearTestTables(driver string)
func CopyMigrationFilesTo ¶
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)
Types ¶
type TestConfig ¶
type TestMigration ¶
Click to show internal directories.
Click to hide internal directories.