Postgres: Switch the datasource plugin from lib/pq to pgx (#83768)

postgres: switch from lib/pq to pgx
This commit is contained in:
Gábor Farkas
2024-03-13 09:52:39 +01:00
committed by GitHub
parent 2acd48d1c2
commit ecd6de826a
17 changed files with 1082 additions and 947 deletions

View File

@ -3,7 +3,6 @@ package postgres
import (
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
"regexp"
@ -51,20 +50,6 @@ func TestIntegrationPostgresSnapshots(t *testing.T) {
t.Skip()
}
getCnnStr := func() string {
host := os.Getenv("POSTGRES_HOST")
if host == "" {
host = "localhost"
}
port := os.Getenv("POSTGRES_PORT")
if port == "" {
port = "5432"
}
return fmt.Sprintf("user=grafanatest password=grafanatest host=%s port=%s dbname=grafanadstest sslmode=disable",
host, port)
}
sqlQueryCommentRe := regexp.MustCompile(`^-- (.+)\n`)
readSqlFile := func(path string) (string, string) {
@ -148,18 +133,34 @@ func TestIntegrationPostgresSnapshots(t *testing.T) {
ConnMaxLifetime: 14400,
Timescaledb: false,
ConfigurationMethod: "file-path",
Mode: "disable",
}
host := os.Getenv("POSTGRES_HOST")
if host == "" {
host = "localhost"
}
port := os.Getenv("POSTGRES_PORT")
if port == "" {
port = "5432"
}
dsInfo := sqleng.DataSourceInfo{
JsonData: jsonData,
DecryptedSecureJSONData: map[string]string{},
JsonData: jsonData,
DecryptedSecureJSONData: map[string]string{
"password": "grafanatest",
},
URL: host + ":" + port,
Database: "grafanadstest",
User: "grafanatest",
}
logger := log.New()
cnnstr := getCnnStr()
db, handler, err := newPostgres(context.Background(), "error", 10000, dsInfo, cnnstr, logger, backend.DataSourceInstanceSettings{})
settings := backend.DataSourceInstanceSettings{}
proxyClient, err := settings.ProxyClient(context.Background())
require.NoError(t, err)
db, handler, err := newPostgres("error", 10000, dsInfo, logger, proxyClient)
t.Cleanup((func() {
_, err := db.Exec("DROP TABLE tbl")