sqlstore

package
v0.0.0-...-926a698 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2025 License: AGPL-3.0, Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

Copyright (c) 2020-present Mattermost, Inc. All Rights Reserved. See LICENSE.txt for license information.

Index

Constants

View Source
const (
	// we group the inserts on batches of 1000 because PostgreSQL
	// supports a limit of around 64K values (not rows) on an insert
	// query, so we want to stay safely below.
	CategoryInsertBatch = 1000

	TemplatesToTeamsMigrationKey              = "TemplatesToTeamsMigrationComplete"
	UniqueIDsMigrationKey                     = "UniqueIDsMigrationComplete"
	CategoryUUIDIDMigrationKey                = "CategoryUuidIdMigrationComplete"
	TeamLessBoardsMigrationKey                = "TeamLessBoardsMigrationComplete"
	DeletedMembershipBoardsMigrationKey       = "DeletedMembershipBoardsMigrationComplete"
	DeDuplicateCategoryBoardTableMigrationKey = "DeDuplicateCategoryBoardTableComplete"
)

Variables

View Source
var Assets embed.FS
View Source
var ErrInvalidCardLimitValue = errors.New("card limit value is invalid")
View Source
var (
	ErrUnsupportedDatabaseType = errors.New("database type is unsupported")
)

Functions

func PrepareNewTestDatabase

func PrepareNewTestDatabase() (dbType string, connectionString string, err error)

Types

type BlockDoesntBelongToBoardsErr

type BlockDoesntBelongToBoardsErr struct {
	// contains filtered or unexported fields
}

func (BlockDoesntBelongToBoardsErr) Error

type ErrInvalidDBType

type ErrInvalidDBType struct {
	// contains filtered or unexported fields
}

func (ErrInvalidDBType) Error

func (e ErrInvalidDBType) Error() string

type ErrStoreParam

type ErrStoreParam struct {
	// contains filtered or unexported fields
}

func (ErrStoreParam) Error

func (e ErrStoreParam) Error() string

type MutexFactory

type MutexFactory func(name string) (*cluster.Mutex, error)

MutexFactory is used by the store in plugin mode to generate a cluster mutex.

type Number

type Number interface {
	int64 | int
}

type Params

type Params struct {
	DBType           string
	ConnectionString string
	DBPingAttempts   int
	TablePrefix      string
	Logger           mlog.LoggerIFace
	DB               *sql.DB
	NewMutexFn       MutexFactory
	ServicesAPI      servicesAPI
	SkipMigrations   bool
	ConfigFn         func() *mmModel.Config
}

func (Params) CheckValid

func (p Params) CheckValid() error

type RetentionTableDeletionInfo

type RetentionTableDeletionInfo struct {
	Table         string
	PrimaryKeys   []string
	BoardIDColumn string
}

type SQLStore

type SQLStore struct {
	NewMutexFn MutexFactory
	// contains filtered or unexported fields
}

SQLStore is a SQL database.

func New

func New(params Params) (*SQLStore, error)

New creates a new SQL implementation of the store.

func (*SQLStore) AddUpdateCategoryBoard

func (s *SQLStore) AddUpdateCategoryBoard(userID string, categoryID string, boardIDs []string) error

func (*SQLStore) CanSeeUser

func (s *SQLStore) CanSeeUser(seerID string, seenID string) (bool, error)

func (*SQLStore) CloseRows

func (s *SQLStore) CloseRows(rows *sql.Rows)

func (*SQLStore) CreateBoardsAndBlocks

func (s *SQLStore) CreateBoardsAndBlocks(bab *model.BoardsAndBlocks, userID string) (*model.BoardsAndBlocks, error)

func (*SQLStore) CreateBoardsAndBlocksWithAdmin

func (s *SQLStore) CreateBoardsAndBlocksWithAdmin(bab *model.BoardsAndBlocks, userID string) (*model.BoardsAndBlocks, []*model.BoardMember, error)

func (*SQLStore) CreateCategory

func (s *SQLStore) CreateCategory(category model.Category) error

func (*SQLStore) CreateSubscription

func (s *SQLStore) CreateSubscription(sub *model.Subscription) (*model.Subscription, error)

func (*SQLStore) DBHandle

func (s *SQLStore) DBHandle() *sql.DB

DBHandle returns the raw sql.DB handle. It is used by the mattermostauthlayer to run their own raw SQL queries.

func (*SQLStore) DBType

func (s *SQLStore) DBType() string

DBType returns the DB driver used for the store.

func (*SQLStore) DBVersion

func (s *SQLStore) DBVersion() string

func (*SQLStore) DeleteBlock

func (s *SQLStore) DeleteBlock(blockID string, modifiedBy string) error

func (*SQLStore) DeleteBlockRecord

func (s *SQLStore) DeleteBlockRecord(blockID string, modifiedBy string) error

func (*SQLStore) DeleteBoard

func (s *SQLStore) DeleteBoard(boardID string, userID string) error

func (*SQLStore) DeleteBoardRecord

func (s *SQLStore) DeleteBoardRecord(boardID string, modifiedBy string) error

func (*SQLStore) DeleteBoardsAndBlocks

func (s *SQLStore) DeleteBoardsAndBlocks(dbab *model.DeleteBoardsAndBlocks, userID string) error

func (*SQLStore) DeleteCategory

func (s *SQLStore) DeleteCategory(categoryID string, userID string, teamID string) error

func (*SQLStore) DeleteMember

func (s *SQLStore) DeleteMember(boardID string, userID string) error

func (*SQLStore) DeleteNotificationHint

func (s *SQLStore) DeleteNotificationHint(blockID string) error

func (*SQLStore) DeleteSubscription

func (s *SQLStore) DeleteSubscription(blockID string, subscriberID string) error

func (*SQLStore) DuplicateBlock

func (s *SQLStore) DuplicateBlock(boardID string, blockID string, userID string, asTemplate bool) ([]*model.Block, error)

func (*SQLStore) DuplicateBoard

func (s *SQLStore) DuplicateBoard(boardID string, userID string, toTeam string, asTemplate bool) (*model.BoardsAndBlocks, []*model.BoardMember, error)

func (*SQLStore) EnsureSchemaMigrationFormat

func (s *SQLStore) EnsureSchemaMigrationFormat() error

EnsureSchemaMigrationFormat checks the schema migrations table format and, if it's not using the new shape, it migrates the old one's status before initializing the migrations engine.

func (*SQLStore) GetActiveUserCount

func (s *SQLStore) GetActiveUserCount(updatedSecondsAgo int64) (int, error)

func (*SQLStore) GetAllTeams

func (s *SQLStore) GetAllTeams() ([]*model.Team, error)

func (*SQLStore) GetBlock

func (s *SQLStore) GetBlock(blockID string) (*model.Block, error)

func (*SQLStore) GetBlockCountsByType

func (s *SQLStore) GetBlockCountsByType() (map[string]int64, error)

func (*SQLStore) GetBlockHistory

func (s *SQLStore) GetBlockHistory(blockID string, opts model.QueryBlockHistoryOptions) ([]*model.Block, error)

func (*SQLStore) GetBlockHistoryDescendants

func (s *SQLStore) GetBlockHistoryDescendants(boardID string, opts model.QueryBlockHistoryOptions) ([]*model.Block, error)

func (*SQLStore) GetBlockHistoryNewestChildren

func (s *SQLStore) GetBlockHistoryNewestChildren(parentID string, opts model.QueryBlockHistoryChildOptions) ([]*model.Block, bool, error)

func (*SQLStore) GetBlocks

func (s *SQLStore) GetBlocks(opts model.QueryBlocksOptions) ([]*model.Block, error)

func (*SQLStore) GetBlocksByIDs

func (s *SQLStore) GetBlocksByIDs(ids []string) ([]*model.Block, error)

func (*SQLStore) GetBlocksComplianceHistory

func (s *SQLStore) GetBlocksComplianceHistory(opts model.QueryBlocksComplianceHistoryOptions) ([]*model.BlockHistory, bool, error)

func (*SQLStore) GetBlocksForBoard

func (s *SQLStore) GetBlocksForBoard(boardID string) ([]*model.Block, error)

func (*SQLStore) GetBlocksWithParent

func (s *SQLStore) GetBlocksWithParent(boardID string, parentID string) ([]*model.Block, error)

func (*SQLStore) GetBlocksWithParentAndType

func (s *SQLStore) GetBlocksWithParentAndType(boardID string, parentID string, blockType string) ([]*model.Block, error)

func (*SQLStore) GetBlocksWithType

func (s *SQLStore) GetBlocksWithType(boardID string, blockType string) ([]*model.Block, error)

func (*SQLStore) GetBoard

func (s *SQLStore) GetBoard(id string) (*model.Board, error)

func (*SQLStore) GetBoardAndCard

