Private
Public Access
1
0

feat(db): migrate from MySQL to PostgreSQL
All checks were successful
continuous-integration/drone/push Build is passing

Replace MySQL driver with pgx/v5 and pgxpool:
- Update sqlc to use postgresql engine
- Convert query.sql to PostgreSQL syntax ($1 params, CASE WHEN,
  ANY() arrays)
- Replace sql.DB with pgxpool.Pool throughout
- Change nullable types from sql.Null* to pgtype.*
- Update ID types from uint32 to int64 for PostgreSQL compatibility
- Delete MySQL-specific dynamic_connect.go
- Add opentelemetry.gowrap template for tracing
This commit is contained in:
2025-11-29 10:59:15 -08:00
parent 85d86bc837
commit c9481d12c6
22 changed files with 3293 additions and 1309 deletions

View File

@@ -1,11 +1,11 @@
package server
import (
"database/sql"
"errors"
"net/http"
"net/netip"
"github.com/jackc/pgx/v5"
"github.com/labstack/echo/v4"
"go.opentelemetry.io/otel/attribute"
"golang.org/x/sync/errgroup"
@@ -56,7 +56,7 @@ func (srv *Server) dnsAnswers(c echo.Context) error {
queryGroup, ctx := errgroup.WithContext(ctx)
var zoneStats []ntpdb.GetZoneStatsV2Row
var serverNetspeed uint32
var serverNetspeed int64
queryGroup.Go(func() error {
var err error
@@ -64,7 +64,7 @@ func (srv *Server) dnsAnswers(c echo.Context) error {
serverNetspeed, err = q.GetServerNetspeed(ctx, ip.String())
if err != nil {
if !errors.Is(err, sql.ErrNoRows) {
if !errors.Is(err, pgx.ErrNoRows) {
log.Error("GetServerNetspeed", "err", err)
}
return err // this will return if the server doesn't exist
@@ -116,7 +116,7 @@ func (srv *Server) dnsAnswers(c echo.Context) error {
err = queryGroup.Wait()
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
if errors.Is(err, pgx.ErrNoRows) {
return c.String(http.StatusNotFound, "Not found")
}
log.Error("query error", "err", err)
@@ -130,7 +130,7 @@ func (srv *Server) dnsAnswers(c echo.Context) error {
if zn == "@" {
zn = ""
}
zoneTotals[zn] = z.NetspeedActive // binary.BigEndian.Uint64(...)
zoneTotals[zn] = int(z.NetspeedActive) // binary.BigEndian.Uint64(...)
// log.Info("zone netspeed", "cc", z.ZoneName, "speed", z.NetspeedActive)
}