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
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
976296cd52
Коммит
dd6fac50f2
@@ -462,19 +462,19 @@ func (ss *SqlStore) AlterColumnTypeIfExists(tableName string, columnName string,
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *SqlStore) CreateUniqueIndexIfNotExists(indexName string, tableName string, columnName string) {
|
func (ss *SqlStore) CreateUniqueIndexIfNotExists(indexName string, tableName string, columnName string) bool {
|
||||||
ss.createIndexIfNotExists(indexName, tableName, columnName, INDEX_TYPE_DEFAULT, true)
|
return ss.createIndexIfNotExists(indexName, tableName, columnName, INDEX_TYPE_DEFAULT, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *SqlStore) CreateIndexIfNotExists(indexName string, tableName string, columnName string) {
|
func (ss *SqlStore) CreateIndexIfNotExists(indexName string, tableName string, columnName string) bool {
|
||||||
ss.createIndexIfNotExists(indexName, tableName, columnName, INDEX_TYPE_DEFAULT, false)
|
return ss.createIndexIfNotExists(indexName, tableName, columnName, INDEX_TYPE_DEFAULT, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *SqlStore) CreateFullTextIndexIfNotExists(indexName string, tableName string, columnName string) {
|
func (ss *SqlStore) CreateFullTextIndexIfNotExists(indexName string, tableName string, columnName string) bool {
|
||||||
ss.createIndexIfNotExists(indexName, tableName, columnName, INDEX_TYPE_FULL_TEXT, false)
|
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 := ""
|
uniqueStr := ""
|
||||||
if unique {
|
if unique {
|
||||||
@@ -485,7 +485,7 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c
|
|||||||
_, err := ss.GetMaster().SelectStr("SELECT $1::regclass", indexName)
|
_, err := ss.GetMaster().SelectStr("SELECT $1::regclass", indexName)
|
||||||
// It should fail if the index does not exist
|
// It should fail if the index does not exist
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
query := ""
|
query := ""
|
||||||
@@ -512,7 +512,7 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fullTextIndex := ""
|
fullTextIndex := ""
|
||||||
@@ -531,15 +531,17 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c
|
|||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
os.Exit(EXIT_CREATE_INDEX_MISSING)
|
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 {
|
if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
|
||||||
_, err := ss.GetMaster().SelectStr("SELECT $1::regclass", indexName)
|
_, err := ss.GetMaster().SelectStr("SELECT $1::regclass", indexName)
|
||||||
// It should fail if the index does not exist
|
// It should fail if the index does not exist
|
||||||
if err == nil {
|
if err != nil {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ss.GetMaster().Exec("DROP INDEX " + indexName)
|
_, err = ss.GetMaster().Exec("DROP INDEX " + indexName)
|
||||||
@@ -548,6 +550,8 @@ func (ss *SqlStore) RemoveIndexIfExists(indexName string, tableName string) {
|
|||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
os.Exit(EXIT_REMOVE_INDEX_POSTGRES)
|
os.Exit(EXIT_REMOVE_INDEX_POSTGRES)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
} else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL {
|
} 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)
|
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)
|
os.Exit(EXIT_REMOVE_INDEX_MYSQL)
|
||||||
}
|
}
|
||||||
|
|
||||||
if count > 0 {
|
if count <= 0 {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ss.GetMaster().Exec("DROP INDEX " + indexName + " ON " + tableName)
|
_, 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)
|
time.Sleep(time.Second)
|
||||||
os.Exit(EXIT_REMOVE_INDEX_MISSING)
|
os.Exit(EXIT_REMOVE_INDEX_MISSING)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsUniqueConstraintError(err string, indexName []string) bool {
|
func IsUniqueConstraintError(err string, indexName []string) bool {
|
||||||
|
|||||||
@@ -118,3 +118,51 @@ func TestAlertDbCmds(t *testing.T) {
|
|||||||
t.Fatal("Column should not exist")
|
t.Fatal("Column should not exist")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCreateIndexIfNotExists(t *testing.T) {
|
||||||
|
Setup()
|
||||||
|
|
||||||
|
sqlStore := store.(*SqlStore)
|
||||||
|
|
||||||
|
defer sqlStore.RemoveColumnIfExists("Systems", "Test")
|
||||||
|
if !sqlStore.CreateColumnIfNotExists("Systems", "Test", "VARCHAR(50)", "VARCHAR(50)", "") {
|
||||||
|
t.Fatal("Failed to create test column")
|
||||||
|
}
|
||||||
|
|
||||||
|
defer sqlStore.RemoveIndexIfExists("idx_systems_create_index_test", "Systems")
|
||||||
|
if !sqlStore.CreateIndexIfNotExists("idx_systems_create_index_test", "Systems", "Test") {
|
||||||
|
t.Fatal("Should've created test index")
|
||||||
|
}
|
||||||
|
|
||||||
|
if sqlStore.CreateIndexIfNotExists("idx_systems_create_index_test", "Systems", "Test") {
|
||||||
|
t.Fatal("Shouldn't have created index that already exists")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRemoveIndexIfExists(t *testing.T) {
|
||||||
|
Setup()
|
||||||
|
|
||||||
|
sqlStore := store.(*SqlStore)
|
||||||
|
|
||||||
|
defer sqlStore.RemoveColumnIfExists("Systems", "Test")
|
||||||
|
if !sqlStore.CreateColumnIfNotExists("Systems", "Test", "VARCHAR(50)", "VARCHAR(50)", "") {
|
||||||
|
t.Fatal("Failed to create test column")
|
||||||
|
}
|
||||||
|
|
||||||
|
if sqlStore.RemoveIndexIfExists("idx_systems_remove_index_test", "Systems") {
|
||||||
|
t.Fatal("Should've failed to remove index that doesn't exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
defer sqlStore.RemoveIndexIfExists("idx_systems_remove_index_test", "Systems")
|
||||||
|
if !sqlStore.CreateIndexIfNotExists("idx_systems_remove_index_test", "Systems", "Test") {
|
||||||
|
t.Fatal("Should've created test index")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !sqlStore.RemoveIndexIfExists("idx_systems_remove_index_test", "Systems") {
|
||||||
|
t.Fatal("Should've removed index that exists")
|
||||||
|
}
|
||||||
|
|
||||||
|
if sqlStore.RemoveIndexIfExists("idx_systems_remove_index_test", "Systems") {
|
||||||
|
t.Fatal("Should've failed to remove index that was already removed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func NewSqlTeamStore(sqlStore *SqlStore) TeamStore {
|
|||||||
|
|
||||||
func (s SqlTeamStore) CreateIndexesIfNotExists() {
|
func (s SqlTeamStore) CreateIndexesIfNotExists() {
|
||||||
s.CreateIndexIfNotExists("idx_teams_name", "Teams", "Name")
|
s.CreateIndexIfNotExists("idx_teams_name", "Teams", "Name")
|
||||||
s.CreateIndexIfNotExists("idx_teams_description", "Teams", "Description")
|
s.RemoveIndexIfExists("idx_teams_description", "Teams")
|
||||||
s.CreateIndexIfNotExists("idx_teams_invite_id", "Teams", "InviteId")
|
s.CreateIndexIfNotExists("idx_teams_invite_id", "Teams", "InviteId")
|
||||||
s.CreateIndexIfNotExists("idx_teams_update_at", "Teams", "UpdateAt")
|
s.CreateIndexIfNotExists("idx_teams_update_at", "Teams", "UpdateAt")
|
||||||
s.CreateIndexIfNotExists("idx_teams_create_at", "Teams", "CreateAt")
|
s.CreateIndexIfNotExists("idx_teams_create_at", "Teams", "CreateAt")
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user