1
0
mirror of https://github.com/mattermost/focalboard.git synced 2025-01-08 15:06:08 +02:00

Fixed a bug where migrations didn't run on a clean DB (#3104)

This commit is contained in:
Harshil Sharma 2022-05-24 13:10:34 +05:30 committed by GitHub
parent 3f49be606b
commit d6e494ca29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 2 deletions

View File

@ -216,8 +216,12 @@ func (s *SQLStore) getBoardByCondition(db sq.BaseRunner, conditions ...interface
} }
func (s *SQLStore) getBoardsByCondition(db sq.BaseRunner, conditions ...interface{}) ([]*model.Board, error) { func (s *SQLStore) getBoardsByCondition(db sq.BaseRunner, conditions ...interface{}) ([]*model.Board, error) {
return s.getBoardsFieldsByCondition(db, boardFields(""), conditions...)
}
func (s *SQLStore) getBoardsFieldsByCondition(db sq.BaseRunner, fields []string, conditions ...interface{}) ([]*model.Board, error) {
query := s.getQueryBuilder(db). query := s.getQueryBuilder(db).
Select(boardFields("")...). Select(fields...).
From(s.tablePrefix + "boards") From(s.tablePrefix + "boards")
for _, c := range conditions { for _, c := range conditions {
query = query.Where(c) query = query.Where(c)

View File

@ -386,7 +386,7 @@ func (s *SQLStore) getDMBoards(tx sq.BaseRunner) ([]*model.Board, error) {
}, },
} }
boards, err := s.getBoardsByCondition(tx, conditions) boards, err := s.getLegacyBoardsByCondition(tx, conditions)
if err != nil && model.IsErrNotFound(err) { if err != nil && model.IsErrNotFound(err) {
return []*model.Board{}, nil return []*model.Board{}, nil
} }

View File

@ -3,6 +3,7 @@ package sqlstore
import ( import (
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"strings"
"github.com/mattermost/focalboard/server/utils" "github.com/mattermost/focalboard/server/utils"
@ -12,6 +13,46 @@ import (
"github.com/mattermost/mattermost-server/v6/shared/mlog" "github.com/mattermost/mattermost-server/v6/shared/mlog"
) )
func legacyBoardFields(prefix string) []string {
// substitute new columns with `"\"\""` (empty string) so as to allow
// row scan to continue to work with new models.
fields := []string{
"id",
"team_id",
"COALESCE(channel_id, '')",
"COALESCE(created_by, '')",
"modified_by",
"type",
"\"\"", // substitute for minimum_role column.
"title",
"description",
"icon",
"show_description",
"is_template",
"template_version",
"COALESCE(properties, '{}')",
"COALESCE(card_properties, '[]')",
"create_at",
"update_at",
"delete_at",
}
if prefix == "" {
return fields
}
prefixedFields := make([]string, len(fields))
for i, field := range fields {
if strings.HasPrefix(field, "COALESCE(") {
prefixedFields[i] = strings.Replace(field, "COALESCE(", "COALESCE("+prefix, 1)
} else {
prefixedFields[i] = prefix + field
}
}
return prefixedFields
}
// legacyBlocksFromRows is the old getBlock version that still uses // legacyBlocksFromRows is the old getBlock version that still uses
// the old block model. This method is kept to enable the unique IDs // the old block model. This method is kept to enable the unique IDs
// data migration. // data migration.
@ -206,3 +247,7 @@ func (s *SQLStore) insertLegacyBlock(db sq.BaseRunner, workspaceID string, block
return nil return nil
} }
func (s *SQLStore) getLegacyBoardsByCondition(db sq.BaseRunner, conditions ...interface{}) ([]*model.Board, error) {
return s.getBoardsFieldsByCondition(db, legacyBoardFields(""), conditions...)
}