github.com/tsmith1024/pop@v4.12.2+incompatible/migration.go (about)

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