()
| 1091 | } |
| 1092 | |
| 1093 | func (suite *MigratorTestSuite) TestRevert() { |
| 1094 | ctx := context.Background() |
| 1095 | |
| 1096 | _, err := suite.db.ExecContext(ctx, fmt.Sprintf("CREATE TABLE %s (id INT PRIMARY KEY, s CHAR(32))", getTestTableName())) |
| 1097 | suite.Require().NoError(err) |
| 1098 | |
| 1099 | numRows := 0 |
| 1100 | for range 100 { |
| 1101 | _, err = suite.db.ExecContext(ctx, |
| 1102 | fmt.Sprintf("INSERT INTO %s (id, s) VALUES (%d, MD5('%d'))", getTestTableName(), numRows, numRows)) |
| 1103 | suite.Require().NoError(err) |
| 1104 | numRows += 1 |
| 1105 | } |
| 1106 | |
| 1107 | var oldTableName string |
| 1108 | |
| 1109 | connectionConfig, err := getTestConnectionConfig(ctx, suite.mysqlContainer) |
| 1110 | suite.Require().NoError(err) |
| 1111 | // perform original migration |
| 1112 | { |
| 1113 | migrationContext := newTestMigrationContext() |
| 1114 | migrationContext.ApplierConnectionConfig = connectionConfig |
| 1115 | migrationContext.InspectorConnectionConfig = connectionConfig |
| 1116 | migrationContext.SetConnectionConfig("innodb") |
| 1117 | migrationContext.AlterStatement = "ADD INDEX idx1 (s)" |
| 1118 | migrationContext.Checkpoint = true |
| 1119 | migrationContext.CheckpointIntervalSeconds = 10 |
| 1120 | migrationContext.DropServeSocket = true |
| 1121 | migrationContext.InitiallyDropOldTable = true |
| 1122 | migrationContext.UseGTIDs = true |
| 1123 | |
| 1124 | migrator := NewMigrator(migrationContext, "0.0.0") |
| 1125 | |
| 1126 | err = migrator.Migrate() |
| 1127 | oldTableName = migrationContext.GetOldTableName() |
| 1128 | suite.Require().NoError(err) |
| 1129 | } |
| 1130 | |
| 1131 | // do some writes |
| 1132 | for range 100 { |
| 1133 | _, err = suite.db.ExecContext(ctx, |
| 1134 | fmt.Sprintf("INSERT INTO %s (id, s) VALUES (%d, MD5('%d'))", getTestTableName(), numRows, numRows)) |
| 1135 | suite.Require().NoError(err) |
| 1136 | numRows += 1 |
| 1137 | } |
| 1138 | for i := 0; i < numRows; i += 7 { |
| 1139 | _, err = suite.db.ExecContext(ctx, |
| 1140 | fmt.Sprintf("UPDATE %s SET s=MD5('%d') where id=%d", getTestTableName(), 2*i, i)) |
| 1141 | suite.Require().NoError(err) |
| 1142 | } |
| 1143 | |
| 1144 | // revert the original migration |
| 1145 | { |
| 1146 | migrationContext := newTestMigrationContext() |
| 1147 | migrationContext.ApplierConnectionConfig = connectionConfig |
| 1148 | migrationContext.InspectorConnectionConfig = connectionConfig |
| 1149 | migrationContext.SetConnectionConfig("innodb") |
| 1150 | migrationContext.DropServeSocket = true |
nothing calls this directly
no test coverage detected