Skip to content

fix(ers): use pgx database/sql driver in SQL ERS provider#3543

Open
jp-ayyappan wants to merge 13 commits into
mainfrom
fix/ers-sql-provider-register-postgres-driver
Open

fix(ers): use pgx database/sql driver in SQL ERS provider#3543
jp-ayyappan wants to merge 13 commits into
mainfrom
fix/ers-sql-provider-register-postgres-driver

Conversation

@jp-ayyappan

@jp-ayyappan jp-ayyappan commented May 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #3539.

The multi-strategy ERS SQL provider called sql.Open(config.Driver, ...) but did not ensure the PostgreSQL database/sql driver was available in the platform service binary. This PR makes PostgreSQL SQL provider configs work without requiring consumers to add their own blank import.

Changes

  1. Imports github.com/jackc/pgx/v5/stdlib in the SQL provider package so the pgx database/sql drivers are registered when the provider package is loaded.
  2. Defaults SQL provider configs to the versioned pgx/v5 driver name.
  3. Normalizes PostgreSQL aliases before opening the database connection:
    • pgx -> pgx/v5
    • postgres -> pgx/v5
    • postgresql -> pgx/v5
    • mixed-case and whitespace-padded values are trimmed/lowercased first
  4. Updates README and example configs to recommend driver: pgx/v5.
  5. Adds tests for the default driver, alias normalization, and connection-string construction for supported PostgreSQL aliases.

Behavior

Scenario Result
SQL provider uses default config Opens with pgx/v5
Consumer passes driver: pgx/v5 Opens with pgx/v5
Consumer passes driver: pgx Normalized to pgx/v5
Consumer passes driver: postgres or driver: postgresql Normalized to pgx/v5
Consumer passes driver: Postgres Normalized to pgx/v5
Consumer already blank-imports github.com/lib/pq SQL ERS provider still uses pgx/v5; the existing postgres registration is ignored because the provider normalizes to the versioned pgx driver name
Consumer passes driver: mysql Not auto-registered; consumer must import/register the driver
Consumer passes driver: sqlite or driver: sqlite3 Not auto-registered; consumer must import/register the driver

Testing

  • go test ./entityresolution/multi-strategy/providers/sql -race
  • go test ./entityresolution/multi-strategy/...
  • GOCACHE=/private/tmp/go-build-cache GOLANGCI_LINT_CACHE=/private/tmp/golangci-lint-cache golangci-lint run --config ../.golangci.yaml ./entityresolution/multi-strategy/providers/sql --new-from-rev=origin/main

Notes

  • Existing configs using driver: postgres, driver: postgresql, or driver: pgx continue to work via alias normalization.
  • The documented recommended value is now driver: pgx/v5 to avoid ambiguity with the process-global unversioned pgx driver name.

Summary by CodeRabbit

  • New Features

    • PostgreSQL driver is now available to the SQL ERS provider without consumer-side blank imports.
  • Improvements

    • PostgreSQL driver aliases are normalized to the versioned pgx/v5 driver name for consistent resolution.
    • The default PostgreSQL driver value is standardized to a single constant.
  • Notes

    • MySQL and SQLite still require consumer-provided driver imports.

@jp-ayyappan jp-ayyappan requested a review from a team as a code owner May 28, 2026 20:27
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the SQL ERS provider to handle database driver registration internally and lazily. By moving registration from global init() calls to the provider instantiation phase, the module reduces unnecessary dependencies for consumers who do not utilize the SQL ERS tier, while maintaining backward compatibility for those who continue to register drivers manually.

Highlights

  • Lazy Driver Registration: Implemented a thread-safe lazy registration mechanism for database/sql drivers, removing the requirement for consumers to perform global blank imports.
  • PostgreSQL Support: Integrated pgx/v5/stdlib to automatically register the 'postgres' driver when a SQL ERS provider is instantiated.
  • Compatibility: Added a pre-check against sql.Drivers() to ensure that existing consumer-side driver registrations are respected and do not cause duplicate-registration panics.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.


The driver waits in silent sleep, Until the provider starts to creep. No global import needed now, We register with a lazy bow.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The SQL provider adds a module-level PostgreSQL driver constant, a mutex-protected lazy driver registration helper, and calls that helper from NewProvider to auto-register PostgreSQL via pgx stdlib before opening the DB; MySQL/SQLite still require consumer imports.

Changes

Lazy PostgreSQL Driver Auto-Registration

