This repo demonstrates how a MariaDB migration that adds a new UUID primary key can silently corrupt replication and eventually trigger:
ERROR 1032: Can't find record in '<table>'
This happens because MariaDB executes DDL as SQL on both master and replica, causing uuid() defaults to generate different PKs on each server.
Start master + replica:
docker compose up -dCheck replication:
docker exec -it replica mariadb -uroot -proot -e "SHOW SLAVE STATUS\G"Should show:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
docker exec -it replica mariadb -uroot -proot -e "CREATE DATABASE IF NOT EXISTS demo;"- Run initial migration + seed
DB_HOST=127.0.0.1 DB_PORT=3306 npm run initial:migrate
DB_HOST=127.0.0.1 DB_PORT=3306 npm run seed- Apply the problematic migration
DB_HOST=127.0.0.1 DB_PORT=3306 npm run bad:migrateThis migration:
- Drops the old PK
- Adds id with DEFAULT uuid()
- Makes id the new PK
- → master + replica now have different UUIDs
- Trigger replication failure
DB_HOST=127.0.0.1 DB_PORT=3306 npm run trigger-failuredocker exec -it replica mariadb -uroot -proot -e "SHOW SLAVE STATUS\G"Expected:
Last_SQL_Errno: 1032
Last_SQL_Error: ... Can't find record ...
Slave_SQL_Running: No