-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathmigrate.go
More file actions
44 lines (36 loc) · 951 Bytes
/
migrate.go
File metadata and controls
44 lines (36 loc) · 951 Bytes
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 main
import (
"github.com/deso-protocol/core/lib"
"log"
"os"
"github.com/deso-protocol/core/migrate"
"github.com/go-pg/pg/v10"
migrations "github.com/robinjoseph08/go-pg-migrations/v3"
)
const directory = "migrate"
//
// This file provides a database migration CLI. For example:
//
// Create a new migration: go run migrate.go create MyMigration
// Migrate the database: go run migrate.go migrate
// Rollback the database: go run migrate.go rollback
//
func main() {
migrate.LoadMigrations()
// Default postgres connection options
pgOptions := &pg.Options{
Addr: "localhost:5432",
User: "admin",
Database: "admin",
Password: "",
}
// If set, use custom postgres connection options.
if len(os.Getenv("POSTGRES_URI")) > 0 {
pgOptions = lib.ParsePostgresURI(os.Getenv("POSTGRES_URI"))
}
db := pg.Connect(pgOptions)
err := migrations.Run(db, directory, os.Args)
if err != nil {
log.Fatalln(err)
}
}