Skip to content

Commit

Permalink
Add compatibility to create databases on mariadb instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Phylu committed Jun 6, 2019
1 parent 46dba1c commit cde30f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions mysql/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ func serverVersion(db *sql.DB) (*version.Version, error) {
return version.NewVersion(versionString)
}

func serverVersionString(db *sql.DB) (string, error) {
var versionString string
err := db.QueryRow("SELECT @@GLOBAL.version").Scan(&versionString)
if err != nil {
return "", err
}

return versionString, nil
}

func connectToMySQL(conf *mysql.Config) (*sql.DB, error) {
dsn := conf.FormatDSN()
var db *sql.DB
Expand Down
7 changes: 6 additions & 1 deletion mysql/resource_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,14 @@ func ReadDatabase(d *schema.ResourceData, meta interface{}) error {
return err
}

serverVersionString, err := serverVersionString(db)
if err != nil {
return err
}

// MySQL 8 returns more data in a row.
var res error
if currentVersion.GreaterThan(requiredVersion) {
if !strings.Contains(serverVersionString, "MariaDB") && currentVersion.GreaterThan(requiredVersion) {
res = db.QueryRow(stmtSQL, defaultCharset).Scan(&defaultCollation, &empty, &empty, &empty, &empty, &empty, &empty)
} else {
res = db.QueryRow(stmtSQL, defaultCharset).Scan(&defaultCollation, &empty, &empty, &empty, &empty, &empty)
Expand Down

0 comments on commit cde30f2

Please sign in to comment.