separate write db and read db#121
Conversation
|
CLA Assistant Lite bot: I have read the CLA Document and I hereby sign the CLA sredny buitrago seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. |
🔍 Code Analysis ResultsThis is an excellent pull request that introduces a crucial feature for database scalability. Here is a comprehensive analysis: 1. Change Impact AnalysisWhat this PR accomplishesThis pull request refactors the PostgreSQL database driver to support read/write splitting. It introduces the ability to configure separate database connections for write operations (like This is a significant architectural improvement that enables:
The implementation is backward-compatible. If a separate read connection string is not provided, the driver defaults to using the primary (write) connection for all operations, ensuring existing deployments continue to work without any configuration changes. Key technical changes introduced
Affected system componentsThe changes are well-encapsulated within the PostgreSQL driver located at 2. Architecture VisualizationThe following diagram illustrates the new database connection architecture. It shows how the graph TD
title PostgreSQL Read/Write Connection Separation
subgraph Application
PostgresDriver
end
subgraph "Database Infrastructure"
PrimaryDB["Primary DB (Writes)"]
ReplicaDB["Read Replica (Reads)"]
end
PostgresDriver -- "writeDB Connection (INSERT, UPDATE, DELETE, etc.)" --> PrimaryDB
PostgresDriver -- "readDB Connection (SELECT, COUNT, etc.)" --> ReplicaDB
PrimaryDB -- "Data Replication" --> ReplicaDB
classDef note fill:#f9f,stroke:#333,stroke-width:2px;
subgraph Note
direction LR
A["If ReadConnectionString is not provided,<br/>the readDB connection points to the Primary DB,<br/>using the same connection as writeDB."]
end
class Note note
Powered by Visor from Probelabs Last updated: 2025-09-30T13:45:53.090Z | Triggered by: synchronize | Commit: bbab3b8 |
🔍 Code Analysis ResultsSecurity Issues (4)
Performance Issues (3)
Quality Issues (5)
Style Issues (7)
Powered by Visor from Probelabs Last updated: 2025-09-30T13:45:54.819Z | Triggered by: synchronize | Commit: bbab3b8 |
|


Description
For postgres handle 2 connections: write connection that will write in main db, and read connection that will read replicas, if readConnection string is not set then we will use the same connection to the main server.
There are some visor warning that will not be addressed here:
Am not returning the error from gorm, but a generated error
Outdated, we do not have that and we check readDb and write DB
Same as indexes creation, we cannot receive normalized params as it represents a braking change in the interface. Anyway users do not have access to the query executed here.
outdated as well
Related Issue
Motivation and Context
Test Coverage For This Change
Screenshots (if appropriate)
Types of changes
Checklist
master!masterbranch (left side). Also, it would be best if you started your change off our latestmaster.go mod tidy && go mod vendorgofmt -s -w .go vet ./...