db

package
v0.5.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

README

Database management

This file briefly documents how the db package initializes the MariaDB connection and applies schema SQL included in the repository.

Paths

  • db/create.sql — embedded initial schema (creates all required tables).
  • db/upgrade.sql — embedded SQL file containing idempotent schema upgrades.

Environment variables (used to build DSN)

-- NETHVOICE_MIDDLEWARE_MARIADB_HOST (default: localhost) -- NETHVOICE_MIDDLEWARE_MARIADB_PORT (default: 3306) -- NETHVOICE_MIDDLEWARE_MARIADB_USER (default: root) -- NETHVOICE_MIDDLEWARE_MARIADB_PASSWORD (default: root in local/test) -- NETHVOICE_MIDDLEWARE_MARIADB_DATABASE (default: nethcti3)

Satellite DB connection (transcripts, PostgreSQL): -- SATELLITE_PGSQL_HOST (default: localhost) -- SATELLITE_PGSQL_PORT (default: 5432 when host is set) -- SATELLITE_PGSQL_USER (default: satellite when host is set) -- SATELLITE_PGSQL_PASSWORD -- SATELLITE_PGSQL_DB (default: satellite when host is set)

Schema Migrations & Upgrades

If the database already exists when the application starts, db.Init() will run the embedded db/upgrade.sql automatically. The statements in upgrade.sql must be idempotent and safe to re-run.

Please note that db/upgrade.sql should contain idempotent statements (or checks) because it may be executed on existing databases and can be re-run in tests/CI.

Connection Pool Configuration

The middleware uses a connection pool with the following defaults:

  • Max open connections: 25
  • Max idle connections: 5
  • Connection max lifetime: 5 minutes

These can be adjusted in db/db.go if needed for your workload.

Testing

  • Unit tests for the package run with go test ./db.
  • Integration tests that exercise the real DB require a running MariaDB instance (see agents.md for a Podman/Docker command).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Access the CDR database with GetCDRDB() to ensure proper initialization and reconnection.
	CDRDB *sql.DB
)
View Source
var (
	// Access the database with GetDB() to ensure proper initialization and reconnection.
	DB *sql.DB
)
View Source
var (
	SatelliteDB *sql.DB
)

Functions

func Close

func Close() error

Close gracefully closes the database connection pool.

func CloseCDR added in v0.5.0

func CloseCDR() error

CloseCDR gracefully closes the CDR database connection pool.

func CloseSatellite added in v0.5.0

func CloseSatellite() error

CloseSatellite gracefully closes the satellite database connection pool.

func GetCDRDB added in v0.5.0

func GetCDRDB() *sql.DB

GetCDRDB returns a ready-to-use CDR DB connection, initializing it on demand.

func GetDB

func GetDB() *sql.DB

func GetSatelliteDB added in v0.5.0

func GetSatelliteDB() *sql.DB

GetSatelliteDB returns a ready-to-use satellite DB connection, initializing it on demand.

func Init

func Init() error

Init initializes the database connection pool with the configured MariaDB settings. It performs health checks and creates necessary schema.

func InitCDR added in v0.5.0

func InitCDR() error

InitCDR initializes the CDR database connection pool with the configured MariaDB settings.

func InitSatellite added in v0.5.0

func InitSatellite() error

InitSatellite initializes the satellite database connection pool.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL