@@ -585,6 +585,32 @@ def test_drop_column(self):
585
585
finally :
586
586
self .resetBinLog ()
587
587
588
+ def test_alter_column (self ):
589
+ self .stream .close ()
590
+ self .execute ("CREATE TABLE test_alter_column (id INTEGER(11), data VARCHAR(50))" )
591
+ self .execute ("INSERT INTO test_alter_column VALUES (1, 'A value')" )
592
+ self .execute ("COMMIT" )
593
+ # this is a problem only when column is added in position other than at the end
594
+ self .execute ("ALTER TABLE test_alter_column ADD COLUMN another_data VARCHAR(50) AFTER id" )
595
+ self .execute ("INSERT INTO test_alter_column VALUES (2, 'Another value', 'A value')" )
596
+ self .execute ("COMMIT" )
597
+
598
+ self .stream = BinLogStreamReader (
599
+ self .database ,
600
+ server_id = 1024 ,
601
+ only_events = (WriteRowsEvent ,),
602
+ )
603
+ event = self .stream .fetchone () # insert with two values
604
+ # both of these asserts fail because of issue underlying proble described in issue #118
605
+ # because it got table schema info after the alter table, it wrongly assumes the second
606
+ # column of the first insert is 'another_data'
607
+ # ER: {'id': 1, 'data': 'A value'}
608
+ # AR: {'id': 1, 'another_data': 'A value'}
609
+ self .assertIn ("data" , event .rows [0 ]["values" ])
610
+ self .assertNot ("another_data" , event .rows [0 ]["values" ])
611
+ self .assertEqual (event .rows [0 ]["values" ]["data" ], 'A value' )
612
+ self .stream .fetchone () # insert with three values
613
+
588
614
589
615
class TestGtidBinLogStreamReader (base .PyMySQLReplicationTestCase ):
590
616
def setUp (self ):
0 commit comments