Update teamless boards migration to check for deleted entities (#3613)

* Update teamless boards migration to check for deleted entities

After this changes, the `TeamLessBoardsMigration` will check the team
and the team membership of the users to discard deleted entities when
cosidering what team to assign a board to

* Fix linter
This commit is contained in:
Miguel de la Cruz 2022-08-09 13:04:03 +02:00 committed by GitHub
parent b7a35364fb
commit ad3eb4ba8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View file

@ -347,7 +347,7 @@ func (s *SQLStore) createCategoryBoards(db sq.BaseRunner) 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 (s *SQLStore) migrateTeamLessBoards() error {
func (s *SQLStore) runTeamLessBoardsMigration() error {
if !s.isPlugin {
return nil
}
@ -376,7 +376,7 @@ func (s *SQLStore) migrateTeamLessBoards() error {
tx, err := s.db.BeginTx(context.Background(), nil)
if err != nil {
s.logger.Error("error starting transaction in migrateTeamLessBoards", mlog.Err(err))
s.logger.Error("error starting transaction in runTeamLessBoardsMigration", mlog.Err(err))
return err
}
@ -417,7 +417,7 @@ func (s *SQLStore) migrateTeamLessBoards() error {
}
if err := tx.Commit(); err != nil {
s.logger.Error("failed to commit migrateTeamLessBoards transaction", mlog.Err(err))
s.logger.Error("failed to commit runTeamLessBoardsMigration transaction", mlog.Err(err))
return err
}
@ -514,10 +514,15 @@ func (s *SQLStore) getBestTeamForBoard(tx sq.BaseRunner, board *model.Board) (st
func (s *SQLStore) getBoardUserTeams(tx sq.BaseRunner, board *model.Board) (map[string][]string, error) {
query := s.getQueryBuilder(tx).
Select("TeamMembers.UserId", "TeamMembers.TeamId").
From("ChannelMembers").
Join("TeamMembers ON ChannelMembers.UserId = TeamMembers.UserId").
Where(sq.Eq{"ChannelId": board.ChannelID})
Select("tm.UserId", "tm.TeamId").
From("ChannelMembers cm").
Join("TeamMembers tm ON cm.UserId = tm.UserId").
Join("Teams t ON tm.TeamId = t.Id").
Where(sq.Eq{
"cm.ChannelId": board.ChannelID,
"t.DeleteAt": 0,
"tm.DeleteAt": 0,
})
rows, err := query.Query()
if err != nil {

View file

@ -237,7 +237,7 @@ func (s *SQLStore) Migrate() error {
return mErr
}
if mErr := s.migrateTeamLessBoards(); mErr != nil {
if mErr := s.runTeamLessBoardsMigration(); mErr != nil {
return mErr
}