MCPcopy
hub / github.com/rubenv/sql-migrate / TestMigrateDown

Method TestMigrateDown

migrate_test.go:232–269  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

230}
231
232func (s *SqliteMigrateSuite) TestMigrateDown(c *C) {
233 migrations := &FileMigrationSource{
234 Dir: "test-migrations",
235 }
236
237 n, err := Exec(s.Db, "sqlite3", migrations, Up)
238 c.Assert(err, IsNil)
239 c.Assert(n, Equals, 2)
240
241 // Has data
242 id, err := s.DbMap.SelectInt("SELECT id FROM people")
243 c.Assert(err, IsNil)
244 c.Assert(id, Equals, int64(1))
245
246 // Undo the last one
247 n, err = ExecMax(s.Db, "sqlite3", migrations, Down, 1)
248 c.Assert(err, IsNil)
249 c.Assert(n, Equals, 1)
250
251 // No more data
252 id, err = s.DbMap.SelectInt("SELECT COUNT(*) FROM people")
253 c.Assert(err, IsNil)
254 c.Assert(id, Equals, int64(0))
255
256 // Remove the table.
257 n, err = ExecMax(s.Db, "sqlite3", migrations, Down, 1)
258 c.Assert(err, IsNil)
259 c.Assert(n, Equals, 1)
260
261 // Cannot query it anymore
262 _, err = s.DbMap.SelectInt("SELECT COUNT(*) FROM people")
263 c.Assert(err, Not(IsNil))
264
265 // Nothing left to do.
266 n, err = ExecMax(s.Db, "sqlite3", migrations, Down, 1)
267 c.Assert(err, IsNil)
268 c.Assert(n, Equals, 0)
269}
270
271func (s *SqliteMigrateSuite) TestMigrateDownFull(c *C) {
272 migrations := &FileMigrationSource{

Callers

nothing calls this directly

Calls 2

ExecFunction · 0.85
ExecMaxFunction · 0.85

Tested by

no test coverage detected