PLT-3695 refactoring to use sql_upgrader (#3788)
* PLT-3695 unitying upgrade support * PLT-3695 refactoring to use sql_upgrader * Fixing unit test * Adding 3.3 to 3.4 * Fixing upgrading * Seperating DB schema from version.go * Fixing upgrade cmd * Moving to const for exit codes * remving old unused code
Этот коммит содержится в:
@@ -9,9 +9,7 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
)
|
||||
@@ -49,77 +47,6 @@ func NewSqlUserStore(sqlStore *SqlStore) UserStore {
|
||||
return us
|
||||
}
|
||||
|
||||
func (us SqlUserStore) UpgradeSchemaIfNeeded() {
|
||||
// ADDED for 2.0 REMOVE for 2.4
|
||||
us.CreateColumnIfNotExists("Users", "Locale", "varchar(5)", "character varying(5)", model.DEFAULT_LOCALE)
|
||||
|
||||
// ADDED for 3.2 REMOVE for 3.6
|
||||
if us.DoesColumnExist("Users", "ThemeProps") {
|
||||
params := map[string]interface{}{
|
||||
"Category": model.PREFERENCE_CATEGORY_THEME,
|
||||
"Name": "",
|
||||
}
|
||||
|
||||
transaction, err := us.GetMaster().Begin()
|
||||
if err != nil {
|
||||
themeMigrationFailed(err)
|
||||
}
|
||||
|
||||
// increase size of Value column of Preferences table to match the size of the ThemeProps column
|
||||
if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
|
||||
if _, err := transaction.Exec("ALTER TABLE Preferences ALTER COLUMN Value TYPE varchar(2000)"); err != nil {
|
||||
themeMigrationFailed(err)
|
||||
}
|
||||
} else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL {
|
||||
if _, err := transaction.Exec("ALTER TABLE Preferences MODIFY Value text"); err != nil {
|
||||
themeMigrationFailed(err)
|
||||
}
|
||||
}
|
||||
|
||||
// copy data across
|
||||
if _, err := transaction.Exec(
|
||||
`INSERT INTO
|
||||
Preferences(UserId, Category, Name, Value)
|
||||
SELECT
|
||||
Id, '`+model.PREFERENCE_CATEGORY_THEME+`', '', ThemeProps
|
||||
FROM
|
||||
Users
|
||||
WHERE
|
||||
Users.ThemeProps != 'null'`, params); err != nil {
|
||||
themeMigrationFailed(err)
|
||||
}
|
||||
|
||||
// delete old data
|
||||
if _, err := transaction.Exec("ALTER TABLE Users DROP COLUMN ThemeProps"); err != nil {
|
||||
themeMigrationFailed(err)
|
||||
}
|
||||
|
||||
if err := transaction.Commit(); err != nil {
|
||||
themeMigrationFailed(err)
|
||||
}
|
||||
|
||||
// rename solarized_* code themes to solarized-* to match client changes in 3.0
|
||||
var data model.Preferences
|
||||
if _, err := us.GetReplica().Select(&data, "SELECT * FROM Preferences WHERE Category = '"+model.PREFERENCE_CATEGORY_THEME+"' AND Value LIKE '%solarized_%'"); err == nil {
|
||||
for i := range data {
|
||||
data[i].Value = strings.Replace(data[i].Value, "solarized_", "solarized-", -1)
|
||||
}
|
||||
|
||||
us.Preference().Save(&data)
|
||||
}
|
||||
}
|
||||
|
||||
// ADDED for 3.3 remove for 3.7
|
||||
us.RemoveColumnIfExists("Users", "LastActivityAt")
|
||||
us.RemoveColumnIfExists("Users", "LastPingAt")
|
||||
}
|
||||
|
||||
func themeMigrationFailed(err error) {
|
||||
l4g.Critical(utils.T("store.sql_user.migrate_theme.critical"), err)
|
||||
time.Sleep(time.Second)
|
||||
panic(fmt.Sprintf(utils.T("store.sql_user.migrate_theme.critical"), err.Error()))
|
||||
}
|
||||
|
||||
func (us SqlUserStore) CreateIndexesIfNotExists() {
|
||||
us.CreateIndexIfNotExists("idx_users_email", "Users", "Email")
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user