Skip to content

Fix PostgreSQL DSN: reconstruct full URI in store, keep drivers consistent#6

Open
pubmatt wants to merge 2 commits into
edrlab:mainfrom
Riidr:main
Open

Fix PostgreSQL DSN: reconstruct full URI in store, keep drivers consistent#6
pubmatt wants to merge 2 commits into
edrlab:mainfrom
Riidr:main

Conversation

@pubmatt
Copy link
Copy Markdown

@pubmatt pubmatt commented Feb 13, 2026

Summary

Fixes PostgreSQL connections by ensuring the store passes a full postgres://... URI to the driver, and keeps all DB drivers using the same pattern (no DSN manipulation inside drivers).

Problem

The store splits the DSN on :// and passes only the part after the scheme to GormDialector. The PostgreSQL driver expects a full URI (postgres://user:...@host:5432/dbname?sslmode=...). Passing only the fragment caused connection failures or incorrect parsing.

Solution

  • Store (pkg/stor/store.go): After addDialectSpecificParams, build the DSN passed to GormDialector. For postgres, use the full URI (dialect + "://" + cnx); for MySQL and SQLite, keep passing cnx as before. PostgreSQL is handled in the same place as other dialect-specific logic.
  • PostgreSQL driver (pkg/stor/driver_pgsql.go): Use postgres.Open(cnx) only, with no string prepending, matching driver_mysql.go and driver_sqlite.go.

Result

  • PostgreSQL works when building with -tags PGSQL and a postgres://... DSN.
  • All three drivers share the same contract: they receive the connection string in the form the store prepared for that dialect and call Open(cnx) only.

Ensures the PostgreSQL connection string is correctly formatted as a full URI (e.g., `postgres://...`) when passed to the GORM dialector. This addresses the PostgreSQL driver's expectation for a URI-prefixed DSN, preventing connection issues.
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.

1 participant