Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

*: add test for #1329 and add VIEW & EVENT in builtin filter #1331

Merged
merged 5 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ var (
"^ALTER\\s+PROCEDURE",

// view
"^CREATE\\s*(OR REPLACE)?\\s+(ALGORITHM\\s?=.+?)?(DEFINER\\s?=.+?)?\\s+(SQL SECURITY DEFINER)?VIEW",
"^DROP\\s+VIEW",
"^ALTER\\s+(ALGORITHM\\s?=.+?)?(DEFINER\\s?=.+?)?(SQL SECURITY DEFINER)?VIEW",

// function
Expand All @@ -78,6 +80,11 @@ var (
"^ALTER\\s+TABLESPACE",
"^DROP\\s+TABLESPACE",

// event
"^CREATE\\s+(DEFINER\\s?=.+?)?EVENT",
"^ALTER\\s+(DEFINER\\s?=.+?)?EVENT",
"^DROP\\s+EVENT",

// account management
"^GRANT",
"^REVOKE",
Expand Down
11 changes: 8 additions & 3 deletions syncer/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ BEGIN
END`, true},

// view
{"CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `v` AS SELECT qty, price, qty*price AS value FROM t", false},
{"CREATE OR REPLACE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `v` AS SELECT qty, price, qty*price AS value FROM t", false},
{"CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `v` AS SELECT qty, price, qty*price AS value FROM t", true},
{"CREATE OR REPLACE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `v` AS SELECT qty, price, qty*price AS value FROM t", true},
{"ALTER ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `v` AS SELECT qty, price, qty*price AS value FROM t", true},
{"DROP VIEW v", false},
{"DROP VIEW v", true},
{"CREATE TABLE `VIEW`(id int)", false},
{"ALTER TABLE `VIEW`(id int)", false},

Expand Down Expand Up @@ -95,6 +95,11 @@ END`, true},
{"ALTER TABLESPACE `ts1` DROP DATAFILE 'ts1.idb' ENGIEN=NDB", true},
{"DROP TABLESPACE ts1", true},

// event
{"CREATE DEFINER=CURRENT_USER EVENT myevent ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO UPDATE myschema.mytable SET mycol = mycol + 1;", true},
{"ALTER DEFINER = CURRENT_USER EVENT myevent ON SCHEDULE EVERY 12 HOUR STARTS CURRENT_TIMESTAMP + INTERVAL 4 HOUR;", true},
{"DROP EVENT myevent;", true},

// account management
{"CREATE USER 't'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*93E34F4B81FEC9E8271655EA87646ED01AF377CC'", true},
{"ALTER USER 't'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*1114744159A0EF13B12FC371C94877763F9512D0'", true},
Expand Down
10 changes: 0 additions & 10 deletions syncer/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1567,16 +1567,6 @@ func (s *testSyncerSuite) TestTrackDDL(c *C) {
sqlmock.NewRows([]string{"Table", "Create Table"}).
AddRow(testTbl, " CREATE TABLE `"+testTbl+"` (\n `c` int(11) DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
}},

// test VIEW
{"CREATE VIEW tmp AS SELECT * FROM " + testTbl, func() {
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(
sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
mock.ExpectQuery("SHOW CREATE TABLE.*").WillReturnRows(
sqlmock.NewRows([]string{"Table", "Create Table"}).
AddRow(testTbl, " CREATE TABLE `"+testTbl+"` (\n `c` int(11) DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
}},
{"DROP VIEW IF EXISTS tmp", func() {}},
}

p := parser.New()
Expand Down
3 changes: 0 additions & 3 deletions tests/others_integration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import_v10x
tls
sharding2
ha
ha_master
full_mode
start_task
dm_syncer
sequence_sharding_optimistic
sequence_sharding_removemeta
drop_column_with_index
handle_error
5 changes: 4 additions & 1 deletion tests/safe_mode/data/db2.increment.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use safe_mode_test;
delete from t3 where name = 'Santa Sofía de la Piedad';
alter table t2 add column age int;
insert into t2 (uid, name, age) values (40002, 'Remedios Moscote', 100), (40003, 'Amaranta', 103);
start transaction;
insert into t2 (uid, name, age) values (40002, 'Remedios Moscote', 100);
insert into t2 (uid, name, age) values (40003, 'Amaranta', 103);
commit;
insert into t3 (uid, name) values (30004, 'Aureliano José'), (30005, 'Santa Sofía de la Piedad'), (30006, '17 Aurelianos');
alter table t3 add column age int;
update t3 set age = 1;