-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathcreate.go
44 lines (33 loc) · 807 Bytes
/
create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package migrations
import (
"fmt"
"os"
"path"
"time"
)
const timeFormat = "20060102150405"
var template = `package main
import (
"github.com/go-pg/pg/v10/orm"
migrations "github.com/robinjoseph08/go-pg-migrations/v3"
)
func init() {
up := func(db orm.DB) error {
_, err := db.Exec("")
return err
}
down := func(db orm.DB) error {
_, err := db.Exec("")
return err
}
opts := migrations.MigrationOptions{}
migrations.Register("%s", up, down, opts)
}
`
func (m *migrator) create(directory, name string) error {
version := time.Now().UTC().Format(timeFormat)
fullname := fmt.Sprintf("%s_%s", version, name)
filename := path.Join(directory, fullname+".go")
fmt.Printf("Creating %s...\n", filename)
return os.WriteFile(filename, []byte(fmt.Sprintf(template, fullname)), 0644)
}