Chore: Enable ANSI_QUOTES for Mysql Database (#53277)

* remove the quote dialect

* add environment variable
This commit is contained in:
ying-jeanne 2022-08-08 11:14:17 -05:00 committed by GitHub
parent 732c22ed02
commit ba89471598
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View File

@ -281,6 +281,10 @@ func (ss *SQLStore) buildConnectionString() (string, error) {
cnnstr += fmt.Sprintf("&tx_isolation=%s", val)
}
if ss.Cfg.IsFeatureToggleEnabled("mysqlAnsiQuotes") {
cnnstr += "&sql_mode='ANSI_QUOTES'"
}
cnnstr += ss.buildExtraConnectionString('&')
case migrator.Postgres:
addr, err := util.SplitHostPortDefault(ss.dbCfg.Host, "127.0.0.1", "5432")

View File

@ -72,6 +72,12 @@ var sqlStoreTestCases = []sqlStoreTest{
dbURL: "://invalid.com/",
err: &url.Error{Op: "parse", URL: "://invalid.com/", Err: errors.New("missing protocol scheme")},
},
{
name: "Sql mode set to ANSI_QUOTES",
dbType: "mysql",
dbHost: "[::1]",
connStrValues: []string{"sql_mode='ANSI_QUOTES'"},
},
}
func TestIntegrationSQLConnectionString(t *testing.T) {
@ -112,5 +118,7 @@ func makeSQLStoreTestConfig(t *testing.T, dbType, host, dbURL string) *setting.C
_, err = sec.NewKey("password", "pass")
require.NoError(t, err)
cfg.IsFeatureToggleEnabled = func(key string) bool { return true }
return cfg
}

View File

@ -28,9 +28,13 @@ func MySQLTestDB() TestDB {
if port == "" {
port = "3306"
}
conn_str := fmt.Sprintf("grafana:password@tcp(%s:%s)/grafana_tests?collation=utf8mb4_unicode_ci", host, port)
if _, present := os.LookupEnv("MYSQL_ANSI_QUOTES"); present {
conn_str += "&sql_mode='ANSI_QUOTES'"
}
return TestDB{
DriverName: "mysql",
ConnStr: fmt.Sprintf("grafana:password@tcp(%s:%s)/grafana_tests?collation=utf8mb4_unicode_ci", host, port),
ConnStr: conn_str,
}
}