@@ -238,7 +238,7 @@ func (s *SqliteMigrateSuite) TestMigrateVersionInt2(c *C) {
238238 c .Assert (id , Equals , int64 (1 ))
239239}
240240
241- func (s * SqliteMigrateSuite ) TestMigrateVersionIntFailed (c * C ) {
241+ func (s * SqliteMigrateSuite ) TestMigrateVersionIntFailedWithNotExistingVerion (c * C ) {
242242 migrations := & FileMigrationSource {
243243 Dir : "test-migrations" ,
244244 }
@@ -248,7 +248,7 @@ func (s *SqliteMigrateSuite) TestMigrateVersionIntFailed(c *C) {
248248 c .Assert (err , NotNil )
249249}
250250
251- func (s * SqliteMigrateSuite ) TestMigrateVersionIntFailed2 (c * C ) {
251+ func (s * SqliteMigrateSuite ) TestMigrateVersionIntFailedWithInvalidVerion (c * C ) {
252252 migrations := & FileMigrationSource {
253253 Dir : "test-migrations" ,
254254 }
@@ -380,55 +380,12 @@ func (s *SqliteMigrateSuite) TestPlanMigration(c *C) {
380380 Down : []string {"ALTER TABLE people DROP COLUMN middle_name" },
381381 })
382382
383- plannedMigrations , _ , err := PlanMigration (s .Db , "sqlite3" , migrations , Up , 0 , - 1 )
383+ plannedMigrations , _ , err := PlanMigration (s .Db , "sqlite3" , migrations , Up , 0 )
384384 c .Assert (err , IsNil )
385385 c .Assert (plannedMigrations , HasLen , 1 )
386386 c .Assert (plannedMigrations [0 ].Migration , Equals , migrations .Migrations [3 ])
387387
388- plannedMigrations , _ , err = PlanMigration (s .Db , "sqlite3" , migrations , Down , 0 , - 1 )
389- c .Assert (err , IsNil )
390- c .Assert (plannedMigrations , HasLen , 3 )
391- c .Assert (plannedMigrations [0 ].Migration , Equals , migrations .Migrations [2 ])
392- c .Assert (plannedMigrations [1 ].Migration , Equals , migrations .Migrations [1 ])
393- c .Assert (plannedMigrations [2 ].Migration , Equals , migrations .Migrations [0 ])
394- }
395-
396- func (s * SqliteMigrateSuite ) TestPlanMigrationWithVersion (c * C ) {
397- migrations := & MemoryMigrationSource {
398- Migrations : []* Migration {
399- {
400- Id : "1_create_table.sql" ,
401- Up : []string {"CREATE TABLE people (id int)" },
402- Down : []string {"DROP TABLE people" },
403- },
404- {
405- Id : "2_alter_table.sql" ,
406- Up : []string {"ALTER TABLE people ADD COLUMN first_name text" },
407- Down : []string {"SELECT 0" }, // Not really supported
408- },
409- {
410- Id : "10_add_last_name.sql" ,
411- Up : []string {"ALTER TABLE people ADD COLUMN last_name text" },
412- Down : []string {"ALTER TABLE people DROP COLUMN last_name" },
413- },
414- },
415- }
416- n , err := Exec (s .Db , "sqlite3" , migrations , Up )
417- c .Assert (err , IsNil )
418- c .Assert (n , Equals , 3 )
419-
420- migrations .Migrations = append (migrations .Migrations , & Migration {
421- Id : "11_add_middle_name.sql" ,
422- Up : []string {"ALTER TABLE people ADD COLUMN middle_name text" },
423- Down : []string {"ALTER TABLE people DROP COLUMN middle_name" },
424- })
425-
426- plannedMigrations , _ , err := PlanMigration (s .Db , "sqlite3" , migrations , Up , 0 , 11 )
427- c .Assert (err , IsNil )
428- c .Assert (plannedMigrations , HasLen , 1 )
429- c .Assert (plannedMigrations [0 ].Migration , Equals , migrations .Migrations [3 ])
430-
431- plannedMigrations , _ , err = PlanMigration (s .Db , "sqlite3" , migrations , Down , 0 , 1 )
388+ plannedMigrations , _ , err = PlanMigration (s .Db , "sqlite3" , migrations , Down , 0 )
432389 c .Assert (err , IsNil )
433390 c .Assert (plannedMigrations , HasLen , 3 )
434391 c .Assert (plannedMigrations [0 ].Migration , Equals , migrations .Migrations [2 ])
@@ -514,7 +471,7 @@ func (s *SqliteMigrateSuite) TestPlanMigrationWithHoles(c *C) {
514471 })
515472
516473 // apply all the missing migrations
517- plannedMigrations , _ , err := PlanMigration (s .Db , "sqlite3" , migrations , Up , 0 , - 1 )
474+ plannedMigrations , _ , err := PlanMigration (s .Db , "sqlite3" , migrations , Up , 0 )
518475 c .Assert (err , IsNil )
519476 c .Assert (plannedMigrations , HasLen , 3 )
520477 c .Assert (plannedMigrations [0 ].Migration .Id , Equals , "2" )
@@ -525,7 +482,7 @@ func (s *SqliteMigrateSuite) TestPlanMigrationWithHoles(c *C) {
525482 c .Assert (plannedMigrations [2 ].Queries [0 ], Equals , up )
526483
527484 // first catch up to current target state 123, then migrate down 1 step to 12
528- plannedMigrations , _ , err = PlanMigration (s .Db , "sqlite3" , migrations , Down , 1 , - 1 )
485+ plannedMigrations , _ , err = PlanMigration (s .Db , "sqlite3" , migrations , Down , 1 )
529486 c .Assert (err , IsNil )
530487 c .Assert (plannedMigrations , HasLen , 2 )
531488 c .Assert (plannedMigrations [0 ].Migration .Id , Equals , "2" )
@@ -534,7 +491,7 @@ func (s *SqliteMigrateSuite) TestPlanMigrationWithHoles(c *C) {
534491 c .Assert (plannedMigrations [1 ].Queries [0 ], Equals , down )
535492
536493 // first catch up to current target state 123, then migrate down 2 steps to 1
537- plannedMigrations , _ , err = PlanMigration (s .Db , "sqlite3" , migrations , Down , 2 , - 1 )
494+ plannedMigrations , _ , err = PlanMigration (s .Db , "sqlite3" , migrations , Down , 2 )
538495 c .Assert (err , IsNil )
539496 c .Assert (plannedMigrations , HasLen , 3 )
540497 c .Assert (plannedMigrations [0 ].Migration .Id , Equals , "2" )
@@ -598,12 +555,12 @@ func (s *SqliteMigrateSuite) TestPlanMigrationWithUnknownDatabaseMigrationApplie
598555 Down : []string {"ALTER TABLE people DROP COLUMN middle_name" },
599556 })
600557
601- _ , _ , err = PlanMigration (s .Db , "sqlite3" , migrations , Up , 0 , - 1 )
558+ _ , _ , err = PlanMigration (s .Db , "sqlite3" , migrations , Up , 0 )
602559 c .Assert (err , NotNil , Commentf ("Up migrations should not have been applied when there " +
603560 "is an unknown migration in the database" ))
604561 c .Assert (err , FitsTypeOf , & PlanError {})
605562
606- _ , _ , err = PlanMigration (s .Db , "sqlite3" , migrations , Down , 0 , - 1 )
563+ _ , _ , err = PlanMigration (s .Db , "sqlite3" , migrations , Down , 0 )
607564 c .Assert (err , NotNil , Commentf ("Down migrations should not have been applied when there " +
608565 "is an unknown migration in the database" ))
609566 c .Assert (err , FitsTypeOf , & PlanError {})
@@ -642,14 +599,57 @@ func (s *SqliteMigrateSuite) TestPlanMigrationWithIgnoredUnknownDatabaseMigratio
642599 Down : []string {"ALTER TABLE people DROP COLUMN middle_name" },
643600 })
644601
645- _ , _ , err = PlanMigration (s .Db , "sqlite3" , migrations , Up , 0 , - 1 )
602+ _ , _ , err = PlanMigration (s .Db , "sqlite3" , migrations , Up , 0 )
646603 c .Assert (err , IsNil )
647604
648- _ , _ , err = PlanMigration (s .Db , "sqlite3" , migrations , Down , 0 , - 1 )
605+ _ , _ , err = PlanMigration (s .Db , "sqlite3" , migrations , Down , 0 )
649606 c .Assert (err , IsNil )
650607 SetIgnoreUnknown (false ) // Make sure we are not breaking other tests as this is globaly set
651608}
652609
610+ func (s * SqliteMigrateSuite ) TestPlanMigrationToVersion (c * C ) {
611+ migrations := & MemoryMigrationSource {
612+ Migrations : []* Migration {
613+ {
614+ Id : "1_create_table.sql" ,
615+ Up : []string {"CREATE TABLE people (id int)" },
616+ Down : []string {"DROP TABLE people" },
617+ },
618+ {
619+ Id : "2_alter_table.sql" ,
620+ Up : []string {"ALTER TABLE people ADD COLUMN first_name text" },
621+ Down : []string {"SELECT 0" }, // Not really supported
622+ },
623+ {
624+ Id : "10_add_last_name.sql" ,
625+ Up : []string {"ALTER TABLE people ADD COLUMN last_name text" },
626+ Down : []string {"ALTER TABLE people DROP COLUMN last_name" },
627+ },
628+ },
629+ }
630+ n , err := Exec (s .Db , "sqlite3" , migrations , Up )
631+ c .Assert (err , IsNil )
632+ c .Assert (n , Equals , 3 )
633+
634+ migrations .Migrations = append (migrations .Migrations , & Migration {
635+ Id : "11_add_middle_name.sql" ,
636+ Up : []string {"ALTER TABLE people ADD COLUMN middle_name text" },
637+ Down : []string {"ALTER TABLE people DROP COLUMN middle_name" },
638+ })
639+
640+ plannedMigrations , _ , err := PlanMigrationToVersion (s .Db , "sqlite3" , migrations , Up , 11 )
641+ c .Assert (err , IsNil )
642+ c .Assert (plannedMigrations , HasLen , 1 )
643+ c .Assert (plannedMigrations [0 ].Migration , Equals , migrations .Migrations [3 ])
644+
645+ plannedMigrations , _ , err = PlanMigrationToVersion (s .Db , "sqlite3" , migrations , Down , 1 )
646+ c .Assert (err , IsNil )
647+ c .Assert (plannedMigrations , HasLen , 3 )
648+ c .Assert (plannedMigrations [0 ].Migration , Equals , migrations .Migrations [2 ])
649+ c .Assert (plannedMigrations [1 ].Migration , Equals , migrations .Migrations [1 ])
650+ c .Assert (plannedMigrations [2 ].Migration , Equals , migrations .Migrations [0 ])
651+ }
652+
653653// TestExecWithUnknownMigrationInDatabase makes sure that problems found with planning the
654654// migrations are propagated and returned by Exec.
655655func (s * SqliteMigrateSuite ) TestExecWithUnknownMigrationInDatabase (c * C ) {
0 commit comments