MM-29067 Add deterministic IDs for default sidebar categories (#16030)

Automatic Merge
Этот коммит содержится в:
Harrison Healey
2020-10-29 10:24:01 -04:00
коммит произвёл GitHub
родитель 28983fa88d
Коммит 8bb772638c
8 изменённых файлов: 113 добавлений и 10 удалений

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

@@ -391,7 +391,7 @@ func newSqlChannelStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface)
tablePublicChannels.ColMap("Purpose").SetMaxSize(250)
tableSidebarCategories := db.AddTableWithName(model.SidebarCategory{}, "SidebarCategories").SetKeys(false, "Id")
tableSidebarCategories.ColMap("Id").SetMaxSize(26)
tableSidebarCategories.ColMap("Id").SetMaxSize(128)
tableSidebarCategories.ColMap("UserId").SetMaxSize(26)
tableSidebarCategories.ColMap("TeamId").SetMaxSize(26)
tableSidebarCategories.ColMap("Sorting").SetMaxSize(64)
@@ -401,7 +401,7 @@ func newSqlChannelStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface)
tableSidebarChannels := db.AddTableWithName(model.SidebarChannel{}, "SidebarChannels").SetKeys(false, "ChannelId", "UserId", "CategoryId")
tableSidebarChannels.ColMap("ChannelId").SetMaxSize(26)
tableSidebarChannels.ColMap("UserId").SetMaxSize(26)
tableSidebarChannels.ColMap("CategoryId").SetMaxSize(26)
tableSidebarChannels.ColMap("CategoryId").SetMaxSize(128)
}
return s

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

@@ -53,9 +53,12 @@ func (s SqlChannelStore) createInitialSidebarCategoriesT(transaction *gorp.Trans
hasCategoryOfType[existingType] = true
}
if !hasCategoryOfType[model.SidebarCategoryFavorites] {
favoritesCategoryId := model.NewId()
// Use deterministic IDs for default categories to prevent potentially creating multiple copies of a default category
favoritesCategoryId := fmt.Sprintf("%s_%s_%s", model.SidebarCategoryFavorites, userId, teamId)
channelsCategoryId := fmt.Sprintf("%s_%s_%s", model.SidebarCategoryChannels, userId, teamId)
directMessagesCategoryId := fmt.Sprintf("%s_%s_%s", model.SidebarCategoryDirectMessages, userId, teamId)
if !hasCategoryOfType[model.SidebarCategoryFavorites] {
// Create the SidebarChannels first since there's more opportunity for something to fail here
if err := s.migrateFavoritesToSidebarT(transaction, userId, teamId, favoritesCategoryId); err != nil {
return errors.Wrap(err, "createInitialSidebarCategoriesT: failed to migrate favorites to sidebar")
@@ -77,7 +80,7 @@ func (s SqlChannelStore) createInitialSidebarCategoriesT(transaction *gorp.Trans
if !hasCategoryOfType[model.SidebarCategoryChannels] {
if err := transaction.Insert(&model.SidebarCategory{
DisplayName: "Channels", // This will be retranslateed by the client into the user's locale
Id: model.NewId(),
Id: channelsCategoryId,
UserId: userId,
TeamId: teamId,
Sorting: model.SidebarCategorySortDefault,
@@ -91,7 +94,7 @@ func (s SqlChannelStore) createInitialSidebarCategoriesT(transaction *gorp.Trans
if !hasCategoryOfType[model.SidebarCategoryDirectMessages] {
if err := transaction.Insert(&model.SidebarCategory{
DisplayName: "Direct Messages", // This will be retranslateed by the client into the user's locale
Id: model.NewId(),
Id: directMessagesCategoryId,
UserId: userId,
TeamId: teamId,
Sorting: model.SidebarCategorySortRecent,

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

@@ -20,6 +20,7 @@ import (
const (
CURRENT_SCHEMA_VERSION = VERSION_5_28_1
VERSION_5_29_0 = "5.29.0"
VERSION_5_28_1 = "5.28.1"
VERSION_5_28_0 = "5.28.0"
VERSION_5_27_0 = "5.27.0"
@@ -190,6 +191,7 @@ func upgradeDatabase(sqlStore SqlStore, currentModelVersionString string) error
upgradeDatabaseToVersion527(sqlStore)
upgradeDatabaseToVersion528(sqlStore)
upgradeDatabaseToVersion5281(sqlStore)
upgradeDatabaseToVersion529(sqlStore)
return nil
}
@@ -915,3 +917,15 @@ func precheckMigrationToVersion528(sqlStore SqlStore) error {
return nil
}
func upgradeDatabaseToVersion529(sqlStore SqlStore) {
// if shouldPerformUpgrade(sqlStore, VERSION_5_28_0, VERSION_5_29_0) {
sqlStore.AlterColumnTypeIfExists("SidebarCategories", "Id", "VARCHAR(128)", "VARCHAR(128)")
sqlStore.AlterColumnDefaultIfExists("SidebarCategories", "Id", model.NewString(""), nil)
sqlStore.AlterColumnTypeIfExists("SidebarChannels", "CategoryId", "VARCHAR(128)", "VARCHAR(128)")
sqlStore.AlterColumnDefaultIfExists("SidebarChannels", "CategoryId", model.NewString(""), nil)
// saveSchemaVersion(sqlStore, VERSION_5_29_0)
// }
}