@@ -45,7 +45,9 @@ function run() {
4545 echo " Waiting for routing to complete..."
4646 check_table_exists target_db.finish_mark_routed ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
4747
48+ # ============================================
4849 # Verify schema routing: tables should be in target_db, not source_db
50+ # ============================================
4951 echo " Verifying schema routing..."
5052 check_table_exists target_db.users_routed ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
5153 check_table_exists target_db.orders_routed ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
@@ -55,29 +57,112 @@ function run() {
5557 check_table_not_exists source_db.users ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
5658 check_table_not_exists source_db.orders ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
5759
58- # Verify data was replicated correctly
59- echo " Verifying data replication..."
60+ # ============================================
61+ # Verify DDL: CREATE TABLE
62+ # ============================================
63+ echo " Verifying CREATE TABLE routing..."
64+ check_table_exists target_db.products_routed ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
6065
61- # Check users table data
66+ # ============================================
67+ # Verify DDL: CREATE TABLE LIKE
68+ # ============================================
69+ echo " Verifying CREATE TABLE LIKE routing..."
70+ check_table_exists target_db.products_backup_routed ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
71+ run_sql " SELECT COUNT(*) as cnt FROM target_db.products_backup_routed" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
72+ check_contains " cnt: 1"
73+
74+ # ============================================
75+ # Verify DDL: RENAME TABLE
76+ # ============================================
77+ echo " Verifying RENAME TABLE routing..."
78+ # temp_table was renamed to renamed_table, so only renamed_table_routed should exist
79+ check_table_not_exists target_db.temp_table_routed ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
80+ check_table_exists target_db.renamed_table_routed ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
81+ # Verify DML on renamed table worked
82+ run_sql " SELECT COUNT(*) as cnt FROM target_db.renamed_table_routed" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
83+ check_contains " cnt: 2"
84+ run_sql " SELECT value FROM target_db.renamed_table_routed WHERE id = 1" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
85+ check_contains " updated"
86+
87+ # ============================================
88+ # Verify DDL: TRUNCATE TABLE
89+ # ============================================
90+ echo " Verifying TRUNCATE TABLE routing..."
91+ check_table_exists target_db.truncate_test_routed ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
92+ # After truncate, only 1 row should exist (inserted after truncate)
93+ run_sql " SELECT COUNT(*) as cnt FROM target_db.truncate_test_routed" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
94+ check_contains " cnt: 1"
95+ run_sql " SELECT id FROM target_db.truncate_test_routed" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
96+ check_contains " id: 10"
97+
98+ # ============================================
99+ # Verify DDL: ALTER TABLE ADD/DROP COLUMN
100+ # ============================================
101+ echo " Verifying ALTER TABLE routing..."
102+ # created_at column was added then dropped, so it should NOT exist
103+ run_sql " SHOW COLUMNS FROM target_db.users_routed LIKE 'created_at'" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
104+ check_not_contains " created_at"
105+
106+ # ============================================
107+ # Verify DDL: ALTER TABLE ADD INDEX
108+ # ============================================
109+ echo " Verifying ADD INDEX routing..."
110+ run_sql " SHOW INDEX FROM target_db.orders_routed WHERE Key_name = 'idx_user_id'" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
111+ check_contains " idx_user_id"
112+
113+ # ============================================
114+ # Verify DDL: DROP TABLE
115+ # ============================================
116+ echo " Verifying DROP TABLE routing..."
117+ check_table_not_exists target_db.to_be_dropped_routed ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
118+
119+ # ============================================
120+ # Verify DML: INSERT, UPDATE, DELETE on users
121+ # ============================================
122+ echo " Verifying DML operations on users table..."
123+ # After all operations:
124+ # - Started with id 1,2 from prepare.sql
125+ # - Added id 3,4,5 in test.sql
126+ # - Deleted id 5
127+ # Final count should be 4 (ids: 1, 2, 3, 4)
62128 run_sql " SELECT COUNT(*) as cnt FROM target_db.users_routed" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
63- check_contains " cnt: 3 "
129+ check_contains " cnt: 4 "
64130
65- # Check the updated email
131+ # Check UPDATE worked ( email updated for id=1)
66132 run_sql " SELECT email FROM target_db.users_routed WHERE id = 1" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
67133 check_contains
" [email protected] " 68134
69- # Check orders table data
135+ # Check batch UPDATE worked (names updated for ids 3,4)
136+ run_sql " SELECT name FROM target_db.users_routed WHERE id = 3" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
137+ check_contains " Charlie_v2"
138+ run_sql " SELECT name FROM target_db.users_routed WHERE id = 4" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
139+ check_contains " Diana_v2"
140+
141+ # ============================================
142+ # Verify DML: INSERT, UPDATE, DELETE on orders
143+ # ============================================
144+ echo " Verifying DML operations on orders table..."
145+ # Started with id 1,2, added id 3, deleted id 2
146+ # Final count should be 2 (ids: 1, 3)
70147 run_sql " SELECT COUNT(*) as cnt FROM target_db.orders_routed" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
71- check_contains " cnt: 3 "
148+ check_contains " cnt: 2 "
72149
73- # Check products table data
150+ # Check UPDATE worked (amount updated for id=1)
151+ run_sql " SELECT amount FROM target_db.orders_routed WHERE id = 1" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
152+ check_contains " 150.00"
153+
154+ # ============================================
155+ # Verify DML: INSERT, UPDATE, DELETE on products
156+ # ============================================
157+ echo " Verifying DML operations on products table..."
158+ # Started with ids 1,2
159+ # Updated id 1 (price to 12.99)
160+ # Deleted where price < 15.00 (deletes both since 12.99 < 15)
161+ # Final count should be 0
74162 run_sql " SELECT COUNT(*) as cnt FROM target_db.products_routed" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
75- check_contains " cnt: 2 "
163+ check_contains " cnt: 0 "
76164
77- # Verify DDL was applied correctly (the ALTER TABLE ADD COLUMN)
78- echo " Verifying DDL routing..."
79- run_sql " SHOW COLUMNS FROM target_db.users_routed LIKE 'created_at'" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
80- check_contains " created_at"
165+ echo " All routing verifications passed!"
81166
82167 cleanup_process $CDC_BINARY
83168}
0 commit comments