| 365 | } |
| 366 | |
| 367 | func (s *SqliteMigrateSuite) TestSkipMigration(c *C) { |
| 368 | migrations := &MemoryMigrationSource{ |
| 369 | Migrations: []*Migration{ |
| 370 | { |
| 371 | Id: "1_create_table.sql", |
| 372 | Up: []string{"CREATE TABLE people (id int)"}, |
| 373 | Down: []string{"DROP TABLE people"}, |
| 374 | }, |
| 375 | { |
| 376 | Id: "2_alter_table.sql", |
| 377 | Up: []string{"ALTER TABLE people ADD COLUMN first_name text"}, |
| 378 | Down: []string{"SELECT 0"}, // Not really supported |
| 379 | }, |
| 380 | { |
| 381 | Id: "10_add_last_name.sql", |
| 382 | Up: []string{"ALTER TABLE people ADD COLUMN last_name text"}, |
| 383 | Down: []string{"ALTER TABLE people DROP COLUMN last_name"}, |
| 384 | }, |
| 385 | }, |
| 386 | } |
| 387 | n, err := SkipMax(s.Db, "sqlite3", migrations, Up, 0) |
| 388 | // there should be no errors |
| 389 | c.Assert(err, IsNil) |
| 390 | // we should have detected and skipped 3 migrations |
| 391 | c.Assert(n, Equals, 3) |
| 392 | // should not actually have the tables now since it was skipped |
| 393 | // so this query should fail |
| 394 | _, err = s.DbMap.Exec("SELECT * FROM people") |
| 395 | c.Assert(err, NotNil) |
| 396 | // run the migrations again, should execute none of them since we pegged the db level |
| 397 | // in the skip command |
| 398 | n2, err2 := Exec(s.Db, "sqlite3", migrations, Up) |
| 399 | // there should be no errors |
| 400 | c.Assert(err2, IsNil) |
| 401 | // we should not have executed any migrations |
| 402 | c.Assert(n2, Equals, 0) |
| 403 | } |
| 404 | |
| 405 | func (s *SqliteMigrateSuite) TestPlanMigrationWithHoles(c *C) { |
| 406 | up := "SELECT 0" |