From 22466f2e7a31eef31382d4c5719aa44d4b9a4e34 Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Thu, 17 Dec 2020 18:58:25 +0800 Subject: [PATCH] cherry pick #1331 to release-2.0 (#1343) --- pkg/utils/util.go | 7 +++++++ syncer/filter_test.go | 11 ++++++++--- syncer/syncer_test.go | 10 ---------- tests/others_integration.txt | 3 --- tests/safe_mode/data/db2.increment.sql | 5 ++++- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/pkg/utils/util.go b/pkg/utils/util.go index 18b7807e93..57ec74944c 100644 --- a/pkg/utils/util.go +++ b/pkg/utils/util.go @@ -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 @@ -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", diff --git a/syncer/filter_test.go b/syncer/filter_test.go index a881966b00..5dce9f42cc 100644 --- a/syncer/filter_test.go +++ b/syncer/filter_test.go @@ -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}, @@ -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}, diff --git a/syncer/syncer_test.go b/syncer/syncer_test.go index c059dca212..017e96a663 100644 --- a/syncer/syncer_test.go +++ b/syncer/syncer_test.go @@ -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() diff --git a/tests/others_integration.txt b/tests/others_integration.txt index f9b6dbfb4a..4631ecf8b5 100644 --- a/tests/others_integration.txt +++ b/tests/others_integration.txt @@ -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 diff --git a/tests/safe_mode/data/db2.increment.sql b/tests/safe_mode/data/db2.increment.sql index 91a5e00525..95155fc4b6 100644 --- a/tests/safe_mode/data/db2.increment.sql +++ b/tests/safe_mode/data/db2.increment.sql @@ -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;