Skip to content

Instantly share code, notes, and snippets.

@suzaku
Created July 31, 2019 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suzaku/7528882490dfd740989a7c53f65a8ef1 to your computer and use it in GitHub Desktop.
Save suzaku/7528882490dfd740989a7c53f65a8ef1 to your computer and use it in GitHub Desktop.
syntax = "proto3";
// for date and time type, string_value is set
// for int type int64 or uint64_value is set
// for float, double, double_value is set
// for decimal, string_value is set in human-readable now
// for bit, bytes_value is set
// for text and char type, string_value is set
// for blob and binary type, bytes_value is set
// for enum, set, uint64_value is set
// for json, bytes_value is set
message Column {
oneof value {
bool is_null = 1;
int64 int64_value = 2;
uint64 uint64_value = 3;
double double_value = 4;
bytes bytes_value = 5;
string string_value = 6;
}
}
message ColumnInfo {
string name = 1;
// lower case column field type in mysql
// https://dev.mysql.com/doc/refman/8.0/en/data-types.html
// for numeric type: int bigint smallint tinyint float double decimal bit
// for string type: text longtext mediumtext char tinytext varchar
// blob longblob mediumblob binary tinyblob varbinary
// enum set
// for json type: json
string mysql_type = 2;
bool is_primary_key = 3;
}
message Row {
repeated Column columns = 1;
}
enum MutationType {
Insert = 0;
Update = 1;
Delete = 2;
}
// Table contains mutations in a table.
message Table {
string schema_name = 1;
string table_name = 2;
repeated ColumnInfo column_info = 3;
repeated TableMutation mutations = 4;
}
message TableMutation {
MutationType type = 1;
Row row = 2;
// for Update MutationType only
Row changed_row = 3;
}
message DMLData {
// tables contains all the table changes.
repeated Table tables = 1;
}
message DDLData {
// the current database use
string schema_name = 1;
// the relate table
string table_name = 2;
// ddl_query is the original ddl statement query.
bytes ddl_query = 3;
}
enum BinlogType {
DML = 0; // has dml_data
DDL = 1; // has ddl_query
}
// Binlog contains all the changes in a transaction.
message Binlog {
BinlogType type = 1;
int64 commit_ts = 2;
oneof payload {
// dml_data is marshalled from DML type
DMLData dml_data = 3;
DDLData ddl_data = 4;
}
}
enum EventType {
BINLOG = 0;
RESOLVED = 1;
SCHEMA_CHANGED = 2;
}
message Event {
EventType type = 1;
oneof body {
Binlog binlog = 2; // For BINLOG
int64 resolved_ts = 3; // For RESOLVED
int64 commit_ts = 4; // For SCHEMA_CHANGED, represent the time when the change happened
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment