-
Notifications
You must be signed in to change notification settings - Fork 25
Architecture Improvements [MYSQL + POSTGRESQL DB SUPPORT] #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Denes-cilwal
wants to merge
21
commits into
develop
Choose a base branch
from
feat/postgres-db-support
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
380ad2d
refactor env to seperate env variables based on category
projectmap 9d164ab
rename AWSConfig userPoolID and ClientID field name to include cognit…
projectmap 450979c
rename DatabaseConfig DBUsername to Username and ServerConfig ServerP…
projectmap 3906de3
feat: implement database provider interface with MySQL and PostgreSQL…
Denes-cilwal 4e6c3f1
fix: remove sensitive URL logging in Postgres connection
Denes-cilwal f4718f4
Update pkg/infrastructure/db.go
Denes-cilwal c0931e5
Update pkg/infrastructure/db.go
Denes-cilwal 0fa4d0d
Initial plan
Copilot b22a0cc
Initial plan
Copilot fd5cea5
Merge pull request #125 from wesionaryTEAM/copilot/sub-pr-122-again
Denes-cilwal 52d7413
Merge pull request #124 from wesionaryTEAM/copilot/sub-pr-122
Denes-cilwal 81d9dc9
Initial plan
Copilot 0dd97d4
Merge pull request #126 from wesionaryTEAM/copilot/sub-pr-122-another…
Denes-cilwal 08bdbf5
Add TranslateError option to gorm.Config in MySQL and PostgreSQL conn…
Denes-cilwal fe3d2b7
Initial plan
Copilot 06f0724
feat: add database name validation to prevent SQL injection
Copilot 42d3ccb
refactor: improve database name validation with stricter rules
Copilot c676101
Merge pull request #127 from wesionaryTEAM/copilot/sub-pr-122-another…
Denes-cilwal 78f4bc3
refactor: remove redundant comments and improve database name validation
Denes-cilwal 9aa0ad2
Merge branch 'develop' into env/refactor
Denes-cilwal eb0e9cd
refactor: restructure environment configuration and update references…
Denes-cilwal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package infrastructure | ||
|
|
||
| import "clean-architecture/pkg/framework" | ||
|
|
||
| // NewDBProvider is an Fx constructor that provides the concrete DBProvider. | ||
| func NewDBProvider(env *framework.Env) DBProvider { | ||
| return providerDBFactory(env) | ||
| } | ||
|
|
||
| // NewDatabase receives a DBProvider via Fx and returns a connected Database. | ||
| func NewDatabase(logger framework.Logger, env *framework.Env, provider DBProvider) Database { | ||
| db, err := provider.Connect(logger, env) | ||
| if err != nil { | ||
| logger.Panic("failed to connect database: ", err) | ||
| } | ||
| return *db | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package infrastructure | ||
|
|
||
| import ( | ||
| "clean-architecture/pkg/framework" | ||
| "strings" | ||
| ) | ||
|
|
||
| // DBProvider interface | ||
| type DBProvider interface { | ||
| Connect(logger framework.Logger, env *framework.Env) (*Database, error) | ||
| Type() string | ||
| } | ||
|
|
||
| // providerDBFactory chooses correct provider based on env.DBType. | ||
| func providerDBFactory(env *framework.Env) DBProvider { | ||
| dbType := strings.ToLower(strings.TrimSpace(env.DBType)) | ||
| if dbType == "" { | ||
| return &MySQLProvider{} | ||
| } | ||
| switch dbType { | ||
| case "mysql": | ||
| return &MySQLProvider{} | ||
| case "postgres", "postgresql": | ||
| return &PostgresProvider{} | ||
| default: | ||
| return &MySQLProvider{} // fallback for unknown types | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package infrastructure | ||
|
|
||
| import "clean-architecture/pkg/framework" | ||
|
|
||
| // MySQLProvider implements DBProvider for MySQL. | ||
| type MySQLProvider struct{} | ||
|
|
||
| func (p *MySQLProvider) Type() string { return "mysql" } | ||
|
|
||
| func (p *MySQLProvider) Connect(logger framework.Logger, env *framework.Env) (*Database, error) { | ||
| db, err := MySQLConnect(logger, env) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return &Database{DB: db}, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package infrastructure | ||
|
|
||
| import "clean-architecture/pkg/framework" | ||
|
|
||
| // PostgresProvider implements DBProvider for PostgreSQL. | ||
| type PostgresProvider struct{} | ||
|
|
||
| func (p *PostgresProvider) Type() string { return "postgres" } | ||
|
|
||
| func (p *PostgresProvider) Connect(logger framework.Logger, env *framework.Env) (*Database, error) { | ||
| db, err := PostgresConnect(logger, env) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return &Database{DB: db}, nil | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.