Skip to content

Commit

Permalink
Add b/w compat for cockroachdb
Browse files Browse the repository at this point in the history
Signed-off-by: Sambhav Kothari <[email protected]>
  • Loading branch information
sambhav committed Sep 20, 2024
1 parent a163888 commit 163f906
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/drivers/pgsql/pgsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,20 @@ func New(ctx context.Context, dataSourceName string, tlsInfo tls.Config, connPoo

func setup(db *sql.DB) error {
logrus.Infof("Configuring database table schema and indexes, this may take a moment...")
var version string
collationSupported := true
if err := db.QueryRow("select version()", version); err == nil && strings.Contains(strings.ToLower(version), "cockroachdb") {
// CockroadDB does not seem to support "C" as a collation
// It looks like it's using golang.org/x/text/language and ends up calling something like v, err := language.Parse("C")
// which parses it as a BCP47 language tag instead of a collation.
collationSupported = false
}

for _, stmt := range schema {
logrus.Tracef("SETUP EXEC : %v", util.Stripped(stmt))
if !collationSupported {
stmt = strings.ReplaceAll(stmt, ` COLLATE "C"`, "")
}
if _, err := db.Exec(stmt); err != nil {
return err
}
Expand All @@ -180,6 +191,9 @@ func setup(db *sql.DB) error {
if i >= int(schemaVersion) {
break
}
if !collationSupported {
stmt = strings.ReplaceAll(stmt, ` COLLATE "C"`, "")
}
if stmt == "" {
continue
}
Expand Down

0 comments on commit 163f906

Please sign in to comment.