@@ -334,6 +334,9 @@ func (suite *MigratorTestSuite) TearDownTest() {
334334 suite .Require ().NoError (err )
335335 _ , err = suite .db .ExecContext (ctx , "DROP TABLE IF EXISTS " + getTestGhostTableName ())
336336 suite .Require ().NoError (err )
337+ _ , err = suite .db .ExecContext (ctx , "DROP TABLE IF EXISTS " + getTestRevertedTableName ())
338+ suite .Require ().NoError (err )
339+ _ , err = suite .db .ExecContext (ctx , "DROP TABLE IF EXISTS " + getTestOldTableName ())
337340}
338341
339342func (suite * MigratorTestSuite ) TestMigrateEmpty () {
@@ -668,6 +671,57 @@ func (suite *MigratorTestSuite) TestCutOverLossDataCaseLockGhostBeforeRename() {
668671 suite .Require ().Equal ("CREATE TABLE `testing` (\n `id` int NOT NULL,\n `name` varchar(64) DEFAULT NULL,\n `foobar` varchar(255) DEFAULT NULL,\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" , createTableSQL )
669672}
670673
674+ func (suite * MigratorTestSuite ) TestRevertEmpty () {
675+ ctx := context .Background ()
676+
677+ _ , err := suite .db .ExecContext (ctx , fmt .Sprintf ("CREATE TABLE %s (id INT PRIMARY KEY, s CHAR(32))" , getTestTableName ()))
678+ suite .Require ().NoError (err )
679+
680+ var oldTableName string
681+
682+ // perform original migration
683+ connectionConfig , err := getTestConnectionConfig (ctx , suite .mysqlContainer )
684+ suite .Require ().NoError (err )
685+ {
686+ migrationContext := newTestMigrationContext ()
687+ migrationContext .ApplierConnectionConfig = connectionConfig
688+ migrationContext .InspectorConnectionConfig = connectionConfig
689+ migrationContext .SetConnectionConfig ("innodb" )
690+ migrationContext .AlterStatement = "ADD COLUMN newcol CHAR(32)"
691+ migrationContext .Checkpoint = true
692+ migrationContext .CheckpointIntervalSeconds = 10
693+ migrationContext .DropServeSocket = true
694+ migrationContext .InitiallyDropOldTable = true
695+ migrationContext .UseGTIDs = true
696+
697+ migrator := NewMigrator (migrationContext , "0.0.0" )
698+
699+ err = migrator .Migrate ()
700+ oldTableName = migrationContext .GetOldTableName ()
701+ suite .Require ().NoError (err )
702+ }
703+
704+ // revert the original migration
705+ {
706+ migrationContext := newTestMigrationContext ()
707+ migrationContext .ApplierConnectionConfig = connectionConfig
708+ migrationContext .InspectorConnectionConfig = connectionConfig
709+ migrationContext .SetConnectionConfig ("innodb" )
710+ migrationContext .DropServeSocket = true
711+ migrationContext .UseGTIDs = true
712+ migrationContext .Revert = true
713+ migrationContext .OkToDropTable = true
714+ migrationContext .OldTableName = oldTableName
715+
716+ migrator := NewMigrator (migrationContext , "0.0.0" )
717+
718+ err = migrator .Revert ()
719+ oldTableName = migrationContext .GetOldTableName ()
720+ suite .Require ().NoError (err )
721+ }
722+
723+ }
724+
671725func (suite * MigratorTestSuite ) TestRevert () {
672726 ctx := context .Background ()
673727
0 commit comments