diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2017-01-18 08:50:01 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-18 08:50:01 -0500 |
commit | dd6fac50f2741ecc8e7e07c42a3e94b37720bd5e (patch) | |
tree | dac3eea7eb0fbe6b4cef0cb7e90da9c11ca58993 /store/sql_store.go | |
parent | 976296cd52533ff565407e55e872339cc312a0cf (diff) | |
download | chat-dd6fac50f2741ecc8e7e07c42a3e94b37720bd5e.tar.gz chat-dd6fac50f2741ecc8e7e07c42a3e94b37720bd5e.tar.bz2 chat-dd6fac50f2741ecc8e7e07c42a3e94b37720bd5e.zip |
Removed index on Teams.Description column (#5095)
* Removed index on Teams.Description column
* Fixed RemoveIndexIfExists when running with MySQL
* Fixed RemoveIndexIfExists when running Postgres and added unit tests
Diffstat (limited to 'store/sql_store.go')
-rw-r--r-- | store/sql_store.go | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/store/sql_store.go b/store/sql_store.go index 6a852430c..214bce720 100644 --- a/store/sql_store.go +++ b/store/sql_store.go @@ -462,19 +462,19 @@ func (ss *SqlStore) AlterColumnTypeIfExists(tableName string, columnName string, return true } -func (ss *SqlStore) CreateUniqueIndexIfNotExists(indexName string, tableName string, columnName string) { - ss.createIndexIfNotExists(indexName, tableName, columnName, INDEX_TYPE_DEFAULT, true) +func (ss *SqlStore) CreateUniqueIndexIfNotExists(indexName string, tableName string, columnName string) bool { + return ss.createIndexIfNotExists(indexName, tableName, columnName, INDEX_TYPE_DEFAULT, true) } -func (ss *SqlStore) CreateIndexIfNotExists(indexName string, tableName string, columnName string) { - ss.createIndexIfNotExists(indexName, tableName, columnName, INDEX_TYPE_DEFAULT, false) +func (ss *SqlStore) CreateIndexIfNotExists(indexName string, tableName string, columnName string) bool { + return ss.createIndexIfNotExists(indexName, tableName, columnName, INDEX_TYPE_DEFAULT, false) } -func (ss *SqlStore) CreateFullTextIndexIfNotExists(indexName string, tableName string, columnName string) { - ss.createIndexIfNotExists(indexName, tableName, columnName, INDEX_TYPE_FULL_TEXT, false) +func (ss *SqlStore) CreateFullTextIndexIfNotExists(indexName string, tableName string, columnName string) bool { + return ss.createIndexIfNotExists(indexName, tableName, columnName, INDEX_TYPE_FULL_TEXT, false) } -func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, columnName string, indexType string, unique bool) { +func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, columnName string, indexType string, unique bool) bool { uniqueStr := "" if unique { @@ -485,7 +485,7 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c _, err := ss.GetMaster().SelectStr("SELECT $1::regclass", indexName) // It should fail if the index does not exist if err == nil { - return + return false } query := "" @@ -512,7 +512,7 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c } if count > 0 { - return + return false } fullTextIndex := "" @@ -531,15 +531,17 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c time.Sleep(time.Second) os.Exit(EXIT_CREATE_INDEX_MISSING) } + + return true } -func (ss *SqlStore) RemoveIndexIfExists(indexName string, tableName string) { +func (ss *SqlStore) RemoveIndexIfExists(indexName string, tableName string) bool { if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES { _, err := ss.GetMaster().SelectStr("SELECT $1::regclass", indexName) // It should fail if the index does not exist - if err == nil { - return + if err != nil { + return false } _, err = ss.GetMaster().Exec("DROP INDEX " + indexName) @@ -548,6 +550,8 @@ func (ss *SqlStore) RemoveIndexIfExists(indexName string, tableName string) { time.Sleep(time.Second) os.Exit(EXIT_REMOVE_INDEX_POSTGRES) } + + return true } else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL { count, err := ss.GetMaster().SelectInt("SELECT COUNT(0) AS index_exists FROM information_schema.statistics WHERE TABLE_SCHEMA = DATABASE() and table_name = ? AND index_name = ?", tableName, indexName) @@ -557,8 +561,8 @@ func (ss *SqlStore) RemoveIndexIfExists(indexName string, tableName string) { os.Exit(EXIT_REMOVE_INDEX_MYSQL) } - if count > 0 { - return + if count <= 0 { + return false } _, err = ss.GetMaster().Exec("DROP INDEX " + indexName + " ON " + tableName) @@ -572,6 +576,8 @@ func (ss *SqlStore) RemoveIndexIfExists(indexName string, tableName string) { time.Sleep(time.Second) os.Exit(EXIT_REMOVE_INDEX_MISSING) } + + return true } func IsUniqueConstraintError(err string, indexName []string) bool { |