Skip to content

Commit

Permalink
add drop column, rename column/index for incompatible ddl changes (#751)
Browse files Browse the repository at this point in the history
  • Loading branch information
GMHDBJD authored Oct 31, 2023
1 parent 31f40b8 commit a020d2c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 38 deletions.
51 changes: 26 additions & 25 deletions pkg/binlog-filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,23 @@ const (
ValueRangeDecrease EventType = "value range decrease"
PrecisionDecrease EventType = "precision decrease"
ModifyColumn EventType = "modify column"
Rename EventType = "rename"
Drop EventType = "drop"
Truncate EventType = "truncate"
ModifyPK EventType = "modify pk"
ModifyUK EventType = "modify uk"
RenameColumn EventType = "rename column"
RenameIndex EventType = "rename index"
DropColumn EventType = "drop column"
DropPrimaryKey EventType = "drop primary key"
DropUniqueKey EventType = "drop unique key"
ModifyDefaultValue EventType = "modify default value"
ModifyConstraint EventType = "modify constaints"
ModifyColumnsOrder EventType = "modify columns order"
ModifyCharset EventType = "modify charset"
ModifyCollation EventType = "modify collation"
RemoveAutoIncrement EventType = "remove auto increment"
ModifyStorageEngine EventType = "modify storage engine"
ReorganizePartion EventType = "reorganize partition"
RebuildPartition EventType = "rebuild partition"
CoalescePartition EventType = "coalesce partition"
SplitPartition EventType = "split partition"
ExchangePartition EventType = "exchange partition"
ReorganizePartion EventType = "reorganize table partition"
RebuildPartition EventType = "rebuild table partition"
CoalescePartition EventType = "coalesce table partition"
SplitPartition EventType = "split table partition"
ExchangePartition EventType = "exchange table partition"

// NullEvent is used to represents unsupported ddl event type when we
// convert a ast.StmtNode or a string to EventType.
Expand All @@ -112,34 +112,26 @@ func ClassifyEvent(event EventType) (EventType, error) {
DeleteEvent:
return dml, nil
case CreateDatabase,
DropDatabase,
AlterDatabase,
AlterSchema,
CreateTable,
DropTable,
TruncateTable,
RenameTable,
CreateIndex,
DropIndex,
CreateView,
DropView,
AlterTable,
CreateSchema,
DropSchema,
AddTablePartition,
DropTablePartition,
TruncateTablePartition:
AddTablePartition:
return ddl, nil
case NullEvent:
return NullEvent, nil
case ValueRangeDecrease,
PrecisionDecrease,
ModifyColumn,
Rename,
Drop,
Truncate,
ModifyPK,
ModifyUK,
RenameColumn,
RenameIndex,
DropColumn,
DropPrimaryKey,
DropUniqueKey,
ModifyDefaultValue,
ModifyConstraint,
ModifyColumnsOrder,
Expand All @@ -151,7 +143,16 @@ func ClassifyEvent(event EventType) (EventType, error) {
RebuildPartition,
CoalescePartition,
SplitPartition,
ExchangePartition:
ExchangePartition,

DropDatabase,
DropTable,
DropIndex,
RenameTable,
TruncateTable,
DropSchema,
DropTablePartition,
TruncateTablePartition:
return incompatibleDDL, nil
default:
return NullEvent, errors.NotValidf("event type %s", event)
Expand Down
16 changes: 8 additions & 8 deletions pkg/binlog-filter/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,21 +302,21 @@ func (t *testFilterSuite) TestClassifyEvent(c *C) {
// ddl
{CreateDatabase, ddl, nil},
{CreateSchema, ddl, nil},
{DropDatabase, ddl, nil},
{DropSchema, ddl, nil},
{DropDatabase, incompatibleDDL, nil},
{DropSchema, incompatibleDDL, nil},
{AlterSchema, ddl, nil},
{CreateTable, ddl, nil},
{DropTable, ddl, nil},
{TruncateTable, ddl, nil},
{RenameTable, ddl, nil},
{DropTable, incompatibleDDL, nil},
{TruncateTable, incompatibleDDL, nil},
{RenameTable, incompatibleDDL, nil},
{CreateIndex, ddl, nil},
{DropIndex, ddl, nil},
{DropIndex, incompatibleDDL, nil},
{CreateView, ddl, nil},
{DropView, ddl, nil},
{AlterTable, ddl, nil},
{AddTablePartition, ddl, nil},
{DropTablePartition, ddl, nil},
{TruncateTablePartition, ddl, nil},
{DropTablePartition, incompatibleDDL, nil},
{TruncateTablePartition, incompatibleDDL, nil},
{"create", NullEvent, errors.NotValidf("event type %s", "create")},
{EventType("xxx"), NullEvent, errors.NotValidf("event type %s", "xxx")},
{EventType("I don't know"), NullEvent, errors.NotValidf("event type %s", "I don't know")},
Expand Down
10 changes: 5 additions & 5 deletions pkg/binlog-filter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ func toEventType(es string) (EventType, error) {
ValueRangeDecrease,
PrecisionDecrease,
ModifyColumn,
Rename,
Drop,
Truncate,
ModifyPK,
ModifyUK,
RenameColumn,
RenameIndex,
DropColumn,
DropPrimaryKey,
DropUniqueKey,
ModifyDefaultValue,
ModifyConstraint,
ModifyColumnsOrder,
Expand Down

0 comments on commit a020d2c

Please sign in to comment.