Layer / File(s) Summary
Config default constant
service/entityresolution/multi-strategy/providers/sql/sql_config.go
Adds defaultPostgreSQLDriver constant and uses it in DefaultConfig() instead of an inline "postgres" literal.
Driver auto-registration mechanism
service/entityresolution/multi-strategy/providers/sql/sql_provider.go
Adds mutex-protected registeredDrivers tracking and ensureDriverRegistered() which normalizes driver names, checks sql.Drivers(), and lazily registers the PostgreSQL driver via pgx/v5/stdlib.
Provider initialization integration
service/entityresolution/multi-strategy/providers/sql/sql_provider.go
NewProvider() normalizes config.Driver and calls ensureDriverRegistered(config.Driver) before opening the DB; buildConnectionString’s PostgreSQL branch now uses defaultPostgreSQLDriver.
sequenceDiagram
  participant NewProvider
  participant ensureDriverRegistered
  participant sql.Drivers
  participant pgx_stdlib
  NewProvider->>ensureDriverRegistered: call with normalized driver name
  ensureDriverRegistered->>sql.Drivers: list existing drivers
  ensureDriverRegistered-->>pgx_stdlib: register defaultPostgreSQLDriver when missing
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I nibble through code at dawn's first light,
I stitch a driver in the quiet night,
Lazy and safe, no blank imports to show,
Postgres wakes when the provider says go,
A small hop makes connections flow.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The PR title states 'use pgx database/sql driver' but the actual primary change is lazy registration of the driver with concurrency safety, not merely using it. Consider revising the title to better reflect the main change: 'lazily register database/sql driver in SQL ERS provider' would more accurately describe the core implementation change.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR successfully implements all coding objectives from issue #3539: lazy driver registration in NewProvider, mutex-guarded concurrency safety, driver name normalization, duplicate registration prevention via pre-checks, and PostgreSQL auto-registration via pgx/v5.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue: driver registration logic in sql_provider.go and using a named constant for the PostgreSQL driver in sql_config.go. No unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ers-sql-provider-register-postgres-driver

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces lazy driver registration for SQL providers to avoid requiring consumers to manually import database drivers. It adds a helper function ensureDriverRegistered that registers the postgres driver using pgx/v5/stdlib if it is not already registered. Feedback on this change highlights a potential issue where mixed-case driver names (e.g., 'Postgres') can bypass the registration check, leading to a duplicate registration panic or an unknown driver error. Normalizing config.Driver to lowercase before registration is recommended to prevent these issues.

Comment thread service/entityresolution/multi-strategy/providers/sql/sql_provider.go Outdated
@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 179.887088ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 91.089647ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 433.789716ms
Throughput 230.53 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 43.442746309s
Average Latency 431.74303ms
Throughput 115.09 requests/second

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@service/entityresolution/multi-strategy/providers/sql/sql_provider.go`:
- Around line 32-48: The ensureDriverRegistered function should normalize the
driver name (e.g., via strings.ToLower) before any checks and keying to avoid
duplicate registration panics: use a lowercasedDriver variable for lookups into
registeredDrivers and comparisons against sql.Drivers(), store the normalized
key into registeredDrivers, and use the normalized value in the switch so
sql.Register("postgres", ...) is only called when no existing "postgres" driver
was found; update references to registeredDrivers, sql.Drivers(), and the switch
in ensureDriverRegistered accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 065a65f0-ebb5-452a-9d63-c23933b085c3

📥 Commits

Reviewing files that changed from the base of the PR and between 5d0508f and 4828bd8.

📒 Files selected for processing (1)
  • service/entityresolution/multi-strategy/providers/sql/sql_provider.go

Comment thread service/entityresolution/multi-strategy/providers/sql/sql_provider.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@service/entityresolution/multi-strategy/providers/sql/sql_provider.go`:
- Around line 29-31: ensureDriverRegistered lowercases the local driver but
NewProvider still calls sql.Open(config.Driver,...), causing unknown driver
errors; change the flow so the normalized driver is used for opening the DB —
either have ensureDriverRegistered return the normalized driver (or set
config.Driver = normalized inside it) and then call sql.Open(normalizedDriver,
cfg.ConnectionString) in NewProvider (references: ensureDriverRegistered,
NewProvider, sql.Open, config.Driver).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 76124089-096c-473f-bda9-db8191e3b3cd

📥 Commits

Reviewing files that changed from the base of the PR and between 4828bd8 and b2cf821.

📒 Files selected for processing (1)
  • service/entityresolution/multi-strategy/providers/sql/sql_provider.go

Comment thread service/entityresolution/multi-strategy/providers/sql/sql_provider.go Outdated
@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 148.362773ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 79.031597ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 405.419888ms
Throughput 246.66 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 41.392929377s
Average Latency 412.698266ms
Throughput 120.79 requests/second

@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 185.854726ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 101.708203ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 414.975939ms
Throughput 240.98 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 45.038496371s
Average Latency 448.816346ms
Throughput 111.02 requests/second

Previously the SQL provider required consumers to add a blank driver
import (e.g. _ "github.com/lib/pq") to their own binaries, causing
the driver to be registered globally at init time even when the SQL
ERS tier was not configured.

This change moves driver registration into NewProvider() using
pgx/v5/stdlib (already a direct dependency of this module), guarded by
a sync.Mutex and a sql.Drivers() pre-check to prevent duplicate-register
panics when consumers have already registered the driver themselves.

The registration is now lazy: it happens only when a SQL ERS provider is
actually instantiated, and only if the driver has not already been
registered by the consumer or another code path.

Fixes: #3539
Both the registeredDrivers map lookup and the sql.Drivers() pre-check
were case-sensitive, while the switch used strings.ToLower. A consumer
passing driver: Postgres (capital P) would bypass the pre-check and
trigger a duplicate sql.Register panic.

Normalize to strings.ToLower(strings.TrimSpace(driver)) at the top of
ensureDriverRegistered and use strings.EqualFold for the sql.Drivers()
comparison so all case variants map to a single canonical key.

Addresses review feedback from gemini-code-assist and coderabbitai.
ensureDriverRegistered already normalizes its input to lowercase, but
NewProvider was still passing the raw config.Driver to sql.Open. A
mixed-case driver (e.g. 'Postgres') would pass through ensureDriverRegistered
correctly but then fail sql.Open with 'unknown driver' since database/sql
matches driver names by exact string.

Normalize config.Driver at the top of NewProvider so both
ensureDriverRegistered and sql.Open receive the canonical lowercase name.

Addresses review feedback from coderabbitai and gemini-code-assist.
Signed-off-by: jp-ayyappan <jp@as2max.com>
@jp-ayyappan jp-ayyappan force-pushed the fix/ers-sql-provider-register-postgres-driver branch from 0eed6d9 to aa544af Compare June 9, 2026 16:07
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 210.569784ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 102.802107ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 447.056712ms
Throughput 223.69 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 44.436573565s
Average Latency 442.408397ms
Throughput 112.52 requests/second

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@service/entityresolution/multi-strategy/providers/sql/sql_provider.go`:
- Around line 43-46: The pre-check in ensureDriverRegistered incorrectly uses
case-insensitive comparison and can treat a mixed-case registered driver (e.g.,
"Postgres") as satisfying the canonical lowercase name, causing us to skip
registering "postgres"; update the check to compare canonical lowercase names
instead (e.g., use if strings.ToLower(d) == driver) so we only treat an existing
driver as registered when its lowercase form equals the canonical driver
variable, and apply the same change to the other occurrence referenced in the
file; refer to ensureDriverRegistered, registeredDrivers and the sql.Drivers()
loop when making the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7cc5b123-3f36-4c03-9bb4-06317f2d3fe1

📥 Commits

Reviewing files that changed from the base of the PR and between b2cf821 and aa544af.

📒 Files selected for processing (2)
  • service/entityresolution/multi-strategy/providers/sql/sql_config.go
  • service/entityresolution/multi-strategy/providers/sql/sql_provider.go

Comment thread service/entityresolution/multi-strategy/providers/sql/sql_provider.go Outdated
Signed-off-by: jp-ayyappan <jp@as2max.com>
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 180.85678ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 102.498089ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 415.998591ms
Throughput 240.39 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 44.441521128s
Average Latency 442.596709ms
Throughput 112.51 requests/second

…ider.go

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
service/entityresolution/multi-strategy/providers/sql/sql_provider.go (1)

68-77: ⚠️ Potential issue | 🔴 Critical

Fix duplicate NewProvider in sql_provider.go (blocks compilation).

service/entityresolution/multi-strategy/providers/sql/sql_provider.go defines NewProvider twice (at lines 68 and 73), causing a Go syntax error. The first version normalizes with strings.TrimSpace, while the second does not.

Suggested fix
 // NewProvider creates a new SQL provider
 func NewProvider(ctx context.Context, name string, config Config) (*Provider, error) {
 	// Normalize the driver name so "Postgres", "POSTGRES", and "postgres" all
 	// resolve correctly through ensureDriverRegistered and sql.Open, both of
 	// which use case-sensitive driver name matching.
 	config.Driver = strings.ToLower(strings.TrimSpace(config.Driver))
-func NewProvider(ctx context.Context, name string, config Config) (*Provider, error) {
-	config.Driver = strings.ToLower(config.Driver)
 	// Register the database/sql driver for this provider's configured driver name
 	// if it has not already been registered.
 	ensureDriverRegistered(config.Driver)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@service/entityresolution/multi-strategy/providers/sql/sql_provider.go` around
