github.com/vnforks/kid/v5@v5.22.1-0.20200408055009-b89d99c65676/store/store.go (about)

     1  //go:generate go run layer_generators/main.go
     2  
     3  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     4  // See LICENSE.txt for license information.
     5  
     6  package store
     7  
     8  import (
     9  	"context"
    10  
    11  	"github.com/vnforks/kid/v5/model"
    12  )
    13  
    14  type StoreResult struct {
    15  	Data interface{}
    16  	Err  *model.AppError
    17  }
    18  
    19  type Store interface {
    20  	Branch() BranchStore
    21  	Class() ClassStore
    22  	Post() PostStore
    23  	User() UserStore
    24  	Audit() AuditStore
    25  	ClusterDiscovery() ClusterDiscoveryStore
    26  	Compliance() ComplianceStore
    27  	Session() SessionStore
    28  	OAuth() OAuthStore
    29  	System() SystemStore
    30  	Webhook() WebhookStore
    31  	Command() CommandStore
    32  	CommandWebhook() CommandWebhookStore
    33  	Preference() PreferenceStore
    34  	License() LicenseStore
    35  	Token() TokenStore
    36  	Emoji() EmojiStore
    37  	Status() StatusStore
    38  	FileInfo() FileInfoStore
    39  	Reaction() ReactionStore
    40  	Role() RoleStore
    41  	Scheme() SchemeStore
    42  	Job() JobStore
    43  	UserAccessToken() UserAccessTokenStore
    44  	TermsOfService() TermsOfServiceStore
    45  	UserTermsOfService() UserTermsOfServiceStore
    46  	LinkMetadata() LinkMetadataStore
    47  	MarkSystemRanUnitTests()
    48  	Close()
    49  	LockToMaster()
    50  	UnlockFromMaster()
    51  	DropAllTables()
    52  	GetCurrentSchemaVersion() string
    53  	TotalMasterDbConnections() int
    54  	TotalReadDbConnections() int
    55  	TotalSearchDbConnections() int
    56  	CheckIntegrity() <-chan IntegrityCheckResult
    57  	SetContext(context context.Context)
    58  	Context() context.Context
    59  }
    60  
    61  type BranchStore interface {
    62  	Save(branch *model.Branch) (*model.Branch, *model.AppError)
    63  	Update(branch *model.Branch) (*model.Branch, *model.AppError)
    64  	Get(id string) (*model.Branch, *model.AppError)
    65  	GetByName(name string) (*model.Branch, *model.AppError)
    66  	GetByNames(name []string) ([]*model.Branch, *model.AppError)
    67  	GetAll() ([]*model.Branch, *model.AppError)
    68  	GetAllPage(offset int, limit int) ([]*model.Branch, *model.AppError)
    69  	GetBranchesByUserId(userId string) ([]*model.Branch, *model.AppError)
    70  	GetBySchoolId(schoolId string) (*model.Branch, *model.AppError)
    71  	PermanentDelete(branchId string) *model.AppError
    72  	AnalyticsBranchCount(includeDeleted bool) (int64, *model.AppError)
    73  	SaveMember(member *model.BranchMember, maxUsersPerBranch int) (*model.BranchMember, *model.AppError)
    74  	UpdateMember(member *model.BranchMember) (*model.BranchMember, *model.AppError)
    75  	GetMember(branchId string, userId string) (*model.BranchMember, *model.AppError)
    76  	GetMembers(branchId string, offset int, limit int, branchMembersGetOptions *model.BranchMembersGetOptions) ([]*model.BranchMember, *model.AppError)
    77  	GetMembersByIds(branchId string, userIds []string, restrictions *model.ViewUsersRestrictions) ([]*model.BranchMember, *model.AppError)
    78  	GetTotalMemberCount(branchId string, restrictions *model.ViewUsersRestrictions) (int64, *model.AppError)
    79  	GetActiveMemberCount(branchId string, restrictions *model.ViewUsersRestrictions) (int64, *model.AppError)
    80  	GetBranchesForUser(userId string) ([]*model.BranchMember, *model.AppError)
    81  	GetBranchesForUserWithPagination(userId string, page, perPage int) ([]*model.BranchMember, *model.AppError)
    82  	RemoveMember(branchId string, userId string) *model.AppError
    83  	RemoveAllMembersByBranch(branchId string) *model.AppError
    84  	RemoveAllMembersByUser(userId string) *model.AppError
    85  	UpdateLastBranchIconUpdate(branchId string, curTime int64) *model.AppError
    86  	GetBranchesByScheme(schemeId string, offset int, limit int) ([]*model.Branch, *model.AppError)
    87  	MigrateBranchMembers(fromBranchId string, fromUserId string) (map[string]string, *model.AppError)
    88  	ResetAllBranchSchemes() *model.AppError
    89  	ClearAllCustomRoleAssignments() *model.AppError
    90  	AnalyticsGetBranchCountForScheme(schemeId string) (int64, *model.AppError)
    91  	GetAllForExportAfter(limit int, afterId string) ([]*model.BranchForExport, *model.AppError)
    92  	GetBranchMembersForExport(userId string) ([]*model.BranchMemberForExport, *model.AppError)
    93  	UserBelongsToBranches(userId string, branchIds []string) (bool, *model.AppError)
    94  	GetUserBranchIds(userId string, allowFromCache bool) ([]string, *model.AppError)
    95  	InvalidateAllBranchIdsForUser(userId string)
    96  	ClearCaches()
    97  
    98  	// UpdateMembersRole sets all of the given branch members to admins and all of the other members of the branch to
    99  	// non-admin members.
   100  	UpdateMembersRole(branchID string, userIDs []string) *model.AppError
   101  }
   102  
   103  type ClassStore interface {
   104  	Save(class *model.Class, maxClassesPerBranch int64) (*model.Class, *model.AppError)
   105  	CreateDirectClass(userId *model.User, otherUserId *model.User) (*model.Class, *model.AppError)
   106  	SaveDirectClass(class *model.Class, member1 *model.ClassMember, member2 *model.ClassMember) (*model.Class, *model.AppError)
   107  	Update(class *model.Class) (*model.Class, *model.AppError)
   108  	Get(id string, allowFromCache bool) (*model.Class, *model.AppError)
   109  	InvalidateClass(id string)
   110  	InvalidateClassByName(branchId, name string)
   111  	GetFromMaster(id string) (*model.Class, *model.AppError)
   112  	Delete(classId string, time int64) *model.AppError
   113  	Restore(classId string, time int64) *model.AppError
   114  	SetDeleteAt(classId string, deleteAt int64, updateAt int64) *model.AppError
   115  	PermanentDelete(classId string) *model.AppError
   116  	PermanentDeleteByBranch(branchId string) *model.AppError
   117  	GetForPost(postId string) (*model.Class, *model.AppError)
   118  	GetByName(branch_id string, name string, allowFromCache bool) (*model.Class, *model.AppError)
   119  	GetByNames(branch_id string, names []string, allowFromCache bool) ([]*model.Class, *model.AppError)
   120  	GetByNameIncludeDeleted(branch_id string, name string, allowFromCache bool) (*model.Class, *model.AppError)
   121  	GetDeletedByName(branch_id string, name string) (*model.Class, *model.AppError)
   122  	GetDeleted(branch_id string, offset int, limit int, userId string) (*model.ClassList, *model.AppError)
   123  	GetClasses(branchId string, userId string, includeDeleted bool) (*model.ClassList, *model.AppError)
   124  	GetAllClasses(page, perPage int, opts ClassSearchOpts) (*model.ClassListWithBranchData, *model.AppError)
   125  	GetAllClassesCount(opts ClassSearchOpts) (int64, *model.AppError)
   126  	GetMoreClasses(branchId string, userId string, offset int, limit int) (*model.ClassList, *model.AppError)
   127  	GetBranchClasses(branchId string) (*model.ClassList, *model.AppError)
   128  	GetAll(branchId string) ([]*model.Class, *model.AppError)
   129  	GetClassesByIds(classIds []string, includeDeleted bool) ([]*model.Class, *model.AppError)
   130  	GetMemberForPost(postId string, userId string) (*model.ClassMember, *model.AppError)
   131  	SaveMember(member *model.ClassMember) (*model.ClassMember, *model.AppError)
   132  	UpdateMember(member *model.ClassMember) (*model.ClassMember, *model.AppError)
   133  	GetMembers(classId string, offset, limit int) (*model.ClassMembers, *model.AppError)
   134  	GetMember(classId string, userId string) (*model.ClassMember, *model.AppError)
   135  	GetClassMembersTimezones(classId string) ([]model.StringMap, *model.AppError)
   136  	GetAllClassMembersForUser(userId string, allowFromCache bool, includeDeleted bool) (map[string]string, *model.AppError)
   137  	InvalidateAllClassMembersForUser(userId string)
   138  	IsUserInClassUseCache(userId string, classId string) bool
   139  	GetAllClassMembersNotifyPropsForClass(classId string, allowFromCache bool) (map[string]model.StringMap, *model.AppError)
   140  	InvalidateCacheForClassMembersNotifyProps(classId string)
   141  	InvalidateMemberCount(classId string)
   142  	GetMemberCountFromCache(classId string) int64
   143  	GetMemberCount(classId string, allowFromCache bool) (int64, *model.AppError)
   144  	RemoveMember(classId string, userId string) *model.AppError
   145  	PermanentDeleteMembersByUser(userId string) *model.AppError
   146  	PermanentDeleteMembersByClass(classId string) *model.AppError
   147  	GetMembersForUser(branchId string, userId string) (*model.ClassMembers, *model.AppError)
   148  	GetMembersForUserWithPagination(branchId, userId string, page, perPage int) (*model.ClassMembers, *model.AppError)
   149  	GetMembersByIds(classId string, userIds []string) (*model.ClassMembers, *model.AppError)
   150  	ClearCaches()
   151  	GetClassesByScheme(schemeId string, offset int, limit int) (model.ClassList, *model.AppError)
   152  	MigrateClassMembers(fromClassId string, fromUserId string) (map[string]string, *model.AppError)
   153  	ResetAllClassSchemes() *model.AppError
   154  	ClearAllCustomRoleAssignments() *model.AppError
   155  	GetAllClassesForExportAfter(limit int, afterId string) ([]*model.ClassForExport, *model.AppError)
   156  	GetClassMembersForExport(userId string, branchId string) ([]*model.ClassMemberForExport, *model.AppError)
   157  	RemoveAllDeactivatedMembers(classId string) *model.AppError
   158  	GetClassesBatchForIndexing(startTime, endTime int64, limit int) ([]*model.Class, *model.AppError)
   159  	UserBelongsToClasses(userId string, classIds []string) (bool, *model.AppError)
   160  
   161  	// UpdateMembersRole sets all of the given branch members to admins and all of the other members of the branch to
   162  	// non-admin members.
   163  	UpdateMembersRole(classID string, userIDs []string) *model.AppError
   164  }
   165  
   166  type PostStore interface {
   167  	SaveMultiple(posts []*model.Post) ([]*model.Post, *model.AppError)
   168  	Save(post *model.Post) (*model.Post, *model.AppError)
   169  	Update(newPost *model.Post, oldPost *model.Post) (*model.Post, *model.AppError)
   170  	Get(id string, skipFetchThreads bool) (*model.PostList, *model.AppError)
   171  	GetSingle(id string) (*model.Post, *model.AppError)
   172  	Delete(postId string, time int64, deleteByID string) *model.AppError
   173  	PermanentDeleteByUser(userId string) *model.AppError
   174  	PermanentDeleteByClass(classId string) *model.AppError
   175  	GetPosts(options model.GetPostsOptions, allowFromCache bool) (*model.PostList, *model.AppError)
   176  	GetFlaggedPosts(userId string, offset int, limit int) (*model.PostList, *model.AppError)
   177  	// @openTracingParams userId, branchId, offset, limit
   178  	GetFlaggedPostsForBranch(userId, branchId string, offset int, limit int) (*model.PostList, *model.AppError)
   179  	GetFlaggedPostsForClass(userId, classId string, offset int, limit int) (*model.PostList, *model.AppError)
   180  	GetPostsBefore(options model.GetPostsOptions) (*model.PostList, *model.AppError)
   181  	GetPostsAfter(options model.GetPostsOptions) (*model.PostList, *model.AppError)
   182  	GetPostsSince(options model.GetPostsSinceOptions, allowFromCache bool) (*model.PostList, *model.AppError)
   183  	GetPostAfterTime(classId string, time int64) (*model.Post, *model.AppError)
   184  	GetPostIdAfterTime(classId string, time int64) (string, *model.AppError)
   185  	GetPostIdBeforeTime(classId string, time int64) (string, *model.AppError)
   186  	GetEtag(classId string, allowFromCache bool) string
   187  	Search(branchId string, userId string, params *model.SearchParams) (*model.PostList, *model.AppError)
   188  	AnalyticsUserCountsWithPostsByDay(branchId string) (model.AnalyticsRows, *model.AppError)
   189  	AnalyticsPostCountsByDay(options *model.AnalyticsPostCountsOptions) (model.AnalyticsRows, *model.AppError)
   190  	AnalyticsPostCount(branchId string, mustHaveFile bool, mustHaveHashtag bool) (int64, *model.AppError)
   191  	ClearCaches()
   192  	InvalidateLastPostTimeCache(classId string)
   193  	GetPostsCreatedAt(classId string, time int64) ([]*model.Post, *model.AppError)
   194  	Overwrite(post *model.Post) (*model.Post, *model.AppError)
   195  	OverwriteMultiple(posts []*model.Post) ([]*model.Post, *model.AppError)
   196  	GetPostsByIds(postIds []string) ([]*model.Post, *model.AppError)
   197  	GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) ([]*model.PostForIndexing, *model.AppError)
   198  	PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError)
   199  	GetOldest() (*model.Post, *model.AppError)
   200  	GetMaxPostSize() int
   201  }
   202  
   203  type UserStore interface {
   204  	Save(user *model.User) (*model.User, *model.AppError)
   205  	Update(user *model.User, allowRoleUpdate bool) (*model.UserUpdate, *model.AppError)
   206  	UpdateLastPictureUpdate(userId string) *model.AppError
   207  	ResetLastPictureUpdate(userId string) *model.AppError
   208  	UpdatePassword(userId, newPassword string) *model.AppError
   209  	UpdateUpdateAt(userId string) (int64, *model.AppError)
   210  	UpdateAuthData(userId string, service string, authData *string, email string, resetMfa bool) (string, *model.AppError)
   211  	UpdateMfaSecret(userId, secret string) *model.AppError
   212  	UpdateMfaActive(userId string, active bool) *model.AppError
   213  	Get(id string) (*model.User, *model.AppError)
   214  	GetAll() ([]*model.User, *model.AppError)
   215  	ClearCaches()
   216  	InvalidateProfilesInClassCacheByUser(userId string)
   217  	InvalidateProfilesInClassCache(classId string)
   218  	GetProfilesInClass(classId string, offset int, limit int) ([]*model.User, *model.AppError)
   219  	GetProfilesInClassByStatus(classId string, offset int, limit int) ([]*model.User, *model.AppError)
   220  	GetAllProfilesInClass(classId string, allowFromCache bool) (map[string]*model.User, *model.AppError)
   221  	GetProfilesNotInClass(branchId string, classId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
   222  	GetProfilesWithoutBranch(options *model.UserGetOptions) ([]*model.User, *model.AppError)
   223  	GetProfilesByUsernames(usernames []string, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
   224  	GetAllProfiles(options *model.UserGetOptions) ([]*model.User, *model.AppError)
   225  	GetProfiles(options *model.UserGetOptions) ([]*model.User, *model.AppError)
   226  	GetProfileByIds(userIds []string, options *UserGetByIdsOpts, allowFromCache bool) ([]*model.User, *model.AppError)
   227  	InvalidateProfileCacheForUser(userId string)
   228  	GetByEmail(email string) (*model.User, *model.AppError)
   229  	GetByAuth(authData *string, authService string) (*model.User, *model.AppError)
   230  	GetAllUsingAuthService(authService string) ([]*model.User, *model.AppError)
   231  	GetByUsername(username string) (*model.User, *model.AppError)
   232  	GetForLogin(loginId string, allowSignInWithUsername, allowSignInWithEmail bool) (*model.User, *model.AppError)
   233  	GetUnreadCount(userId string) (int64, *model.AppError)
   234  	VerifyEmail(userId, email string) (string, *model.AppError)
   235  	GetEtagForAllProfiles() string
   236  	GetEtagForProfiles(branchId string) string
   237  	UpdateFailedPasswordAttempts(userId string, attempts int) *model.AppError
   238  	GetSystemAdminProfiles() (map[string]*model.User, *model.AppError)
   239  	PermanentDelete(userId string) *model.AppError
   240  	AnalyticsActiveCount(time int64, options model.UserCountOptions) (int64, *model.AppError)
   241  	GetRecentlyActiveUsersForBranch(branchId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
   242  	GetNewUsersForBranch(branchId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
   243  	AnalyticsGetInactiveUsersCount() (int64, *model.AppError)
   244  	AnalyticsGetSystemAdminCount() (int64, *model.AppError)
   245  	ClearAllCustomRoleAssignments() *model.AppError
   246  	InferSystemInstallDate() (int64, *model.AppError)
   247  	GetAllAfter(limit int, afterId string) ([]*model.User, *model.AppError)
   248  	GetUsersBatchForIndexing(startTime, endTime int64, limit int) ([]*model.UserForIndexing, *model.AppError)
   249  	Count(options model.UserCountOptions) (int64, *model.AppError)
   250  }
   251  
   252  type SessionStore interface {
   253  	Get(sessionIdOrToken string) (*model.Session, *model.AppError)
   254  	Save(session *model.Session) (*model.Session, *model.AppError)
   255  	GetSessions(userId string) ([]*model.Session, *model.AppError)
   256  	GetSessionsWithActiveDeviceIds(userId string) ([]*model.Session, *model.AppError)
   257  	Remove(sessionIdOrToken string) *model.AppError
   258  	RemoveAllSessions() *model.AppError
   259  	PermanentDeleteSessionsByUser(branchId string) *model.AppError
   260  	UpdateLastActivityAt(sessionId string, time int64) *model.AppError
   261  	UpdateRoles(userId string, roles string) (string, *model.AppError)
   262  	UpdateDeviceId(id string, deviceId string, expiresAt int64) (string, *model.AppError)
   263  	UpdateProps(session *model.Session) *model.AppError
   264  	AnalyticsSessionCount() (int64, *model.AppError)
   265  	Cleanup(expiryTime int64, batchSize int64)
   266  }
   267  
   268  type AuditStore interface {
   269  	Save(audit *model.Audit) *model.AppError
   270  	Get(user_id string, offset int, limit int) (model.Audits, *model.AppError)
   271  	PermanentDeleteByUser(userId string) *model.AppError
   272  }
   273  
   274  type ClusterDiscoveryStore interface {
   275  	Save(discovery *model.ClusterDiscovery) *model.AppError
   276  	Delete(discovery *model.ClusterDiscovery) (bool, *model.AppError)
   277  	Exists(discovery *model.ClusterDiscovery) (bool, *model.AppError)
   278  	GetAll(discoveryType, clusterName string) ([]*model.ClusterDiscovery, *model.AppError)
   279  	SetLastPingAt(discovery *model.ClusterDiscovery) *model.AppError
   280  	Cleanup() *model.AppError
   281  }
   282  
   283  type ComplianceStore interface {
   284  	Save(compliance *model.Compliance) (*model.Compliance, *model.AppError)
   285  	Update(compliance *model.Compliance) (*model.Compliance, *model.AppError)
   286  	Get(id string) (*model.Compliance, *model.AppError)
   287  	GetAll(offset, limit int) (model.Compliances, *model.AppError)
   288  	ComplianceExport(compliance *model.Compliance) ([]*model.CompliancePost, *model.AppError)
   289  	MessageExport(after int64, limit int) ([]*model.MessageExport, *model.AppError)
   290  }
   291  
   292  type OAuthStore interface {
   293  	SaveApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError)
   294  	UpdateApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError)
   295  	GetApp(id string) (*model.OAuthApp, *model.AppError)
   296  	GetAppByUser(userId string, offset, limit int) ([]*model.OAuthApp, *model.AppError)
   297  	GetApps(offset, limit int) ([]*model.OAuthApp, *model.AppError)
   298  	GetAuthorizedApps(userId string, offset, limit int) ([]*model.OAuthApp, *model.AppError)
   299  	DeleteApp(id string) *model.AppError
   300  	SaveAuthData(authData *model.AuthData) (*model.AuthData, *model.AppError)
   301  	GetAuthData(code string) (*model.AuthData, *model.AppError)
   302  	RemoveAuthData(code string) *model.AppError
   303  	PermanentDeleteAuthDataByUser(userId string) *model.AppError
   304  	SaveAccessData(accessData *model.AccessData) (*model.AccessData, *model.AppError)
   305  	UpdateAccessData(accessData *model.AccessData) (*model.AccessData, *model.AppError)
   306  	GetAccessData(token string) (*model.AccessData, *model.AppError)
   307  	GetAccessDataByUserForApp(userId, clientId string) ([]*model.AccessData, *model.AppError)
   308  	GetAccessDataByRefreshToken(token string) (*model.AccessData, *model.AppError)
   309  	GetPreviousAccessData(userId, clientId string) (*model.AccessData, *model.AppError)
   310  	RemoveAccessData(token string) *model.AppError
   311  	RemoveAllAccessData() *model.AppError
   312  }
   313  
   314  type SystemStore interface {
   315  	Save(system *model.System) *model.AppError
   316  	SaveOrUpdate(system *model.System) *model.AppError
   317  	Update(system *model.System) *model.AppError
   318  	Get() (model.StringMap, *model.AppError)
   319  	GetByName(name string) (*model.System, *model.AppError)
   320  	PermanentDeleteByName(name string) (*model.System, *model.AppError)
   321  }
   322  
   323  type WebhookStore interface {
   324  	SaveIncoming(webhook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError)
   325  	GetIncoming(id string, allowFromCache bool) (*model.IncomingWebhook, *model.AppError)
   326  	GetIncomingList(offset, limit int) ([]*model.IncomingWebhook, *model.AppError)
   327  	GetIncomingListByUser(userId string, offset, limit int) ([]*model.IncomingWebhook, *model.AppError)
   328  	GetIncomingByBranch(branchId string, offset, limit int) ([]*model.IncomingWebhook, *model.AppError)
   329  	GetIncomingByBranchByUser(branchId string, userId string, offset, limit int) ([]*model.IncomingWebhook, *model.AppError)
   330  	UpdateIncoming(webhook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError)
   331  	GetIncomingByClass(classId string) ([]*model.IncomingWebhook, *model.AppError)
   332  	DeleteIncoming(webhookId string, time int64) *model.AppError
   333  	PermanentDeleteIncomingByClass(classId string) *model.AppError
   334  	PermanentDeleteIncomingByUser(userId string) *model.AppError
   335  
   336  	SaveOutgoing(webhook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
   337  	GetOutgoing(id string) (*model.OutgoingWebhook, *model.AppError)
   338  	GetOutgoingByClass(classId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError)
   339  	GetOutgoingByClassByUser(classId string, userId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError)
   340  	GetOutgoingList(offset, limit int) ([]*model.OutgoingWebhook, *model.AppError)
   341  	GetOutgoingListByUser(userId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError)
   342  	GetOutgoingByBranch(branchId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError)
   343  	GetOutgoingByBranchByUser(branchId string, userId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError)
   344  	DeleteOutgoing(webhookId string, time int64) *model.AppError
   345  	PermanentDeleteOutgoingByClass(classId string) *model.AppError
   346  	PermanentDeleteOutgoingByUser(userId string) *model.AppError
   347  	UpdateOutgoing(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
   348  
   349  	AnalyticsIncomingCount(branchId string) (int64, *model.AppError)
   350  	AnalyticsOutgoingCount(branchId string) (int64, *model.AppError)
   351  	InvalidateWebhookCache(webhook string)
   352  	ClearCaches()
   353  }
   354  
   355  type CommandStore interface {
   356  	Save(webhook *model.Command) (*model.Command, *model.AppError)
   357  	GetByTrigger(branchId string, trigger string) (*model.Command, *model.AppError)
   358  	Get(id string) (*model.Command, *model.AppError)
   359  	GetByBranch(branchId string) ([]*model.Command, *model.AppError)
   360  	Delete(commandId string, time int64) *model.AppError
   361  	PermanentDeleteByBranch(branchId string) *model.AppError
   362  	PermanentDeleteByUser(userId string) *model.AppError
   363  	Update(hook *model.Command) (*model.Command, *model.AppError)
   364  	AnalyticsCommandCount(branchId string) (int64, *model.AppError)
   365  }
   366  
   367  type CommandWebhookStore interface {
   368  	Save(webhook *model.CommandWebhook) (*model.CommandWebhook, *model.AppError)
   369  	Get(id string) (*model.CommandWebhook, *model.AppError)
   370  	TryUse(id string, limit int) *model.AppError
   371  	Cleanup()
   372  }
   373  
   374  type PreferenceStore interface {
   375  	Save(preferences *model.Preferences) *model.AppError
   376  	GetCategory(userId string, category string) (model.Preferences, *model.AppError)
   377  	Get(userId string, category string, name string) (*model.Preference, *model.AppError)
   378  	GetAll(userId string) (model.Preferences, *model.AppError)
   379  	Delete(userId, category, name string) *model.AppError
   380  	DeleteCategory(userId string, category string) *model.AppError
   381  	DeleteCategoryAndName(category string, name string) *model.AppError
   382  	PermanentDeleteByUser(userId string) *model.AppError
   383  	CleanupFlagsBatch(limit int64) (int64, *model.AppError)
   384  }
   385  
   386  type LicenseStore interface {
   387  	Save(license *model.LicenseRecord) (*model.LicenseRecord, *model.AppError)
   388  	Get(id string) (*model.LicenseRecord, *model.AppError)
   389  }
   390  
   391  type TokenStore interface {
   392  	Save(recovery *model.Token) *model.AppError
   393  	Delete(token string) *model.AppError
   394  	GetByToken(token string) (*model.Token, *model.AppError)
   395  	Cleanup()
   396  	RemoveAllTokensByType(tokenType string) *model.AppError
   397  }
   398  
   399  type EmojiStore interface {
   400  	Save(emoji *model.Emoji) (*model.Emoji, *model.AppError)
   401  	Get(id string, allowFromCache bool) (*model.Emoji, *model.AppError)
   402  	GetByName(name string, allowFromCache bool) (*model.Emoji, *model.AppError)
   403  	GetMultipleByName(names []string) ([]*model.Emoji, *model.AppError)
   404  	GetList(offset, limit int, sort string) ([]*model.Emoji, *model.AppError)
   405  	Delete(emoji *model.Emoji, time int64) *model.AppError
   406  	Search(name string, prefixOnly bool, limit int) ([]*model.Emoji, *model.AppError)
   407  }
   408  
   409  type StatusStore interface {
   410  	SaveOrUpdate(status *model.Status) *model.AppError
   411  	Get(userId string) (*model.Status, *model.AppError)
   412  	GetByIds(userIds []string) ([]*model.Status, *model.AppError)
   413  	ResetAll() *model.AppError
   414  	GetTotalActiveUsersCount() (int64, *model.AppError)
   415  	UpdateLastActivityAt(userId string, lastActivityAt int64) *model.AppError
   416  }
   417  
   418  type FileInfoStore interface {
   419  	Save(info *model.FileInfo) (*model.FileInfo, *model.AppError)
   420  	Get(id string) (*model.FileInfo, *model.AppError)
   421  	GetByPath(path string) (*model.FileInfo, *model.AppError)
   422  	GetForPost(postId string, readFromMaster, includeDeleted, allowFromCache bool) ([]*model.FileInfo, *model.AppError)
   423  	GetForUser(userId string) ([]*model.FileInfo, *model.AppError)
   424  	GetWithOptions(page, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, *model.AppError)
   425  	InvalidateFileInfosForPostCache(postId string, deleted bool)
   426  	AttachToPost(fileId string, postId string, creatorId string) *model.AppError
   427  	DeleteForPost(postId string) (string, *model.AppError)
   428  	PermanentDelete(fileId string) *model.AppError
   429  	PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError)
   430  	PermanentDeleteByUser(userId string) (int64, *model.AppError)
   431  	ClearCaches()
   432  }
   433  
   434  type ReactionStore interface {
   435  	Save(reaction *model.Reaction) (*model.Reaction, *model.AppError)
   436  	Delete(reaction *model.Reaction) (*model.Reaction, *model.AppError)
   437  	GetForPost(postId string, allowFromCache bool) ([]*model.Reaction, *model.AppError)
   438  	DeleteAllWithEmojiName(emojiName string) *model.AppError
   439  	PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError)
   440  	BulkGetForPosts(postIds []string) ([]*model.Reaction, *model.AppError)
   441  }
   442  
   443  type JobStore interface {
   444  	Save(job *model.Job) (*model.Job, *model.AppError)
   445  	UpdateOptimistically(job *model.Job, currentStatus string) (bool, *model.AppError)
   446  	UpdateStatus(id string, status string) (*model.Job, *model.AppError)
   447  	UpdateStatusOptimistically(id string, currentStatus string, newStatus string) (bool, *model.AppError)
   448  	Get(id string) (*model.Job, *model.AppError)
   449  	GetAllPage(offset int, limit int) ([]*model.Job, *model.AppError)
   450  	GetAllByType(jobType string) ([]*model.Job, *model.AppError)
   451  	GetAllByTypePage(jobType string, offset int, limit int) ([]*model.Job, *model.AppError)
   452  	GetAllByStatus(status string) ([]*model.Job, *model.AppError)
   453  	GetNewestJobByStatusAndType(status string, jobType string) (*model.Job, *model.AppError)
   454  	GetCountByStatusAndType(status string, jobType string) (int64, *model.AppError)
   455  	Delete(id string) (string, *model.AppError)
   456  }
   457  
   458  type UserAccessTokenStore interface {
   459  	Save(token *model.UserAccessToken) (*model.UserAccessToken, *model.AppError)
   460  	DeleteAllForUser(userId string) *model.AppError
   461  	Delete(tokenId string) *model.AppError
   462  	Get(tokenId string) (*model.UserAccessToken, *model.AppError)
   463  	GetAll(offset int, limit int) ([]*model.UserAccessToken, *model.AppError)
   464  	GetByToken(tokenString string) (*model.UserAccessToken, *model.AppError)
   465  	GetByUser(userId string, page, perPage int) ([]*model.UserAccessToken, *model.AppError)
   466  	Search(term string) ([]*model.UserAccessToken, *model.AppError)
   467  	UpdateTokenEnable(tokenId string) *model.AppError
   468  	UpdateTokenDisable(tokenId string) *model.AppError
   469  }
   470  
   471  type RoleStore interface {
   472  	Save(role *model.Role) (*model.Role, *model.AppError)
   473  	Get(roleId string) (*model.Role, *model.AppError)
   474  	GetAll() ([]*model.Role, *model.AppError)
   475  	GetByName(name string) (*model.Role, *model.AppError)
   476  	GetByNames(names []string) ([]*model.Role, *model.AppError)
   477  	Delete(roleId string) (*model.Role, *model.AppError)
   478  	PermanentDeleteAll() *model.AppError
   479  
   480  	// HigherScopedPermissions retrieves the higher-scoped permissions of a list of role names. The higher-scope
   481  	// (either branch scheme or system scheme) is determined based on whether the branch has a scheme or not.
   482  	ClassHigherScopedPermissions(roleNames []string) (map[string]*model.RolePermissions, *model.AppError)
   483  
   484  	// AllClassSchemeRoles returns all of the roles associated to class schemes.
   485  	AllClassSchemeRoles() ([]*model.Role, *model.AppError)
   486  
   487  	// ClassRolesUnderBranchRole returns all of the non-deleted roles that are affected by updates to the
   488  	// given role.
   489  	ClassRolesUnderBranchRole(roleName string) ([]*model.Role, *model.AppError)
   490  }
   491  
   492  type SchemeStore interface {
   493  	Save(scheme *model.Scheme) (*model.Scheme, *model.AppError)
   494  	Get(schemeId string) (*model.Scheme, *model.AppError)
   495  	GetByName(schemeName string) (*model.Scheme, *model.AppError)
   496  	GetAllPage(scope string, offset int, limit int) ([]*model.Scheme, *model.AppError)
   497  	Delete(schemeId string) (*model.Scheme, *model.AppError)
   498  	PermanentDeleteAll() *model.AppError
   499  	CountByScope(scope string) (int64, *model.AppError)
   500  	CountWithoutPermission(scope, permissionID string, roleScope model.RoleScope, roleType model.RoleType) (int64, *model.AppError)
   501  }
   502  
   503  type TermsOfServiceStore interface {
   504  	Save(termsOfService *model.TermsOfService) (*model.TermsOfService, *model.AppError)
   505  	GetLatest(allowFromCache bool) (*model.TermsOfService, *model.AppError)
   506  	Get(id string, allowFromCache bool) (*model.TermsOfService, *model.AppError)
   507  }
   508  
   509  type UserTermsOfServiceStore interface {
   510  	GetByUser(userId string) (*model.UserTermsOfService, *model.AppError)
   511  	Save(userTermsOfService *model.UserTermsOfService) (*model.UserTermsOfService, *model.AppError)
   512  	Delete(userId, termsOfServiceId string) *model.AppError
   513  }
   514  
   515  type LinkMetadataStore interface {
   516  	Save(linkMetadata *model.LinkMetadata) (*model.LinkMetadata, *model.AppError)
   517  	Get(url string, timestamp int64) (*model.LinkMetadata, *model.AppError)
   518  }
   519  
   520  // ClassSearchOpts contains options for searching classes.
   521  //
   522  // NotAssociatedToGroup will exclude classes that have associated, active GroupClasses records.
   523  // IncludeDeleted will include class records where DeleteAt != 0.
   524  // ExcludeClassNames will exclude classes from the results by name.
   525  // Paginate whether to paginate the results.
   526  // Page page requested, if results are paginated.
   527  // PerPage number of results per page, if paginated.
   528  //
   529  type ClassSearchOpts struct {
   530  	IncludeDeleted    bool
   531  	ExcludeClassNames []string
   532  	Page              *int
   533  	PerPage           *int
   534  }
   535  
   536  func (c *ClassSearchOpts) IsPaginated() bool {
   537  	return c.Page != nil && c.PerPage != nil
   538  }
   539  
   540  type UserGetByIdsOpts struct {
   541  	// IsAdmin tracks whether or not the request is being made by an administrator. Does nothing when provided by a client.
   542  	IsAdmin bool
   543  
   544  	// Restrict to search in a list of branches and classes. Does nothing when provided by a client.
   545  	ViewRestrictions *model.ViewUsersRestrictions
   546  
   547  	// Since filters the users based on their UpdateAt timestamp.
   548  	Since int64
   549  }
   550  
   551  type OrphanedRecord struct {
   552  	ParentId *string
   553  	ChildId  *string
   554  }
   555  
   556  type RelationalIntegrityCheckData struct {
   557  	ParentName   string
   558  	ChildName    string
   559  	ParentIdAttr string
   560  	ChildIdAttr  string
   561  	Records      []OrphanedRecord
   562  }
   563  
   564  type IntegrityCheckResult struct {
   565  	Data interface{}
   566  	Err  error
   567  }