github.com/deso-protocol/core@v1.2.9/scripts/migrate.go (about)

     1  package main
     2  
     3  import (
     4  	"log"
     5  	"os"
     6  
     7  	"github.com/deso-protocol/core/migrate"
     8  	"github.com/go-pg/pg/v10"
     9  	migrations "github.com/robinjoseph08/go-pg-migrations/v3"
    10  )
    11  
    12  const directory = "migrate"
    13  
    14  //
    15  // This file provides a database migration CLI. For example:
    16  //
    17  // Create a new migration: go run migrate.go create MyMigration
    18  // Migrate the database:   go run migrate.go migrate
    19  // Rollback the database:  go run migrate.go rollback
    20  //
    21  
    22  func main() {
    23  	migrate.LoadMigrations()
    24  
    25  	db := pg.Connect(&pg.Options{
    26  		Addr:     "localhost:5432",
    27  		User:     "admin",
    28  		Database: "admin",
    29  		Password: "",
    30  	})
    31  
    32  	err := migrations.Run(db, directory, os.Args)
    33  	if err != nil {
    34  		log.Fatalln(err)
    35  	}
    36  }