MM-31063: Change constants to use CamelCase (#16608)
* MM-31063: Change constants to use CamelCase * store package * change allcaps to camel case (#16615) * New tools.mod Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8b6ac5f5d2
Коммит
c1dd23a3c8
@@ -4,12 +4,12 @@
|
||||
package store
|
||||
|
||||
const (
|
||||
CHANNEL_EXISTS_ERROR = "store.sql_channel.save_channel.exists.app_error"
|
||||
ChannelExistsError = "store.sql_channel.save_channel.exists.app_error"
|
||||
|
||||
USER_SEARCH_OPTION_NAMES_ONLY = "names_only"
|
||||
USER_SEARCH_OPTION_NAMES_ONLY_NO_FULL_NAME = "names_only_no_full_name"
|
||||
USER_SEARCH_OPTION_ALL_NO_FULL_NAME = "all_no_full_name"
|
||||
USER_SEARCH_OPTION_ALLOW_INACTIVE = "allow_inactive"
|
||||
UserSearchOptionNamesOnly = "names_only"
|
||||
UserSearchOptionNamesOnlyNoFullName = "names_only_no_full_name"
|
||||
UserSearchOptionAllNoFullName = "all_no_full_name"
|
||||
UserSearchOptionAllowInactive = "allow_inactive"
|
||||
|
||||
FEATURE_TOGGLE_PREFIX = "feature_enabled_"
|
||||
FeatureTogglePrefix = "feature_enabled_"
|
||||
)
|
||||
|
||||
@@ -19,12 +19,12 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
OPEN_TRACING_PARAMS_MARKER = "@openTracingParams"
|
||||
ERROR_TYPE = "error"
|
||||
OpenTracingParamsMarker = "@openTracingParams"
|
||||
ErrorType = "error"
|
||||
)
|
||||
|
||||
func isError(typeName string) bool {
|
||||
return strings.Contains(typeName, ERROR_TYPE)
|
||||
return strings.Contains(typeName, ErrorType)
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -109,8 +109,8 @@ func extractMethodMetadata(method *ast.Field, src []byte) methodData {
|
||||
if method.Doc != nil {
|
||||
for _, comment := range method.Doc.List {
|
||||
s := comment.Text
|
||||
if idx := strings.Index(s, OPEN_TRACING_PARAMS_MARKER); idx != -1 {
|
||||
for _, p := range strings.Split(s[idx+len(OPEN_TRACING_PARAMS_MARKER):], ",") {
|
||||
if idx := strings.Index(s, OpenTracingParamsMarker); idx != -1 {
|
||||
for _, p := range strings.Split(s[idx+len(OpenTracingParamsMarker):], ",") {
|
||||
paramsToTrace[strings.TrimSpace(p)] = true
|
||||
}
|
||||
}
|
||||
@@ -138,7 +138,7 @@ func extractMethodMetadata(method *ast.Field, src []byte) methodData {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
log.Fatalf("Unable to find a parameter called '%s' (method '%s') that is mentioned in the '%s' comment. Maybe it was renamed?", paramName, method.Names[0].Name, OPEN_TRACING_PARAMS_MARKER)
|
||||
log.Fatalf("Unable to find a parameter called '%s' (method '%s') that is mentioned in the '%s' comment. Maybe it was renamed?", paramName, method.Names[0].Name, OpenTracingParamsMarker)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ type LocalCacheChannelStore struct {
|
||||
}
|
||||
|
||||
func (s *LocalCacheChannelStore) handleClusterInvalidateChannelMemberCounts(msg *model.ClusterMessage) {
|
||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||
if msg.Data == ClearCacheMessageData {
|
||||
s.rootStore.channelMemberCountsCache.Purge()
|
||||
} else {
|
||||
s.rootStore.channelMemberCountsCache.Remove(msg.Data)
|
||||
@@ -22,7 +22,7 @@ func (s *LocalCacheChannelStore) handleClusterInvalidateChannelMemberCounts(msg
|
||||
}
|
||||
|
||||
func (s *LocalCacheChannelStore) handleClusterInvalidateChannelPinnedPostCount(msg *model.ClusterMessage) {
|
||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||
if msg.Data == ClearCacheMessageData {
|
||||
s.rootStore.channelPinnedPostCountsCache.Purge()
|
||||
} else {
|
||||
s.rootStore.channelPinnedPostCountsCache.Remove(msg.Data)
|
||||
@@ -30,7 +30,7 @@ func (s *LocalCacheChannelStore) handleClusterInvalidateChannelPinnedPostCount(m
|
||||
}
|
||||
|
||||
func (s *LocalCacheChannelStore) handleClusterInvalidateChannelGuestCounts(msg *model.ClusterMessage) {
|
||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||
if msg.Data == ClearCacheMessageData {
|
||||
s.rootStore.channelGuestCountCache.Purge()
|
||||
} else {
|
||||
s.rootStore.channelGuestCountCache.Remove(msg.Data)
|
||||
@@ -38,7 +38,7 @@ func (s *LocalCacheChannelStore) handleClusterInvalidateChannelGuestCounts(msg *
|
||||
}
|
||||
|
||||
func (s *LocalCacheChannelStore) handleClusterInvalidateChannelById(msg *model.ClusterMessage) {
|
||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||
if msg.Data == ClearCacheMessageData {
|
||||
s.rootStore.channelByIdCache.Purge()
|
||||
} else {
|
||||
s.rootStore.channelByIdCache.Remove(msg.Data)
|
||||
|
||||
@@ -14,7 +14,7 @@ type LocalCacheEmojiStore struct {
|
||||
}
|
||||
|
||||
func (es *LocalCacheEmojiStore) handleClusterInvalidateEmojiById(msg *model.ClusterMessage) {
|
||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||
if msg.Data == ClearCacheMessageData {
|
||||
es.rootStore.emojiCacheById.Purge()
|
||||
} else {
|
||||
es.rootStore.emojiCacheById.Remove(msg.Data)
|
||||
@@ -22,7 +22,7 @@ func (es *LocalCacheEmojiStore) handleClusterInvalidateEmojiById(msg *model.Clus
|
||||
}
|
||||
|
||||
func (es *LocalCacheEmojiStore) handleClusterInvalidateEmojiIdByName(msg *model.ClusterMessage) {
|
||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||
if msg.Data == ClearCacheMessageData {
|
||||
es.rootStore.emojiIdCacheByName.Purge()
|
||||
} else {
|
||||
es.rootStore.emojiIdCacheByName.Remove(msg.Data)
|
||||
|
||||
@@ -14,7 +14,7 @@ type LocalCacheFileInfoStore struct {
|
||||
}
|
||||
|
||||
func (s *LocalCacheFileInfoStore) handleClusterInvalidateFileInfo(msg *model.ClusterMessage) {
|
||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||
if msg.Data == ClearCacheMessageData {
|
||||
s.rootStore.fileInfoCache.Purge()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -14,53 +14,53 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
REACTION_CACHE_SIZE = 20000
|
||||
REACTION_CACHE_SEC = 30 * 60
|
||||
ReactionCacheSize = 20000
|
||||
ReactionCacheSec = 30 * 60
|
||||
|
||||
ROLE_CACHE_SIZE = 20000
|
||||
ROLE_CACHE_SEC = 30 * 60
|
||||
RoleCacheSize = 20000
|
||||
RoleCacheSec = 30 * 60
|
||||
|
||||
SCHEME_CACHE_SIZE = 20000
|
||||
SCHEME_CACHE_SEC = 30 * 60
|
||||
SchemeCacheSize = 20000
|
||||
SchemeCacheSec = 30 * 60
|
||||
|
||||
FILE_INFO_CACHE_SIZE = 25000
|
||||
FILE_INFO_CACHE_SEC = 30 * 60
|
||||
FileInfoCacheSize = 25000
|
||||
FileInfoCacheSec = 30 * 60
|
||||
|
||||
CHANNEL_GUEST_COUNT_CACHE_SIZE = model.CHANNEL_CACHE_SIZE
|
||||
CHANNEL_GUEST_COUNT_CACHE_SEC = 30 * 60
|
||||
ChannelGuestCountCacheSize = model.CHANNEL_CACHE_SIZE
|
||||
ChannelGuestCountCacheSec = 30 * 60
|
||||
|
||||
WEBHOOK_CACHE_SIZE = 25000
|
||||
WEBHOOK_CACHE_SEC = 15 * 60
|
||||
WebhookCacheSize = 25000
|
||||
WebhookCacheSec = 15 * 60
|
||||
|
||||
EMOJI_CACHE_SIZE = 5000
|
||||
EMOJI_CACHE_SEC = 30 * 60
|
||||
EmojiCacheSize = 5000
|
||||
EmojiCacheSec = 30 * 60
|
||||
|
||||
CHANNEL_PINNEDPOSTS_COUNTS_CACHE_SIZE = model.CHANNEL_CACHE_SIZE
|
||||
CHANNEL_PINNEDPOSTS_COUNTS_CACHE_SEC = 30 * 60
|
||||
ChannelPinnedPostsCounsCacheSize = model.CHANNEL_CACHE_SIZE
|
||||
ChannelPinnedPostsCountsCacheSec = 30 * 60
|
||||
|
||||
CHANNEL_MEMBERS_COUNTS_CACHE_SIZE = model.CHANNEL_CACHE_SIZE
|
||||
CHANNEL_MEMBERS_COUNTS_CACHE_SEC = 30 * 60
|
||||
ChannelMembersCountsCacheSize = model.CHANNEL_CACHE_SIZE
|
||||
ChannelMembersCountsCacheSec = 30 * 60
|
||||
|
||||
LAST_POSTS_CACHE_SIZE = 20000
|
||||
LAST_POSTS_CACHE_SEC = 30 * 60
|
||||
LastPostsCacheSize = 20000
|
||||
LastPostsCacheSec = 30 * 60
|
||||
|
||||
TERMS_OF_SERVICE_CACHE_SIZE = 20000
|
||||
TERMS_OF_SERVICE_CACHE_SEC = 30 * 60
|
||||
LAST_POST_TIME_CACHE_SIZE = 25000
|
||||
LAST_POST_TIME_CACHE_SEC = 15 * 60
|
||||
TermsOfServiceCacheSize = 20000
|
||||
TermsOfServiceCacheSec = 30 * 60
|
||||
LastPostTimeCacheSize = 25000
|
||||
LastPostTimeCacheSec = 15 * 60
|
||||
|
||||
USER_PROFILE_BY_ID_CACHE_SIZE = 20000
|
||||
USER_PROFILE_BY_ID_SEC = 30 * 60
|
||||
UserProfileByIDCacheSize = 20000
|
||||
UserProfileByIDSec = 30 * 60
|
||||
|
||||
PROFILES_IN_CHANNEL_CACHE_SIZE = model.CHANNEL_CACHE_SIZE
|
||||
PROFILES_IN_CHANNEL_CACHE_SEC = 15 * 60
|
||||
ProfilesInChannelCacheSize = model.CHANNEL_CACHE_SIZE
|
||||
PROFILES_IN_ChannelCacheSec = 15 * 60
|
||||
|
||||
TEAM_CACHE_SIZE = 20000
|
||||
TEAM_CACHE_SEC = 30 * 60
|
||||
TeamCacheSize = 20000
|
||||
TeamCacheSec = 30 * 60
|
||||
|
||||
CLEAR_CACHE_MESSAGE_DATA = ""
|
||||
ClearCacheMessageData = ""
|
||||
|
||||
CHANNEL_CACHE_SEC = 15 * 60 // 15 mins
|
||||
ChannelCacheSec = 15 * 60 // 15 mins
|
||||
)
|
||||
|
||||
type LocalCacheStore struct {
|
||||
@@ -117,9 +117,9 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf
|
||||
}
|
||||
// Reactions
|
||||
if localCacheStore.reactionCache, err = cacheProvider.NewCache(&cache.CacheOptions{
|
||||
Size: REACTION_CACHE_SIZE,
|
||||
Size: ReactionCacheSize,
|
||||
Name: "Reaction",
|
||||
DefaultExpiry: REACTION_CACHE_SEC * time.Second,
|
||||
DefaultExpiry: ReactionCacheSec * time.Second,
|
||||
InvalidateClusterEvent: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_REACTIONS,
|
||||
}); err != nil {
|
||||
return
|
||||
@@ -128,9 +128,9 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf
|
||||
|
||||
// Roles
|
||||
if localCacheStore.roleCache, err = cacheProvider.NewCache(&cache.CacheOptions{
|
||||
Size: ROLE_CACHE_SIZE,
|
||||
Size: RoleCacheSize,
|
||||
Name: "Role",
|
||||
DefaultExpiry: ROLE_CACHE_SEC * time.Second,
|
||||
DefaultExpiry: RoleCacheSec * time.Second,
|
||||
InvalidateClusterEvent: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_ROLES,
|
||||
Striped: true,
|
||||
StripedBuckets: maxInt(runtime.NumCPU()-1, 1),
|
||||
@@ -138,9 +138,9 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf
|
||||
return
|
||||
}
|
||||
if localCacheStore.rolePermissionsCache, err = cacheProvider.NewCache(&cache.CacheOptions{
|
||||
Size: ROLE_CACHE_SIZE,
|
||||
Size: RoleCacheSize,
|
||||
Name: "RolePermission",
|
||||
DefaultExpiry: ROLE_CACHE_SEC * time.Second,
|
||||
DefaultExpiry: RoleCacheSec * time.Second,
|
||||
InvalidateClusterEvent: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_ROLE_PERMISSIONS,
|
||||
}); err != nil {
|
||||
return
|
||||
@@ -149,9 +149,9 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf
|
||||
|
||||
// Schemes
|
||||
if localCacheStore.schemeCache, err = cacheProvider.NewCache(&cache.CacheOptions{
|
||||
Size: SCHEME_CACHE_SIZE,
|
||||
Size: SchemeCacheSize,
|
||||
Name: "Scheme",
|
||||
DefaultExpiry: SCHEME_CACHE_SEC * time.Second,
|
||||
DefaultExpiry: SchemeCacheSec * time.Second,
|
||||
InvalidateClusterEvent: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_SCHEMES,
|
||||
}); err != nil {
|
||||
return
|
||||
@@ -160,9 +160,9 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf
|
||||
|
||||
// FileInfo
|
||||
if localCacheStore.fileInfoCache, err = cacheProvider.NewCache(&cache.CacheOptions{
|
||||
Size: FILE_INFO_CACHE_SIZE,
|
||||
Size: FileInfoCacheSize,
|
||||
Name: "FileInfo",
|
||||
DefaultExpiry: FILE_INFO_CACHE_SEC * time.Second,
|
||||
DefaultExpiry: FileInfoCacheSec * time.Second,
|
||||
InvalidateClusterEvent: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_FILE_INFOS,
|
||||
}); err != nil {
|
||||
return
|
||||
@@ -171,9 +171,9 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf
|
||||
|
||||
// Webhooks
|
||||
if localCacheStore.webhookCache, err = cacheProvider.NewCache(&cache.CacheOptions{
|
||||
Size: WEBHOOK_CACHE_SIZE,
|
||||
Size: WebhookCacheSize,
|
||||
Name: "Webhook",
|
||||
DefaultExpiry: WEBHOOK_CACHE_SEC * time.Second,
|
||||
DefaultExpiry: WebhookCacheSec * time.Second,
|
||||
InvalidateClusterEvent: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOKS,
|
||||
}); err != nil {
|
||||
return
|
||||
@@ -182,17 +182,17 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf
|
||||
|
||||
// Emojis
|
||||
if localCacheStore.emojiCacheById, err = cacheProvider.NewCache(&cache.CacheOptions{
|
||||
Size: EMOJI_CACHE_SIZE,
|
||||
Size: EmojiCacheSize,
|
||||
Name: "EmojiById",
|
||||
DefaultExpiry: EMOJI_CACHE_SEC * time.Second,
|
||||
DefaultExpiry: EmojiCacheSec * time.Second,
|
||||
InvalidateClusterEvent: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_EMOJIS_BY_ID,
|
||||
}); err != nil {
|
||||
return
|
||||
}
|
||||
if localCacheStore.emojiIdCacheByName, err = cacheProvider.NewCache(&cache.CacheOptions{
|
||||
Size: EMOJI_CACHE_SIZE,
|
||||
Size: EmojiCacheSize,
|
||||
Name: "EmojiByName",
|
||||
DefaultExpiry: EMOJI_CACHE_SEC * time.Second,
|
||||
DefaultExpiry: EmojiCacheSec * time.Second,
|
||||
InvalidateClusterEvent: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_EMOJIS_ID_BY_NAME,
|
||||
}); err != nil {
|
||||
return
|
||||
@@ -201,25 +201,25 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf
|
||||
|
||||
// Channels
|
||||
if localCacheStore.channelPinnedPostCountsCache, err = cacheProvider.NewCache(&cache.CacheOptions{
|
||||
Size: CHANNEL_PINNEDPOSTS_COUNTS_CACHE_SIZE,
|
||||
Size: ChannelPinnedPostsCounsCacheSize,
|
||||
Name: "ChannelPinnedPostsCounts",
|
||||
DefaultExpiry: CHANNEL_PINNEDPOSTS_COUNTS_CACHE_SEC * time.Second,
|
||||
DefaultExpiry: ChannelPinnedPostsCountsCacheSec * time.Second,
|
||||
InvalidateClusterEvent: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_PINNEDPOSTS_COUNTS,
|
||||
}); err != nil {
|
||||
return
|
||||
}
|
||||
if localCacheStore.channelMemberCountsCache, err = cacheProvider.NewCache(&cache.CacheOptions{
|
||||
Size: CHANNEL_MEMBERS_COUNTS_CACHE_SIZE,
|
||||
Size: ChannelMembersCountsCacheSize,
|
||||
Name: "ChannelMemberCounts",
|
||||
DefaultExpiry: CHANNEL_MEMBERS_COUNTS_CACHE_SEC * time.Second,
|
||||
DefaultExpiry: ChannelMembersCountsCacheSec * time.Second,
|
||||
InvalidateClusterEvent: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBER_COUNTS,
|
||||
}); err != nil {
|
||||
return
|
||||
}
|
||||
if localCacheStore.channelGuestCountCache, err = cacheProvider.NewCache(&cache.CacheOptions{
|
||||
Size: CHANNEL_GUEST_COUNT_CACHE_SIZE,
|
||||
Size: ChannelGuestCountCacheSize,
|
||||
Name: "ChannelGuestsCount",
|
||||
DefaultExpiry: CHANNEL_GUEST_COUNT_CACHE_SEC * time.Second,
|
||||
DefaultExpiry: ChannelGuestCountCacheSec * time.Second,
|
||||
InvalidateClusterEvent: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_GUEST_COUNT,
|
||||
}); err != nil {
|
||||
return
|
||||
@@ -227,7 +227,7 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf
|
||||
if localCacheStore.channelByIdCache, err = cacheProvider.NewCache(&cache.CacheOptions{
|
||||
Size: model.CHANNEL_CACHE_SIZE,
|
||||
Name: "channelById",
|
||||
DefaultExpiry: CHANNEL_CACHE_SEC * time.Second,
|
||||
DefaultExpiry: ChannelCacheSec * time.Second,
|
||||
InvalidateClusterEvent: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL,
|
||||
}); err != nil {
|
||||
return
|
||||
@@ -236,17 +236,17 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf
|
||||
|
||||
// Posts
|
||||
if localCacheStore.postLastPostsCache, err = cacheProvider.NewCache(&cache.CacheOptions{
|
||||
Size: LAST_POSTS_CACHE_SIZE,
|
||||
Size: LastPostsCacheSize,
|
||||
Name: "LastPost",
|
||||
DefaultExpiry: LAST_POSTS_CACHE_SEC * time.Second,
|
||||
DefaultExpiry: LastPostsCacheSec * time.Second,
|
||||
InvalidateClusterEvent: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_LAST_POSTS,
|
||||
}); err != nil {
|
||||
return
|
||||
}
|
||||
if localCacheStore.lastPostTimeCache, err = cacheProvider.NewCache(&cache.CacheOptions{
|
||||
Size: LAST_POST_TIME_CACHE_SIZE,
|
||||
Size: LastPostTimeCacheSize,
|
||||
Name: "LastPostTime",
|
||||
DefaultExpiry: LAST_POST_TIME_CACHE_SEC * time.Second,
|
||||
DefaultExpiry: LastPostTimeCacheSec * time.Second,
|
||||
InvalidateClusterEvent: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_LAST_POST_TIME,
|
||||
}); err != nil {
|
||||
return
|
||||
@@ -255,9 +255,9 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf
|
||||
|
||||
// TOS
|
||||
if localCacheStore.termsOfServiceCache, err = cacheProvider.NewCache(&cache.CacheOptions{
|
||||
Size: TERMS_OF_SERVICE_CACHE_SIZE,
|
||||
Size: TermsOfServiceCacheSize,
|
||||
Name: "TermsOfService",
|
||||
DefaultExpiry: TERMS_OF_SERVICE_CACHE_SEC * time.Second,
|
||||
DefaultExpiry: TermsOfServiceCacheSec * time.Second,
|
||||
InvalidateClusterEvent: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_TERMS_OF_SERVICE,
|
||||
}); err != nil {
|
||||
return
|
||||
@@ -266,9 +266,9 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf
|
||||
|
||||
// Users
|
||||
if localCacheStore.userProfileByIdsCache, err = cacheProvider.NewCache(&cache.CacheOptions{
|
||||
Size: USER_PROFILE_BY_ID_CACHE_SIZE,
|
||||
Size: UserProfileByIDCacheSize,
|
||||
Name: "UserProfileByIds",
|
||||
DefaultExpiry: USER_PROFILE_BY_ID_SEC * time.Second,
|
||||
DefaultExpiry: UserProfileByIDSec * time.Second,
|
||||
InvalidateClusterEvent: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_PROFILE_BY_IDS,
|
||||
Striped: true,
|
||||
StripedBuckets: maxInt(runtime.NumCPU()-1, 1),
|
||||
@@ -276,9 +276,9 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf
|
||||
return
|
||||
}
|
||||
if localCacheStore.profilesInChannelCache, err = cacheProvider.NewCache(&cache.CacheOptions{
|
||||
Size: PROFILES_IN_CHANNEL_CACHE_SIZE,
|
||||
Size: ProfilesInChannelCacheSize,
|
||||
Name: "ProfilesInChannel",
|
||||
DefaultExpiry: PROFILES_IN_CHANNEL_CACHE_SEC * time.Second,
|
||||
DefaultExpiry: PROFILES_IN_ChannelCacheSec * time.Second,
|
||||
InvalidateClusterEvent: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_PROFILE_IN_CHANNEL,
|
||||
}); err != nil {
|
||||
return
|
||||
@@ -287,9 +287,9 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf
|
||||
|
||||
// Teams
|
||||
if localCacheStore.teamAllTeamIdsForUserCache, err = cacheProvider.NewCache(&cache.CacheOptions{
|
||||
Size: TEAM_CACHE_SIZE,
|
||||
Size: TeamCacheSize,
|
||||
Name: "Team",
|
||||
DefaultExpiry: TEAM_CACHE_SEC * time.Second,
|
||||
DefaultExpiry: TeamCacheSec * time.Second,
|
||||
InvalidateClusterEvent: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_TEAMS,
|
||||
}); err != nil {
|
||||
return
|
||||
@@ -411,7 +411,7 @@ func (s *LocalCacheStore) doClearCacheCluster(cache cache.Cache) {
|
||||
msg := &model.ClusterMessage{
|
||||
Event: cache.GetInvalidateClusterEvent(),
|
||||
SendType: model.CLUSTER_SEND_BEST_EFFORT,
|
||||
Data: CLEAR_CACHE_MESSAGE_DATA,
|
||||
Data: ClearCacheMessageData,
|
||||
}
|
||||
s.cluster.SendClusterMessage(msg)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ type LocalCachePostStore struct {
|
||||
}
|
||||
|
||||
func (s *LocalCachePostStore) handleClusterInvalidateLastPostTime(msg *model.ClusterMessage) {
|
||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||
if msg.Data == ClearCacheMessageData {
|
||||
s.rootStore.lastPostTimeCache.Purge()
|
||||
} else {
|
||||
s.rootStore.lastPostTimeCache.Remove(msg.Data)
|
||||
@@ -27,7 +27,7 @@ func (s *LocalCachePostStore) handleClusterInvalidateLastPostTime(msg *model.Clu
|
||||
}
|
||||
|
||||
func (s *LocalCachePostStore) handleClusterInvalidateLastPosts(msg *model.ClusterMessage) {
|
||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||
if msg.Data == ClearCacheMessageData {
|
||||
s.rootStore.postLastPostsCache.Purge()
|
||||
} else {
|
||||
s.rootStore.postLastPostsCache.Remove(msg.Data)
|
||||
|
||||
@@ -14,7 +14,7 @@ type LocalCacheReactionStore struct {
|
||||
}
|
||||
|
||||
func (s *LocalCacheReactionStore) handleClusterInvalidateReaction(msg *model.ClusterMessage) {
|
||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||
if msg.Data == ClearCacheMessageData {
|
||||
s.rootStore.reactionCache.Purge()
|
||||
} else {
|
||||
s.rootStore.reactionCache.Remove(msg.Data)
|
||||
|
||||
@@ -17,7 +17,7 @@ type LocalCacheRoleStore struct {
|
||||
}
|
||||
|
||||
func (s *LocalCacheRoleStore) handleClusterInvalidateRole(msg *model.ClusterMessage) {
|
||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||
if msg.Data == ClearCacheMessageData {
|
||||
s.rootStore.roleCache.Purge()
|
||||
} else {
|
||||
s.rootStore.roleCache.Remove(msg.Data)
|
||||
@@ -25,7 +25,7 @@ func (s *LocalCacheRoleStore) handleClusterInvalidateRole(msg *model.ClusterMess
|
||||
}
|
||||
|
||||
func (s *LocalCacheRoleStore) handleClusterInvalidateRolePermissions(msg *model.ClusterMessage) {
|
||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||
if msg.Data == ClearCacheMessageData {
|
||||
s.rootStore.rolePermissionsCache.Purge()
|
||||
} else {
|
||||
s.rootStore.rolePermissionsCache.Remove(msg.Data)
|
||||
|
||||
@@ -14,7 +14,7 @@ type LocalCacheSchemeStore struct {
|
||||
}
|
||||
|
||||
func (s *LocalCacheSchemeStore) handleClusterInvalidateScheme(msg *model.ClusterMessage) {
|
||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||
if msg.Data == ClearCacheMessageData {
|
||||
s.rootStore.schemeCache.Purge()
|
||||
} else {
|
||||
s.rootStore.schemeCache.Remove(msg.Data)
|
||||
|
||||
@@ -14,7 +14,7 @@ type LocalCacheTeamStore struct {
|
||||
}
|
||||
|
||||
func (s *LocalCacheTeamStore) handleClusterInvalidateTeam(msg *model.ClusterMessage) {
|
||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||
if msg.Data == ClearCacheMessageData {
|
||||
s.rootStore.teamAllTeamIdsForUserCache.Purge()
|
||||
} else {
|
||||
s.rootStore.teamAllTeamIdsForUserCache.Remove(msg.Data)
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
LATEST_KEY = "latest"
|
||||
LatestKey = "latest"
|
||||
)
|
||||
|
||||
type LocalCacheTermsOfServiceStore struct {
|
||||
@@ -18,7 +18,7 @@ type LocalCacheTermsOfServiceStore struct {
|
||||
}
|
||||
|
||||
func (s *LocalCacheTermsOfServiceStore) handleClusterInvalidateTermsOfService(msg *model.ClusterMessage) {
|
||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||
if msg.Data == ClearCacheMessageData {
|
||||
s.rootStore.termsOfServiceCache.Purge()
|
||||
} else {
|
||||
s.rootStore.termsOfServiceCache.Remove(msg.Data)
|
||||
@@ -38,7 +38,7 @@ func (s LocalCacheTermsOfServiceStore) Save(termsOfService *model.TermsOfService
|
||||
|
||||
if err == nil {
|
||||
s.rootStore.doStandardAddToCache(s.rootStore.termsOfServiceCache, tos.Id, tos)
|
||||
s.rootStore.doInvalidateCacheCluster(s.rootStore.termsOfServiceCache, LATEST_KEY)
|
||||
s.rootStore.doInvalidateCacheCluster(s.rootStore.termsOfServiceCache, LatestKey)
|
||||
}
|
||||
return tos, err
|
||||
}
|
||||
@@ -47,7 +47,7 @@ func (s LocalCacheTermsOfServiceStore) GetLatest(allowFromCache bool) (*model.Te
|
||||
if allowFromCache {
|
||||
if len, err := s.rootStore.termsOfServiceCache.Len(); err == nil && len != 0 {
|
||||
var cacheItem *model.TermsOfService
|
||||
if err := s.rootStore.doStandardReadCache(s.rootStore.termsOfServiceCache, LATEST_KEY, &cacheItem); err == nil {
|
||||
if err := s.rootStore.doStandardReadCache(s.rootStore.termsOfServiceCache, LatestKey, &cacheItem); err == nil {
|
||||
return cacheItem, nil
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func (s LocalCacheTermsOfServiceStore) GetLatest(allowFromCache bool) (*model.Te
|
||||
|
||||
if allowFromCache && err == nil {
|
||||
s.rootStore.doStandardAddToCache(s.rootStore.termsOfServiceCache, termsOfService.Id, termsOfService)
|
||||
s.rootStore.doStandardAddToCache(s.rootStore.termsOfServiceCache, LATEST_KEY, termsOfService)
|
||||
s.rootStore.doStandardAddToCache(s.rootStore.termsOfServiceCache, LatestKey, termsOfService)
|
||||
}
|
||||
|
||||
return termsOfService, err
|
||||
|
||||
@@ -14,7 +14,7 @@ type LocalCacheUserStore struct {
|
||||
}
|
||||
|
||||
func (s *LocalCacheUserStore) handleClusterInvalidateScheme(msg *model.ClusterMessage) {
|
||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||
if msg.Data == ClearCacheMessageData {
|
||||
s.rootStore.userProfileByIdsCache.Purge()
|
||||
} else {
|
||||
s.rootStore.userProfileByIdsCache.Remove(msg.Data)
|
||||
@@ -22,7 +22,7 @@ func (s *LocalCacheUserStore) handleClusterInvalidateScheme(msg *model.ClusterMe
|
||||
}
|
||||
|
||||
func (s *LocalCacheUserStore) handleClusterInvalidateProfilesInChannel(msg *model.ClusterMessage) {
|
||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||
if msg.Data == ClearCacheMessageData {
|
||||
s.rootStore.profilesInChannelCache.Purge()
|
||||
} else {
|
||||
s.rootStore.profilesInChannelCache.Remove(msg.Data)
|
||||
|
||||
@@ -14,7 +14,7 @@ type LocalCacheWebhookStore struct {
|
||||
}
|
||||
|
||||
func (s *LocalCacheWebhookStore) handleClusterInvalidateWebhook(msg *model.ClusterMessage) {
|
||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||
if msg.Data == ClearCacheMessageData {
|
||||
s.rootStore.webhookCache.Purge()
|
||||
} else {
|
||||
s.rootStore.webhookCache.Remove(msg.Data)
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
|
||||
package searchlayer
|
||||
|
||||
var MYSQL_STOP_WORDS = []string{"a", "about", "an", "are", "as", "at", "be", "by", "com", "de", "en", "for", "from", "how", "i", "in", "is", "it", "la", "of",
|
||||
var MySQLStopWords = []string{"a", "about", "an", "are", "as", "at", "be", "by", "com", "de", "en", "for", "from", "how", "i", "in", "is", "it", "la", "of",
|
||||
"on", "or", "that", "the", "this", "to", "was", "what", "when", "where", "who", "will", "with", "und", "the", "www"}
|
||||
|
||||
@@ -15,52 +15,52 @@ var searchChannelStoreTests = []searchTest{
|
||||
{
|
||||
Name: "Should be able to autocomplete a channel by name",
|
||||
Fn: testAutocompleteChannelByName,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to autocomplete a channel by display name",
|
||||
Fn: testAutocompleteChannelByDisplayName,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to autocomplete a channel by a part of its name when has parts splitted by - character",
|
||||
Fn: testAutocompleteChannelByNameSplittedWithDashChar,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to autocomplete a channel by a part of its name when has parts splitted by _ character",
|
||||
Fn: testAutocompleteChannelByNameSplittedWithUnderscoreChar,
|
||||
Tags: []string{ENGINE_MYSQL, ENGINE_ELASTICSEARCH, ENGINE_BLEVE},
|
||||
Tags: []string{EngineMySql, EngineElasticSearch, EngineBleve},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to autocomplete a channel by a part of its display name when has parts splitted by whitespace character",
|
||||
Fn: testAutocompleteChannelByDisplayNameSplittedByWhitespaces,
|
||||
Tags: []string{ENGINE_MYSQL, ENGINE_ELASTICSEARCH, ENGINE_BLEVE},
|
||||
Tags: []string{EngineMySql, EngineElasticSearch, EngineBleve},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to autocomplete retrieving all channels if the term is empty",
|
||||
Fn: testAutocompleteAllChannelsIfTermIsEmpty,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to autocomplete channels in a case insensitive manner",
|
||||
Fn: testSearchChannelsInCaseInsensitiveManner,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should autocomplete only returning public channels",
|
||||
Fn: testSearchOnlyPublicChannels,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should support to autocomplete having a hyphen as the last character",
|
||||
Fn: testSearchShouldSupportHavingHyphenAsLastCharacter,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should support to autocomplete with archived channels",
|
||||
Fn: testSearchShouldSupportAutocompleteWithArchivedChannels,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -16,250 +16,250 @@ var searchPostStoreTests = []searchTest{
|
||||
{
|
||||
Name: "Should be able to search posts including results from DMs",
|
||||
Fn: testSearchPostsIncludingDMs,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search posts using pagination",
|
||||
Fn: testSearchPostsWithPagination,
|
||||
Tags: []string{ENGINE_ELASTICSEARCH, ENGINE_BLEVE},
|
||||
Tags: []string{EngineElasticSearch, EngineBleve},
|
||||
},
|
||||
{
|
||||
Name: "Should return pinned and unpinned posts",
|
||||
Fn: testSearchReturnPinnedAndUnpinned,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search for exact phrases in quotes",
|
||||
Fn: testSearchExactPhraseInQuotes,
|
||||
Tags: []string{ENGINE_POSTGRES, ENGINE_MYSQL, ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EnginePostgres, EngineMySql, EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search for email addresses with or without quotes",
|
||||
Fn: testSearchEmailAddresses,
|
||||
Tags: []string{ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search when markdown underscores are applied",
|
||||
Fn: testSearchMarkdownUnderscores,
|
||||
Tags: []string{ENGINE_POSTGRES, ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EnginePostgres, EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search for non-latin words",
|
||||
Fn: testSearchNonLatinWords,
|
||||
Tags: []string{ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search for alternative spellings of words",
|
||||
Fn: testSearchAlternativeSpellings,
|
||||
Tags: []string{ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search for alternative spellings of words with and without accents",
|
||||
Fn: testSearchAlternativeSpellingsAccents,
|
||||
Tags: []string{ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search or exclude messages written by a specific user",
|
||||
Fn: testSearchOrExcludePostsBySpecificUser,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search or exclude messages written in a specific channel",
|
||||
Fn: testSearchOrExcludePostsInChannel,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search or exclude messages written in a DM or GM",
|
||||
Fn: testSearchOrExcludePostsInDMGM,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to filter messages written after a specific date",
|
||||
Fn: testFilterMessagesAfterSpecificDate,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to filter messages written before a specific date",
|
||||
Fn: testFilterMessagesBeforeSpecificDate,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to filter messages written on a specific date",
|
||||
Fn: testFilterMessagesInSpecificDate,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to exclude messages that contain a serch term",
|
||||
Fn: testFilterMessagesWithATerm,
|
||||
Tags: []string{ENGINE_MYSQL, ENGINE_POSTGRES},
|
||||
Tags: []string{EngineMySql, EnginePostgres},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search using boolean operators",
|
||||
Fn: testSearchUsingBooleanOperators,
|
||||
Tags: []string{ENGINE_MYSQL, ENGINE_POSTGRES, ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EngineMySql, EnginePostgres, EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search with combined filters",
|
||||
Fn: testSearchUsingCombinedFilters,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to ignore stop words",
|
||||
Fn: testSearchIgnoringStopWords,
|
||||
Tags: []string{ENGINE_MYSQL, ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EngineMySql, EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should support search stemming",
|
||||
Fn: testSupportStemming,
|
||||
Tags: []string{ENGINE_POSTGRES, ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EnginePostgres, EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should support search with wildcards",
|
||||
Fn: testSupportWildcards,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should not support search with preceding wildcards",
|
||||
Fn: testNotSupportPrecedingWildcards,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should discard a wildcard if it's not placed immediately by text",
|
||||
Fn: testSearchDiscardWildcardAlone,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should support terms with dash",
|
||||
Fn: testSupportTermsWithDash,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
Skip: true,
|
||||
},
|
||||
{
|
||||
Name: "Should support terms with underscore",
|
||||
Fn: testSupportTermsWithUnderscore,
|
||||
Tags: []string{ENGINE_MYSQL, ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EngineMySql, EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should search or exclude post using hashtags",
|
||||
Fn: testSearchOrExcludePostsWithHashtags,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should support searching for hashtags surrounded by markdown",
|
||||
Fn: testSearchHashtagWithMarkdown,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should support searching for multiple hashtags",
|
||||
Fn: testSearcWithMultipleHashtags,
|
||||
Tags: []string{ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should support searching hashtags with dots",
|
||||
Fn: testSearchPostsWithDotsInHashtags,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search or exclude messages with hashtags in a case insensitive manner",
|
||||
Fn: testSearchHashtagCaseInsensitive,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search by hashtags with dashes",
|
||||
Fn: testSearchHashtagWithDash,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search by hashtags with numbers",
|
||||
Fn: testSearchHashtagWithNumbers,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search by hashtags with dots",
|
||||
Fn: testSearchHashtagWithDots,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search by hashtags with underscores",
|
||||
Fn: testSearchHashtagWithUnderscores,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should not return system messages",
|
||||
Fn: testSearchShouldExcludeSytemMessages,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search matching by mentions",
|
||||
Fn: testSearchShouldBeAbleToMatchByMentions,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search in deleted/archived channels",
|
||||
Fn: testSearchInDeletedOrArchivedChannels,
|
||||
Tags: []string{ENGINE_MYSQL, ENGINE_POSTGRES},
|
||||
Tags: []string{EngineMySql, EnginePostgres},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search terms with dashes",
|
||||
Fn: testSearchTermsWithDashes,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
Skip: true,
|
||||
SkipMessage: "Not working",
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search terms with dots",
|
||||
Fn: testSearchTermsWithDots,
|
||||
Tags: []string{ENGINE_POSTGRES, ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EnginePostgres, EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search terms with underscores",
|
||||
Fn: testSearchTermsWithUnderscores,
|
||||
Tags: []string{ENGINE_MYSQL, ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EngineMySql, EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search posts made by bot accounts",
|
||||
Fn: testSearchBotAccountsPosts,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to combine stemming and wildcards",
|
||||
Fn: testSupportStemmingAndWildcards,
|
||||
Tags: []string{ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should support wildcard outside quotes",
|
||||
Fn: testSupportWildcardOutsideQuotes,
|
||||
Tags: []string{ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should support hashtags with 3 or more characters",
|
||||
Fn: testHashtagSearchShouldSupportThreeOrMoreCharacters,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should not support slash as character separator",
|
||||
Fn: testSlashShouldNotBeCharSeparator,
|
||||
Tags: []string{ENGINE_MYSQL, ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EngineMySql, EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search emails without quoting them",
|
||||
Fn: testSearchEmailsWithoutQuotes,
|
||||
Tags: []string{ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search in comments",
|
||||
Fn: testSupportSearchInComments,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search terms within links",
|
||||
Fn: testSupportSearchTermsWithinLinks,
|
||||
Tags: []string{ENGINE_MYSQL, ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EngineMySql, EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should not return links that are embedded in markdown",
|
||||
Fn: testShouldNotReturnLinksEmbeddedInMarkdown,
|
||||
Tags: []string{ENGINE_POSTGRES, ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EnginePostgres, EngineElasticSearch},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -11,11 +11,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ENGINE_ALL = "all"
|
||||
ENGINE_MYSQL = "mysql"
|
||||
ENGINE_POSTGRES = "postgres"
|
||||
ENGINE_ELASTICSEARCH = "elasticsearch"
|
||||
ENGINE_BLEVE = "bleve"
|
||||
EngineAll = "all"
|
||||
EngineMySql = "mysql"
|
||||
EnginePostgres = "postgres"
|
||||
EngineElasticSearch = "elasticsearch"
|
||||
EngineBleve = "bleve"
|
||||
)
|
||||
|
||||
type SearchTestEngine struct {
|
||||
@@ -35,7 +35,7 @@ type searchTest struct {
|
||||
func filterTestsByTag(tests []searchTest, tags ...string) []searchTest {
|
||||
filteredTests := []searchTest{}
|
||||
for _, test := range tests {
|
||||
if utils.StringInSlice(ENGINE_ALL, test.Tags) {
|
||||
if utils.StringInSlice(EngineAll, test.Tags) {
|
||||
filteredTests = append(filteredTests, test)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -15,141 +15,141 @@ var searchUserStoreTests = []searchTest{
|
||||
{
|
||||
Name: "Should retrieve all users in a channel if the search term is empty",
|
||||
Fn: testGetAllUsersInChannelWithEmptyTerm,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should honor channel restrictions when autocompleting users",
|
||||
Fn: testHonorChannelRestrictionsAutocompletingUsers,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should honor team restrictions when autocompleting users",
|
||||
Fn: testHonorTeamRestrictionsAutocompletingUsers,
|
||||
Tags: []string{ENGINE_ELASTICSEARCH, ENGINE_BLEVE},
|
||||
Tags: []string{EngineElasticSearch, EngineBleve},
|
||||
},
|
||||
{
|
||||
Name: "Should return nothing if the user can't access the channels of a given search",
|
||||
Fn: testShouldReturnNothingWithoutProperAccess,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
Skip: true,
|
||||
SkipMessage: "Failing when the ListOfAllowedChannels property is empty",
|
||||
},
|
||||
{
|
||||
Name: "Should autocomplete for user using username",
|
||||
Fn: testAutocompleteUserByUsername,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should autocomplete user searching by first name",
|
||||
Fn: testAutocompleteUserByFirstName,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should autocomplete user searching by last name",
|
||||
Fn: testAutocompleteUserByLastName,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should autocomplete for user using nickname",
|
||||
Fn: testAutocompleteUserByNickName,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should autocomplete for user using email",
|
||||
Fn: testAutocompleteUserByEmail,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
Skip: true,
|
||||
SkipMessage: "Failing for multiple different reasons in the engines",
|
||||
},
|
||||
{
|
||||
Name: "Should be able not to match specific queries with mail",
|
||||
Fn: testShouldNotMatchSpecificQueriesEmail,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to autocomplete a user by part of its username splitted by Dot",
|
||||
Fn: testAutocompleteUserByUsernameWithDot,
|
||||
Tags: []string{ENGINE_ELASTICSEARCH, ENGINE_BLEVE},
|
||||
Tags: []string{EngineElasticSearch, EngineBleve},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to autocomplete a user by part of its username splitted by underscore",
|
||||
Fn: testAutocompleteUserByUsernameWithUnderscore,
|
||||
Tags: []string{ENGINE_ELASTICSEARCH, ENGINE_BLEVE},
|
||||
Tags: []string{EngineElasticSearch, EngineBleve},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to autocomplete a user by part of its username splitted by hyphen",
|
||||
Fn: testAutocompleteUserByUsernameWithHyphen,
|
||||
Tags: []string{ENGINE_ELASTICSEARCH, ENGINE_BLEVE},
|
||||
Tags: []string{EngineElasticSearch, EngineBleve},
|
||||
},
|
||||
{
|
||||
Name: "Should escape the percentage character",
|
||||
Fn: testShouldEscapePercentageCharacter,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should escape the dash character",
|
||||
Fn: testShouldEscapeUnderscoreCharacter,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search inactive users",
|
||||
Fn: testShouldBeAbleToSearchInactiveUsers,
|
||||
Tags: []string{ENGINE_MYSQL, ENGINE_POSTGRES, ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EngineMySql, EnginePostgres, EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search filtering by role",
|
||||
Fn: testShouldBeAbleToSearchFilteringByRole,
|
||||
Tags: []string{ENGINE_MYSQL, ENGINE_POSTGRES, ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EngineMySql, EnginePostgres, EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should ignore leading @ when searching users",
|
||||
Fn: testShouldIgnoreLeadingAtSymbols,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should search users in a case insensitive manner",
|
||||
Fn: testSearchUsersShouldBeCaseInsensitive,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should support one or two character usernames and first/last names in search",
|
||||
Fn: testSearchOneTwoCharUsersnameAndFirstLastNames,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should support Korean characters",
|
||||
Fn: testShouldSupportKoreanCharacters,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should support search with a hyphen at the end of the term",
|
||||
Fn: testSearchWithHyphenAtTheEndOfTheTerm,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should support search all users in a team",
|
||||
Fn: testSearchUsersInTeam,
|
||||
Tags: []string{ENGINE_ELASTICSEARCH},
|
||||
Tags: []string{EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should support search users by full name",
|
||||
Fn: testSearchUsersByFullName,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should support search all users in a team with username containing a dot",
|
||||
Fn: testSearchUsersInTeamUsernameWithDot,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should support search all users in a team with username containing a hyphen",
|
||||
Fn: testSearchUsersInTeamUsernameWithHyphen,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should support search all users in a team with username containing a underscore",
|
||||
Fn: testSearchUsersInTeamUsernameWithUnderscore,
|
||||
Tags: []string{ENGINE_ALL},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -23,13 +23,13 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SIZE = model.SESSION_CACHE_SIZE
|
||||
ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_DURATION = 15 * time.Minute // 15 mins
|
||||
AllChannelMembersForUserCacheSize = model.SESSION_CACHE_SIZE
|
||||
AllChannelMembersForUserCacheDuration = 15 * time.Minute // 15 mins
|
||||
|
||||
ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SIZE = model.SESSION_CACHE_SIZE
|
||||
ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_DURATION = 30 * time.Minute // 30 mins
|
||||
AllChannelMembersNotifyPropsForChannelCacheSize = model.SESSION_CACHE_SIZE
|
||||
AllChannelMembersNotifyPropsForChannelCacheDuration = 30 * time.Minute // 30 mins
|
||||
|
||||
CHANNEL_CACHE_DURATION = 15 * time.Minute // 15 mins
|
||||
ChannelCacheDuration = 15 * time.Minute // 15 mins
|
||||
)
|
||||
|
||||
type SqlChannelStore struct {
|
||||
@@ -335,10 +335,10 @@ type publicChannel struct {
|
||||
}
|
||||
|
||||
var allChannelMembersForUserCache = cache.NewLRU(cache.LRUOptions{
|
||||
Size: ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SIZE,
|
||||
Size: AllChannelMembersForUserCacheSize,
|
||||
})
|
||||
var allChannelMembersNotifyPropsForChannelCache = cache.NewLRU(cache.LRUOptions{
|
||||
Size: ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SIZE,
|
||||
Size: AllChannelMembersNotifyPropsForChannelCacheSize,
|
||||
})
|
||||
var channelByNameCache = cache.NewLRU(cache.LRUOptions{
|
||||
Size: model.CHANNEL_CACHE_SIZE,
|
||||
@@ -1266,7 +1266,7 @@ func (s SqlChannelStore) GetByNames(teamId string, names []string, allowFromCach
|
||||
return nil, errors.Wrap(err, msg)
|
||||
}
|
||||
for _, channel := range dbChannels {
|
||||
channelByNameCache.SetWithExpiry(teamId+channel.Name, channel, CHANNEL_CACHE_DURATION)
|
||||
channelByNameCache.SetWithExpiry(teamId+channel.Name, channel, ChannelCacheDuration)
|
||||
channels = append(channels, channel)
|
||||
}
|
||||
// Not all channels are in cache. Increment aggregate miss counter.
|
||||
@@ -1316,7 +1316,7 @@ func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bo
|
||||
return nil, errors.Wrapf(err, "failed to find channel with TeamId=%s and Name=%s", teamId, name)
|
||||
}
|
||||
|
||||
channelByNameCache.SetWithExpiry(teamId+name, &channel, CHANNEL_CACHE_DURATION)
|
||||
channelByNameCache.SetWithExpiry(teamId+name, &channel, ChannelCacheDuration)
|
||||
return &channel, nil
|
||||
}
|
||||
|
||||
@@ -1360,7 +1360,7 @@ func (s SqlChannelStore) GetDeleted(teamId string, offset int, limit int, userId
|
||||
return channels, nil
|
||||
}
|
||||
|
||||
var CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY = `
|
||||
var ChannelMembersWithSchemeSelectQuery = `
|
||||
SELECT
|
||||
ChannelMembers.*,
|
||||
TeamScheme.DefaultChannelGuestRole TeamSchemeDefaultGuestRole,
|
||||
@@ -1586,7 +1586,7 @@ func (s SqlChannelStore) UpdateMultipleMembers(members []*model.ChannelMember) (
|
||||
|
||||
// TODO: Get this out of the transaction when is possible
|
||||
var dbMember channelMemberWithSchemeRoles
|
||||
if err := transaction.SelectOne(&dbMember, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId = :UserId", map[string]interface{}{"ChannelId": member.ChannelId, "UserId": member.UserId}); err != nil {
|
||||
if err := transaction.SelectOne(&dbMember, ChannelMembersWithSchemeSelectQuery+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId = :UserId", map[string]interface{}{"ChannelId": member.ChannelId, "UserId": member.UserId}); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("ChannelMember", fmt.Sprintf("channelId=%s, userId=%s", member.ChannelId, member.UserId))
|
||||
}
|
||||
@@ -1611,7 +1611,7 @@ func (s SqlChannelStore) UpdateMember(member *model.ChannelMember) (*model.Chann
|
||||
|
||||
func (s SqlChannelStore) GetMembers(channelId string, offset, limit int) (*model.ChannelMembers, error) {
|
||||
var dbMembers channelMemberWithSchemeRolesList
|
||||
_, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelId = :ChannelId LIMIT :Limit OFFSET :Offset", map[string]interface{}{"ChannelId": channelId, "Limit": limit, "Offset": offset})
|
||||
_, err := s.GetReplica().Select(&dbMembers, ChannelMembersWithSchemeSelectQuery+"WHERE ChannelId = :ChannelId LIMIT :Limit OFFSET :Offset", map[string]interface{}{"ChannelId": channelId, "Limit": limit, "Offset": offset})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get ChannelMembers with channelId=%s", channelId)
|
||||
}
|
||||
@@ -1641,7 +1641,7 @@ func (s SqlChannelStore) GetChannelMembersTimezones(channelId string) ([]model.S
|
||||
func (s SqlChannelStore) GetMember(channelId string, userId string) (*model.ChannelMember, error) {
|
||||
var dbMember channelMemberWithSchemeRoles
|
||||
|
||||
if err := s.GetReplica().SelectOne(&dbMember, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId = :UserId", map[string]interface{}{"ChannelId": channelId, "UserId": userId}); err != nil {
|
||||
if err := s.GetReplica().SelectOne(&dbMember, ChannelMembersWithSchemeSelectQuery+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId = :UserId", map[string]interface{}{"ChannelId": channelId, "UserId": userId}); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, store.NewErrNotFound("ChannelMember", fmt.Sprintf("channelId=%s, userId=%s", channelId, userId))
|
||||
}
|
||||
@@ -1791,7 +1791,7 @@ func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCac
|
||||
ids := data.ToMapStringString()
|
||||
|
||||
if allowFromCache {
|
||||
allChannelMembersForUserCache.SetWithExpiry(cache_key, ids, ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_DURATION)
|
||||
allChannelMembersForUserCache.SetWithExpiry(cache_key, ids, AllChannelMembersForUserCacheDuration)
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
@@ -1838,7 +1838,7 @@ func (s SqlChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId str
|
||||
props[data[i].UserId] = data[i].NotifyProps
|
||||
}
|
||||
|
||||
allChannelMembersNotifyPropsForChannelCache.SetWithExpiry(channelId, props, ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_DURATION)
|
||||
allChannelMembersNotifyPropsForChannelCache.SetWithExpiry(channelId, props, AllChannelMembersNotifyPropsForChannelCacheDuration)
|
||||
|
||||
return props, nil
|
||||
}
|
||||
@@ -2363,7 +2363,7 @@ func (s SqlChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType st
|
||||
|
||||
func (s SqlChannelStore) GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, error) {
|
||||
var dbMembers channelMemberWithSchemeRolesList
|
||||
_, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.UserId = :UserId AND (Teams.Id = :TeamId OR Teams.Id = '' OR Teams.Id IS NULL)", map[string]interface{}{"TeamId": teamId, "UserId": userId})
|
||||
_, err := s.GetReplica().Select(&dbMembers, ChannelMembersWithSchemeSelectQuery+"WHERE ChannelMembers.UserId = :UserId AND (Teams.Id = :TeamId OR Teams.Id = '' OR Teams.Id IS NULL)", map[string]interface{}{"TeamId": teamId, "UserId": userId})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find ChannelMembers data with teamId=%s and userId=%s", teamId, userId)
|
||||
}
|
||||
@@ -2374,7 +2374,7 @@ func (s SqlChannelStore) GetMembersForUser(teamId string, userId string) (*model
|
||||
func (s SqlChannelStore) GetMembersForUserWithPagination(teamId, userId string, page, perPage int) (*model.ChannelMembers, error) {
|
||||
var dbMembers channelMemberWithSchemeRolesList
|
||||
offset := page * perPage
|
||||
_, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.UserId = :UserId Limit :Limit Offset :Offset", map[string]interface{}{"TeamId": teamId, "UserId": userId, "Limit": perPage, "Offset": offset})
|
||||
_, err := s.GetReplica().Select(&dbMembers, ChannelMembersWithSchemeSelectQuery+"WHERE ChannelMembers.UserId = :UserId Limit :Limit Offset :Offset", map[string]interface{}{"TeamId": teamId, "UserId": userId, "Limit": perPage, "Offset": offset})
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find ChannelMembers data with teamId=%s and userId=%s", teamId, userId)
|
||||
@@ -2959,7 +2959,7 @@ func (s SqlChannelStore) GetMembersByIds(channelId string, userIds []string) (*m
|
||||
keys, props := MapStringsToQueryParams(userIds, "User")
|
||||
props["ChannelId"] = channelId
|
||||
|
||||
if _, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId IN "+keys, props); err != nil {
|
||||
if _, err := s.GetReplica().Select(&dbMembers, ChannelMembersWithSchemeSelectQuery+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId IN "+keys, props); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find ChannelMembers with channelId=%s and userId in %v", channelId, userIds)
|
||||
}
|
||||
|
||||
@@ -2972,7 +2972,7 @@ func (s SqlChannelStore) GetMembersByChannelIds(channelIds []string, userId stri
|
||||
keys, props := MapStringsToQueryParams(channelIds, "Channel")
|
||||
props["UserId"] = userId
|
||||
|
||||
if _, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.UserId = :UserId AND ChannelMembers.ChannelId IN "+keys, props); err != nil {
|
||||
if _, err := s.GetReplica().Select(&dbMembers, ChannelMembersWithSchemeSelectQuery+"WHERE ChannelMembers.UserId = :UserId AND ChannelMembers.ChannelId IN "+keys, props); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find ChannelMembers with userId=%s and channelId in %v", userId, channelIds)
|
||||
}
|
||||
|
||||
|
||||
@@ -1378,8 +1378,8 @@ func (s *SqlPostStore) search(teamId string, userId string, params *model.Search
|
||||
}
|
||||
|
||||
func removeMysqlStopWordsFromTerms(terms string) (string, error) {
|
||||
stopWords := make([]string, len(searchlayer.MYSQL_STOP_WORDS))
|
||||
copy(stopWords, searchlayer.MYSQL_STOP_WORDS)
|
||||
stopWords := make([]string, len(searchlayer.MySQLStopWords))
|
||||
copy(stopWords, searchlayer.MySQLStopWords)
|
||||
re, err := regexp.Compile(fmt.Sprintf(`^(%s)$`, strings.Join(stopWords, "|")))
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -46,7 +46,7 @@ func (s SqlPreferenceStore) deleteUnusedFeatures() {
|
||||
WHERE
|
||||
Category = :Category
|
||||
AND Value = :Value
|
||||
AND Name LIKE '` + store.FEATURE_TOGGLE_PREFIX + `%'`
|
||||
AND Name LIKE '` + store.FeatureTogglePrefix + `%'`
|
||||
|
||||
queryParams := map[string]string{
|
||||
"Category": model.PREFERENCE_CATEGORY_ADVANCED_SETTINGS,
|
||||
|
||||
@@ -29,25 +29,25 @@ func TestDeleteUnusedFeatures(t *testing.T) {
|
||||
{
|
||||
UserId: userId1,
|
||||
Category: category,
|
||||
Name: store.FEATURE_TOGGLE_PREFIX + feature1,
|
||||
Name: store.FeatureTogglePrefix + feature1,
|
||||
Value: "true",
|
||||
},
|
||||
{
|
||||
UserId: userId2,
|
||||
Category: category,
|
||||
Name: store.FEATURE_TOGGLE_PREFIX + feature1,
|
||||
Name: store.FeatureTogglePrefix + feature1,
|
||||
Value: "false",
|
||||
},
|
||||
{
|
||||
UserId: userId1,
|
||||
Category: category,
|
||||
Name: store.FEATURE_TOGGLE_PREFIX + feature2,
|
||||
Name: store.FeatureTogglePrefix + feature2,
|
||||
Value: "false",
|
||||
},
|
||||
{
|
||||
UserId: userId2,
|
||||
Category: category,
|
||||
Name: store.FEATURE_TOGGLE_PREFIX + feature2,
|
||||
Name: store.FeatureTogglePrefix + feature2,
|
||||
Value: "true",
|
||||
},
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func TestDeleteUnusedFeatures(t *testing.T) {
|
||||
FROM Preferences
|
||||
WHERE Category = :Category
|
||||
AND Value = :Val
|
||||
AND Name LIKE '`+store.FEATURE_TOGGLE_PREFIX+`%'`, map[string]interface{}{"Category": model.PREFERENCE_CATEGORY_ADVANCED_SETTINGS, "Val": "false"}); err != nil {
|
||||
AND Name LIKE '`+store.FeatureTogglePrefix+`%'`, map[string]interface{}{"Category": model.PREFERENCE_CATEGORY_ADVANCED_SETTINGS, "Val": "false"}); err != nil {
|
||||
require.Nil(t, err)
|
||||
} else if val != 0 {
|
||||
require.Fail(t, "Found %d features with value 'false', expected all to be deleted", val)
|
||||
@@ -73,7 +73,7 @@ func TestDeleteUnusedFeatures(t *testing.T) {
|
||||
FROM Preferences
|
||||
WHERE Category = :Category
|
||||
AND Value = :Val
|
||||
AND Name LIKE '`+store.FEATURE_TOGGLE_PREFIX+`%'`, map[string]interface{}{"Category": model.PREFERENCE_CATEGORY_ADVANCED_SETTINGS, "Val": "true"}); err != nil {
|
||||
AND Name LIKE '`+store.FeatureTogglePrefix+`%'`, map[string]interface{}{"Category": model.PREFERENCE_CATEGORY_ADVANCED_SETTINGS, "Val": "true"}); err != nil {
|
||||
require.Nil(t, err)
|
||||
} else if val == 0 {
|
||||
require.Fail(t, "Found %d features with value 'true', expected to find at least %d features", val, 2)
|
||||
|
||||
@@ -132,7 +132,7 @@ func (s *SqlReactionStore) DeleteAllWithEmojiName(emojiName string) error {
|
||||
|
||||
for _, reaction := range reactions {
|
||||
reaction := reaction
|
||||
_, err := s.GetMaster().Exec(UPDATE_POST_HAS_REACTIONS_ON_DELETE_QUERY,
|
||||
_, err := s.GetMaster().Exec(UpdatePostHasReactionsOnDeleteQuery,
|
||||
map[string]interface{}{
|
||||
"PostId": reaction.PostId,
|
||||
"UpdateAt": model.GetMillis(),
|
||||
@@ -191,7 +191,7 @@ func deleteReactionAndUpdatePost(transaction *gorp.Transaction, reaction *model.
|
||||
}
|
||||
|
||||
const (
|
||||
UPDATE_POST_HAS_REACTIONS_ON_DELETE_QUERY = `UPDATE
|
||||
UpdatePostHasReactionsOnDeleteQuery = `UPDATE
|
||||
Posts
|
||||
SET
|
||||
UpdateAt = :UpdateAt,
|
||||
@@ -202,7 +202,7 @@ const (
|
||||
|
||||
func updatePostForReactionsOnDelete(transaction *gorp.Transaction, postId string) error {
|
||||
updateAt := model.GetMillis()
|
||||
_, err := transaction.Exec(UPDATE_POST_HAS_REACTIONS_ON_DELETE_QUERY, map[string]interface{}{"PostId": postId, "UpdateAt": updateAt})
|
||||
_, err := transaction.Exec(UpdatePostHasReactionsOnDeleteQuery, map[string]interface{}{"PostId": postId, "UpdateAt": updateAt})
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
SESSIONS_CLEANUP_DELAY_MILLISECONDS = 100
|
||||
SessionsCleanupDelayMilliseconds = 100
|
||||
)
|
||||
|
||||
type SqlSessionStore struct {
|
||||
@@ -304,6 +304,6 @@ func (me SqlSessionStore) Cleanup(expiryTime int64, batchSize int64) {
|
||||
return
|
||||
}
|
||||
|
||||
time.Sleep(SESSIONS_CLEANUP_DELAY_MILLISECONDS * time.Millisecond)
|
||||
time.Sleep(SessionsCleanupDelayMilliseconds * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,52 +33,52 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
INDEX_TYPE_FULL_TEXT = "full_text"
|
||||
INDEX_TYPE_DEFAULT = "default"
|
||||
PG_DUP_TABLE_ERROR_CODE = "42P07" // see https://github.com/lib/pq/blob/master/error.go#L268
|
||||
MYSQL_DUP_TABLE_ERROR_CODE = uint16(1050) // see https://dev.mysql.com/doc/mysql-errors/5.7/en/server-error-reference.html#error_er_table_exists_error
|
||||
DB_PING_ATTEMPTS = 18
|
||||
DB_PING_TIMEOUT_SECS = 10
|
||||
IndexTypeFullText = "full_text"
|
||||
IndexTypeDefault = "default"
|
||||
PGDupTableErrorCode = "42P07" // see https://github.com/lib/pq/blob/master/error.go#L268
|
||||
MySQLDupTableErrorCode = uint16(1050) // see https://dev.mysql.com/doc/mysql-errors/5.7/en/server-error-reference.html#error_er_table_exists_error
|
||||
DBPingAttempts = 18
|
||||
DBPingTimeoutSecs = 10
|
||||
// This is a numerical version string by postgres. The format is
|
||||
// 2 characters for major, minor, and patch version prior to 10.
|
||||
// After 10, it's major and minor only.
|
||||
// 10.1 would be 100001.
|
||||
// 9.6.3 would be 90603.
|
||||
MINIMUM_REQUIRED_POSTGRES_VERSION = 100000
|
||||
MinimumRequiredPostgresVersion = 100000
|
||||
)
|
||||
|
||||
const (
|
||||
EXIT_GENERIC_FAILURE = 1
|
||||
EXIT_CREATE_TABLE = 100
|
||||
EXIT_DB_OPEN = 101
|
||||
EXIT_PING = 102
|
||||
EXIT_NO_DRIVER = 103
|
||||
EXIT_TABLE_EXISTS = 104
|
||||
EXIT_TABLE_EXISTS_MYSQL = 105
|
||||
EXIT_COLUMN_EXISTS = 106
|
||||
EXIT_DOES_COLUMN_EXISTS_POSTGRES = 107
|
||||
EXIT_DOES_COLUMN_EXISTS_MYSQL = 108
|
||||
EXIT_DOES_COLUMN_EXISTS_MISSING = 109
|
||||
EXIT_CREATE_COLUMN_POSTGRES = 110
|
||||
EXIT_CREATE_COLUMN_MYSQL = 111
|
||||
EXIT_CREATE_COLUMN_MISSING = 112
|
||||
EXIT_REMOVE_COLUMN = 113
|
||||
EXIT_RENAME_COLUMN = 114
|
||||
EXIT_MAX_COLUMN = 115
|
||||
EXIT_ALTER_COLUMN = 116
|
||||
EXIT_CREATE_INDEX_POSTGRES = 117
|
||||
EXIT_CREATE_INDEX_MYSQL = 118
|
||||
EXIT_CREATE_INDEX_FULL_MYSQL = 119
|
||||
EXIT_CREATE_INDEX_MISSING = 120
|
||||
EXIT_REMOVE_INDEX_POSTGRES = 121
|
||||
EXIT_REMOVE_INDEX_MYSQL = 122
|
||||
EXIT_REMOVE_INDEX_MISSING = 123
|
||||
EXIT_REMOVE_TABLE = 134
|
||||
EXIT_CREATE_INDEX_SQLITE = 135
|
||||
EXIT_REMOVE_INDEX_SQLITE = 136
|
||||
EXIT_TABLE_EXISTS_SQLITE = 137
|
||||
EXIT_DOES_COLUMN_EXISTS_SQLITE = 138
|
||||
EXIT_ALTER_PRIMARY_KEY = 139
|
||||
ExitGenericFailure = 1
|
||||
ExitCreateTable = 100
|
||||
ExitDBOpen = 101
|
||||
ExitPing = 102
|
||||
ExitNoDriver = 103
|
||||
ExitTableExists = 104
|
||||
ExitTableExistsMySQL = 105
|
||||
ExitColumnExists = 106
|
||||
ExitDoesColumnExistsPostgres = 107
|
||||
ExitDoesColumnExistsMySQL = 108
|
||||
ExitDoesColumnExistsMissing = 109
|
||||
ExitCreateColumnPostgres = 110
|
||||
ExitCreateColumnMySQL = 111
|
||||
ExitCreateColumnMissing = 112
|
||||
ExitRemoveColumn = 113
|
||||
ExitRenameColumn = 114
|
||||
ExitMaxColumn = 115
|
||||
ExitAlterColumn = 116
|
||||
ExitCreateIndexPostgres = 117
|
||||
ExitCreateIndexMySQL = 118
|
||||
ExitCreateIndexFullMySQL = 119
|
||||
ExitCreateIndexMissing = 120
|
||||
ExitRemoveIndexPostgres = 121
|
||||
ExitRemoveIndexMySQL = 122
|
||||
ExitRemoveIndexMissing = 123
|
||||
ExitRemoveTable = 134
|
||||
ExitCreateIndexSqlite = 135
|
||||
ExitRemoveIndexSqlite = 136
|
||||
ExitTableExists_SQLITE = 137
|
||||
ExitDoesColumnExistsSqlite = 138
|
||||
ExitAlterPrimaryKey = 139
|
||||
)
|
||||
|
||||
type SqlStoreStores struct {
|
||||
@@ -193,7 +193,7 @@ func New(settings model.SqlSettings, metrics einterfaces.MetricsInterface) *SqlS
|
||||
mlog.Warn("Duplicate key error occurred; assuming table already created and proceeding.", mlog.Err(err))
|
||||
} else {
|
||||
mlog.Critical("Error creating database tables.", mlog.Err(err))
|
||||
os.Exit(EXIT_CREATE_TABLE)
|
||||
os.Exit(ExitCreateTable)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ func New(settings model.SqlSettings, metrics einterfaces.MetricsInterface) *SqlS
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to upgrade database.", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
os.Exit(ExitGenericFailure)
|
||||
}
|
||||
|
||||
store.stores.team.(*SqlTeamStore).createIndexesIfNotExists()
|
||||
@@ -244,24 +244,24 @@ func setupConnection(con_type string, dataSource string, settings *model.SqlSett
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to open SQL connection to err.", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_DB_OPEN)
|
||||
os.Exit(ExitDBOpen)
|
||||
}
|
||||
|
||||
for i := 0; i < DB_PING_ATTEMPTS; i++ {
|
||||
for i := 0; i < DBPingAttempts; i++ {
|
||||
mlog.Info("Pinging SQL", mlog.String("database", con_type))
|
||||
ctx, cancel := context.WithTimeout(context.Background(), DB_PING_TIMEOUT_SECS*time.Second)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), DBPingTimeoutSecs*time.Second)
|
||||
defer cancel()
|
||||
err = db.PingContext(ctx)
|
||||
if err == nil {
|
||||
break
|
||||
} else {
|
||||
if i == DB_PING_ATTEMPTS-1 {
|
||||
if i == DBPingAttempts-1 {
|
||||
mlog.Critical("Failed to ping DB, server will exit.", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_PING)
|
||||
os.Exit(ExitPing)
|
||||
} else {
|
||||
mlog.Error("Failed to ping DB", mlog.Err(err), mlog.Int("retrying in seconds", DB_PING_TIMEOUT_SECS))
|
||||
time.Sleep(DB_PING_TIMEOUT_SECS * time.Second)
|
||||
mlog.Error("Failed to ping DB", mlog.Err(err), mlog.Int("retrying in seconds", DBPingTimeoutSecs))
|
||||
time.Sleep(DBPingTimeoutSecs * time.Second)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -283,7 +283,7 @@ func setupConnection(con_type string, dataSource string, settings *model.SqlSett
|
||||
} else {
|
||||
mlog.Critical("Failed to create dialect specific driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_NO_DRIVER)
|
||||
os.Exit(ExitNoDriver)
|
||||
}
|
||||
|
||||
if settings.Trace != nil && *settings.Trace {
|
||||
@@ -441,7 +441,7 @@ func (ss *SqlStore) DoesTableExist(tableName string) bool {
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to check if table exists", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_TABLE_EXISTS)
|
||||
os.Exit(ExitTableExists)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
@@ -463,7 +463,7 @@ func (ss *SqlStore) DoesTableExist(tableName string) bool {
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to check if table exists", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_TABLE_EXISTS_MYSQL)
|
||||
os.Exit(ExitTableExistsMySQL)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
@@ -477,7 +477,7 @@ func (ss *SqlStore) DoesTableExist(tableName string) bool {
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to check if table exists", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_TABLE_EXISTS_SQLITE)
|
||||
os.Exit(ExitTableExists_SQLITE)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
@@ -485,7 +485,7 @@ func (ss *SqlStore) DoesTableExist(tableName string) bool {
|
||||
} else {
|
||||
mlog.Critical("Failed to check if column exists because of missing driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_COLUMN_EXISTS)
|
||||
os.Exit(ExitColumnExists)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -509,7 +509,7 @@ func (ss *SqlStore) DoesColumnExist(tableName string, columnName string) bool {
|
||||
|
||||
mlog.Critical("Failed to check if column exists", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_DOES_COLUMN_EXISTS_POSTGRES)
|
||||
os.Exit(ExitDoesColumnExistsPostgres)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
@@ -532,7 +532,7 @@ func (ss *SqlStore) DoesColumnExist(tableName string, columnName string) bool {
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to check if column exists", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_DOES_COLUMN_EXISTS_MYSQL)
|
||||
os.Exit(ExitDoesColumnExistsMySQL)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
@@ -547,7 +547,7 @@ func (ss *SqlStore) DoesColumnExist(tableName string, columnName string) bool {
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to check if column exists", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_DOES_COLUMN_EXISTS_SQLITE)
|
||||
os.Exit(ExitDoesColumnExistsSqlite)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
@@ -555,7 +555,7 @@ func (ss *SqlStore) DoesColumnExist(tableName string, columnName string) bool {
|
||||
} else {
|
||||
mlog.Critical("Failed to check if column exists because of missing driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_DOES_COLUMN_EXISTS_MISSING)
|
||||
os.Exit(ExitDoesColumnExistsMissing)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -574,7 +574,7 @@ func (ss *SqlStore) DoesTriggerExist(triggerName string) bool {
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to check if trigger exists", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
os.Exit(ExitGenericFailure)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
@@ -593,7 +593,7 @@ func (ss *SqlStore) DoesTriggerExist(triggerName string) bool {
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to check if trigger exists", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
os.Exit(ExitGenericFailure)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
@@ -601,7 +601,7 @@ func (ss *SqlStore) DoesTriggerExist(triggerName string) bool {
|
||||
} else {
|
||||
mlog.Critical("Failed to check if column exists because of missing driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
os.Exit(ExitGenericFailure)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -617,7 +617,7 @@ func (ss *SqlStore) CreateColumnIfNotExists(tableName string, columnName string,
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to create column", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_COLUMN_POSTGRES)
|
||||
os.Exit(ExitCreateColumnPostgres)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -627,7 +627,7 @@ func (ss *SqlStore) CreateColumnIfNotExists(tableName string, columnName string,
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to create column", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_COLUMN_MYSQL)
|
||||
os.Exit(ExitCreateColumnMySQL)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -635,7 +635,7 @@ func (ss *SqlStore) CreateColumnIfNotExists(tableName string, columnName string,
|
||||
} else {
|
||||
mlog.Critical("Failed to create column because of missing driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_COLUMN_MISSING)
|
||||
os.Exit(ExitCreateColumnMissing)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -651,7 +651,7 @@ func (ss *SqlStore) CreateColumnIfNotExistsNoDefault(tableName string, columnNam
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to create column", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_COLUMN_POSTGRES)
|
||||
os.Exit(ExitCreateColumnPostgres)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -661,7 +661,7 @@ func (ss *SqlStore) CreateColumnIfNotExistsNoDefault(tableName string, columnNam
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to create column", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_COLUMN_MYSQL)
|
||||
os.Exit(ExitCreateColumnMySQL)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -669,7 +669,7 @@ func (ss *SqlStore) CreateColumnIfNotExistsNoDefault(tableName string, columnNam
|
||||
} else {
|
||||
mlog.Critical("Failed to create column because of missing driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_COLUMN_MISSING)
|
||||
os.Exit(ExitCreateColumnMissing)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -684,7 +684,7 @@ func (ss *SqlStore) RemoveColumnIfExists(tableName string, columnName string) bo
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to drop column", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_REMOVE_COLUMN)
|
||||
os.Exit(ExitRemoveColumn)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -699,7 +699,7 @@ func (ss *SqlStore) RemoveTableIfExists(tableName string) bool {
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to drop table", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_REMOVE_TABLE)
|
||||
os.Exit(ExitRemoveTable)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -720,7 +720,7 @@ func (ss *SqlStore) RenameColumnIfExists(tableName string, oldColumnName string,
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to rename column", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_RENAME_COLUMN)
|
||||
os.Exit(ExitRenameColumn)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -742,7 +742,7 @@ func (ss *SqlStore) GetMaxLengthOfColumnIfExists(tableName string, columnName st
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to get max length of column", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_MAX_COLUMN)
|
||||
os.Exit(ExitMaxColumn)
|
||||
}
|
||||
|
||||
return result
|
||||
@@ -763,7 +763,7 @@ func (ss *SqlStore) AlterColumnTypeIfExists(tableName string, columnName string,
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to alter column type", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_ALTER_COLUMN)
|
||||
os.Exit(ExitAlterColumn)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -798,7 +798,7 @@ func (ss *SqlStore) AlterColumnDefaultIfExists(tableName string, columnName stri
|
||||
} else {
|
||||
mlog.Critical("Failed to alter column default because of missing driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
os.Exit(ExitGenericFailure)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -812,7 +812,7 @@ func (ss *SqlStore) AlterColumnDefaultIfExists(tableName string, columnName stri
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to alter column", mlog.String("table", tableName), mlog.String("column", columnName), mlog.String("default value", defaultValue), mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
os.Exit(ExitGenericFailure)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -857,7 +857,7 @@ func (ss *SqlStore) AlterPrimaryKey(tableName string, columnNames []string) bool
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to get current primary key", mlog.String("table", tableName), mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_ALTER_PRIMARY_KEY)
|
||||
os.Exit(ExitAlterPrimaryKey)
|
||||
}
|
||||
|
||||
primaryKey := strings.Join(columnNames, ",")
|
||||
@@ -875,29 +875,29 @@ func (ss *SqlStore) AlterPrimaryKey(tableName string, columnNames []string) bool
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to alter primary key", mlog.String("table", tableName), mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_ALTER_PRIMARY_KEY)
|
||||
os.Exit(ExitAlterPrimaryKey)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (ss *SqlStore) CreateUniqueIndexIfNotExists(indexName string, tableName string, columnName string) bool {
|
||||
return ss.createIndexIfNotExists(indexName, tableName, []string{columnName}, INDEX_TYPE_DEFAULT, true)
|
||||
return ss.createIndexIfNotExists(indexName, tableName, []string{columnName}, IndexTypeDefault, true)
|
||||
}
|
||||
|
||||
func (ss *SqlStore) CreateIndexIfNotExists(indexName string, tableName string, columnName string) bool {
|
||||
return ss.createIndexIfNotExists(indexName, tableName, []string{columnName}, INDEX_TYPE_DEFAULT, false)
|
||||
return ss.createIndexIfNotExists(indexName, tableName, []string{columnName}, IndexTypeDefault, false)
|
||||
}
|
||||
|
||||
func (ss *SqlStore) CreateCompositeIndexIfNotExists(indexName string, tableName string, columnNames []string) bool {
|
||||
return ss.createIndexIfNotExists(indexName, tableName, columnNames, INDEX_TYPE_DEFAULT, false)
|
||||
return ss.createIndexIfNotExists(indexName, tableName, columnNames, IndexTypeDefault, false)
|
||||
}
|
||||
|
||||
func (ss *SqlStore) CreateUniqueCompositeIndexIfNotExists(indexName string, tableName string, columnNames []string) bool {
|
||||
return ss.createIndexIfNotExists(indexName, tableName, columnNames, INDEX_TYPE_DEFAULT, true)
|
||||
return ss.createIndexIfNotExists(indexName, tableName, columnNames, IndexTypeDefault, true)
|
||||
}
|
||||
|
||||
func (ss *SqlStore) CreateFullTextIndexIfNotExists(indexName string, tableName string, columnName string) bool {
|
||||
return ss.createIndexIfNotExists(indexName, tableName, []string{columnName}, INDEX_TYPE_FULL_TEXT, false)
|
||||
return ss.createIndexIfNotExists(indexName, tableName, []string{columnName}, IndexTypeFullText, false)
|
||||
}
|
||||
|
||||
func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, columnNames []string, indexType string, unique bool) bool {
|
||||
@@ -915,10 +915,10 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c
|
||||
}
|
||||
|
||||
query := ""
|
||||
if indexType == INDEX_TYPE_FULL_TEXT {
|
||||
if indexType == IndexTypeFullText {
|
||||
if len(columnNames) != 1 {
|
||||
mlog.Critical("Unable to create multi column full text index")
|
||||
os.Exit(EXIT_CREATE_INDEX_POSTGRES)
|
||||
os.Exit(ExitCreateIndexPostgres)
|
||||
}
|
||||
columnName := columnNames[0]
|
||||
postgresColumnNames := convertMySQLFullTextColumnsToPostgres(columnName)
|
||||
@@ -931,7 +931,7 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to create index", mlog.Err(errExists), mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_INDEX_POSTGRES)
|
||||
os.Exit(ExitCreateIndexPostgres)
|
||||
}
|
||||
} else if ss.DriverName() == model.DATABASE_DRIVER_MYSQL {
|
||||
|
||||
@@ -939,7 +939,7 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to check index", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_INDEX_MYSQL)
|
||||
os.Exit(ExitCreateIndexMySQL)
|
||||
}
|
||||
|
||||
if count > 0 {
|
||||
@@ -947,7 +947,7 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c
|
||||
}
|
||||
|
||||
fullTextIndex := ""
|
||||
if indexType == INDEX_TYPE_FULL_TEXT {
|
||||
if indexType == IndexTypeFullText {
|
||||
fullTextIndex = " FULLTEXT "
|
||||
}
|
||||
|
||||
@@ -955,19 +955,19 @@ func (ss *SqlStore) createIndexIfNotExists(indexName string, tableName string, c
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to create index", mlog.String("table", tableName), mlog.String("index_name", indexName), mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_INDEX_FULL_MYSQL)
|
||||
os.Exit(ExitCreateIndexFullMySQL)
|
||||
}
|
||||
} else if ss.DriverName() == model.DATABASE_DRIVER_SQLITE {
|
||||
_, err := ss.GetMaster().ExecNoTimeout("CREATE INDEX IF NOT EXISTS " + indexName + " ON " + tableName + " (" + strings.Join(columnNames, ", ") + ")")
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to create index", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_INDEX_SQLITE)
|
||||
os.Exit(ExitCreateIndexSqlite)
|
||||
}
|
||||
} else {
|
||||
mlog.Critical("Failed to create index because of missing driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_CREATE_INDEX_MISSING)
|
||||
os.Exit(ExitCreateIndexMissing)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -986,7 +986,7 @@ func (ss *SqlStore) RemoveIndexIfExists(indexName string, tableName string) bool
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to remove index", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_REMOVE_INDEX_POSTGRES)
|
||||
os.Exit(ExitRemoveIndexPostgres)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -996,7 +996,7 @@ func (ss *SqlStore) RemoveIndexIfExists(indexName string, tableName string) bool
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to check index", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_REMOVE_INDEX_MYSQL)
|
||||
os.Exit(ExitRemoveIndexMySQL)
|
||||
}
|
||||
|
||||
if count <= 0 {
|
||||
@@ -1007,19 +1007,19 @@ func (ss *SqlStore) RemoveIndexIfExists(indexName string, tableName string) bool
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to remove index", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_REMOVE_INDEX_MYSQL)
|
||||
os.Exit(ExitRemoveIndexMySQL)
|
||||
}
|
||||
} else if ss.DriverName() == model.DATABASE_DRIVER_SQLITE {
|
||||
_, err := ss.GetMaster().ExecNoTimeout("DROP INDEX IF EXISTS " + indexName)
|
||||
if err != nil {
|
||||
mlog.Critical("Failed to remove index", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_REMOVE_INDEX_SQLITE)
|
||||
os.Exit(ExitRemoveIndexSqlite)
|
||||
}
|
||||
} else {
|
||||
mlog.Critical("Failed to create index because of missing driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_REMOVE_INDEX_MISSING)
|
||||
os.Exit(ExitRemoveIndexMissing)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -1350,11 +1350,11 @@ func IsDuplicate(err error) bool {
|
||||
var mysqlErr *mysql.MySQLError
|
||||
switch {
|
||||
case errors.As(errors.Cause(err), &pqErr):
|
||||
if pqErr.Code == PG_DUP_TABLE_ERROR_CODE {
|
||||
if pqErr.Code == PGDupTableErrorCode {
|
||||
return true
|
||||
}
|
||||
case errors.As(errors.Cause(err), &mysqlErr):
|
||||
if mysqlErr.Number == MYSQL_DUP_TABLE_ERROR_CODE {
|
||||
if mysqlErr.Number == MySQLDupTableErrorCode {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,11 +456,11 @@ func TestGetAllConns(t *testing.T) {
|
||||
|
||||
func TestIsDuplicate(t *testing.T) {
|
||||
testErrors := map[error]bool{
|
||||
&pq.Error{Code: "42P06"}: false,
|
||||
&pq.Error{Code: PG_DUP_TABLE_ERROR_CODE}: true,
|
||||
&mysql.MySQLError{Number: uint16(1000)}: false,
|
||||
&mysql.MySQLError{Number: MYSQL_DUP_TABLE_ERROR_CODE}: true,
|
||||
errors.New("Random error"): false,
|
||||
&pq.Error{Code: "42P06"}: false,
|
||||
&pq.Error{Code: PGDupTableErrorCode}: true,
|
||||
&mysql.MySQLError{Number: uint16(1000)}: false,
|
||||
&mysql.MySQLError{Number: MySQLDupTableErrorCode}: true,
|
||||
errors.New("Random error"): false,
|
||||
}
|
||||
|
||||
for err, expected := range testErrors {
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
TEAM_MEMBER_EXISTS_ERROR = "store.sql_team.save_member.exists.app_error"
|
||||
TeamMemberExistsError = "store.sql_team.save_member.exists.app_error"
|
||||
)
|
||||
|
||||
type SqlTeamStore struct {
|
||||
|
||||
@@ -19,73 +19,73 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
CURRENT_SCHEMA_VERSION = VERSION_5_31_0
|
||||
VERSION_5_32_0 = "5.32.0"
|
||||
VERSION_5_31_0 = "5.31.0"
|
||||
VERSION_5_30_0 = "5.30.0"
|
||||
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"
|
||||
VERSION_5_26_0 = "5.26.0"
|
||||
VERSION_5_25_0 = "5.25.0"
|
||||
VERSION_5_24_0 = "5.24.0"
|
||||
VERSION_5_23_0 = "5.23.0"
|
||||
VERSION_5_22_0 = "5.22.0"
|
||||
VERSION_5_21_0 = "5.21.0"
|
||||
VERSION_5_20_0 = "5.20.0"
|
||||
VERSION_5_19_0 = "5.19.0"
|
||||
VERSION_5_18_0 = "5.18.0"
|
||||
VERSION_5_17_0 = "5.17.0"
|
||||
VERSION_5_16_0 = "5.16.0"
|
||||
VERSION_5_15_0 = "5.15.0"
|
||||
VERSION_5_14_0 = "5.14.0"
|
||||
VERSION_5_13_0 = "5.13.0"
|
||||
VERSION_5_12_0 = "5.12.0"
|
||||
VERSION_5_11_0 = "5.11.0"
|
||||
VERSION_5_10_0 = "5.10.0"
|
||||
VERSION_5_9_0 = "5.9.0"
|
||||
VERSION_5_8_0 = "5.8.0"
|
||||
VERSION_5_7_0 = "5.7.0"
|
||||
VERSION_5_6_0 = "5.6.0"
|
||||
VERSION_5_5_0 = "5.5.0"
|
||||
VERSION_5_4_0 = "5.4.0"
|
||||
VERSION_5_3_0 = "5.3.0"
|
||||
VERSION_5_2_0 = "5.2.0"
|
||||
VERSION_5_1_0 = "5.1.0"
|
||||
VERSION_5_0_0 = "5.0.0"
|
||||
VERSION_4_10_0 = "4.10.0"
|
||||
VERSION_4_9_0 = "4.9.0"
|
||||
VERSION_4_8_1 = "4.8.1"
|
||||
VERSION_4_8_0 = "4.8.0"
|
||||
VERSION_4_7_2 = "4.7.2"
|
||||
VERSION_4_7_1 = "4.7.1"
|
||||
VERSION_4_7_0 = "4.7.0"
|
||||
VERSION_4_6_0 = "4.6.0"
|
||||
VERSION_4_5_0 = "4.5.0"
|
||||
VERSION_4_4_0 = "4.4.0"
|
||||
VERSION_4_3_0 = "4.3.0"
|
||||
VERSION_4_2_0 = "4.2.0"
|
||||
VERSION_4_1_0 = "4.1.0"
|
||||
VERSION_4_0_0 = "4.0.0"
|
||||
VERSION_3_10_0 = "3.10.0"
|
||||
VERSION_3_9_0 = "3.9.0"
|
||||
VERSION_3_8_0 = "3.8.0"
|
||||
VERSION_3_7_0 = "3.7.0"
|
||||
VERSION_3_6_0 = "3.6.0"
|
||||
VERSION_3_5_0 = "3.5.0"
|
||||
VERSION_3_4_0 = "3.4.0"
|
||||
VERSION_3_3_0 = "3.3.0"
|
||||
VERSION_3_2_0 = "3.2.0"
|
||||
VERSION_3_1_0 = "3.1.0"
|
||||
VERSION_3_0_0 = "3.0.0"
|
||||
OLDEST_SUPPORTED_VERSION = VERSION_3_0_0
|
||||
CurrentSchemaVersion = Version5310
|
||||
Version5320 = "5.32.0"
|
||||
Version5310 = "5.31.0"
|
||||
Version5300 = "5.30.0"
|
||||
Version5290 = "5.29.0"
|
||||
Version5281 = "5.28.1"
|
||||
Version5280 = "5.28.0"
|
||||
Version5270 = "5.27.0"
|
||||
Version5260 = "5.26.0"
|
||||
Version5250 = "5.25.0"
|
||||
Version5240 = "5.24.0"
|
||||
Version5230 = "5.23.0"
|
||||
Version5220 = "5.22.0"
|
||||
Version5210 = "5.21.0"
|
||||
Version5200 = "5.20.0"
|
||||
Version5190 = "5.19.0"
|
||||
Version5180 = "5.18.0"
|
||||
Version5170 = "5.17.0"
|
||||
Version5160 = "5.16.0"
|
||||
Version5150 = "5.15.0"
|
||||
Version5140 = "5.14.0"
|
||||
Version5130 = "5.13.0"
|
||||
Version5120 = "5.12.0"
|
||||
Version5110 = "5.11.0"
|
||||
Version5100 = "5.10.0"
|
||||
Version590 = "5.9.0"
|
||||
Version580 = "5.8.0"
|
||||
Version570 = "5.7.0"
|
||||
Version560 = "5.6.0"
|
||||
Version550 = "5.5.0"
|
||||
Version540 = "5.4.0"
|
||||
Version530 = "5.3.0"
|
||||
Version520 = "5.2.0"
|
||||
Version510 = "5.1.0"
|
||||
Version500 = "5.0.0"
|
||||
Version4100 = "4.10.0"
|
||||
Version490 = "4.9.0"
|
||||
Version481 = "4.8.1"
|
||||
Version480 = "4.8.0"
|
||||
Version472 = "4.7.2"
|
||||
Version471 = "4.7.1"
|
||||
Version470 = "4.7.0"
|
||||
Version460 = "4.6.0"
|
||||
Version450 = "4.5.0"
|
||||
Version440 = "4.4.0"
|
||||
Version430 = "4.3.0"
|
||||
Version420 = "4.2.0"
|
||||
Version410 = "4.1.0"
|
||||
Version400 = "4.0.0"
|
||||
Version3100 = "3.10.0"
|
||||
Version390 = "3.9.0"
|
||||
Version380 = "3.8.0"
|
||||
Version370 = "3.7.0"
|
||||
Version360 = "3.6.0"
|
||||
Version350 = "3.5.0"
|
||||
Version340 = "3.4.0"
|
||||
Version330 = "3.3.0"
|
||||
Version320 = "3.2.0"
|
||||
Version310 = "3.1.0"
|
||||
Version300 = "3.0.0"
|
||||
OldestSupportedVersion = Version300
|
||||
)
|
||||
|
||||
const (
|
||||
EXIT_VERSION_SAVE = 1003
|
||||
EXIT_THEME_MIGRATION = 1004
|
||||
EXIT_TEAM_INVITEID_MIGRATION_FAILED = 1006
|
||||
ExitVersionSave = 1003
|
||||
ExitThemeMigration = 1004
|
||||
ExitTeamInviteIDMigrationFailed = 1006
|
||||
)
|
||||
|
||||
// upgradeDatabase attempts to migrate the schema to the latest supported version.
|
||||
@@ -101,9 +101,9 @@ func upgradeDatabase(sqlStore *SqlStore, currentModelVersionString string) error
|
||||
Major: currentModelVersion.Major + 1,
|
||||
}
|
||||
|
||||
oldestSupportedVersion, err := semver.Parse(OLDEST_SUPPORTED_VERSION)
|
||||
oldestSupportedVersion, err := semver.Parse(OldestSupportedVersion)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to parse oldest supported version %s", OLDEST_SUPPORTED_VERSION)
|
||||
return errors.Wrapf(err, "failed to parse oldest supported version %s", OldestSupportedVersion)
|
||||
}
|
||||
|
||||
var currentSchemaVersion *semver.Version
|
||||
@@ -206,7 +206,7 @@ func saveSchemaVersion(sqlStore *SqlStore, version string) {
|
||||
if err := sqlStore.System().SaveOrUpdate(&model.System{Name: "Version", Value: version}); err != nil {
|
||||
mlog.Critical(err.Error())
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_VERSION_SAVE)
|
||||
os.Exit(ExitVersionSave)
|
||||
}
|
||||
|
||||
mlog.Warn("The database schema version has been upgraded", mlog.String("version", version))
|
||||
@@ -223,28 +223,28 @@ func shouldPerformUpgrade(sqlStore *SqlStore, currentSchemaVersion string, expec
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion31(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_0_0, VERSION_3_1_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version300, Version310) {
|
||||
sqlStore.CreateColumnIfNotExists("OutgoingWebhooks", "ContentType", "varchar(128)", "varchar(128)", "")
|
||||
saveSchemaVersion(sqlStore, VERSION_3_1_0)
|
||||
saveSchemaVersion(sqlStore, Version310)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion32(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_1_0, VERSION_3_2_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version310, Version320) {
|
||||
sqlStore.CreateColumnIfNotExists("TeamMembers", "DeleteAt", "bigint(20)", "bigint", "0")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_3_2_0)
|
||||
saveSchemaVersion(sqlStore, Version320)
|
||||
}
|
||||
}
|
||||
|
||||
func themeMigrationFailed(err error) {
|
||||
mlog.Critical("Failed to migrate User.ThemeProps to Preferences table", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_THEME_MIGRATION)
|
||||
os.Exit(ExitThemeMigration)
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion33(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_2_0, VERSION_3_3_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version320, Version330) {
|
||||
if sqlStore.DoesColumnExist("Users", "ThemeProps") {
|
||||
params := map[string]interface{}{
|
||||
"Category": model.PREFERENCE_CATEGORY_THEME,
|
||||
@@ -322,21 +322,21 @@ func upgradeDatabaseToVersion33(sqlStore *SqlStore) {
|
||||
|
||||
sqlStore.CreateColumnIfNotExists("OutgoingWebhooks", "TriggerWhen", "tinyint", "integer", "0")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_3_3_0)
|
||||
saveSchemaVersion(sqlStore, Version330)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion34(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_3_0, VERSION_3_4_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version330, Version340) {
|
||||
sqlStore.CreateColumnIfNotExists("Status", "Manual", "BOOLEAN", "BOOLEAN", "0")
|
||||
sqlStore.CreateColumnIfNotExists("Status", "ActiveChannel", "varchar(26)", "varchar(26)", "")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_3_4_0)
|
||||
saveSchemaVersion(sqlStore, Version340)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion35(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_4_0, VERSION_3_5_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version340, Version350) {
|
||||
sqlStore.GetMaster().Exec("UPDATE Users SET Roles = 'system_user' WHERE Roles = ''")
|
||||
sqlStore.GetMaster().Exec("UPDATE Users SET Roles = 'system_user system_admin' WHERE Roles = 'system_admin'")
|
||||
sqlStore.GetMaster().Exec("UPDATE TeamMembers SET Roles = 'team_user' WHERE Roles = ''")
|
||||
@@ -354,12 +354,12 @@ func upgradeDatabaseToVersion35(sqlStore *SqlStore) {
|
||||
|
||||
sqlStore.Session().RemoveAllSessions()
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_3_5_0)
|
||||
saveSchemaVersion(sqlStore, Version350)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion36(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_5_0, VERSION_3_6_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version350, Version360) {
|
||||
sqlStore.CreateColumnIfNotExists("Posts", "HasReactions", "tinyint", "boolean", "0")
|
||||
|
||||
// Create Team Description column
|
||||
@@ -371,51 +371,51 @@ func upgradeDatabaseToVersion36(sqlStore *SqlStore) {
|
||||
// Remove ActiveChannel column from Status
|
||||
sqlStore.RemoveColumnIfExists("Status", "ActiveChannel")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_3_6_0)
|
||||
saveSchemaVersion(sqlStore, Version360)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion37(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_6_0, VERSION_3_7_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version360, Version370) {
|
||||
// Add EditAt column to Posts
|
||||
sqlStore.CreateColumnIfNotExists("Posts", "EditAt", " bigint", " bigint", "0")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_3_7_0)
|
||||
saveSchemaVersion(sqlStore, Version370)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion38(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_7_0, VERSION_3_8_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version370, Version380) {
|
||||
// Add the IsPinned column to posts.
|
||||
sqlStore.CreateColumnIfNotExists("Posts", "IsPinned", "boolean", "boolean", "0")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_3_8_0)
|
||||
saveSchemaVersion(sqlStore, Version380)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion39(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_8_0, VERSION_3_9_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version380, Version390) {
|
||||
sqlStore.CreateColumnIfNotExists("OAuthAccessData", "Scope", "varchar(128)", "varchar(128)", model.DEFAULT_SCOPE)
|
||||
sqlStore.RemoveTableIfExists("PasswordRecovery")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_3_9_0)
|
||||
saveSchemaVersion(sqlStore, Version390)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion310(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_9_0, VERSION_3_10_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_3_10_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version390, Version3100) {
|
||||
saveSchemaVersion(sqlStore, Version3100)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion40(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_3_10_0, VERSION_4_0_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_4_0_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version3100, Version400) {
|
||||
saveSchemaVersion(sqlStore, Version400)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion41(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_0_0, VERSION_4_1_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version400, Version410) {
|
||||
// Increase maximum length of the Users table Roles column.
|
||||
if sqlStore.GetMaxLengthOfColumnIfExists("Users", "Roles") != "256" {
|
||||
sqlStore.AlterColumnTypeIfExists("Users", "Roles", "varchar(256)", "varchar(256)")
|
||||
@@ -423,52 +423,52 @@ func upgradeDatabaseToVersion41(sqlStore *SqlStore) {
|
||||
|
||||
sqlStore.RemoveTableIfExists("JobStatuses")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_4_1_0)
|
||||
saveSchemaVersion(sqlStore, Version410)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion42(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_1_0, VERSION_4_2_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_4_2_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version410, Version420) {
|
||||
saveSchemaVersion(sqlStore, Version420)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion43(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_2_0, VERSION_4_3_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_4_3_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version420, Version430) {
|
||||
saveSchemaVersion(sqlStore, Version430)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion44(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_3_0, VERSION_4_4_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version430, Version440) {
|
||||
// Add the IsActive column to UserAccessToken.
|
||||
sqlStore.CreateColumnIfNotExists("UserAccessTokens", "IsActive", "boolean", "boolean", "1")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_4_4_0)
|
||||
saveSchemaVersion(sqlStore, Version440)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion45(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_4_0, VERSION_4_5_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_4_5_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version440, Version450) {
|
||||
saveSchemaVersion(sqlStore, Version450)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion46(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_5_0, VERSION_4_6_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version450, Version460) {
|
||||
sqlStore.CreateColumnIfNotExists("IncomingWebhooks", "Username", "varchar(64)", "varchar(64)", "")
|
||||
sqlStore.CreateColumnIfNotExists("IncomingWebhooks", "IconURL", "varchar(1024)", "varchar(1024)", "")
|
||||
saveSchemaVersion(sqlStore, VERSION_4_6_0)
|
||||
saveSchemaVersion(sqlStore, Version460)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion47(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_6_0, VERSION_4_7_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version460, Version470) {
|
||||
sqlStore.AlterColumnTypeIfExists("Users", "Position", "varchar(128)", "varchar(128)")
|
||||
sqlStore.AlterColumnTypeIfExists("OAuthAuthData", "State", "varchar(1024)", "varchar(1024)")
|
||||
sqlStore.RemoveColumnIfExists("ChannelMemberHistory", "Email")
|
||||
sqlStore.RemoveColumnIfExists("ChannelMemberHistory", "Username")
|
||||
saveSchemaVersion(sqlStore, VERSION_4_7_0)
|
||||
saveSchemaVersion(sqlStore, Version470)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,29 +476,29 @@ func upgradeDatabaseToVersion471(sqlStore *SqlStore) {
|
||||
// If any new instances started with 4.7, they would have the bad Email column on the
|
||||
// ChannelMemberHistory table. So for those cases we need to do an upgrade between
|
||||
// 4.7.0 and 4.7.1
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_7_0, VERSION_4_7_1) {
|
||||
if shouldPerformUpgrade(sqlStore, Version470, Version471) {
|
||||
sqlStore.RemoveColumnIfExists("ChannelMemberHistory", "Email")
|
||||
saveSchemaVersion(sqlStore, VERSION_4_7_1)
|
||||
saveSchemaVersion(sqlStore, Version471)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion472(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_7_1, VERSION_4_7_2) {
|
||||
if shouldPerformUpgrade(sqlStore, Version471, Version472) {
|
||||
sqlStore.RemoveIndexIfExists("idx_channels_displayname", "Channels")
|
||||
saveSchemaVersion(sqlStore, VERSION_4_7_2)
|
||||
saveSchemaVersion(sqlStore, Version472)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion48(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_7_2, VERSION_4_8_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_4_8_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version472, Version480) {
|
||||
saveSchemaVersion(sqlStore, Version480)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion481(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_8_0, VERSION_4_8_1) {
|
||||
if shouldPerformUpgrade(sqlStore, Version480, Version481) {
|
||||
sqlStore.RemoveIndexIfExists("idx_channels_displayname", "Channels")
|
||||
saveSchemaVersion(sqlStore, VERSION_4_8_1)
|
||||
saveSchemaVersion(sqlStore, Version481)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,7 +507,7 @@ func upgradeDatabaseToVersion49(sqlStore *SqlStore) {
|
||||
// a number of parameters in `config.json` to a `Roles` table in the database. The migration code can be seen
|
||||
// in the file `app/app.go` in the function `DoAdvancedPermissionsMigration()`.
|
||||
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_8_1, VERSION_4_9_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version481, Version490) {
|
||||
sqlStore.CreateColumnIfNotExists("Teams", "LastTeamIconUpdate", "bigint", "bigint", "0")
|
||||
defaultTimezone := timezones.DefaultUserTimezone()
|
||||
defaultTimezoneValue, err := json.Marshal(defaultTimezone)
|
||||
@@ -516,18 +516,18 @@ func upgradeDatabaseToVersion49(sqlStore *SqlStore) {
|
||||
}
|
||||
sqlStore.CreateColumnIfNotExists("Users", "Timezone", "varchar(256)", "varchar(256)", string(defaultTimezoneValue))
|
||||
sqlStore.RemoveIndexIfExists("idx_channels_displayname", "Channels")
|
||||
saveSchemaVersion(sqlStore, VERSION_4_9_0)
|
||||
saveSchemaVersion(sqlStore, Version490)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion410(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_9_0, VERSION_4_10_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version490, Version4100) {
|
||||
|
||||
sqlStore.RemoveIndexIfExists("Name_2", "Channels")
|
||||
sqlStore.RemoveIndexIfExists("Name_2", "Emoji")
|
||||
sqlStore.RemoveIndexIfExists("ClientId_2", "OAuthAccessData")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_4_10_0)
|
||||
saveSchemaVersion(sqlStore, Version4100)
|
||||
sqlStore.GetMaster().Exec("UPDATE Users SET AuthData=LOWER(AuthData) WHERE AuthService = 'saml'")
|
||||
}
|
||||
}
|
||||
@@ -550,7 +550,7 @@ func upgradeDatabaseToVersion50(sqlStore *SqlStore) {
|
||||
// UPDATE ChannelMembers SET Roles = CONCAT(Roles, ' channel_admin'), SchemeAdmin = NULL where SchemeAdmin = 1;
|
||||
// DELETE from Systems WHERE Name = 'migration_advanced_permissions_phase_2';
|
||||
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_10_0, VERSION_5_0_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version4100, Version500) {
|
||||
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("Teams", "SchemeId", "varchar(26)", "varchar(26)")
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("Channels", "SchemeId", "varchar(26)", "varchar(26)")
|
||||
@@ -567,51 +567,51 @@ func upgradeDatabaseToVersion50(sqlStore *SqlStore) {
|
||||
|
||||
sqlStore.RemoveIndexIfExists("idx_channels_txt", "Channels")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_0_0)
|
||||
saveSchemaVersion(sqlStore, Version500)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion51(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_0_0, VERSION_5_1_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_1_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version500, Version510) {
|
||||
saveSchemaVersion(sqlStore, Version510)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion52(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_1_0, VERSION_5_2_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version510, Version520) {
|
||||
sqlStore.CreateColumnIfNotExists("OutgoingWebhooks", "Username", "varchar(64)", "varchar(64)", "")
|
||||
sqlStore.CreateColumnIfNotExists("OutgoingWebhooks", "IconURL", "varchar(1024)", "varchar(1024)", "")
|
||||
saveSchemaVersion(sqlStore, VERSION_5_2_0)
|
||||
saveSchemaVersion(sqlStore, Version520)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion53(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_2_0, VERSION_5_3_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_3_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version520, Version530) {
|
||||
saveSchemaVersion(sqlStore, Version530)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion54(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_3_0, VERSION_5_4_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version530, Version540) {
|
||||
sqlStore.AlterColumnTypeIfExists("OutgoingWebhooks", "Description", "varchar(500)", "varchar(500)")
|
||||
sqlStore.AlterColumnTypeIfExists("IncomingWebhooks", "Description", "varchar(500)", "varchar(500)")
|
||||
if err := sqlStore.Channel().MigratePublicChannels(); err != nil {
|
||||
mlog.Critical("Failed to migrate PublicChannels table", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
os.Exit(ExitGenericFailure)
|
||||
}
|
||||
saveSchemaVersion(sqlStore, VERSION_5_4_0)
|
||||
saveSchemaVersion(sqlStore, Version540)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion55(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_4_0, VERSION_5_5_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_5_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version540, Version550) {
|
||||
saveSchemaVersion(sqlStore, Version550)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion56(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_5_0, VERSION_5_6_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version550, Version560) {
|
||||
sqlStore.CreateColumnIfNotExists("PluginKeyValueStore", "ExpireAt", "bigint(20)", "bigint", "0")
|
||||
|
||||
// migrating user's accepted terms of service data into the new table
|
||||
@@ -625,19 +625,19 @@ func upgradeDatabaseToVersion56(sqlStore *SqlStore) {
|
||||
sqlStore.RemoveIndexIfExists("idx_users_lastname_lower", "lower(LastName)")
|
||||
}
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_6_0)
|
||||
saveSchemaVersion(sqlStore, Version560)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion57(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_6_0, VERSION_5_7_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_7_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version560, Version570) {
|
||||
saveSchemaVersion(sqlStore, Version570)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion58(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_7_0, VERSION_5_8_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version570, Version580) {
|
||||
// idx_channels_txt was removed in `upgradeDatabaseToVersion50`, but merged as part of
|
||||
// v5.1, so the migration wouldn't apply to anyone upgrading from v5.0. Remove it again to
|
||||
// bring the upgraded (from v5.0) and fresh install schemas back in sync.
|
||||
@@ -652,30 +652,30 @@ func upgradeDatabaseToVersion58(sqlStore *SqlStore) {
|
||||
sqlStore.AlterColumnDefaultIfExists("OutgoingWebhooks", "IconURL", nil, model.NewString(""))
|
||||
sqlStore.AlterColumnDefaultIfExists("PluginKeyValueStore", "ExpireAt", model.NewString("NULL"), model.NewString("NULL"))
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_8_0)
|
||||
saveSchemaVersion(sqlStore, Version580)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion59(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_8_0, VERSION_5_9_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_9_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version580, Version590) {
|
||||
saveSchemaVersion(sqlStore, Version590)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion510(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_9_0, VERSION_5_10_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version590, Version5100) {
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("Channels", "GroupConstrained", "tinyint(4)", "boolean")
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("Teams", "GroupConstrained", "tinyint(4)", "boolean")
|
||||
|
||||
sqlStore.CreateIndexIfNotExists("idx_groupteams_teamid", "GroupTeams", "TeamId")
|
||||
sqlStore.CreateIndexIfNotExists("idx_groupchannels_channelid", "GroupChannels", "ChannelId")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_10_0)
|
||||
saveSchemaVersion(sqlStore, Version5100)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion511(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_10_0, VERSION_5_11_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5100, Version5110) {
|
||||
// Enforce all teams have an InviteID set
|
||||
var teams []*model.Team
|
||||
if _, err := sqlStore.GetReplica().Select(&teams, "SELECT * FROM Teams WHERE InviteId = ''"); err != nil {
|
||||
@@ -689,12 +689,12 @@ func upgradeDatabaseToVersion511(sqlStore *SqlStore) {
|
||||
}
|
||||
}
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_11_0)
|
||||
saveSchemaVersion(sqlStore, Version5110)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion512(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_11_0, VERSION_5_12_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5110, Version5120) {
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("TeamMembers", "SchemeGuest", "boolean", "boolean")
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("ChannelMembers", "SchemeGuest", "boolean", "boolean")
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("Schemes", "DefaultTeamGuestRole", "text", "VARCHAR(64)")
|
||||
@@ -705,39 +705,39 @@ func upgradeDatabaseToVersion512(sqlStore *SqlStore) {
|
||||
// Saturday, January 24, 2065 5:20:00 AM GMT. To remove all personal access token sessions.
|
||||
sqlStore.GetMaster().Exec("DELETE FROM Sessions WHERE ExpiresAt > 3000000000000")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_12_0)
|
||||
saveSchemaVersion(sqlStore, Version5120)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion513(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_12_0, VERSION_5_13_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5120, Version5130) {
|
||||
// The previous jobs ran once per minute, cluttering the Jobs table with somewhat useless entries. Clean that up.
|
||||
sqlStore.GetMaster().Exec("DELETE FROM Jobs WHERE Type = 'plugins'")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_13_0)
|
||||
saveSchemaVersion(sqlStore, Version5130)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion514(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_13_0, VERSION_5_14_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_14_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5130, Version5140) {
|
||||
saveSchemaVersion(sqlStore, Version5140)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion515(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_14_0, VERSION_5_15_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_15_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5140, Version5150) {
|
||||
saveSchemaVersion(sqlStore, Version5150)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion516(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_15_0, VERSION_5_16_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5150, Version5160) {
|
||||
if sqlStore.DriverName() == model.DATABASE_DRIVER_POSTGRES {
|
||||
sqlStore.GetMaster().Exec("ALTER TABLE Tokens ALTER COLUMN Extra TYPE varchar(2048)")
|
||||
} else if sqlStore.DriverName() == model.DATABASE_DRIVER_MYSQL {
|
||||
sqlStore.GetMaster().Exec("ALTER TABLE Tokens MODIFY Extra text")
|
||||
}
|
||||
saveSchemaVersion(sqlStore, VERSION_5_16_0)
|
||||
saveSchemaVersion(sqlStore, Version5160)
|
||||
|
||||
// Fix mismatches between the canonical and migrated schemas.
|
||||
sqlStore.AlterColumnTypeIfExists("TeamMembers", "SchemeGuest", "tinyint(4)", "boolean")
|
||||
@@ -758,25 +758,25 @@ func upgradeDatabaseToVersion516(sqlStore *SqlStore) {
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion517(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_16_0, VERSION_5_17_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_17_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5160, Version5170) {
|
||||
saveSchemaVersion(sqlStore, Version5170)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion518(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_17_0, VERSION_5_18_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_18_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5170, Version5180) {
|
||||
saveSchemaVersion(sqlStore, Version5180)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion519(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_18_0, VERSION_5_19_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_19_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5180, Version5190) {
|
||||
saveSchemaVersion(sqlStore, Version5190)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion520(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_19_0, VERSION_5_20_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5190, Version5200) {
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("Bots", "LastIconUpdate", "bigint", "bigint")
|
||||
|
||||
sqlStore.CreateColumnIfNotExists("GroupTeams", "SchemeAdmin", "boolean", "boolean", "0")
|
||||
@@ -785,18 +785,18 @@ func upgradeDatabaseToVersion520(sqlStore *SqlStore) {
|
||||
sqlStore.CreateColumnIfNotExists("GroupChannels", "SchemeAdmin", "boolean", "boolean", "0")
|
||||
sqlStore.CreateIndexIfNotExists("idx_groupchannels_schemeadmin", "GroupChannels", "SchemeAdmin")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_20_0)
|
||||
saveSchemaVersion(sqlStore, Version5200)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion521(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_20_0, VERSION_5_21_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_21_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5200, Version5210) {
|
||||
saveSchemaVersion(sqlStore, Version5210)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion522(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_21_0, VERSION_5_22_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5210, Version5220) {
|
||||
sqlStore.CreateIndexIfNotExists("idx_teams_scheme_id", "Teams", "SchemeId")
|
||||
sqlStore.CreateIndexIfNotExists("idx_channels_scheme_id", "Channels", "SchemeId")
|
||||
sqlStore.CreateIndexIfNotExists("idx_channels_scheme_id", "Channels", "SchemeId")
|
||||
@@ -804,51 +804,51 @@ func upgradeDatabaseToVersion522(sqlStore *SqlStore) {
|
||||
sqlStore.CreateIndexIfNotExists("idx_schemes_channel_user_role", "Schemes", "DefaultChannelUserRole")
|
||||
sqlStore.CreateIndexIfNotExists("idx_schemes_channel_admin_role", "Schemes", "DefaultChannelAdminRole")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_22_0)
|
||||
saveSchemaVersion(sqlStore, Version5220)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion523(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_22_0, VERSION_5_23_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_23_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5220, Version5230) {
|
||||
saveSchemaVersion(sqlStore, Version5230)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion524(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_23_0, VERSION_5_24_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5230, Version5240) {
|
||||
sqlStore.CreateColumnIfNotExists("UserGroups", "AllowReference", "boolean", "boolean", "0")
|
||||
sqlStore.GetMaster().Exec("UPDATE UserGroups SET Name = null, AllowReference = false")
|
||||
sqlStore.AlterPrimaryKey("Reactions", []string{"PostId", "UserId", "EmojiName"})
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_24_0)
|
||||
saveSchemaVersion(sqlStore, Version5240)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion525(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_24_0, VERSION_5_25_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_25_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5240, Version5250) {
|
||||
saveSchemaVersion(sqlStore, Version5250)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion526(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_25_0, VERSION_5_26_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5250, Version5260) {
|
||||
sqlStore.CreateColumnIfNotExists("Sessions", "ExpiredNotify", "boolean", "boolean", "0")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_26_0)
|
||||
saveSchemaVersion(sqlStore, Version5260)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion527(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_26_0, VERSION_5_27_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_27_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5260, Version5270) {
|
||||
saveSchemaVersion(sqlStore, Version5270)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion528(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_27_0, VERSION_5_28_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5270, Version5280) {
|
||||
if err := precheckMigrationToVersion528(sqlStore); err != nil {
|
||||
mlog.Critical("Error upgrading DB schema to 5.28.0", mlog.Err(err))
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
os.Exit(ExitGenericFailure)
|
||||
}
|
||||
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("Commands", "PluginId", "VARCHAR(190)", "VARCHAR(190)")
|
||||
@@ -859,15 +859,15 @@ func upgradeDatabaseToVersion528(sqlStore *SqlStore) {
|
||||
sqlStore.AlterColumnTypeIfExists("IncomingWebhooks", "Username", "varchar(255)", "varchar(255)")
|
||||
sqlStore.AlterColumnTypeIfExists("IncomingWebhooks", "IconURL", "text", "varchar(1024)")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_28_0)
|
||||
saveSchemaVersion(sqlStore, Version5280)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion5281(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_28_0, VERSION_5_28_1) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5280, Version5281) {
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("FileInfo", "MiniPreview", "MEDIUMBLOB", "bytea")
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_28_1)
|
||||
saveSchemaVersion(sqlStore, Version5281)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -925,7 +925,7 @@ func precheckMigrationToVersion528(sqlStore *SqlStore) error {
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion529(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_28_1, VERSION_5_29_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5281, Version5290) {
|
||||
sqlStore.AlterColumnTypeIfExists("SidebarCategories", "Id", "VARCHAR(128)", "VARCHAR(128)")
|
||||
sqlStore.AlterColumnDefaultIfExists("SidebarCategories", "Id", model.NewString(""), nil)
|
||||
sqlStore.AlterColumnTypeIfExists("SidebarChannels", "CategoryId", "VARCHAR(128)", "VARCHAR(128)")
|
||||
@@ -941,30 +941,30 @@ func upgradeDatabaseToVersion529(sqlStore *SqlStore) {
|
||||
mlog.Error("Error updating ChannelId in Threads table", mlog.Err(err))
|
||||
}
|
||||
|
||||
saveSchemaVersion(sqlStore, VERSION_5_29_0)
|
||||
saveSchemaVersion(sqlStore, Version5290)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion530(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_29_0, VERSION_5_30_0) {
|
||||
if shouldPerformUpgrade(sqlStore, Version5290, Version5300) {
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("FileInfo", "Content", "longtext", "text")
|
||||
|
||||
sqlStore.CreateColumnIfNotExists("SidebarCategories", "Muted", "tinyint(1)", "boolean", "0")
|
||||
saveSchemaVersion(sqlStore, VERSION_5_30_0)
|
||||
saveSchemaVersion(sqlStore, Version5300)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion531(sqlStore *SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_5_30_0, VERSION_5_31_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_31_0)
|
||||
if shouldPerformUpgrade(sqlStore, Version5300, Version5310) {
|
||||
saveSchemaVersion(sqlStore, Version5310)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion532(sqlStore *SqlStore) {
|
||||
// if shouldPerformUpgrade(sqlStore, VERSION_5_31_0, VERSION_5_32_0) {
|
||||
// if shouldPerformUpgrade(sqlStore, Version5310, Version5320) {
|
||||
// allow 10 files per post
|
||||
sqlStore.AlterColumnTypeIfExists("Posts", "FileIds", "text", "varchar(300)")
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("Channels", "Shared", "tinyint(1)", "boolean")
|
||||
// saveSchemaVersion(sqlStore, VERSION_5_32_0)
|
||||
// saveSchemaVersion(sqlStore, Version5320)
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -34,26 +34,26 @@ func TestStoreUpgrade(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("upgrade from earliest supported version", func(t *testing.T) {
|
||||
saveSchemaVersion(sqlStore, VERSION_3_0_0)
|
||||
err := upgradeDatabase(sqlStore, CURRENT_SCHEMA_VERSION)
|
||||
saveSchemaVersion(sqlStore, Version300)
|
||||
err := upgradeDatabase(sqlStore, CurrentSchemaVersion)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CURRENT_SCHEMA_VERSION, sqlStore.GetCurrentSchemaVersion())
|
||||
require.Equal(t, CurrentSchemaVersion, sqlStore.GetCurrentSchemaVersion())
|
||||
})
|
||||
|
||||
t.Run("upgrade from no existing version", func(t *testing.T) {
|
||||
saveSchemaVersion(sqlStore, "")
|
||||
err := upgradeDatabase(sqlStore, CURRENT_SCHEMA_VERSION)
|
||||
err := upgradeDatabase(sqlStore, CurrentSchemaVersion)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CURRENT_SCHEMA_VERSION, sqlStore.GetCurrentSchemaVersion())
|
||||
require.Equal(t, CurrentSchemaVersion, sqlStore.GetCurrentSchemaVersion())
|
||||
})
|
||||
|
||||
t.Run("upgrade schema running earlier minor version", func(t *testing.T) {
|
||||
saveSchemaVersion(sqlStore, "5.1.0")
|
||||
err := upgradeDatabase(sqlStore, "5.8.0")
|
||||
require.NoError(t, err)
|
||||
// Assert CURRENT_SCHEMA_VERSION, not 5.8.0, since the migrations will move
|
||||
// Assert CurrentSchemaVersion, not 5.8.0, since the migrations will move
|
||||
// past 5.8.0 regardless of the input parameter.
|
||||
require.Equal(t, CURRENT_SCHEMA_VERSION, sqlStore.GetCurrentSchemaVersion())
|
||||
require.Equal(t, CurrentSchemaVersion, sqlStore.GetCurrentSchemaVersion())
|
||||
})
|
||||
|
||||
t.Run("upgrade schema running later minor version", func(t *testing.T) {
|
||||
@@ -65,9 +65,9 @@ func TestStoreUpgrade(t *testing.T) {
|
||||
|
||||
t.Run("upgrade schema running earlier major version", func(t *testing.T) {
|
||||
saveSchemaVersion(sqlStore, "4.1.0")
|
||||
err := upgradeDatabase(sqlStore, CURRENT_SCHEMA_VERSION)
|
||||
err := upgradeDatabase(sqlStore, CurrentSchemaVersion)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, CURRENT_SCHEMA_VERSION, sqlStore.GetCurrentSchemaVersion())
|
||||
require.Equal(t, CurrentSchemaVersion, sqlStore.GetCurrentSchemaVersion())
|
||||
})
|
||||
|
||||
t.Run("upgrade schema running later major version", func(t *testing.T) {
|
||||
@@ -84,21 +84,21 @@ func TestSaveSchemaVersion(t *testing.T) {
|
||||
sqlStore := ss.(*SqlStore)
|
||||
|
||||
t.Run("set earliest version", func(t *testing.T) {
|
||||
saveSchemaVersion(sqlStore, VERSION_3_0_0)
|
||||
saveSchemaVersion(sqlStore, Version300)
|
||||
props, err := ss.System().Get()
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, VERSION_3_0_0, props["Version"])
|
||||
require.Equal(t, VERSION_3_0_0, sqlStore.GetCurrentSchemaVersion())
|
||||
require.Equal(t, Version300, props["Version"])
|
||||
require.Equal(t, Version300, sqlStore.GetCurrentSchemaVersion())
|
||||
})
|
||||
|
||||
t.Run("set current version", func(t *testing.T) {
|
||||
saveSchemaVersion(sqlStore, CURRENT_SCHEMA_VERSION)
|
||||
saveSchemaVersion(sqlStore, CurrentSchemaVersion)
|
||||
props, err := ss.System().Get()
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, CURRENT_SCHEMA_VERSION, props["Version"])
|
||||
require.Equal(t, CURRENT_SCHEMA_VERSION, sqlStore.GetCurrentSchemaVersion())
|
||||
require.Equal(t, CurrentSchemaVersion, props["Version"])
|
||||
require.Equal(t, CurrentSchemaVersion, sqlStore.GetCurrentSchemaVersion())
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -20,14 +20,14 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
MAX_GROUP_CHANNELS_FOR_PROFILES = 50
|
||||
MaxGroupChannelsForProfiles = 50
|
||||
)
|
||||
|
||||
var (
|
||||
USER_SEARCH_TYPE_NAMES_NO_FULL_NAME = []string{"Username", "Nickname"}
|
||||
USER_SEARCH_TYPE_NAMES = []string{"Username", "FirstName", "LastName", "Nickname"}
|
||||
USER_SEARCH_TYPE_ALL_NO_FULL_NAME = []string{"Username", "Nickname", "Email"}
|
||||
USER_SEARCH_TYPE_ALL = []string{"Username", "FirstName", "LastName", "Nickname", "Email"}
|
||||
UserSearchTypeNames_NO_FULL_NAME = []string{"Username", "Nickname"}
|
||||
UserSearchTypeNames = []string{"Username", "FirstName", "LastName", "Nickname"}
|
||||
UserSearchTypeAll_NO_FULL_NAME = []string{"Username", "Nickname", "Email"}
|
||||
UserSearchTypeAll = []string{"Username", "FirstName", "LastName", "Nickname", "Email"}
|
||||
)
|
||||
|
||||
type SqlUserStore struct {
|
||||
@@ -92,10 +92,10 @@ func (us SqlUserStore) createIndexesIfNotExists() {
|
||||
us.CreateIndexIfNotExists("idx_users_lastname_lower_textpattern", "Users", "lower(LastName) text_pattern_ops")
|
||||
}
|
||||
|
||||
us.CreateFullTextIndexIfNotExists("idx_users_all_txt", "Users", strings.Join(USER_SEARCH_TYPE_ALL, ", "))
|
||||
us.CreateFullTextIndexIfNotExists("idx_users_all_no_full_name_txt", "Users", strings.Join(USER_SEARCH_TYPE_ALL_NO_FULL_NAME, ", "))
|
||||
us.CreateFullTextIndexIfNotExists("idx_users_names_txt", "Users", strings.Join(USER_SEARCH_TYPE_NAMES, ", "))
|
||||
us.CreateFullTextIndexIfNotExists("idx_users_names_no_full_name_txt", "Users", strings.Join(USER_SEARCH_TYPE_NAMES_NO_FULL_NAME, ", "))
|
||||
us.CreateFullTextIndexIfNotExists("idx_users_all_txt", "Users", strings.Join(UserSearchTypeAll, ", "))
|
||||
us.CreateFullTextIndexIfNotExists("idx_users_all_no_full_name_txt", "Users", strings.Join(UserSearchTypeAll_NO_FULL_NAME, ", "))
|
||||
us.CreateFullTextIndexIfNotExists("idx_users_names_txt", "Users", strings.Join(UserSearchTypeNames, ", "))
|
||||
us.CreateFullTextIndexIfNotExists("idx_users_names_no_full_name_txt", "Users", strings.Join(UserSearchTypeNames_NO_FULL_NAME, ", "))
|
||||
}
|
||||
|
||||
func (us SqlUserStore) Save(user *model.User) (*model.User, error) {
|
||||
@@ -936,8 +936,8 @@ type UserWithChannel struct {
|
||||
}
|
||||
|
||||
func (us SqlUserStore) GetProfileByGroupChannelIdsForUser(userId string, channelIds []string) (map[string][]*model.User, error) {
|
||||
if len(channelIds) > MAX_GROUP_CHANNELS_FOR_PROFILES {
|
||||
channelIds = channelIds[0:MAX_GROUP_CHANNELS_FOR_PROFILES]
|
||||
if len(channelIds) > MaxGroupChannelsForProfiles {
|
||||
channelIds = channelIds[0:MaxGroupChannelsForProfiles]
|
||||
}
|
||||
|
||||
isMemberQuery := fmt.Sprintf(`
|
||||
@@ -1402,15 +1402,15 @@ func (us SqlUserStore) performSearch(query sq.SelectBuilder, term string, option
|
||||
var searchType []string
|
||||
if options.AllowEmails {
|
||||
if options.AllowFullNames {
|
||||
searchType = USER_SEARCH_TYPE_ALL
|
||||
searchType = UserSearchTypeAll
|
||||
} else {
|
||||
searchType = USER_SEARCH_TYPE_ALL_NO_FULL_NAME
|
||||
searchType = UserSearchTypeAll_NO_FULL_NAME
|
||||
}
|
||||
} else {
|
||||
if options.AllowFullNames {
|
||||
searchType = USER_SEARCH_TYPE_NAMES
|
||||
searchType = UserSearchTypeNames
|
||||
} else {
|
||||
searchType = USER_SEARCH_TYPE_NAMES_NO_FULL_NAME
|
||||
searchType = UserSearchTypeNames_NO_FULL_NAME
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ func testChannelStoreSaveDirectChannel(t *testing.T, ss store.Store, s SqlStore)
|
||||
returnedChannel, nErr := ss.Channel().SaveDirectChannel(&o1a, &m1, &m2)
|
||||
require.NotNil(t, nErr, "should've failed to save a duplicate direct channel")
|
||||
var cErr *store.ErrConflict
|
||||
require.Truef(t, errors.As(nErr, &cErr), "should've returned CHANNEL_EXISTS_ERROR")
|
||||
require.Truef(t, errors.As(nErr, &cErr), "should've returned ChannelExistsError")
|
||||
require.Equal(t, o1.Id, returnedChannel.Id, "should've failed to save a duplicate direct channel")
|
||||
|
||||
// Attempt to save a non-direct channel
|
||||
|
||||
@@ -17,8 +17,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
DAY_MILLISECONDS = 24 * 60 * 60 * 1000
|
||||
MONTH_MILLISECONDS = 31 * DAY_MILLISECONDS
|
||||
DayMilliseconds = 24 * 60 * 60 * 1000
|
||||
MonthMilliseconds = 31 * DayMilliseconds
|
||||
)
|
||||
|
||||
func cleanupStatusStore(t *testing.T, s SqlStore) {
|
||||
@@ -3870,8 +3870,8 @@ func testUserStoreAnalyticsActiveCount(t *testing.T, ss store.Store, s SqlStore)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
millis := model.GetMillis()
|
||||
millisTwoDaysAgo := model.GetMillis() - (2 * DAY_MILLISECONDS)
|
||||
millisTwoMonthsAgo := model.GetMillis() - (2 * MONTH_MILLISECONDS)
|
||||
millisTwoDaysAgo := model.GetMillis() - (2 * DayMilliseconds)
|
||||
millisTwoMonthsAgo := model.GetMillis() - (2 * MonthMilliseconds)
|
||||
|
||||
// u0 last activity status is two months ago.
|
||||
// u1 last activity status is two days ago.
|
||||
@@ -3883,27 +3883,27 @@ func testUserStoreAnalyticsActiveCount(t *testing.T, ss store.Store, s SqlStore)
|
||||
require.Nil(t, ss.Status().SaveOrUpdate(&model.Status{UserId: u4.Id, Status: model.STATUS_OFFLINE, LastActivityAt: millis}))
|
||||
|
||||
// Daily counts (without bots)
|
||||
count, err := ss.User().AnalyticsActiveCount(DAY_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: true})
|
||||
count, err := ss.User().AnalyticsActiveCount(DayMilliseconds, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: true})
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, int64(2), count)
|
||||
|
||||
// Daily counts (with bots)
|
||||
count, err = ss.User().AnalyticsActiveCount(DAY_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: true, IncludeDeleted: true})
|
||||
count, err = ss.User().AnalyticsActiveCount(DayMilliseconds, model.UserCountOptions{IncludeBotAccounts: true, IncludeDeleted: true})
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, int64(3), count)
|
||||
|
||||
// Monthly counts (without bots)
|
||||
count, err = ss.User().AnalyticsActiveCount(MONTH_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: true})
|
||||
count, err = ss.User().AnalyticsActiveCount(MonthMilliseconds, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: true})
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, int64(3), count)
|
||||
|
||||
// Monthly counts - (with bots)
|
||||
count, err = ss.User().AnalyticsActiveCount(MONTH_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: true, IncludeDeleted: true})
|
||||
count, err = ss.User().AnalyticsActiveCount(MonthMilliseconds, model.UserCountOptions{IncludeBotAccounts: true, IncludeDeleted: true})
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, int64(4), count)
|
||||
|
||||
// Monthly counts - (with bots, excluding deleted)
|
||||
count, err = ss.User().AnalyticsActiveCount(MONTH_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: true, IncludeDeleted: false})
|
||||
count, err = ss.User().AnalyticsActiveCount(MonthMilliseconds, model.UserCountOptions{IncludeBotAccounts: true, IncludeDeleted: false})
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, int64(4), count)
|
||||
}
|
||||
@@ -3955,8 +3955,8 @@ func testUserStoreAnalyticsActiveCountForPeriod(t *testing.T, ss store.Store, s
|
||||
require.Nil(t, nErr)
|
||||
|
||||
millis := model.GetMillis()
|
||||
millisTwoDaysAgo := model.GetMillis() - (2 * DAY_MILLISECONDS)
|
||||
millisTwoMonthsAgo := model.GetMillis() - (2 * MONTH_MILLISECONDS)
|
||||
millisTwoDaysAgo := model.GetMillis() - (2 * DayMilliseconds)
|
||||
millisTwoMonthsAgo := model.GetMillis() - (2 * MonthMilliseconds)
|
||||
|
||||
// u0 last activity status is two months ago.
|
||||
// u1 last activity status is one month ago
|
||||
@@ -3965,9 +3965,9 @@ func testUserStoreAnalyticsActiveCountForPeriod(t *testing.T, ss store.Store, s
|
||||
// u3 last activity is within last day
|
||||
// u4 last activity is within last day
|
||||
require.Nil(t, ss.Status().SaveOrUpdate(&model.Status{UserId: u0.Id, Status: model.STATUS_OFFLINE, LastActivityAt: millisTwoMonthsAgo}))
|
||||
require.Nil(t, ss.Status().SaveOrUpdate(&model.Status{UserId: u1.Id, Status: model.STATUS_OFFLINE, LastActivityAt: millisTwoMonthsAgo + MONTH_MILLISECONDS}))
|
||||
require.Nil(t, ss.Status().SaveOrUpdate(&model.Status{UserId: u1.Id, Status: model.STATUS_OFFLINE, LastActivityAt: millisTwoMonthsAgo + MonthMilliseconds}))
|
||||
require.Nil(t, ss.Status().SaveOrUpdate(&model.Status{UserId: u2.Id, Status: model.STATUS_OFFLINE, LastActivityAt: millisTwoDaysAgo}))
|
||||
require.Nil(t, ss.Status().SaveOrUpdate(&model.Status{UserId: u3.Id, Status: model.STATUS_OFFLINE, LastActivityAt: millisTwoDaysAgo + DAY_MILLISECONDS}))
|
||||
require.Nil(t, ss.Status().SaveOrUpdate(&model.Status{UserId: u3.Id, Status: model.STATUS_OFFLINE, LastActivityAt: millisTwoDaysAgo + DayMilliseconds}))
|
||||
require.Nil(t, ss.Status().SaveOrUpdate(&model.Status{UserId: u4.Id, Status: model.STATUS_OFFLINE, LastActivityAt: millis}))
|
||||
|
||||
// Two months to two days (without bots)
|
||||
|
||||
Ссылка в новой задаче
Block a user