MySQL: Add parseTime=true to SQL connections (#92469)

This commit is contained in:
Ryan McKinley
2024-08-27 14:16:04 +03:00
committed by GitHub
parent c98e3e0483
commit c59dddf7af
10 changed files with 47 additions and 3 deletions
+12 -2
View File
@@ -296,15 +296,24 @@ func (ss *SQLStore) initEngine(engine *xorm.Engine) error {
}
}
if engine == nil {
connection := ss.dbCfg.ConnectionString
// Ensure that parseTime is enabled for MySQL
if ss.dbCfg.Type == migrator.MySQL && !strings.Contains(connection, "parseTime=") {
if ss.features.IsEnabledGlobally(featuremgmt.FlagMysqlParseTime) {
connection += "&parseTime=true"
}
}
var err error
engine, err = xorm.NewEngine(ss.dbCfg.Type, ss.dbCfg.ConnectionString)
engine, err = xorm.NewEngine(ss.dbCfg.Type, connection)
if err != nil {
return err
}
// Only for MySQL or MariaDB, verify we can connect with the current connection string's system var for transaction isolation.
// If not, create a new engine with a compatible connection string.
if ss.dbCfg.Type == migrator.MySQL {
engine, err = ss.ensureTransactionIsolationCompatibility(engine, ss.dbCfg.ConnectionString)
engine, err = ss.ensureTransactionIsolationCompatibility(engine, connection)
if err != nil {
return err
}
@@ -481,6 +490,7 @@ func getCfgForTesting(opts ...InitTestDBOpt) *setting.Cfg {
func getFeaturesForTesting(opts ...InitTestDBOpt) featuremgmt.FeatureToggles {
featureKeys := []any{
featuremgmt.FlagPanelTitleSearch,
featuremgmt.FlagMysqlParseTime,
}
for _, opt := range opts {
if len(opt.FeatureFlags) > 0 {