Passed
Push — master ( 4ddc00...a74778 )
by Tolga
01:15 queued 15s
created

utils.EnsureDBVersion   A

Complexity

Conditions 3

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
package utils
2
3
import (
4
	"database/sql"
5
	"fmt"
6
)
7
8
const (
9
	// The earliest supported version of PostgreSQL is 13.8
10
	earliestPostgresVersion = 130008
11
)
12
13
// EnsureDBVersion checks the version of the given database connection and returns an error if the version is not
14
// supported.
15
func EnsureDBVersion(db *sql.DB) (version int, err error) {
16
	err = db.QueryRow("SHOW server_version_num;").Scan(&version)
17
	if err != nil {
18
		return
19
	}
20
	if version < earliestPostgresVersion {
21
		err = fmt.Errorf("unsupported postgres version: %d, expected >= %d", version, earliestPostgresVersion)
22
	}
23
	return
24
}
25