Skip to content

Commit 9549d6e

Browse files
author
Bartek Ogryczak
committed
unittest for another scenario for issue #118. PR #117 does not fix that one
1 parent 783e5a5 commit 9549d6e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pymysqlreplication/tests/test_basic.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,32 @@ def test_drop_column(self):
585585
finally:
586586
self.resetBinLog()
587587

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+
588614

589615
class TestGtidBinLogStreamReader(base.PyMySQLReplicationTestCase):
590616
def setUp(self):

0 commit comments

Comments
 (0)