lines 68 - 77, There are two duplicate NewProvider function definitions causing
a compile error; remove the duplicate and keep a single NewProvider
implementation that normalizes config.Driver with strings.TrimSpace and
strings.ToLower, then calls ensureDriverRegistered(config.Driver) and proceeds
as before; specifically, consolidate into one NewProvider (retain the
strings.TrimSpace usage on config.Driver and the ensureDriverRegistered call) so
only one function named NewProvider exists in sql_provider.go.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@service/entityresolution/multi-strategy/providers/sql/sql_provider.go`:
- Around line 68-77: There are two duplicate NewProvider function definitions
causing a compile error; remove the duplicate and keep a single NewProvider
implementation that normalizes config.Driver with strings.TrimSpace and
strings.ToLower, then calls ensureDriverRegistered(config.Driver) and proceeds
as before; specifically, consolidate into one NewProvider (retain the
strings.TrimSpace usage on config.Driver and the ensureDriverRegistered call) so
only one function named NewProvider exists in sql_provider.go.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 064fce66-be87-4ec3-8810-2ff8638fffca

📥 Commits

Reviewing files that changed from the base of the PR and between c0d9847 and c381db9.

📒 Files selected for processing (1)
  • service/entityresolution/multi-strategy/providers/sql/sql_provider.go

Signed-off-by: jp-ayyappan <jp@as2max.com>
@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 148.003842ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 76.488023ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 406.310583ms
Throughput 246.12 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 40.709347633s
Average Latency 405.829946ms
Throughput 122.82 requests/second

Signed-off-by: jp-ayyappan <jp@as2max.com>
@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 155.539472ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 81.335161ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 406.135852ms
Throughput 246.22 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 40.768268879s
Average Latency 406.10758ms
Throughput 122.64 requests/second

Signed-off-by: jp-ayyappan <jp@as2max.com>
@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 189.44177ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 92.756757ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 450.181601ms
Throughput 222.13 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 43.250346099s
Average Latency 430.671238ms
Throughput 115.61 requests/second

Signed-off-by: jp-ayyappan <jp@as2max.com>
@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 179.923869ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 98.004265ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 412.212927ms
Throughput 242.59 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 43.870587133s
Average Latency 436.834906ms
Throughput 113.97 requests/second

@jp-ayyappan jp-ayyappan changed the title fix(ers): lazily register database/sql driver in SQL ERS provider fix(ers): use pgx database/sql driver in SQL ERS provider Jun 23, 2026
Signed-off-by: jp-ayyappan <jp@as2max.com>
Signed-off-by: jp-ayyappan <jp@as2max.com>
@github-actions

Copy link
Copy Markdown
Contributor

@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 176.820478ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 93.510025ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 453.123275ms
Throughput 220.69 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 43.907833818s
Average Latency 437.264899ms
Throughput 113.87 requests/second

@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 100.811392ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 46.942062ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 250.649752ms
Throughput 398.96 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 25.181606764s
Average Latency 250.891057ms
Throughput 198.56 requests/second


const (
// Default SQL configuration values
defaultPostgreSQLDriver = "pgx/v5"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd recommend just keeping it postgres, less to test and probably provides the same value.

Comment on lines +75 to +77
if err != nil {
t.Fatalf("expected postgres alias to build connection string: %v", err)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if err != nil {
t.Fatalf("expected postgres alias to build connection string: %v", err)
}
t.Require().NoError(err)

Use the testify module with require.

Comment on lines +78 to +80
if !strings.Contains(connStr, "dbname=identity_db") {
t.Fatalf("expected database name in connection string, got %q", connStr)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if !strings.Contains(connStr, "dbname=identity_db") {
t.Fatalf("expected database name in connection string, got %q", connStr)
}
t.Contains(connStr, "dbname=identity_db")

// _ "github.com/mattn/go-sqlite3" // SQLite driver

// Register the pgx/v5 database/sql driver for SQL providers.
_ "github.com/jackc/pgx/v5/stdlib"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
_ "github.com/jackc/pgx/v5/stdlib"
"github.com/jackc/pgx/v5/stdlib"

Signed-off-by: jp-ayyappan <jp@as2max.com>
@github-actions

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 207.97122ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 120.591168ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 442.570732ms
Throughput 225.95 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 45.328969527s
Average Latency 451.40752ms
Throughput 110.30 requests/second

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Govulncheck found vulnerabilities ⚠️

The following modules have known vulnerabilities:

  • examples
  • otdfctl
  • sdk
  • service
  • lib/fixtures
  • tests-bdd

See the workflow run for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

multi-strategy ERS SQL provider should register its own database/sql driver

2 participants