@@ -516,6 +516,47 @@ func (s *SqliteMigrateSuite) TestPlanMigrationWithUnknownDatabaseMigrationApplie
516516 c .Assert (err , FitsTypeOf , & PlanError {})
517517}
518518
519+ func (s * SqliteMigrateSuite ) TestPlanMigrationWithIgnoredUnknownDatabaseMigrationApplied (c * C ) {
520+ migrations := & MemoryMigrationSource {
521+ Migrations : []* Migration {
522+ & Migration {
523+ Id : "1_create_table.sql" ,
524+ Up : []string {"CREATE TABLE people (id int)" },
525+ Down : []string {"DROP TABLE people" },
526+ },
527+ & Migration {
528+ Id : "2_alter_table.sql" ,
529+ Up : []string {"ALTER TABLE people ADD COLUMN first_name text" },
530+ Down : []string {"SELECT 0" }, // Not really supported
531+ },
532+ & Migration {
533+ Id : "10_add_last_name.sql" ,
534+ Up : []string {"ALTER TABLE people ADD COLUMN last_name text" },
535+ Down : []string {"ALTER TABLE people DROP COLUMN last_name" },
536+ },
537+ },
538+ }
539+ SetIgnoreUnknown (true )
540+ n , err := Exec (s .Db , "sqlite3" , migrations , Up )
541+ c .Assert (err , IsNil )
542+ c .Assert (n , Equals , 3 )
543+
544+ // Note that migration 10_add_last_name.sql is missing from the new migrations source
545+ // so it is considered an "unknown" migration for the planner.
546+ migrations .Migrations = append (migrations .Migrations [:2 ], & Migration {
547+ Id : "10_add_middle_name.sql" ,
548+ Up : []string {"ALTER TABLE people ADD COLUMN middle_name text" },
549+ Down : []string {"ALTER TABLE people DROP COLUMN middle_name" },
550+ })
551+
552+ _ , _ , err = PlanMigration (s .Db , "sqlite3" , migrations , Up , 0 )
553+ c .Assert (err , IsNil )
554+
555+ _ , _ , err = PlanMigration (s .Db , "sqlite3" , migrations , Down , 0 )
556+ c .Assert (err , IsNil )
557+ SetIgnoreUnknown (false ) // Make sure we are not breaking other tests as this is globaly set
558+ }
559+
519560// TestExecWithUnknownMigrationInDatabase makes sure that problems found with planning the
520561// migrations are propagated and returned by Exec.
521562func (s * SqliteMigrateSuite ) TestExecWithUnknownMigrationInDatabase (c * C ) {
0 commit comments