github.com/yuukihogo/migrate@v3.0.0+incompatible/migrate/v1compat.go (about) 1 // Deprecated: package migrate makes this version backwards compatible. 2 // Expect this to be removed very soon. 3 package migrate 4 5 import ( 6 "fmt" 7 8 "github.com/mattes/migrate" 9 "github.com/mattes/migrate/migrate/file" 10 ) 11 12 var deprecatedMessage = "" 13 14 func Up(pipe chan interface{}, url, migrationsPath string) { 15 m, err := migrate.New("file://"+migrationsPath, url) 16 if err != nil { 17 pipe <- err 18 return 19 } 20 21 if err := m.Up(); err != nil { 22 pipe <- err 23 } 24 } 25 26 func UpSync(url, migrationsPath string) (errs []error, ok bool) { 27 m, err := migrate.New("file://"+migrationsPath, url) 28 if err != nil { 29 return []error{err}, false 30 } 31 if err := m.Up(); err != nil { 32 return []error{err}, false 33 } 34 return nil, true 35 } 36 37 func Down(pipe chan interface{}, url, migrationsPath string) { 38 m, err := migrate.New("file://"+migrationsPath, url) 39 if err != nil { 40 pipe <- err 41 return 42 } 43 44 if err := m.Down(); err != nil { 45 pipe <- err 46 } 47 } 48 49 func DownSync(url, migrationsPath string) (errs []error, ok bool) { 50 m, err := migrate.New("file://"+migrationsPath, url) 51 if err != nil { 52 return []error{err}, false 53 } 54 if err := m.Down(); err != nil { 55 return []error{err}, false 56 } 57 return nil, true 58 } 59 60 func Redo(pipe chan interface{}, url, migrationsPath string) { 61 m, err := migrate.New("file://"+migrationsPath, url) 62 if err != nil { 63 pipe <- err 64 return 65 } 66 67 if err := m.Steps(-1); err != nil { 68 pipe <- err 69 return 70 } 71 72 if err := m.Steps(1); err != nil { 73 pipe <- err 74 } 75 } 76 77 func RedoSync(url, migrationsPath string) (errs []error, ok bool) { 78 m, err := migrate.New("file://"+migrationsPath, url) 79 if err != nil { 80 return []error{err}, false 81 } 82 if err := m.Steps(-1); err != nil { 83 return []error{err}, false 84 } 85 if err := m.Steps(1); err != nil { 86 return []error{err}, false 87 } 88 return nil, true 89 } 90 91 func Reset(pipe chan interface{}, url, migrationsPath string) { 92 m, err := migrate.New("file://"+migrationsPath, url) 93 if err != nil { 94 pipe <- err 95 return 96 } 97 98 if err := m.Drop(); err != nil { 99 pipe <- err 100 return 101 } 102 103 if err := m.Up(); err != nil { 104 pipe <- err 105 } 106 } 107 108 func ResetSync(url, migrationsPath string) (errs []error, ok bool) { 109 m, err := migrate.New("file://"+migrationsPath, url) 110 if err != nil { 111 return []error{err}, false 112 } 113 if err := m.Drop(); err != nil { 114 return []error{err}, false 115 } 116 if err := m.Up(); err != nil { 117 return []error{err}, false 118 } 119 return nil, true 120 } 121 122 func Migrate(pipe chan interface{}, url, migrationsPath string, relativeN int) { 123 m, err := migrate.New("file://"+migrationsPath, url) 124 if err != nil { 125 pipe <- err 126 return 127 } 128 129 if err := m.Steps(relativeN); err != nil { 130 pipe <- err 131 } 132 } 133 134 func MigrateSync(url, migrationsPath string, relativeN int) (errs []error, ok bool) { 135 m, err := migrate.New("file://"+migrationsPath, url) 136 if err != nil { 137 return []error{err}, false 138 } 139 if err := m.Steps(relativeN); err != nil { 140 return []error{err}, false 141 } 142 return nil, true 143 } 144 145 func Version(url, migrationsPath string) (version uint64, err error) { 146 m, err := migrate.New("file://"+migrationsPath, url) 147 if err != nil { 148 return 0, err 149 } 150 151 v, _, err := m.Version() 152 if err != nil { 153 return 0, err 154 } 155 return uint64(v), nil 156 } 157 158 func Create(url, migrationsPath, name string) (*file.MigrationFile, error) { 159 return nil, fmt.Errorf("You are using a deprecated version of migrate, update at https://github.com/mattes/migrate") 160 } 161 162 func NewPipe() chan interface{} { 163 return make(chan interface{}, 0) 164 } 165 166 func Graceful() {} 167 168 func NonGraceful() {}