func (s *SQLStore) GetBoardAndCard(block *model.Block) (*model.Board, *model.Block, error)

func (*SQLStore) GetBoardAndCardByID

func (s *SQLStore) GetBoardAndCardByID(blockID string) (*model.Board, *model.Block, error)

func (*SQLStore) GetBoardCount

func (s *SQLStore) GetBoardCount(includeDeleted bool) (int64, error)

func (*SQLStore) GetBoardHistory

func (s *SQLStore) GetBoardHistory(boardID string, opts model.QueryBoardHistoryOptions) ([]*model.Board, error)

func (*SQLStore) GetBoardMemberHistory

func (s *SQLStore) GetBoardMemberHistory(boardID string, userID string, limit uint64) ([]*model.BoardMemberHistoryEntry, error)

func (*SQLStore) GetBoardsComplianceHistory

func (s *SQLStore) GetBoardsComplianceHistory(opts model.QueryBoardsComplianceHistoryOptions) ([]*model.BoardHistory, bool, error)

func (*SQLStore) GetBoardsForCompliance

func (s *SQLStore) GetBoardsForCompliance(opts model.QueryBoardsForComplianceOptions) ([]*model.Board, bool, error)

func (*SQLStore) GetBoardsForUserAndTeam

func (s *SQLStore) GetBoardsForUserAndTeam(userID string, teamID string, includePublicBoards bool) ([]*model.Board, error)

func (*SQLStore) GetBoardsInTeamByIds

func (s *SQLStore) GetBoardsInTeamByIds(boardIDs []string, teamID string) ([]*model.Board, error)

func (*SQLStore) GetCardLimitTimestamp

func (s *SQLStore) GetCardLimitTimestamp() (int64, error)

func (*SQLStore) GetCardsCount

func (s *SQLStore) GetCardsCount() (int64, error)

func (*SQLStore) GetCategory

func (s *SQLStore) GetCategory(id string) (*model.Category, error)

func (*SQLStore) GetChannel

func (s *SQLStore) GetChannel(teamID string, channelID string) (*mmModel.Channel, error)

func (*SQLStore) GetFileInfo

func (s *SQLStore) GetFileInfo(id string) (*mmModel.FileInfo, error)

func (*SQLStore) GetLicense

func (s *SQLStore) GetLicense() *mmModel.License

func (*SQLStore) GetMemberForBoard

func (s *SQLStore) GetMemberForBoard(boardID string, userID string) (*model.BoardMember, error)

func (*SQLStore) GetMembersForBoard

func (s *SQLStore) GetMembersForBoard(boardID string) ([]*model.BoardMember, error)

func (*SQLStore) GetMembersForUser

func (s *SQLStore) GetMembersForUser(userID string) ([]*model.BoardMember, error)

func (*SQLStore) GetNextNotificationHint

func (s *SQLStore) GetNextNotificationHint(remove bool) (*model.NotificationHint, error)

func (*SQLStore) GetNotificationHint

func (s *SQLStore) GetNotificationHint(blockID string) (*model.NotificationHint, error)

func (*SQLStore) GetRegisteredUserCount

func (s *SQLStore) GetRegisteredUserCount() (int, error)

func (*SQLStore) GetSchemaName

func (s *SQLStore) GetSchemaName() (string, error)

func (*SQLStore) GetSharing

func (s *SQLStore) GetSharing(rootID string) (*model.Sharing, error)

func (*SQLStore) GetSubTree2

func (s *SQLStore) GetSubTree2(boardID string, blockID string, opts model.QuerySubtreeOptions) ([]*model.Block, error)

func (*SQLStore) GetSubscribersCountForBlock

func (s *SQLStore) GetSubscribersCountForBlock(blockID string) (int, error)

func (*SQLStore) GetSubscribersForBlock

func (s *SQLStore) GetSubscribersForBlock(blockID string) ([]*model.Subscriber, error)

func (*SQLStore) GetSubscription

func (s *SQLStore) GetSubscription(blockID string, subscriberID string) (*model.Subscription, error)

func (*SQLStore) GetSubscriptions

func (s *SQLStore) GetSubscriptions(subscriberID string) ([]*model.Subscription, error)

func (*SQLStore) GetSystemSetting

func (s *SQLStore) GetSystemSetting(key string) (string, error)

func (*SQLStore) GetSystemSettings

func (s *SQLStore) GetSystemSettings() (map[string]string, error)

func (*SQLStore) GetTeam

