diff options
author | Corey Hulen <corey@hulen.com> | 2016-08-24 16:17:40 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-24 16:17:40 -0800 |
commit | c3ae3f20f58b25aa6aba480ddc2239fd09e610cb (patch) | |
tree | 244c273ddb2fc7ed3ff2df2aee3a615aa5d61f28 /store/sql_user_store.go | |
parent | 8efa4dc9a5156c511aae8e3984795e55d4b7947f (diff) | |
download | chat-c3ae3f20f58b25aa6aba480ddc2239fd09e610cb.tar.gz chat-c3ae3f20f58b25aa6aba480ddc2239fd09e610cb.tar.bz2 chat-c3ae3f20f58b25aa6aba480ddc2239fd09e610cb.zip |
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
Diffstat (limited to 'store/sql_user_store.go')
-rw-r--r-- | store/sql_user_store.go | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go index e26183c1e..027dcbd75 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -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") } |