(c *C)
| 322 | } |
| 323 | |
| 324 | func (s *SqliteMigrateSuite) TestPlanMigration(c *C) { |
| 325 | migrations := &MemoryMigrationSource{ |
| 326 | Migrations: []*Migration{ |
| 327 | { |
| 328 | Id: "1_create_table.sql", |
| 329 | Up: []string{"CREATE TABLE people (id int)"}, |
| 330 | Down: []string{"DROP TABLE people"}, |
| 331 | }, |
| 332 | { |
| 333 | Id: "2_alter_table.sql", |
| 334 | Up: []string{"ALTER TABLE people ADD COLUMN first_name text"}, |
| 335 | Down: []string{"SELECT 0"}, // Not really supported |
| 336 | }, |
| 337 | { |
| 338 | Id: "10_add_last_name.sql", |
| 339 | Up: []string{"ALTER TABLE people ADD COLUMN last_name text"}, |
| 340 | Down: []string{"ALTER TABLE people DROP COLUMN last_name"}, |
| 341 | }, |
| 342 | }, |
| 343 | } |
| 344 | n, err := Exec(s.Db, "sqlite3", migrations, Up) |
| 345 | c.Assert(err, IsNil) |
| 346 | c.Assert(n, Equals, 3) |
| 347 | |
| 348 | migrations.Migrations = append(migrations.Migrations, &Migration{ |
| 349 | Id: "11_add_middle_name.sql", |
| 350 | Up: []string{"ALTER TABLE people ADD COLUMN middle_name text"}, |
| 351 | Down: []string{"ALTER TABLE people DROP COLUMN middle_name"}, |
| 352 | }) |
| 353 | |
| 354 | plannedMigrations, _, err := PlanMigration(s.Db, "sqlite3", migrations, Up, 0) |
| 355 | c.Assert(err, IsNil) |
| 356 | c.Assert(plannedMigrations, HasLen, 1) |
| 357 | c.Assert(plannedMigrations[0].Migration, Equals, migrations.Migrations[3]) |
| 358 | |
| 359 | plannedMigrations, _, err = PlanMigration(s.Db, "sqlite3", migrations, Down, 0) |
| 360 | c.Assert(err, IsNil) |
| 361 | c.Assert(plannedMigrations, HasLen, 3) |
| 362 | c.Assert(plannedMigrations[0].Migration, Equals, migrations.Migrations[2]) |
| 363 | c.Assert(plannedMigrations[1].Migration, Equals, migrations.Migrations[1]) |
| 364 | c.Assert(plannedMigrations[2].Migration, Equals, migrations.Migrations[0]) |
| 365 | } |
| 366 | |
| 367 | func (s *SqliteMigrateSuite) TestSkipMigration(c *C) { |
| 368 | migrations := &MemoryMigrationSource{ |
nothing calls this directly
no test coverage detected