Passed
Pull Request — master (#1010)
by
unknown
02:23
created

internal/storage/postgres/utils/version.go   A

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 12
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A utils.EnsureDBVersion 0 9 3
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