1. In the production environment, duplicate data was written to the skill data table, as shown in Figure 1.

2. However, a check for whether the record already exists was performed before writing. The combination of game_code and team_code should be unique, as shown in Figure 2.

3. I recommend first reviewing the URL: https://www.shuijingwanwq.com/2017/04/18/1568/ . Due to the mechanism of the program requested by POST, the ab POST file only supports parameters for a single request and cannot simulate the real scenario. In the real scenario, the parameters for each request would be different, so it is impossible to reproduce the production environment bug.
4. By commenting out the condition that checks whether the record exists, every request now inserts data, simulating a scenario where multiple skill records exist for a single match, as shown in Figure 3.

5. Using Postman, I executed two consecutive requests with different parameters. Ultimately, 4 records existed in MySQL, as shown in Figures 4 and 5.


6. To prevent this situation, I decided to modify the table structure in MySQL. I deleted the 4 records from the table and added game_code and team_code as a composite unique index. In phpMyAdmin, I selected game_code and team_code, then clicked the Unique button, as shown in Figure 6.

7. The SQL statement executed successfully, and the composite unique index was added successfully, as shown in Figures 7 and 8.
ALTER TABLE `kq_game_team_skill` ADD UNIQUE( `game_code`, `team_code`);


8. Using Gii, I regenerated the new model file, as shown in Figure 9.

9. A new line was inserted into rules(), as shown in Figure 10.

10. Using Postman, I executed two consecutive requests with different parameters. An error occurred during the second execution, as shown in Figure 11.

11. The error message had been processed. I printed the original error message, as shown in Figure 12.

12. The original error message: $gameTeamSkill->errors is as follows, as shown in Figure 13.

13. Checking MySQL at this point, there are only 2 skill data records corresponding to a match, and only 1 record per team, which meets expectations, as shown in Figure 14.

14. Even though the ab stress test did not simulate the production environment bug, implementing the composite unique index in MySQL theoretically prevents this bug from recurring. However, the code returned is not a number, which needs further optimization.
