()
| 1040 | } |
| 1041 | |
| 1042 | func (suite *MigratorTestSuite) TestRevertEmpty() { |
| 1043 | ctx := context.Background() |
| 1044 | |
| 1045 | _, err := suite.db.ExecContext(ctx, fmt.Sprintf("CREATE TABLE %s (id INT PRIMARY KEY, s CHAR(32))", getTestTableName())) |
| 1046 | suite.Require().NoError(err) |
| 1047 | |
| 1048 | var oldTableName string |
| 1049 | |
| 1050 | // perform original migration |
| 1051 | connectionConfig, err := getTestConnectionConfig(ctx, suite.mysqlContainer) |
| 1052 | suite.Require().NoError(err) |
| 1053 | { |
| 1054 | migrationContext := newTestMigrationContext() |
| 1055 | migrationContext.ApplierConnectionConfig = connectionConfig |
| 1056 | migrationContext.InspectorConnectionConfig = connectionConfig |
| 1057 | migrationContext.SetConnectionConfig("innodb") |
| 1058 | migrationContext.AlterStatement = "ADD COLUMN newcol CHAR(32)" |
| 1059 | migrationContext.Checkpoint = true |
| 1060 | migrationContext.CheckpointIntervalSeconds = 10 |
| 1061 | migrationContext.DropServeSocket = true |
| 1062 | migrationContext.InitiallyDropOldTable = true |
| 1063 | migrationContext.UseGTIDs = true |
| 1064 | |
| 1065 | migrator := NewMigrator(migrationContext, "0.0.0") |
| 1066 | |
| 1067 | err = migrator.Migrate() |
| 1068 | oldTableName = migrationContext.GetOldTableName() |
| 1069 | suite.Require().NoError(err) |
| 1070 | suite.Require().Less(migrationContext.TimeSinceLastHeartbeatOnChangelog(), 24*time.Hour) |
| 1071 | } |
| 1072 | |
| 1073 | // revert the original migration |
| 1074 | { |
| 1075 | migrationContext := newTestMigrationContext() |
| 1076 | migrationContext.ApplierConnectionConfig = connectionConfig |
| 1077 | migrationContext.InspectorConnectionConfig = connectionConfig |
| 1078 | migrationContext.SetConnectionConfig("innodb") |
| 1079 | migrationContext.DropServeSocket = true |
| 1080 | migrationContext.UseGTIDs = true |
| 1081 | migrationContext.Revert = true |
| 1082 | migrationContext.OkToDropTable = true |
| 1083 | migrationContext.OldTableName = oldTableName |
| 1084 | |
| 1085 | migrator := NewMigrator(migrationContext, "0.0.0") |
| 1086 | |
| 1087 | err = migrator.Revert() |
| 1088 | suite.Require().NoError(err) |
| 1089 | suite.Require().Less(migrationContext.TimeSinceLastHeartbeatOnChangelog(), 24*time.Hour) |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | func (suite *MigratorTestSuite) TestRevert() { |
| 1094 | ctx := context.Background() |
nothing calls this directly
no test coverage detected