Add sqlc-test-setup command for database test environment setup#4304
Merged
kyleconroy merged 12 commits intomainfrom Feb 22, 2026
Merged
Add sqlc-test-setup command for database test environment setup#4304kyleconroy merged 12 commits intomainfrom
kyleconroy merged 12 commits intomainfrom
Conversation
New cmd/sqlc-test-setup package with two subcommands: - `install`: Installs PostgreSQL and MySQL 9 via apt, including apt proxy configuration for Claude Code remote environments. - `start`: Starts both database services, configures authentication (passwords, pg_hba.conf), and verifies connectivity. Both commands log all actions verbosely for easy debugging. https://claude.ai/code/session_01CsyRwSkRxBcQoaQFVkMQsJ
Key fixes: - Use apt-get install -f to resolve dpkg dependency issues (libaio1t64, libmecab2, libnuma1) instead of expecting all dpkg -i to succeed - Remove /etc/init.d/mysql chmod (not present in systemd environments) - Use mysqld_safe to start MySQL (works without systemd/init.d) - Use caching_sha2_password plugin instead of auth_socket for TCP access - Add waitForMySQL polling loop for reliable startup detection Idempotency: - install: Skips apt proxy, PostgreSQL, and MySQL if already present - start: Detects running MySQL via mysqladmin ping, skips pg_hba.conf entry if already configured, skips password setup if already correct, skips MySQL data dir initialization if already done Tested: both commands succeed on first run and on subsequent re-runs. https://claude.ai/code/session_01CsyRwSkRxBcQoaQFVkMQsJ
…UDE.md - docker.Installed(): Also verify Docker daemon is running (not just binary in PATH). Without this, tests try Docker first, fail on docker pull, and t.Fatal instead of falling back to native databases. - expander_test.go: Use the same Docker/native detection chain as other tests instead of hardcoding connection URIs. The PostgreSQL test was hardcoded to password 'mysecretpassword' which doesn't match native setup (password 'postgres'). - CLAUDE.md: Replace manual apt/dpkg database setup instructions with sqlc-test-setup commands. Remove Step 1-4 manual instructions. All 29 test packages pass with zero skips. https://claude.ai/code/session_01CsyRwSkRxBcQoaQFVkMQsJ
Adds database setup before the test step so integration tests can connect to PostgreSQL and MySQL without Docker. https://claude.ai/code/session_01CsyRwSkRxBcQoaQFVkMQsJ
Three fixes for CI failures: 1. mysqlInitialized() now uses `sudo ls` instead of filepath.Glob. The /var/lib/mysql directory is owned by mysql:mysql with restricted permissions, so filepath.Glob silently failed, causing the tool to attempt --initialize-insecure on a non-empty directory. 2. Stop any existing MySQL service before starting our own to avoid port conflicts with pre-installed MySQL on GitHub Actions runners. 3. Remove vestigial `if: matrix.os` condition from the test step in ci.yml — the test job has no matrix and the condition was always truthy, producing a GitHub Actions warning. https://claude.ai/code/session_01CsyRwSkRxBcQoaQFVkMQsJ
On GitHub Actions ubuntu-24.04, the pre-installed MySQL 8.0 uses the auth_socket plugin for root, which requires the OS user to match the MySQL user. Since the runner runs as "runner" (not "root"), plain `mysql -u root` fails with access denied. Fix by falling back to `sudo mysql -u root` when the non-sudo attempt fails, which satisfies auth_socket's OS user check. https://claude.ai/code/session_01CsyRwSkRxBcQoaQFVkMQsJ
When the data directory already exists (e.g. pre-installed MySQL on GitHub Actions), the root password is unknown. Neither blank password, auth_socket, nor sudo can authenticate. Fix by starting MySQL with --skip-grant-tables when an existing data directory is detected, resetting the root password, then restarting normally. https://claude.ai/code/session_01CsyRwSkRxBcQoaQFVkMQsJ
Stops on the first test failure instead of running the full suite, making it faster to identify issues. https://claude.ai/code/session_01CsyRwSkRxBcQoaQFVkMQsJ
The test infrastructure checks if Docker is available before trying native databases. Since GitHub Actions runners have Docker installed, tests were trying to start MySQL/PostgreSQL via Docker instead of using the databases already started by sqlc-test-setup. Setting POSTGRESQL_SERVER_URI and MYSQL_SERVER_URI explicitly ensures tests connect to the native databases. https://claude.ai/code/session_01CsyRwSkRxBcQoaQFVkMQsJ
GitHub Actions runners come with MySQL 8.0 pre-installed. The install step was skipping installation because mysqld already existed, leaving us with MySQL 8.0 which has authentication incompatibilities with the test suite. Now checks the mysqld version string. If it's below 9, stops the old MySQL, removes old packages, clears the data directory, and installs MySQL 9 from Oracle's deb bundle. https://claude.ai/code/session_01CsyRwSkRxBcQoaQFVkMQsJ
This is an internal implementation detail that doesn't need to be documented. https://claude.ai/code/session_01CsyRwSkRxBcQoaQFVkMQsJ
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.
New cmd/sqlc-test-setup package with two subcommands:
install: Installs PostgreSQL and MySQL 9 via apt, including aptproxy configuration for Claude Code remote environments.
start: Starts both database services, configures authentication(passwords, pg_hba.conf), and verifies connectivity.
Both commands log all actions verbosely for easy debugging.
https://claude.ai/code/session_01CsyRwSkRxBcQoaQFVkMQsJ