summaryrefslogtreecommitdiffstats
path: root/store/sql_user_store.go
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2015-07-09 17:06:04 -0400
committerhmhealey <harrisonmhealey@gmail.com>2015-07-17 15:13:31 -0400
commit9d8073328a5e971aaff6285e33e212c08b31b510 (patch)
treed8acd4d666c843064df13eb499ae666f29739865 /store/sql_user_store.go
parent1c7f0be268046d2b509e23268eebcbbef78c5a24 (diff)
downloadchat-9d8073328a5e971aaff6285e33e212c08b31b510.tar.gz
chat-9d8073328a5e971aaff6285e33e212c08b31b510.tar.bz2
chat-9d8073328a5e971aaff6285e33e212c08b31b510.zip
Added FirstName and LastName fields to User object and attempt to populate them from the FullName/Nickname field
Diffstat (limited to 'store/sql_user_store.go')
-rw-r--r--store/sql_user_store.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go
index 9e1cc9331..728c6b243 100644
--- a/store/sql_user_store.go
+++ b/store/sql_user_store.go
@@ -26,6 +26,8 @@ func NewSqlUserStore(sqlStore *SqlStore) UserStore {
table.ColMap("AuthData").SetMaxSize(128)
table.ColMap("Email").SetMaxSize(128)
table.ColMap("Nickname").SetMaxSize(64)
+ table.ColMap("FirstName").SetMaxSize(64)
+ table.ColMap("LastName").SetMaxSize(64)
table.ColMap("Roles").SetMaxSize(64)
table.ColMap("Props").SetMaxSize(4000)
table.ColMap("NotifyProps").SetMaxSize(2000)
@@ -39,8 +41,18 @@ func NewSqlUserStore(sqlStore *SqlStore) UserStore {
func (us SqlUserStore) UpgradeSchemaIfNeeded() {
us.CreateColumnIfNotExists("Users", "LastPictureUpdate", "LastPasswordUpdate", "bigint(20)", "0")
- // migrating the FullName column to Nickname for MM-825
- us.RenameColumnIfExists("Users", "FullName", "Nickname", "varchar(64)")
+ // migrating the FullName column to Nickname and adding the FirstName and LastName columns for MM-825
+ if us.RenameColumnIfExists("Users", "FullName", "Nickname", "varchar(64)") {
+ us.CreateColumnIfNotExists("Users", "FirstName", "Nickname", "varchar(64)", "")
+ us.CreateColumnIfNotExists("Users", "LastName", "FirstName", "varchar(64)", "")
+
+ // infer values of first and last name by splitting the previous full name
+ if _, err := us.GetMaster().Exec("UPDATE Users SET " +
+ "FirstName = SUBSTRING_INDEX(SUBSTRING_INDEX(Nickname, ' ', 1), ' ', -1), " +
+ "LastName = SUBSTRING(Nickname, INSTR(Nickname, ' ') + 1)"); err != nil {
+ panic("Failed to set first and last name columns from nickname " + err.Error())
+ }
+ }
}
//func (ss SqlStore) CreateColumnIfNotExists(tableName string, columnName string, afterName string, colType string, defaultValue string) bool {