-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(testing): implement template database cloning for MySQL #4131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(testing): implement template database cloning for MySQL #4131
Conversation
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>
Use CREATE DATABASE IF NOT EXISTS for idempotent template creation. Check if migrations already exist before running them, allowing reuse of template databases that exist but weren't registered in the tracking table (e.g., from a previous CI run or interrupted process). Use INSERT IGNORE when registering templates to handle race conditions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…chema Query _sqlx_migrations table directly to check if migrations exist. This handles the case where the table exists with entries from a previous run more reliably than checking information_schema.tables. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Check GET_LOCK returns 1 (success) before proceeding - Add debug output to show migration count or error during template check - This should help diagnose the race condition in CI 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
MariaDB returns NULL when GET_LOCK is called with -1 timeout. Use 300 second timeout instead for cross-database compatibility. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
GitHub has deprecated the macOS-13 runner. Remove it from the sqlx-cli workflow matrices. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
While I like the idea in theory, I'm not interested in reviewing vibe-coded PRs, sorry. I have numerous conceptual issues with this PR as well, but I don't see any reason to put the effort into giving a detailed review. |
|
@abonander I'm not sure I understand the problem here. This PR amounts to, outside of test code, maybe 200 lines of changes. Dismissing it on the basis of AI assisting is to do a disservice. It also encourages dishonesty - a small change to the commit messages and PR summary and there would be no indication of AI work anyway. We are running into major problems with running migrations on every test case - hundreds of tests that all take 60+ seconds to run. This is a proposed solution. If I were to submit a non-vibe coded PR with this, would you review it then? It would largely be identical - I did a thorough review of the code myself before submitting this.
This would actually be useful feedback. How could we address those issues you have with the concept so we can upstream changes that will let us feasibly run tests? |
I probably wouldn't have even been suspicious had you not gone so far as to have Claude open the PR for you, bypassing our pull request template. Sorry, I just didn't feel like putting more intellectual labor into reviewing it than it took to create.
How much critical thought did you put into the solution here? Because all the glaring issues really make me wonder. |
Summary
This PR implements template database cloning for
sqlx::testto significantly speed up test runs when using migrations. Instead of running migrations for every test, a template database is created once and cloned for each test.Before (slow)
After (fast)
Implementation Details
Core Infrastructure (
sqlx-core/src/testing/mod.rs)migrations_hash()- computes SHA256 hash of all migration checksums for template namingtemplate_db_name()- generates template database name from hashTestContextwithfrom_template: boolfieldsetup_test_db()to skip migrations when cloned from templateMySQL Implementation (
sqlx-mysql/src/testing/mod.rs)_sqlx_test_templatestracking table for template metadataGET_LOCK()for synchronization during template creationmysqldump/mysqlcommands (fast) with in-process SQL fallbackConfiguration
SQLX_TEST_NO_TEMPLATE=1to disable template cloningTest Plan
migrations_hash()andtemplate_db_name()functionsFuture Work
CREATE DATABASE ... TEMPLATE(follow-up PR)🤖 Generated with Claude Code