коммит произвёл
GitHub
родитель
62495f16bd
Коммит
150c6e7aef
@@ -289,7 +289,6 @@ func SetupConfig(tb testing.TB, updateConfig func(cfg *model.Config)) *TestHelpe
|
||||
dbStore := mainHelper.GetStore()
|
||||
dbStore.DropAllTables()
|
||||
dbStore.MarkSystemRanUnitTests()
|
||||
mainHelper.PreloadBoardsMigrationsIfNeeded()
|
||||
searchEngine := mainHelper.GetSearchEngine()
|
||||
th := setupTestHelper(dbStore, searchEngine, false, true, updateConfig, nil)
|
||||
th.InitLogin()
|
||||
|
||||
@@ -871,7 +871,6 @@ type AppIface interface {
|
||||
HandleImages(previewPathList []string, thumbnailPathList []string, fileData [][]byte)
|
||||
HandleIncomingWebhook(c *request.Context, hookID string, req *model.IncomingWebhookRequest) *model.AppError
|
||||
HandleMessageExportConfig(cfg *model.Config, appCfg *model.Config)
|
||||
HasBoardProduct() (bool, error)
|
||||
HasPermissionTo(askingUserId string, permission *model.Permission) bool
|
||||
HasPermissionToChannel(c request.CTX, askingUserId string, channelID string, permission *model.Permission) bool
|
||||
HasPermissionToChannelByPost(askingUserId string, postID string, permission *model.Permission) bool
|
||||
|
||||
@@ -159,8 +159,6 @@ func SetupWithoutPreloadMigrations(tb testing.TB) *TestHelper {
|
||||
dbStore := mainHelper.GetStore()
|
||||
dbStore.DropAllTables()
|
||||
dbStore.MarkSystemRanUnitTests()
|
||||
// Only boards migrations are applied
|
||||
mainHelper.PreloadBoardsMigrationsIfNeeded()
|
||||
|
||||
return setupTestHelper(dbStore, false, true, nil, tb)
|
||||
}
|
||||
|
||||
@@ -11492,28 +11492,6 @@ func (a *OpenTracingAppLayer) HandleMessageExportConfig(cfg *model.Config, appCf
|
||||
a.app.HandleMessageExportConfig(cfg, appCfg)
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) HasBoardProduct() (bool, error) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.HasBoardProduct")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store().SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store().SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.HasBoardProduct()
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) HasPermissionTo(askingUserId string, permission *model.Permission) bool {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.HasPermissionTo")
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
@@ -77,30 +75,5 @@ func (s *Server) shouldStart(product string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if product == "boards" {
|
||||
if os.Getenv("MM_DISABLE_BOARDS") == "true" {
|
||||
s.Log().Warn("Skipping Boards start: disabled via env var")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *Server) HasBoardProduct() (bool, error) {
|
||||
prod, exists := s.services[product.BoardsKey]
|
||||
if !exists {
|
||||
return false, nil
|
||||
}
|
||||
if prod == nil {
|
||||
return false, errors.New("board product is nil")
|
||||
}
|
||||
if _, ok := prod.(product.BoardsService); !ok {
|
||||
return false, errors.New("board product key does not match its definition")
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (a *App) HasBoardProduct() (bool, error) {
|
||||
return a.Srv().HasBoardProduct()
|
||||
}
|
||||
|
||||
@@ -143,7 +143,6 @@ func setup(tb testing.TB) *TestHelper {
|
||||
dbStore := mainHelper.GetStore()
|
||||
dbStore.DropAllTables()
|
||||
dbStore.MarkSystemRanUnitTests()
|
||||
mainHelper.PreloadBoardsMigrationsIfNeeded()
|
||||
|
||||
return setupTestHelper(dbStore, false, true, tb, nil)
|
||||
}
|
||||
|
||||
@@ -12,8 +12,6 @@ import (
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/request"
|
||||
"github.com/mattermost/mattermost/server/v8/platform/shared/filestore"
|
||||
|
||||
fb_model "github.com/mattermost/mattermost/server/v8/boards/model"
|
||||
)
|
||||
|
||||
// RouterService enables registering the product router to the server. After registering the
|
||||
@@ -214,26 +212,6 @@ type PreferencesService interface {
|
||||
DeletePreferencesForUser(userID string, preferences model.Preferences) *model.AppError
|
||||
}
|
||||
|
||||
// BoardsService is the API for accessing Boards service APIs.
|
||||
//
|
||||
// The service shall be registered via app.BoardsKey service key.
|
||||
type BoardsService interface {
|
||||
GetTemplates(teamID string, userID string) ([]*fb_model.Board, error)
|
||||
GetBoard(boardID string) (*fb_model.Board, error)
|
||||
CreateBoard(board *fb_model.Board, userID string, addmember bool) (*fb_model.Board, error)
|
||||
PatchBoard(boardPatch *fb_model.BoardPatch, boardID string, userID string) (*fb_model.Board, error)
|
||||
DeleteBoard(boardID string, userID string) error
|
||||
SearchBoards(searchTerm string, searchField fb_model.BoardSearchField, userID string, includePublicBoards bool) ([]*fb_model.Board, error)
|
||||
LinkBoardToChannel(boardID string, channelID string, userID string) (*fb_model.Board, error)
|
||||
GetCards(boardID string) ([]*fb_model.Card, error)
|
||||
GetCard(cardID string) (*fb_model.Card, error)
|
||||
CreateCard(card *fb_model.Card, boardID string, userID string) (*fb_model.Card, error)
|
||||
PatchCard(cardPatch *fb_model.CardPatch, cardID string, userID string) (*fb_model.Card, error)
|
||||
DeleteCard(cardID string, userID string) error
|
||||
HasPermissionToBoard(userID, boardID string, permission *model.Permission) bool
|
||||
DuplicateBoard(boardID string, userID string, toTeam string, asTemplate bool) (*fb_model.BoardsAndBlocks, []*fb_model.BoardMember, error)
|
||||
}
|
||||
|
||||
// SessionService is the API for accessing the session.
|
||||
//
|
||||
// The service shall be registered via app.SessionKey service key.
|
||||
|
||||
@@ -25,7 +25,6 @@ const (
|
||||
StoreKey ServiceKey = "storekey"
|
||||
SystemKey ServiceKey = "systemkey"
|
||||
PreferencesKey ServiceKey = "preferenceskey"
|
||||
BoardsKey ServiceKey = "boards"
|
||||
SessionKey ServiceKey = "sessionkey"
|
||||
FrontendKey ServiceKey = "frontendkey"
|
||||
CommandKey ServiceKey = "commandkey"
|
||||
|
||||
@@ -1078,7 +1078,6 @@ func (ss *SqlStore) TrueUpReview() store.TrueUpReviewStore {
|
||||
}
|
||||
|
||||
func (ss *SqlStore) DropAllTables() {
|
||||
var tableSchemaFn string
|
||||
if ss.DriverName() == model.DatabaseDriverPostgres {
|
||||
ss.masterX.Exec(`DO
|
||||
$func$
|
||||
@@ -1088,57 +1087,19 @@ func (ss *SqlStore) DropAllTables() {
|
||||
FROM pg_class
|
||||
WHERE relkind = 'r' -- only tables
|
||||
AND relnamespace = 'public'::regnamespace
|
||||
AND NOT (
|
||||
relname = 'db_migrations' OR
|
||||
relname = 'focalboard_schema_migrations' OR
|
||||
relname = 'focalboard_boards' OR
|
||||
relname = 'focalboard_blocks'
|
||||
)
|
||||
AND NOT relname = 'db_migrations'
|
||||
);
|
||||
END
|
||||
$func$;`)
|
||||
tableSchemaFn = "current_schema()"
|
||||
} else {
|
||||
tables := []string{}
|
||||
ss.masterX.Select(&tables, `show tables`)
|
||||
for _, t := range tables {
|
||||
if t != "db_migrations" &&
|
||||
t != "focalboard_schema_migrations" &&
|
||||
t != "focalboard_boards" &&
|
||||
t != "focalboard_blocks" {
|
||||
if t != "db_migrations" {
|
||||
ss.masterX.Exec(`TRUNCATE TABLE ` + t)
|
||||
|
||||
}
|
||||
}
|
||||
tableSchemaFn = "DATABASE()"
|
||||
}
|
||||
|
||||
var boardsTableCount int
|
||||
err := ss.masterX.Get(&boardsTableCount, `
|
||||
SELECT COUNT(*)
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
WHERE TABLE_SCHEMA = `+tableSchemaFn+`
|
||||
AND TABLE_NAME = 'focalboard_schema_migrations'`)
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "Error dropping all tables. Cannot query INFORMATION_SCHEMA table to check for focalboard_schema_migrations table"))
|
||||
}
|
||||
|
||||
if boardsTableCount != 0 {
|
||||
_, blErr := ss.masterX.Exec(`
|
||||
DELETE FROM focalboard_blocks
|
||||
WHERE board_id IN (
|
||||
SELECT id
|
||||
FROM focalboard_boards
|
||||
WHERE NOT is_template
|
||||
)`)
|
||||
if blErr != nil {
|
||||
panic(errors.Wrap(blErr, "Error deleting all non-template blocks"))
|
||||
}
|
||||
|
||||
_, boErr := ss.masterX.Exec(`DELETE FROM focalboard_boards WHERE NOT is_template`)
|
||||
if boErr != nil {
|
||||
panic(errors.Wrap(boErr, "Error delegint all non-template boards"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -198,67 +198,6 @@ func (h *MainHelper) PreloadMigrations() {
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "Error preloading migrations. Check if you have &multiStatements=true in your DSN if you are using MySQL. Or perhaps the schema changed? If yes, then update the warmup files accordingly"))
|
||||
}
|
||||
|
||||
h.PreloadBoardsMigrationsIfNeeded()
|
||||
}
|
||||
|
||||
// PreloadBoardsMigrationsIfNeeded loads boards migrations if the
|
||||
// focalboard_schema_migrations table exists already.
|
||||
// Besides this, the same compatibility and breaking conditions that
|
||||
// PreloadMigrations has apply here.
|
||||
//
|
||||
// Re-generate the files with:
|
||||
// pg_dump -a -h localhost -U mmuser -d <> --no-comments --inserts -t focalboard_system_settings
|
||||
// mysqldump -u root -p <> --no-create-info --extended-insert=FALSE focalboard_system_settings
|
||||
func (h *MainHelper) PreloadBoardsMigrationsIfNeeded() {
|
||||
tableSchemaFn := "current_schema()"
|
||||
if *h.Settings.DriverName == model.DatabaseDriverMysql {
|
||||
tableSchemaFn = "DATABASE()"
|
||||
}
|
||||
|
||||
basePath := os.Getenv("MM_SERVER_PATH")
|
||||
if basePath == "" {
|
||||
_, errFile := os.Stat("mattermost-server/server")
|
||||
if os.IsNotExist(errFile) {
|
||||
basePath = "mattermost/server"
|
||||
} else {
|
||||
basePath = "mattermost-server/server"
|
||||
}
|
||||
}
|
||||
relPath := "channels/testlib/testdata"
|
||||
|
||||
handle := h.SQLStore.GetMasterX()
|
||||
var boardsTableCount int
|
||||
gErr := handle.Get(&boardsTableCount, `
|
||||
SELECT COUNT(*)
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
WHERE TABLE_SCHEMA = `+tableSchemaFn+`
|
||||
AND TABLE_NAME = 'focalboard_schema_migrations'`)
|
||||
if gErr != nil {
|
||||
panic(errors.Wrap(gErr, "Error preloading migrations. Cannot query INFORMATION_SCHEMA table to check for focalboard_schema_migrations table"))
|
||||
}
|
||||
|
||||
var buf []byte
|
||||
var err error
|
||||
if boardsTableCount != 0 {
|
||||
switch *h.Settings.DriverName {
|
||||
case model.DatabaseDriverPostgres:
|
||||
boardsFinalPath := filepath.Join(basePath, relPath, "boards_postgres_migration_warmup.sql")
|
||||
buf, err = os.ReadFile(boardsFinalPath)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot read file: %v", err))
|
||||
}
|
||||
case model.DatabaseDriverMysql:
|
||||
boardsFinalPath := filepath.Join(basePath, relPath, "boards_mysql_migration_warmup.sql")
|
||||
buf, err = os.ReadFile(boardsFinalPath)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot read file: %v", err))
|
||||
}
|
||||
}
|
||||
if _, err := handle.Exec(string(buf)); err != nil {
|
||||
panic(errors.Wrap(err, "Error preloading boards migrations. Check if you have &multiStatements=true in your DSN if you are using MySQL. Or perhaps the schema changed? If yes, then update the warmup files accordingly"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (h *MainHelper) Close() error {
|
||||
|
||||
@@ -68,7 +68,6 @@ func Setup(tb testing.TB) *TestHelper {
|
||||
}
|
||||
store := mainHelper.GetStore()
|
||||
store.DropAllTables()
|
||||
mainHelper.PreloadBoardsMigrationsIfNeeded()
|
||||
return setupTestHelper(tb, true, nil)
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user