Added FirstName and LastName fields to User object and attempt to populate them from the FullName/Nickname field

Этот коммит содержится в:
hmhealey
2015-07-09 17:06:04 -04:00
родитель 1c7f0be268
Коммит 9d8073328a
2 изменённых файлов: 24 добавлений и 2 удалений

Просмотреть файл

@@ -38,6 +38,8 @@ type User struct {
Email string `json:"email"`
EmailVerified bool `json:"email_verified"`
Nickname string `json:"nickname"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Roles string `json:"roles"`
LastActivityAt int64 `json:"last_activity_at"`
LastPingAt int64 `json:"last_ping_at"`
@@ -86,6 +88,14 @@ func (u *User) IsValid() *AppError {
return NewAppError("User.IsValid", "Invalid nickname", "user_id="+u.Id)
}
if len(u.FirstName) > 64 {
return NewAppError("User.IsValid", "Invalid first name", "user_id="+u.Id)
}
if len(u.LastName) > 64 {
return NewAppError("User.IsValid", "Invalid last name", "user_id="+u.Id)
}
return nil
}

Просмотреть файл

@@ -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 {