blob: d24d1cde9067243193edd5773b796fe25759312b (
plain)
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
|
package main
import (
"os"
"strings"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/sqlite3"
"github.com/golang-migrate/migrate/v4/source/file"
"mokhan.ca/xlgmokha/idp/pkg/db"
"mokhan.ca/xlgmokha/idp/pkg/x"
)
func main() {
db := x.Must(db.New("file:db/development.db"))
defer db.Close()
instance := x.Must(sqlite3.WithInstance(db, &sqlite3.Config{}))
files := x.Must((&file.File{}).Open("./db/migrate"))
defer files.Close()
migrations := x.Must(migrate.NewWithInstance("file", files, "sqlite3", instance))
if len(os.Args) == 2 && strings.ToLower(os.Args[1]) == "down" {
x.Check(migrations.Down())
} else {
x.Check(migrations.Up())
}
}
|