Skip to content

Conversation

@Denes-cilwal
Copy link
Contributor

This pull request introduces support for PostgreSQL as a database option in addition to MySQL, refactoring the database connection logic to use a provider-based architecture. The changes improve modularity and future extensibility, allowing easy addition of new database types. The most important changes are grouped below:

Database provider architecture:

  • Added a new DBProvider interface and provider factory in pkg/infrastructure/db_provider.go, enabling dynamic selection of MySQL or PostgreSQL based on the DB_TYPE environment variable.
  • Implemented MySQLProvider and PostgresProvider in separate files (pkg/infrastructure/mysql_provider.go and pkg/infrastructure/postgres_provider.go) to encapsulate connection logic for each database type. [1] [2]
  • Refactored pkg/infrastructure/database_factory.go to use the provider pattern for database creation, replacing direct instantiation with provider-based construction.

PostgreSQL support:

  • Added PostgreSQL connection logic in pkg/infrastructure/db.go, including database existence checks and dynamic SSL mode selection.
  • Updated Go module dependencies (go.mod) to include gorm.io/driver/postgres and adjust indirect dependencies for both MySQL and PostgreSQL. [1] [2] [3]

Configuration and integration:

  • Updated .env.example to document support for both MySQL and PostgreSQL in the DB_TYPE variable.
  • Registered the new provider and database constructors in the Fx dependency injection module (pkg/infrastructure/module.go).
  • Added the PostgreSQL driver import in pkg/infrastructure/db.go.… support

Copy link

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 refactors the database connection logic to support multiple database providers (MySQL and PostgreSQL) through a provider pattern, replacing the monolithic MySQL-only implementation.

  • Introduced a DBProvider interface with MySQL and PostgreSQL implementations
  • Refactored database connection logic to use dependency injection via the provider pattern
  • Added PostgreSQL driver support alongside the existing MySQL driver

Reviewed Changes

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

Show a summary per file
File Description
pkg/infrastructure/db_provider.go Defines the DBProvider interface and factory function for selecting the appropriate database provider based on configuration
pkg/infrastructure/postgres_provider.go Implements the DBProvider interface for PostgreSQL connections
pkg/infrastructure/mysql_provider.go Implements the DBProvider interface for MySQL connections
pkg/infrastructure/database_factory.go Provides Fx constructors for dependency injection of database providers and connections
pkg/infrastructure/db.go Refactored connection logic into separate MySQLConnect and PostgresConnect functions with proper error handling
pkg/infrastructure/module.go Registers the new NewDBProvider constructor in the Fx module
go.mod Promotes gorm.io/driver/postgres from indirect to direct dependency and moves go-sql-driver/mysql to indirect
go.sum Updates checksums for new and modified dependencies
.env.example Documents postgres as a supported DB_TYPE option

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

This comment was marked as outdated.

This comment was marked as outdated.

[WIP] Update database provider interface based on feedback
[WIP] Update implementation based on feedback for database provider interface

This comment was marked as outdated.

…-one

[WIP] Address feedback on database provider interface implementation
Copy link

Copilot AI commented Oct 30, 2025

@Denes-cilwal I've opened a new pull request, #127, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 3 commits October 30, 2025 07:27
@Denes-cilwal Denes-cilwal changed the title Implement database provider interface with MySQL and PostgreSQL… Architecture Improvements Oct 30, 2025
@paudelgaurav
Copy link
Member

Closes #120

@Denes-cilwal Denes-cilwal changed the title Architecture Improvements Architecture Improvements [MYSQL + POSTGRESQL DB SUPPORT] Nov 3, 2025
@Denes-cilwal
Copy link
Contributor Author

This branch provides support for both MySQL and PostgreSQL.
Use the existing implementation as a reference for MySQL, while the PostgreSQL support has been newly introduced in the develop branch.

@Denes-cilwal Denes-cilwal marked this pull request as draft November 3, 2025 05:24
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.

5 participants