github.com/marinho/drone@v0.2.1-0.20140504195434-d3ba962e89a7/pkg/database/migrate/testing/revisions.go (about) 1 package migrate 2 3 import ( 4 . "github.com/drone/drone/pkg/database/migrate" 5 ) 6 7 type Sample struct { 8 ID int64 `meddler:"id,pk"` 9 Imel string `meddler:"imel"` 10 Name string `meddler:"name"` 11 } 12 13 type RenameSample struct { 14 ID int64 `meddler:"id,pk"` 15 Email string `meddler:"email"` 16 Name string `meddler:"name"` 17 } 18 19 type AddColumnSample struct { 20 ID int64 `meddler:"id,pk"` 21 Imel string `meddler:"imel"` 22 Name string `meddler:"name"` 23 Url string `meddler:"url"` 24 Num int64 `meddler:"num"` 25 } 26 27 // ---------- revision 1 28 29 type revision1 struct{} 30 31 func (r *revision1) Up(mg *MigrationDriver) error { 32 _, err := mg.CreateTable("samples", []string{ 33 mg.T.Integer("id", PRIMARYKEY, AUTOINCREMENT), 34 mg.T.String("imel", UNIQUE), 35 mg.T.String("name"), 36 }) 37 return err 38 } 39 40 func (r *revision1) Down(mg *MigrationDriver) error { 41 _, err := mg.DropTable("samples") 42 return err 43 } 44 45 func (r *revision1) Revision() int64 { 46 return 1 47 } 48 49 // ---------- end of revision 1 50 51 // ---------- revision 2 52 53 type revision2 struct{} 54 55 func (r *revision2) Up(mg *MigrationDriver) error { 56 _, err := mg.RenameTable("samples", "examples") 57 return err 58 } 59 60 func (r *revision2) Down(mg *MigrationDriver) error { 61 _, err := mg.RenameTable("examples", "samples") 62 return err 63 } 64 65 func (r *revision2) Revision() int64 { 66 return 2 67 } 68 69 // ---------- end of revision 2 70 71 // ---------- revision 3 72 73 type revision3 struct{} 74 75 func (r *revision3) Up(mg *MigrationDriver) error { 76 if _, err := mg.AddColumn("samples", "url VARCHAR(255)"); err != nil { 77 return err 78 } 79 _, err := mg.AddColumn("samples", "num INTEGER") 80 return err 81 } 82 83 func (r *revision3) Down(mg *MigrationDriver) error { 84 _, err := mg.DropColumns("samples", "num", "url") 85 return err 86 } 87 88 func (r *revision3) Revision() int64 { 89 return 3 90 } 91 92 // ---------- end of revision 3 93 94 // ---------- revision 4 95 96 type revision4 struct{} 97 98 func (r *revision4) Up(mg *MigrationDriver) error { 99 _, err := mg.RenameColumns("samples", map[string]string{ 100 "imel": "email", 101 }) 102 return err 103 } 104 105 func (r *revision4) Down(mg *MigrationDriver) error { 106 _, err := mg.RenameColumns("samples", map[string]string{ 107 "email": "imel", 108 }) 109 return err 110 } 111 112 func (r *revision4) Revision() int64 { 113 return 4 114 } 115 116 // ---------- end of revision 4 117 118 // ---------- revision 5 119 120 type revision5 struct{} 121 122 func (r *revision5) Up(mg *MigrationDriver) error { 123 _, err := mg.AddIndex("samples", []string{"url", "name"}) 124 return err 125 } 126 127 func (r *revision5) Down(mg *MigrationDriver) error { 128 _, err := mg.DropIndex("samples", []string{"url", "name"}) 129 return err 130 } 131 132 func (r *revision5) Revision() int64 { 133 return 5 134 } 135 136 // ---------- end of revision 5 137 138 // ---------- revision 6 139 type revision6 struct{} 140 141 func (r *revision6) Up(mg *MigrationDriver) error { 142 _, err := mg.RenameColumns("samples", map[string]string{ 143 "url": "host", 144 }) 145 return err 146 } 147 148 func (r *revision6) Down(mg *MigrationDriver) error { 149 _, err := mg.RenameColumns("samples", map[string]string{ 150 "host": "url", 151 }) 152 return err 153 } 154 155 func (r *revision6) Revision() int64 { 156 return 6 157 } 158 159 // ---------- end of revision 6 160 161 // ---------- revision 7 162 type revision7 struct{} 163 164 func (r *revision7) Up(mg *MigrationDriver) error { 165 _, err := mg.DropColumns("samples", "host", "num") 166 return err 167 } 168 169 func (r *revision7) Down(mg *MigrationDriver) error { 170 if _, err := mg.AddColumn("samples", "host VARCHAR(255)"); err != nil { 171 return err 172 } 173 _, err := mg.AddColumn("samples", "num INSTEGER") 174 return err 175 } 176 177 func (r *revision7) Revision() int64 { 178 return 7 179 } 180 181 // ---------- end of revision 7 182 183 // ---------- revision 8 184 type revision8 struct{} 185 186 func (r *revision8) Up(mg *MigrationDriver) error { 187 if _, err := mg.AddColumn("samples", "repo_id INTEGER"); err != nil { 188 return err 189 } 190 _, err := mg.AddColumn("samples", "repo VARCHAR(255)") 191 return err 192 } 193 194 func (r *revision8) Down(mg *MigrationDriver) error { 195 _, err := mg.DropColumns("samples", "repo", "repo_id") 196 return err 197 } 198 199 func (r *revision8) Revision() int64 { 200 return 8 201 } 202 203 // ---------- end of revision 8 204 205 // ---------- revision 9 206 type revision9 struct{} 207 208 func (r *revision9) Up(mg *MigrationDriver) error { 209 _, err := mg.RenameColumns("samples", map[string]string{ 210 "repo": "repository", 211 }) 212 return err 213 } 214 215 func (r *revision9) Down(mg *MigrationDriver) error { 216 _, err := mg.RenameColumns("samples", map[string]string{ 217 "repository": "repo", 218 }) 219 return err 220 } 221 222 func (r *revision9) Revision() int64 { 223 return 9 224 } 225 226 // ---------- end of revision 9 227 228 // ---------- revision 10 229 230 type revision10 struct{} 231 232 func (r *revision10) Revision() int64 { 233 return 10 234 } 235 236 func (r *revision10) Up(mg *MigrationDriver) error { 237 _, err := mg.ChangeColumn("samples", "email", "varchar(512) UNIQUE") 238 return err 239 } 240 241 func (r *revision10) Down(mg *MigrationDriver) error { 242 _, err := mg.ChangeColumn("samples", "email", "varchar(255) unique") 243 return err 244 } 245 246 // ---------- end of revision 10