diff options
author | hmhealey <harrisonmhealey@gmail.com> | 2015-07-10 15:51:45 -0400 |
---|---|---|
committer | hmhealey <harrisonmhealey@gmail.com> | 2015-07-17 15:13:31 -0400 |
commit | b620960cdefe87d9e96958ab526c294ee6502a90 (patch) | |
tree | 7de6c7990739b4ca97373675a793c3bbab2b99ae /store | |
parent | 8dbf03bd10a440db3896c046de7332806f96e889 (diff) | |
download | chat-b620960cdefe87d9e96958ab526c294ee6502a90.tar.gz chat-b620960cdefe87d9e96958ab526c294ee6502a90.tar.bz2 chat-b620960cdefe87d9e96958ab526c294ee6502a90.zip |
Fix migration code so that LastName is populated correctly for users who only have one word in their FullName
Diffstat (limited to 'store')
-rw-r--r-- | store/sql_user_store.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go index 728c6b243..d8ab4482e 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -47,10 +47,14 @@ func (us SqlUserStore) UpgradeSchemaIfNeeded() { 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()) + if _, err := us.GetMaster().Exec("UPDATE Users SET FirstName = SUBSTRING_INDEX(SUBSTRING_INDEX(Nickname, ' ', 1), ' ', -1)"); err != nil { + panic("Failed to set first name from nickname " + err.Error()) + } + + // only set the last name from full names that are comprised of multiple words (ie that have at least one space in them) + if _, err := us.GetMaster().Exec("Update Users SET LastName = SUBSTRING(Nickname, INSTR(Nickname, ' ') + 1) " + + "WHERE CHAR_LENGTH(REPLACE(Nickname, ' ', '')) < CHAR_LENGTH(Nickname)"); err != nil { + panic("Failed to set last name from nickname " + err.Error()) } } } |