Skip to content

Comments

Add sqlc-test-setup command for database test environment setup#4304

Merged
kyleconroy merged 12 commits intomainfrom
claude/sqlc-test-setup-package-MitRq
Feb 22, 2026
Merged

Add sqlc-test-setup command for database test environment setup#4304
kyleconroy merged 12 commits intomainfrom
claude/sqlc-test-setup-package-MitRq

Conversation

@kyleconroy
Copy link
Collaborator

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

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
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. 🔧 golang labels Feb 19, 2026
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
@kyleconroy kyleconroy merged commit 99be46a into main Feb 22, 2026
13 checks passed
@kyleconroy kyleconroy deleted the claude/sqlc-test-setup-package-MitRq branch February 22, 2026 07:14
@dosubot
Copy link

dosubot bot commented Feb 22, 2026

Related Documentation

Checked 0 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files. 🔧 golang

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants