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:
parent
3f49be606b
commit
d6e494ca29
@ -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) {
|
||||
return s.getBoardsFieldsByCondition(db, boardFields(""), conditions...)
|
||||
}
|
||||
|
||||
func (s *SQLStore) getBoardsFieldsByCondition(db sq.BaseRunner, fields []string, conditions ...interface{}) ([]*model.Board, error) {
|
||||
query := s.getQueryBuilder(db).
|
||||
Select(boardFields("")...).
|
||||
Select(fields...).
|
||||
From(s.tablePrefix + "boards")
|
||||
for _, c := range conditions {
|
||||
query = query.Where(c)
|
||||
|
@ -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) {
|
||||
return []*model.Board{}, nil
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package sqlstore
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/focalboard/server/utils"
|
||||
|
||||
@ -12,6 +13,46 @@ import (
|
||||
"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
|
||||
// the old block model. This method is kept to enable the unique IDs
|
||||
// data migration.
|
||||
@ -206,3 +247,7 @@ func (s *SQLStore) insertLegacyBlock(db sq.BaseRunner, workspaceID string, block
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SQLStore) getLegacyBoardsByCondition(db sq.BaseRunner, conditions ...interface{}) ([]*model.Board, error) {
|
||||
return s.getBoardsFieldsByCondition(db, legacyBoardFields(""), conditions...)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user