Repository navigation
Add a MySQL provider - #8
Merged
Merged
Conversation
github.com/bashhack/testdb/mysql gives each test its own MySQL database: mysql.Setup returns a *sql.DB, mysql.New takes a custom initializer, and migrators, keep-on-failure and parallel use work as they do for PostgreSQL. Templates are not available yet (MySQL cannot clone a database); WithTemplate is refused with ErrTemplatesNotSupported, and the README does not list MySQL until they are. Cleanup is designed around MySQL's hazard: DROP DATABASE does not fail while sessions are connected, it waits on their metadata locks, by default for a year. The provider kills the database's sessions first and runs with a five-second lock_wait_timeout so a session it could not kill makes cleanup fail loudly rather than hang. A test leaks an open transaction and checks the drop still completes promptly. The admin DSN may be go-sql-driver's native form or a mysql:// URL; TEST_MYSQL_URL wins over the shared variables, and a PostgreSQL URL in TEST_DATABASE_URL gets an error that says to set it. Test DSNs are built from the admin config so every parameter carries over. mysql.SQLFiles and LoadSQLFile run multi-statement files. The pieces Setup and New are built from move into core as testdb.RunConfiguredMigrations and testdb.RegisterCleanup, so both providers behave identically around a test; a failed migration under KeepOnFailure now keeps the database too. testdb.InspectCommander lets a provider say how to open a kept database in its own client, so the log shows a mysql command line for MySQL and psql for PostgreSQL. The goose adapter infers the MySQL dialect from a native DSN and the golang-migrate adapter gains MySQL through its mysql driver. A mysql:8.4 service joins the compose file (durability off, as for Postgres) and CI; the Makefile waits for both.
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step 4, PR 1 of 2: the
mysqlpackage. PR 2 adds templates (logical clone plus ready databases); until then MySQL is deliberately not listed in the README, perPROVIDER_PARITY.md: isolation without the speed is half the thesis.MySQL's hazard, handled
DROP DATABASEin MySQL does not fail while sessions are connected; it waits on the metadata locks they hold, by default for a year. The provider kills the database's sessions first and runs its admin session withlock_wait_timeout = 5, so a session it could not kill makes cleanup fail loudly rather than hang a CI job.TestCleanupWithOpenTransactionDoesNotHangleaks a transaction holding a lock and checks the drop still completes promptly and the database is gone.DSNs
The admin DSN may be go-sql-driver's native form (
user:pass@tcp(host:port)/db?params) or amysql://URL.TEST_MYSQL_URLwins overTEST_DATABASE_URL/DATABASE_URL; a project whose shared variable points at Postgres gets an error that says to set it (which the local.envhere now does). Test DSNs are built from the parsed admin config, soparseTime, TLS, timeouts etc. all carry over.mysql.SQLFiles/LoadSQLFilerun multi-statement files through amultiStatementsconnection.Core: shared plumbing for parity
testdb.RunConfiguredMigrationsandtestdb.RegisterCleanupare what both providers'Setup/Neware built from, so they behave identically around a test. One behaviour change: a failed migration underKeepOnFailurenow keeps the database (a half-applied migration is what you want to look at).testdb.InspectCommander: a provider says how to open a kept database in its own client. The kept-database log showspsql "…"for Postgres andmysql --host=… --user=… …for MySQL.Adapters, infrastructure
database/mysqldriver (native DSN prefixed withmysql://, the form it parses). Tern stays Postgres-only. Both adapters have MySQL tests.mysql:8.4joinsdocker-compose.test.ymlwith durability off (the MySQL equivalent of the Postgres service'sfsync=off; ~40% faster DDL and drops, measured) and the CI services.make test/db/startwaits for both.CIset) so a broken service can never pass silently.