Skip to content

feat: config file#28

Merged
mickamy merged 5 commits intomainfrom
feat/config-file
Mar 12, 2026
Merged

feat: config file#28
mickamy merged 5 commits intomainfrom
feat/config-file

Conversation

@mickamy
Copy link
Copy Markdown
Owner

@mickamy mickamy commented Mar 12, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 12, 2026 01:06
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

Adds YAML-based configuration support for sql-tapd, allowing runtime settings to be loaded from a config file and overridden by CLI flags.

Changes:

  • Introduces a config package with defaults and a YAML loader (with unknown-field detection).
  • Updates sql-tapd to load config from .sql-tap.yaml (or -config) and apply CLI overrides only for explicitly-set flags.
  • Extends golangci-lint tag style rules to enforce yaml tags as snake_case.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
config/config.go New config model, defaults, and YAML loader with KnownFields(true) to catch typos.
config/config_test.go Unit tests for defaults, explicit/implicit loading behavior, partial overrides, and invalid/unknown YAML.
cmd/sql-tapd/main.go Wires config loading into sql-tapd, implements “explicit flag overrides config” semantics, and refactors run signature.
.golangci.yaml Enforces snake_case for YAML struct tags via tagliatelle.

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

Comment thread cmd/sql-tapd/main.go
Comment thread cmd/sql-tapd/main.go
Comment on lines 44 to 46
driver := fs.String("driver", "", "database driver: postgres, mysql, tidb (required)")
listen := fs.String("listen", "", "client listen address (required)")
upstream := fs.String("upstream", "", "upstream database address (required)")
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

The flag descriptions for -driver/-listen/-upstream still say "(required)", but this PR also allows providing those values via the config file. Consider updating the help text to reflect that they are only required when not set in the config (e.g., "required unless provided by -config / .sql-tap.yaml").

Suggested change
driver := fs.String("driver", "", "database driver: postgres, mysql, tidb (required)")
listen := fs.String("listen", "", "client listen address (required)")
upstream := fs.String("upstream", "", "upstream database address (required)")
driver := fs.String("driver", "", "database driver: postgres, mysql, tidb (required unless provided by -config / .sql-tap.yaml)")
listen := fs.String("listen", "", "client listen address (required unless provided by -config / .sql-tap.yaml)")
upstream := fs.String("upstream", "", "upstream database address (required unless provided by -config / .sql-tap.yaml)")

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings March 12, 2026 01:11
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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

cmd/sql-tapd/main.go:141

  • explainDriver is left as the zero value when cfg.Driver is not one of mysql/tidb/postgres, which maps to explain.Postgres (Driver iota=0). That means an unsupported driver can incorrectly initialize the EXPLAIN client as Postgres before later failing in the proxy switch. Consider adding a default case that returns an error (or validating cfg.Driver once up-front) so unsupported drivers don’t silently fall back to Postgres behavior.
		var explainDriver explain.Driver
		switch cfg.Driver {
		case "mysql":
			explainDriver = explain.MySQL
		case "tidb":
			explainDriver = explain.TiDB
		case "postgres":
			explainDriver = explain.Postgres
		}
		explainClient = explain.NewClient(db, explainDriver)

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

@mickamy mickamy merged commit cfcbe9c into main Mar 12, 2026
5 checks passed
@mickamy mickamy deleted the feat/config-file branch March 12, 2026 01:16
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.

2 participants