Commit c474591
feat(testing): implement template database cloning for MySQL
Add template database cloning optimization to avoid running migrations for
every test. When multiple tests use the same migrations, a template database
is created once and cloned for each test, significantly speeding up test runs.
Implementation details:
- Add migrations_hash() to compute SHA256 of migration checksums
- Add template_db_name() to generate template database names
- Extend TestContext with from_template field to track cloning
- Modify setup_test_db() to skip migrations when cloned from template
- MySQL: Use mysqldump/mysql for fast cloning with in-process fallback
- Add _sqlx_test_templates tracking table with GET_LOCK synchronization
- Add SQLX_TEST_NO_TEMPLATE env var to opt out of template cloning
- Add comprehensive tests for template functionality
- Add template tests to MySQL and MariaDB CI jobs
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>1 parent e8384f2 commit c474591
File tree
7 files changed
+645
-15
lines changed- .github/workflows
- sqlx-core/src/testing
- sqlx-mysql/src/testing
- sqlx-postgres/src/testing
- sqlx-sqlite/src/testing
- tests/mysql
7 files changed
+645
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
371 | 371 | | |
372 | 372 | | |
373 | 373 | | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
374 | 385 | | |
375 | 386 | | |
376 | 387 | | |
| |||
472 | 483 | | |
473 | 484 | | |
474 | 485 | | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
475 | 497 | | |
476 | 498 | | |
477 | 499 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
394 | 399 | | |
395 | 400 | | |
396 | 401 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
5 | 8 | | |
6 | | - | |
| 9 | + | |
7 | 10 | | |
8 | 11 | | |
9 | 12 | | |
| |||
14 | 17 | | |
15 | 18 | | |
16 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
17 | 49 | | |
18 | 50 | | |
19 | 51 | | |
| |||
82 | 114 | | |
83 | 115 | | |
84 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
85 | 120 | | |
86 | 121 | | |
87 | 122 | | |
| |||
226 | 261 | | |
227 | 262 | | |
228 | 263 | | |
229 | | - | |
| 264 | + | |
230 | 265 | | |
231 | 266 | | |
232 | 267 | | |
| |||
246 | 281 | | |
247 | 282 | | |
248 | 283 | | |
| 284 | + | |
249 | 285 | | |
250 | 286 | | |
251 | 287 | | |
| |||
255 | 291 | | |
256 | 292 | | |
257 | 293 | | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
263 | 303 | | |
264 | 304 | | |
265 | 305 | | |
| |||
0 commit comments