[MM-25673] Upgrades and migrations to start using master gorp (#14823)
Database changes needed to reflect gorp master changes
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
0302e0f477
Коммит
f619de2c83
@@ -916,7 +916,7 @@ func (ss *SqlSupplier) createIndexIfNotExists(indexName string, tableName string
|
||||
|
||||
_, err = ss.GetMaster().ExecNoTimeout("CREATE " + uniqueStr + fullTextIndex + " INDEX " + indexName + " ON " + tableName + " (" + strings.Join(columnNames, ", ") + ")")
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to create index", mlog.Err(err))
|
||||
mlog.Critical("Failed to create index", mlog.String("table", tableName), mlog.String("index_name", indexName), mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_INDEX_FULL_MYSQL)
|
||||
}
|
||||
|
||||
@@ -218,10 +218,12 @@ func newSqlTeamStore(sqlStore SqlStore) store.TeamStore {
|
||||
table.ColMap("DisplayName").SetMaxSize(64)
|
||||
table.ColMap("Name").SetMaxSize(64).SetUnique(true)
|
||||
table.ColMap("Description").SetMaxSize(255)
|
||||
table.ColMap("Type").SetMaxSize(255)
|
||||
table.ColMap("Email").SetMaxSize(128)
|
||||
table.ColMap("CompanyName").SetMaxSize(64)
|
||||
table.ColMap("AllowedDomains").SetMaxSize(1000)
|
||||
table.ColMap("InviteId").SetMaxSize(32)
|
||||
table.ColMap("SchemeId").SetMaxSize(26)
|
||||
|
||||
tablem := db.AddTableWithName(teamMember{}, "TeamMembers").SetKeys(false, "TeamId", "UserId")
|
||||
tablem.ColMap("TeamId").SetMaxSize(26)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -838,9 +839,74 @@ func upgradeDatabaseToVersion527(sqlStore SqlStore) {
|
||||
func upgradeDatabaseToVersion528(sqlStore SqlStore) {
|
||||
// TODO: uncomment when the time arrive to upgrade the DB for 5.28
|
||||
//if shouldPerformUpgrade(sqlStore, VERSION_5_27_0, VERSION_5_28_0) {
|
||||
if err := precheckMigrationToVersion528(sqlStore); err != nil {
|
||||
mlog.Error("Error upgrading DB schema to 5.28.0", mlog.Err(err))
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
}
|
||||
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("Commands", "PluginId", "VARCHAR(190)", "VARCHAR(190)")
|
||||
sqlStore.GetMaster().Exec("UPDATE Commands SET PluginId = '' WHERE PluginId IS NULL")
|
||||
|
||||
// saveSchemaVersion(sqlStore, VERSION_5_28_0)
|
||||
sqlStore.AlterColumnTypeIfExists("Teams", "Type", "VARCHAR(255)", "VARCHAR(255)")
|
||||
sqlStore.AlterColumnTypeIfExists("Teams", "SchemeId", "VARCHAR(26)", "VARCHAR(26)")
|
||||
sqlStore.AlterColumnTypeIfExists("IncomingWebhooks", "Username", "varchar(255)", "varchar(255)")
|
||||
sqlStore.AlterColumnTypeIfExists("IncomingWebhooks", "IconURL", "text", "varchar(1024)")
|
||||
|
||||
//saveSchemaVersion(sqlStore, VERSION_5_28_0)
|
||||
//}
|
||||
}
|
||||
|
||||
func precheckMigrationToVersion528(sqlStore SqlStore) error {
|
||||
teamsQuery, _, err := sqlStore.getQueryBuilder().Select(`COALESCE(SUM(CASE
|
||||
WHEN CHAR_LENGTH(SchemeId) > 26 THEN 1
|
||||
ELSE 0
|
||||
END),0) as schemeidwrong,
|
||||
COALESCE(SUM(CASE
|
||||
WHEN CHAR_LENGTH(Type) > 255 THEN 1
|
||||
ELSE 0
|
||||
END),0) as typewrong`).
|
||||
From("Teams").ToSql()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
webhooksQuery, _, err := sqlStore.getQueryBuilder().Select(`COALESCE(SUM(CASE
|
||||
WHEN CHAR_LENGTH(Username) > 255 THEN 1
|
||||
ELSE 0
|
||||
END),0) as usernamewrong,
|
||||
COALESCE(SUM(CASE
|
||||
WHEN CHAR_LENGTH(IconURL) > 1024 THEN 1
|
||||
ELSE 0
|
||||
END),0) as iconurlwrong`).
|
||||
From("IncomingWebhooks").ToSql()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var schemeIdWrong int
|
||||
var typeWrong int
|
||||
row := sqlStore.GetMaster().Db.QueryRow(teamsQuery)
|
||||
if err = row.Scan(&schemeIdWrong, &typeWrong); err != nil && err != sql.ErrNoRows {
|
||||
return err
|
||||
} else if err == nil && schemeIdWrong > 0 {
|
||||
return errors.New("Migration failure: " +
|
||||
"Teams column SchemeId has data larger that 26 characters")
|
||||
} else if err == nil && typeWrong > 0 {
|
||||
return errors.New("Migration failure: " +
|
||||
"Teams column Type has data larger that 255 characters")
|
||||
}
|
||||
|
||||
var usernameWrong int
|
||||
var iconURLWrong int
|
||||
row = sqlStore.GetMaster().Db.QueryRow(webhooksQuery)
|
||||
if err = row.Scan(&usernameWrong, &iconURLWrong); err != nil && err != sql.ErrNoRows {
|
||||
mlog.Error("Error fetching IncomingWebhooks columns data", mlog.Err(err))
|
||||
} else if err == nil && usernameWrong > 0 {
|
||||
return errors.New("Migration failure: " +
|
||||
"IncomingWebhooks column Username has data larger that 255 characters")
|
||||
} else if err == nil && iconURLWrong > 0 {
|
||||
return errors.New("Migration failure: " +
|
||||
"IncomingWebhooks column IconURL has data larger that 1024 characters")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ func newSqlWebhookStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface)
|
||||
table.ColMap("TeamId").SetMaxSize(26)
|
||||
table.ColMap("DisplayName").SetMaxSize(64)
|
||||
table.ColMap("Description").SetMaxSize(500)
|
||||
table.ColMap("Username").SetMaxSize(255)
|
||||
table.ColMap("IconURL").SetMaxSize(1024)
|
||||
|
||||
tableo := db.AddTableWithName(model.OutgoingWebhook{}, "OutgoingWebhooks").SetKeys(false, "Id")
|
||||
tableo.ColMap("Id").SetMaxSize(26)
|
||||
|
||||
Ссылка в новой задаче
Block a user