func (s *SQLStore) GetTeam(ID string) (*model.Team, error)

func (*SQLStore) GetTeamCount

func (s *SQLStore) GetTeamCount() (int64, error)

func (*SQLStore) GetTeamsForUser

func (s *SQLStore) GetTeamsForUser(userID string) ([]*model.Team, error)

func (*SQLStore) GetTemplateBoards

func (s *SQLStore) GetTemplateBoards(teamID string, userID string) ([]*model.Board, error)

func (*SQLStore) GetTemplateHelperFuncs

func (s *SQLStore) GetTemplateHelperFuncs() template.FuncMap

func (*SQLStore) GetUsedCardsCount

func (s *SQLStore) GetUsedCardsCount() (int64, error)

func (*SQLStore) GetUserByEmail

func (s *SQLStore) GetUserByEmail(email string) (*model.User, error)

func (*SQLStore) GetUserByID

func (s *SQLStore) GetUserByID(userID string) (*model.User, error)

func (*SQLStore) GetUserByUsername

func (s *SQLStore) GetUserByUsername(username string) (*model.User, error)

func (*SQLStore) GetUserCategories

func (s *SQLStore) GetUserCategories(userID string, teamID string) ([]model.Category, error)

func (*SQLStore) GetUserCategoryBoards

func (s *SQLStore) GetUserCategoryBoards(userID string, teamID string) ([]model.CategoryBoards, error)

func (*SQLStore) GetUserPreferences

func (s *SQLStore) GetUserPreferences(userID string) (mmModel.Preferences, error)

func (*SQLStore) GetUserTimezone

func (s *SQLStore) GetUserTimezone(userID string) (string, error)

func (*SQLStore) GetUsersByTeam

func (s *SQLStore) GetUsersByTeam(teamID string, asGuestID string, showEmail bool, showName bool) ([]*model.User, error)

func (*SQLStore) GetUsersList

func (s *SQLStore) GetUsersList(userIDs []string, showEmail bool, showName bool) ([]*model.User, error)

func (*SQLStore) InsertBlock

func (s *SQLStore) InsertBlock(block *model.Block, userID string) error

func (*SQLStore) InsertBlocks

func (s *SQLStore) InsertBlocks(blocks []*model.Block, userID string) error

func (*SQLStore) InsertBoard

func (s *SQLStore) InsertBoard(board *model.Board, userID string) (*model.Board, error)

func (*SQLStore) InsertBoardWithAdmin

func (s *SQLStore) InsertBoardWithAdmin(board *model.Board, userID string) (*model.Board, *model.BoardMember, error)

func (*SQLStore) IsErrNotFound

func (s *SQLStore) IsErrNotFound(err error) bool

func (*SQLStore) IsMariaDB

func (s *SQLStore) IsMariaDB() bool

func (*SQLStore) MarshalJSONB

func (s *SQLStore) MarshalJSONB(data interface{}) ([]byte, error)

func (*SQLStore) Migrate

func (s *SQLStore) Migrate() error

func (*SQLStore) PatchBlock

func (s *SQLStore) PatchBlock(blockID string, blockPatch *model.BlockPatch, userID string) error

func (*SQLStore) PatchBlocks

func (s *SQLStore) PatchBlocks(blockPatches *model.BlockPatchBatch, userID string) error

func (*SQLStore) PatchBoard

func (s *SQLStore) PatchBoard(boardID string, boardPatch *model.BoardPatch, userID string) (*model.Board, error)

func (*SQLStore) PatchBoardsAndBlocks

func (s *SQLStore) PatchBoardsAndBlocks(pbab *model.PatchBoardsAndBlocks, userID string) (*model.BoardsAndBlocks, error)

func (*SQLStore) PatchUserPreferences

func (s *SQLStore) PatchUserPreferences(userID string, patch model.UserPreferencesPatch) (mmModel.Preferences, error)

func (*SQLStore) PostMessage

func (s *SQLStore) PostMessage(message string, postType string, channelID string) error

func (*SQLStore) RemoveDefaultTemplates

func (s *SQLStore) RemoveDefaultTemplates(boards []*model.Board) error

func (*SQLStore) ReorderCategories

func (s *SQLStore) ReorderCategories(userID string, teamID string, newCategoryOrder []string) ([]string, error)

func (*SQLStore) ReorderCategoryBoards

func (s *SQLStore) ReorderCategoryBoards(categoryID string, newBoardsOrder []string) ([]string, error)

