MCPcopy
hub / github.com/github/gh-ost / TestRevertEmpty

Method TestRevertEmpty

go/logic/migrator_test.go:1042–1091  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1040}
1041
1042func (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
1093func (suite *MigratorTestSuite) TestRevert() {
1094 ctx := context.Background()

Callers

nothing calls this directly

Calls 9

MigrateMethod · 0.95
RevertMethod · 0.95
getTestTableNameFunction · 0.85
getTestConnectionConfigFunction · 0.85
newTestMigrationContextFunction · 0.85
NewMigratorFunction · 0.85
SetConnectionConfigMethod · 0.80
GetOldTableNameMethod · 0.80

Tested by

no test coverage detected