initial commit

This commit is contained in:
dhax 2017-09-25 18:23:11 +02:00
commit 93d8310491
46 changed files with 3379 additions and 0 deletions

View file

@ -0,0 +1,48 @@
package migrate
import (
"fmt"
"github.com/go-pg/migrations"
)
const bootstrapAdminAccount = `
INSERT INTO accounts (id, email, name, active, roles)
VALUES (DEFAULT, 'admin@boot.io', 'Admin Boot', true, '{admin}')
`
const bootstrapUserAccount = `
INSERT INTO accounts (id, email, name, active)
VALUES (DEFAULT, 'user@boot.io', 'User Boot', true)
`
func init() {
up := []string{
bootstrapAdminAccount,
bootstrapUserAccount,
}
down := []string{
`TRUNCATE accounts CASCADE`,
}
migrations.Register(func(db migrations.DB) error {
fmt.Println("add bootstrap accounts")
for _, q := range up {
_, err := db.Exec(q)
if err != nil {
return err
}
}
return nil
}, func(db migrations.DB) error {
fmt.Println("truncate accounts cascading")
for _, q := range down {
_, err := db.Exec(q)
if err != nil {
return err
}
}
return nil
})
}