github.com/duskeagle/pop@v4.10.1-0.20190417200916-92f2b794aab5+incompatible/migration.go (about)

     1  package pop
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  	"time"
     7  
     8  	"github.com/gobuffalo/makr"
     9  	"github.com/markbates/oncer"
    10  	"github.com/pkg/errors"
    11  )
    12  
    13  // MigrationCreate writes contents for a given migration in normalized files
    14  func MigrationCreate(path, name, ext string, up, down []byte) error {
    15  	g := makr.New()
    16  	n := time.Now().UTC()
    17  	s := n.Format("20060102150405")
    18  
    19  	upf := filepath.Join(path, fmt.Sprintf("%s_%s.up.%s", s, name, ext))
    20  	g.Add(makr.NewFile(upf, string(up)))
    21  
    22  	downf := filepath.Join(path, fmt.Sprintf("%s_%s.down.%s", s, name, ext))
    23  	g.Add(makr.NewFile(downf, string(down)))
    24  
    25  	return g.Run(".", makr.Data{})
    26  }
    27  
    28  // MigrateUp is deprecated, and will be removed in a future version. Use FileMigrator#Up instead.
    29  func (c *Connection) MigrateUp(path string) error {
    30  	oncer.Deprecate(0, "pop.Connection#MigrateUp", "Use pop.FileMigrator#Up instead.")
    31  
    32  	mig, err := NewFileMigrator(path, c)
    33  	if err != nil {
    34  		return errors.WithStack(err)
    35  	}
    36  	return mig.Up()
    37  }
    38  
    39  // MigrateDown is deprecated, and will be removed in a future version. Use FileMigrator#Down instead.
    40  func (c *Connection) MigrateDown(path string, step int) error {
    41  	oncer.Deprecate(0, "pop.Connection#MigrateDown", "Use pop.FileMigrator#Down instead.")
    42  
    43  	mig, err := NewFileMigrator(path, c)
    44  	if err != nil {
    45  		return errors.WithStack(err)
    46  	}
    47  	return mig.Down(step)
    48  }
    49  
    50  // MigrateStatus is deprecated, and will be removed in a future version. Use FileMigrator#Status instead.
    51  func (c *Connection) MigrateStatus(path string) error {
    52  	oncer.Deprecate(0, "pop.Connection#MigrateStatus", "Use pop.FileMigrator#Status instead.")
    53  
    54  	mig, err := NewFileMigrator(path, c)
    55  	if err != nil {
    56  		return errors.WithStack(err)
    57  	}
    58  	return mig.Status()
    59  }
    60  
    61  // MigrateReset is deprecated, and will be removed in a future version. Use FileMigrator#Reset instead.
    62  func (c *Connection) MigrateReset(path string) error {
    63  	oncer.Deprecate(0, "pop.Connection#MigrateReset", "Use pop.FileMigrator#Reset instead.")
    64  
    65  	mig, err := NewFileMigrator(path, c)
    66  	if err != nil {
    67  		return errors.WithStack(err)
    68  	}
    69  	return mig.Reset()
    70  }