MCPcopy Index your code
hub / github.com/bytebase/bytebase / getVersion

Method getVersion

backend/plugin/db/redshift/sync.go:658–688  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

656}
657
658func (d *Driver) getVersion(ctx context.Context) (string, error) {
659 // Redshift doesn't support SHOW server_version to retrieve the clean version number.
660 // We can parse the output of `SELECT version()` to get the PostgreSQL version and the
661 // Redshift version because Redshift is based on PostgreSQL.
662 // For example, the output of `SELECT version()` is:
663 // PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.48042
664 // We will return the 'Redshift 1.0.48042 based on PostgreSQL 8.0.2'.
665 rows, err := d.db.QueryContext(ctx, "SELECT version()")
666 if err != nil {
667 return "", err
668 }
669 defer rows.Close()
670 var version string
671 for rows.Next() {
672 if err := rows.Scan(&version); err != nil {
673 return "", err
674 }
675 }
676 if err := rows.Err(); err != nil {
677 return "", err
678 }
679 // We try to parse the version string to get the PostgreSQL version and the Redshift version, but it's not a big deal if we fail.
680 // We will just return the version string as is.
681 pgVersion, redshiftVersion, err := getPgVersionAndRedshiftVersion(version)
682 if err != nil {
683 slog.Debug("Failed to parse version string", slog.String("version", version))
684 // nolint
685 return version, nil
686 }
687 return buildRedshiftVersionString(redshiftVersion, pgVersion), nil
688}
689
690// parseVersionRegex is a regex to parse the output from Redshift's `SELECT version()`, captures the PostgreSQL version and the Redshift version.
691var parseVersionRegex = regexp.MustCompile(`(?i)^PostgreSQL (?P<pgVersion>\d+\.\d+\.\d+) on .*, Redshift (?P<redshiftVersion>\d+\.\d+\.\d+)`)

Callers 1

SyncInstanceMethod · 0.95

Implementers 15

MockDriverbackend/plugin/advisor/utils_for_tests
Driverbackend/plugin/db/bigquery/bigquery.go
Driverbackend/plugin/db/mongodb/mongodb.go
Driverbackend/plugin/db/trino/trino.go
Driverbackend/plugin/db/redshift/redshift.go
Driverbackend/plugin/db/oracle/oracle.go
Driverbackend/plugin/db/dynamodb/dynamodb.go
Driverbackend/plugin/db/cosmosdb/cosmosdb.go
Driverbackend/plugin/db/spanner/spanner.go
Driverbackend/plugin/db/mssql/mssql.go
Driverbackend/plugin/db/mysql/mysql.go
Driverbackend/plugin/db/pg/pg.go

Calls 8

QueryContextMethod · 0.80
ScanMethod · 0.80
DebugMethod · 0.80
CloseMethod · 0.65
StringMethod · 0.65
NextMethod · 0.45

Tested by

no test coverage detected