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