Skip to content

feat: structured database connection config (#39)#40

Merged
mikkeldamsgaard merged 2 commits into
mainfrom
39-structured-database-config
Mar 14, 2026
Merged

feat: structured database connection config (#39)#40
mikkeldamsgaard merged 2 commits into
mainfrom
39-structured-database-config

Conversation

@mikkeldamsgaard
Copy link
Copy Markdown
Contributor

Summary

  • Add discrete connection fields (host, port, user, password, name, options) to DatabaseConfig as an alternative to url/url_env
  • Build connections using driver-native APIs (PostgreSQL key-value DSN, MySQL OptsBuilder), bypassing URL parsing entirely — passwords with @, %, : etc. work without encoding
  • Validate mutual exclusivity: structured fields and url/url_env cannot be combined

Closes #39

Test plan

  • 168 unit tests pass (6 new: schema parsing, DSN building, connection resolution, escaping)
  • 20 integration tests pass against real PostgreSQL 16 and MySQL 8.0 (2 new: test_seed_postgres_structured_config, test_seed_mysql_structured_config)
  • cargo clippy -- -D warnings clean
  • cargo fmt -- --check clean
cargo test
cargo clippy -- -D warnings
docker compose -f tests/docker-compose.yml up -d --wait
INTEGRATION=1 cargo test --test integration_test -- --test-threads=1
docker compose -f tests/docker-compose.yml down

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings March 14, 2026 10:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds structured database connection configuration as an alternative to URL-based connection strings, closing issue #39. Users can now specify host, port, user, password, name, and options fields directly, avoiding URL-encoding issues with special characters in passwords. Connections are built using driver-native APIs (PostgreSQL key-value DSN, MySQL OptsBuilder).

Changes:

  • New discrete connection fields on DatabaseConfig with mutual exclusivity validation against url/url_env
  • Driver-specific structured connection logic: PostgreSQL key-value DSN builder and MySQL OptsBuilder integration, with SQLite explicitly rejected
  • Comprehensive tests (unit + integration), documentation, and an example spec file

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/seed/schema.rs Adds structured fields to DatabaseConfig, validation, and has_structured_config() helper; moves URL resolution out of SeedPlan
src/seed/db.rs Refactors connect() to accept DatabaseConfig, adds connect_structured(), build_postgres_dsn(), escape_dsn_value(), and unsupported_driver_error()
src/seed/mod.rs Updates call site to pass &plan.database instead of a resolved URL string
docs/seeding.md Documents both connection styles, field reference table, and resolution order
examples/seed/structured-config-seed.yaml Example spec using structured config with templated password
tests/input/seed-postgres-structured.yaml Integration test fixture for PostgreSQL structured config
tests/input/seed-mysql-structured.yaml Integration test fixture for MySQL structured config
tests/integration_test.rs Two new integration tests verifying structured config with real databases
CHANGELOG.md Documents the new feature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/seed/db.rs
mikkeldamsgaard and others added 2 commits March 14, 2026 11:27
… URL (#39)

Add discrete connection fields (host, port, user, password, name, options)
as an alternative to url/url_env. Connections are built using driver-native
APIs (PostgreSQL key-value DSN, MySQL OptsBuilder), bypassing URL parsing
so passwords with special characters work without encoding.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
MySQL's OptsBuilder does not support arbitrary key-value connection
parameters. Return an error listing the unsupported keys instead of
silently ignoring them.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mikkeldamsgaard mikkeldamsgaard force-pushed the 39-structured-database-config branch from c5f483e to 0edbdcd Compare March 14, 2026 10:28
@mikkeldamsgaard mikkeldamsgaard merged commit ad92758 into main Mar 14, 2026
7 checks passed
@mikkeldamsgaard mikkeldamsgaard deleted the 39-structured-database-config branch March 14, 2026 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support structured database connection config as alternative to URL

2 participants