Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 26, 2025

Extends database support beyond SQLite to include MySQL, configurable via YAML or environment variables.

Changes

Configuration

  • Added database.type, host, port, database, username, password fields to DatabaseConfig
  • Environment variables: TW_DATABASE_TYPE, TW_DATABASE_HOST, TW_DATABASE_PORT, TW_DATABASE_NAME, TW_DATABASE_USERNAME, TW_DATABASE_PASSWORD
  • Default remains SQLite when type is unset or "sqlite"

Database Initialization

  • NewDatabase() now switches between SQLite and MySQL dialectors based on database.type
  • Validates required MySQL fields (host, database, username) at startup
  • SQLite-specific PRAGMAs only applied for SQLite connections

Example Configuration

database:
  type: mysql
  host: db.example.com
  port: 3306
  database: taskwizard
  username: appuser
  password: secret
  migration: true

Or via environment:

export TW_DATABASE_TYPE=mysql
export TW_DATABASE_HOST=db.example.com
export TW_DATABASE_NAME=taskwizard
export TW_DATABASE_USERNAME=appuser
export TW_DATABASE_PASSWORD=secret

Dependencies

  • Added gorm.io/driver/mysql for MySQL connectivity
Original prompt

Add support for using a MySQL/MariaDB database on top of the existing Sqlite option. Make sure that config can be set both using the yaml file and env variables. Document that in the README. Make as fewer changes as possible to the code


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add support for MySQL/MariaDB database configuration Add MySQL database support with YAML and environment configuration Oct 26, 2025
Copilot AI requested a review from dkhalife October 26, 2025 13:04
@dkhalife dkhalife marked this pull request as ready for review October 26, 2025 13:06
Copilot AI review requested due to automatic review settings October 26, 2025 13:06
@dkhalife dkhalife enabled auto-merge (squash) October 26, 2025 13:06
Copy link
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 extends database support beyond SQLite to include MySQL/MariaDB, with configuration available through both YAML files and environment variables. The default behavior (SQLite) is preserved when the database type is unset or explicitly set to "sqlite".

Key Changes:

  • Added MySQL database support alongside existing SQLite functionality
  • Extended DatabaseConfig with MySQL-specific fields (type, host, port, database, username, password)
  • Implemented validation for required MySQL configuration fields at startup

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
apiserver/config/config.go Extended DatabaseConfig struct with MySQL fields and added environment variable bindings
apiserver/config/config.yaml Added type: sqlite to explicitly document default database type
apiserver/config/config.dev.yaml Added type: sqlite to development configuration
apiserver/config/config_test.go Added comprehensive tests for MySQL configuration via YAML and environment variables
apiserver/internal/utils/database/database.go Implemented database type switching logic with MySQL DSN construction and SQLite-specific PRAGMA handling
apiserver/internal/utils/database/database_test.go Added validation tests for MySQL required fields and unsupported database types
apiserver/go.mod Added gorm.io/driver/mysql dependency and updated GORM version
README.md Documented MySQL configuration options with examples for both YAML and environment variables

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

@dkhalife dkhalife merged commit 4fa3b57 into main Oct 26, 2025
6 checks passed
@dkhalife dkhalife deleted the copilot/add-mysql-support branch October 26, 2025 13:08
@codecov
Copy link

codecov bot commented Oct 26, 2025

Codecov Report

❌ Patch coverage is 62.85714% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
apiserver/internal/utils/database/database.go 55.17% 10 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

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