Commit 16ab336
committed
Fix MySQL test cleanup using db.synchronize for same connection
The root cause of the FK constraint violations was that MySQL's
SET FOREIGN_KEY_CHECKS is session-specific (per-connection). When using
Sequel's connection pool, each db.run() call can get a different connection,
so SET FOREIGN_KEY_CHECKS=0 executed on one connection doesn't affect
TRUNCATE statements executed on other connections.
Solution: Use db.synchronize to hold a single connection from the pool
and execute all operations (SET FK=0, TRUNCATE, SET FK=1) on that same
connection using conn.query() instead of db.run().
This ensures the FK checks are properly disabled for all TRUNCATE operations
while they execute, then re-enabled afterward, all on the same connection.
PostgreSQL continues to use TRUNCATE with CASCADE, which doesn't require
this workaround as it handles foreign keys correctly in a single statement.
This fixes thousands of FK constraint violations in MySQL 8.2 tests.1 parent c27eaf2 commit 16ab336
1 file changed
+14
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
20 | 27 | | |
21 | | - | |
| 28 | + | |
22 | 29 | | |
| 30 | + | |
23 | 31 | | |
24 | 32 | | |
25 | 33 | | |
| |||
0 commit comments