(c *C)
| 578 | } |
| 579 | |
| 580 | func (s *SqliteMigrateSuite) TestPlanMigrationToVersion(c *C) { |
| 581 | migrations := &MemoryMigrationSource{ |
| 582 | Migrations: []*Migration{ |
| 583 | { |
| 584 | Id: "1_create_table.sql", |
| 585 | Up: []string{"CREATE TABLE people (id int)"}, |
| 586 | Down: []string{"DROP TABLE people"}, |
| 587 | }, |
| 588 | { |
| 589 | Id: "2_alter_table.sql", |
| 590 | Up: []string{"ALTER TABLE people ADD COLUMN first_name text"}, |
| 591 | Down: []string{"SELECT 0"}, // Not really supported |
| 592 | }, |
| 593 | { |
| 594 | Id: "10_add_last_name.sql", |
| 595 | Up: []string{"ALTER TABLE people ADD COLUMN last_name text"}, |
| 596 | Down: []string{"ALTER TABLE people DROP COLUMN last_name"}, |
| 597 | }, |
| 598 | }, |
| 599 | } |
| 600 | n, err := Exec(s.Db, "sqlite3", migrations, Up) |
| 601 | c.Assert(err, IsNil) |
| 602 | c.Assert(n, Equals, 3) |
| 603 | |
| 604 | migrations.Migrations = append(migrations.Migrations, &Migration{ |
| 605 | Id: "11_add_middle_name.sql", |
| 606 | Up: []string{"ALTER TABLE people ADD COLUMN middle_name text"}, |
| 607 | Down: []string{"ALTER TABLE people DROP COLUMN middle_name"}, |
| 608 | }) |
| 609 | |
| 610 | plannedMigrations, _, err := PlanMigrationToVersion(s.Db, "sqlite3", migrations, Up, 11) |
| 611 | c.Assert(err, IsNil) |
| 612 | c.Assert(plannedMigrations, HasLen, 1) |
| 613 | c.Assert(plannedMigrations[0].Migration, Equals, migrations.Migrations[3]) |
| 614 | |
| 615 | plannedMigrations, _, err = PlanMigrationToVersion(s.Db, "sqlite3", migrations, Down, 1) |
| 616 | c.Assert(err, IsNil) |
| 617 | c.Assert(plannedMigrations, HasLen, 3) |
| 618 | c.Assert(plannedMigrations[0].Migration, Equals, migrations.Migrations[2]) |
| 619 | c.Assert(plannedMigrations[1].Migration, Equals, migrations.Migrations[1]) |
| 620 | c.Assert(plannedMigrations[2].Migration, Equals, migrations.Migrations[0]) |
| 621 | } |
| 622 | |
| 623 | // TestExecWithUnknownMigrationInDatabase makes sure that problems found with planning the |
| 624 | // migrations are propagated and returned by Exec. |
nothing calls this directly
no test coverage detected