func (*SQLStore) RestoreFiles

func (s *SQLStore) RestoreFiles(fileIDs []string) error

func (*SQLStore) RunCategoryUUIDIDMigration

func (s *SQLStore) RunCategoryUUIDIDMigration() error

RunCategoryUUIDIDMigration takes care of deriving the categories from the boards and its memberships. The name references UUID because of the preexisting purpose of this migration, and has been preserved for compatibility with already migrated instances.

func (*SQLStore) RunDataRetention

func (s *SQLStore) RunDataRetention(globalRetentionDate int64, batchSize int64) (int64, error)

func (*SQLStore) RunDeDuplicateCategoryBoardsMigration

func (s *SQLStore) RunDeDuplicateCategoryBoardsMigration(currentMigration int) error

func (*SQLStore) RunDeletedMembershipBoardsMigration

func (s *SQLStore) RunDeletedMembershipBoardsMigration() error

func (*SQLStore) RunFixCollationsAndCharsetsMigration

func (s *SQLStore) RunFixCollationsAndCharsetsMigration() error

func (*SQLStore) RunTeamLessBoardsMigration

func (s *SQLStore) RunTeamLessBoardsMigration() error

We no longer support boards existing in DMs and private group messages. This function migrates all boards belonging to a DM to the best possible team.

func (*SQLStore) RunUniqueIDsMigration

func (s *SQLStore) RunUniqueIDsMigration() error

func (*SQLStore) SaveFileInfo

func (s *SQLStore) SaveFileInfo(fileInfo *mmModel.FileInfo) error

func (*SQLStore) SaveMember

func (s *SQLStore) SaveMember(bm *model.BoardMember) (*model.BoardMember, error)

func (*SQLStore) SearchBoardsForUser

func (s *SQLStore) SearchBoardsForUser(term string, searchField model.BoardSearchField, userID string, includePublicBoards bool) ([]*model.Board, error)

func (*SQLStore) SearchBoardsForUserInTeam

func (s *SQLStore) SearchBoardsForUserInTeam(teamID string, term string, userID string) ([]*model.Board, error)

func (*SQLStore) SearchUserChannels

func (s *SQLStore) SearchUserChannels(teamID string, userID string, query string) ([]*mmModel.Channel, error)

func (*SQLStore) SearchUsersByTeam

func (s *SQLStore) SearchUsersByTeam(teamID string, searchQuery string, asGuestID string, excludeBots bool, showEmail bool, showName bool) ([]*model.User, error)

func (*SQLStore) SendMessage

func (s *SQLStore) SendMessage(message string, postType string, receipts []string) error

func (*SQLStore) SetBoardVisibility

func (s *SQLStore) SetBoardVisibility(userID string, categoryID string, boardID string, visible bool) error

func (*SQLStore) SetSystemSetting

func (s *SQLStore) SetSystemSetting(key string, value string) error

func (*SQLStore) Shutdown

func (s *SQLStore) Shutdown() error

Shutdown close the connection with the store.

func (*SQLStore) UndeleteBlock

func (s *SQLStore) UndeleteBlock(blockID string, modifiedBy string) error

func (*SQLStore) UndeleteBoard

func (s *SQLStore) UndeleteBoard(boardID string, modifiedBy string) error

func (*SQLStore) UpdateCardLimitTimestamp

func (s *SQLStore) UpdateCardLimitTimestamp(cardLimit int) (int64, error)

func (*SQLStore) UpdateCategory

func (s *SQLStore) UpdateCategory(category model.Category) error

func (*SQLStore) UpdateSubscribersNotifiedAt

func (s *SQLStore) UpdateSubscribersNotifiedAt(blockID string, notifiedAt int64) error

func (*SQLStore) UpsertNotificationHint

func (s *SQLStore) UpsertNotificationHint(hint *model.NotificationHint, notificationFreq time.Duration) (*model.NotificationHint, error)

func (*SQLStore) UpsertSharing

func (s *SQLStore) UpsertSharing(sharing model.Sharing) error

func (*SQLStore) UpsertTeamSettings

func (s *SQLStore) UpsertTeamSettings(team model.Team) error

func (*SQLStore) UpsertTeamSignupToken

func (s *SQLStore) UpsertTeamSignupToken(team model.Team) error

type UserNotFoundError

type UserNotFoundError struct {
	// contains filtered or unexported fields
}

func (UserNotFoundError) Error

func (unf UserNotFoundError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL