Doug Lauder
2023-03-22 17:22:27 -04:00
коммит произвёл GitHub
родитель b61c096497
Коммит c943ed6859
13276 изменённых файлов: 1695615 добавлений и 223189 удалений

Просмотреть файл

@@ -0,0 +1,51 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package migrationstests
import (
"testing"
"github.com/mattermost/mattermost-server/v6/server/boards/services/store/sqlstore"
"github.com/mgdelacroix/foundation"
"github.com/stretchr/testify/require"
)
func TestDeletedMembershipBoardsMigration(t *testing.T) {
sqlstore.RunStoreTestsWithFoundation(t, func(t *testing.T, f *foundation.Foundation) {
t.Run("should detect a board linked to a team in which the owner has a deleted membership and restore it", func(t *testing.T) {
th, tearDown := SetupTestHelper(t, f)
defer tearDown()
th.f.MigrateToStepSkippingLastInterceptor(18).
ExecFile("./fixtures/deletedMembershipBoardsMigrationFixtures.sql")
boardGroupChannel := struct {
Created_By string
Team_ID string
}{}
boardDirectMessage := struct {
Created_By string
Team_ID string
}{}
th.f.DB().Get(&boardGroupChannel, "SELECT created_by, team_id FROM focalboard_boards WHERE id = 'board-group-channel'")
require.Equal(t, "user-one", boardGroupChannel.Created_By)
require.Equal(t, "team-one", boardGroupChannel.Team_ID)
th.f.DB().Get(&boardDirectMessage, "SELECT created_by, team_id FROM focalboard_boards WHERE id = 'board-group-channel'")
require.Equal(t, "user-one", boardDirectMessage.Created_By)
require.Equal(t, "team-one", boardDirectMessage.Team_ID)
th.f.RunInterceptor(18)
th.f.DB().Get(&boardGroupChannel, "SELECT created_by, team_id FROM focalboard_boards WHERE id = 'board-group-channel'")
require.Equal(t, "user-one", boardGroupChannel.Created_By)
require.Equal(t, "team-three", boardGroupChannel.Team_ID)
th.f.DB().Get(&boardDirectMessage, "SELECT created_by, team_id FROM focalboard_boards WHERE id = 'board-group-channel'")
require.Equal(t, "user-one", boardDirectMessage.Created_By)
require.Equal(t, "team-three", boardDirectMessage.Team_ID)
})
})
}

Просмотреть файл

@@ -0,0 +1,47 @@
INSERT INTO Teams
(Id, Name, Type, DeleteAt)
VALUES
('team-one', 'team-one', 'O', 0),
('team-two', 'team-two', 'O', 0),
('team-three', 'team-three', 'O', 0);
INSERT INTO Channels
(Id, DeleteAt, TeamId, Type, Name, CreatorId)
VALUES
('group-channel', 0, 'team-one', 'G', 'group-channel', 'user-one'),
('direct-channel', 0, 'team-one', 'D', 'direct-channel', 'user-one');
INSERT INTO Users
(Id, Username, Email)
VALUES
('user-one', 'john-doe', 'john-doe@sample.com'),
('user-two', 'jane-doe', 'jane-doe@sample.com');
INSERT INTO focalboard_boards
(id, team_id, channel_id, created_by, modified_by, type, title, description, icon, show_description, is_template, create_at, update_at, delete_at)
VALUES
('board-group-channel', 'team-one', 'group-channel', 'user-one', 'user-one', 'P', 'Group Channel Board', '', '', false, false, 123, 123, 0),
('board-direct-channel', 'team-one', 'direct-channel', 'user-one', 'user-one', 'P', 'Direct Channel Board', '', '', false, false, 123, 123, 0);
INSERT INTO focalboard_board_members
(board_id, user_id, scheme_admin)
VALUES
('board-group-channel', 'user-one', true),
('board-direct-channel', 'user-one', true);
INSERT INTO TeamMembers
(TeamId, UserId, DeleteAt, SchemeAdmin)
VALUES
('team-one', 'user-one', 123, true),
('team-one', 'user-two', 123, true),
('team-two', 'user-one', 123, true),
('team-two', 'user-two', 123, true),
('team-three', 'user-one', 0, true),
('team-three', 'user-two', 0, true);
INSERT INTO ChannelMembers
(ChannelId, UserId, SchemeUser, SchemeAdmin)
VALUES
('group-channel', 'user-one', true, true),
('group-channel', 'two-one', true, false),
('direct-channel', 'user-one', true, true);

Просмотреть файл

@@ -0,0 +1,10 @@
INSERT INTO Channels (Id, CreateAt, UpdateAt, DeleteAt, TeamId, Type, Name, CreatorId) VALUES ('chan-id', 123, 123, 0, 'team-id', 'O', 'channel', 'user-id');
INSERT INTO focalboard_blocks
(id, workspace_id, root_id, parent_id, created_by, modified_by, type, title, create_at, update_at, delete_at, fields)
VALUES
('board-id', 'chan-id', 'board-id', 'board-id', 'user-id', 'user-id', 'board', 'My Board', 123, 123, 0, '{"columnCalculations": {"__title":"countUniqueValue"}}'),
('card-id', 'chan-id', 'board-id', 'board-id', 'user-id', 'user-id', 'card', 'A card', 123, 123, 0, '{}'),
('view-id', 'chan-id', 'board-id', 'board-id', 'user-id', 'user-id', 'view', 'A view', 123, 123, 0, '{"viewType":"table"}'),
('view-id2', 'chan-id', 'board-id', 'board-id', 'user-id', 'user-id', 'view', 'A view2', 123, 123, 0, '{"viewType":"board"}'),
('board-id2', 'chan-id', 'board-id2', 'board-id2', 'user-id', 'user-id', 'board', 'My Board Two', 123, 123, 0, '{"description": "My Description","showDescription":true,"isTemplate":true,"templateVer":1,"columnCalculations":[]}');

Просмотреть файл

@@ -0,0 +1,5 @@
INSERT INTO focalboard_boards
(id, title, type, is_template, channel_id, team_id)
VALUES
('board-id', 'Board', 'O', false, 'linked-channel', 'team-id'),
('template-id', 'Template', 'O', true, 'linked-channel', 'team-id');

Просмотреть файл

@@ -0,0 +1,6 @@
INSERT INTO focalboard_category_boards values
('id-1', 'user_id-1', 'category-id-1', 'board-id-1', 1672988834402, 1672988834402, 0, 0),
('id-2', 'user_id-1', 'category-id-2', 'board-id-1', 1672988834402, 1672988834402, 0, 0),
('id-3', 'user_id-2', 'category-id-3', 'board-id-2', 1672988834402, 1672988834402, 1672988834402, 0),
('id-4', 'user_id-2', 'category-id-3', 'board-id-4', 1672988834402, 1672988834402, 0, 0),
('id-5', 'user_id-3', 'category-id-4', 'board-id-3', 1672988834402, 1672988834402, 1672988834402, 0);

Просмотреть файл

@@ -0,0 +1,6 @@
INSERT INTO focalboard_category_boards values
('id-1', 'user_id-1', 'category-id-1', 'board-id-1', 1672988834402, 1672988834402, 0, 0),
('id-2', 'user_id-1', 'category-id-2', 'board-id-1', 1672988834402, 1672988834402, 0, 0),
('id-3', 'user_id-2', 'category-id-3', 'board-id-2', 1672988834402, 1672988834402, 0, 0),
('id-4', 'user_id-2', 'category-id-3', 'board-id-4', 1672988834402, 1672988834402, 0, 0),
('id-5', 'user_id-3', 'category-id-4', 'board-id-3', 1672988834402, 1672988834402, 0, 0);

Просмотреть файл

@@ -0,0 +1 @@
ALTER TABLE focalboard_category_boards DROP COLUMN delete_at;

Просмотреть файл

@@ -0,0 +1 @@
ALTER TABLE focalboard_category_boards ADD COLUMN hidden boolean;

Просмотреть файл

Просмотреть файл

@@ -0,0 +1,10 @@
INSERT INTO focalboard_category_boards VALUES
('id-1', 'user-id-1', 'category-id-1', 'board-id-1', 1672889246832, 1672889246832, 0, false),
('id-2', 'user-id-1', 'category-id-2', 'board-id-2', 1672889246832, 1672889246832, 0, false),
('id-3', 'user-id-2', 'category-id-3', 'board-id-3', 1672889246832, 1672889246832, 0, false),
('id-4', 'user-id-2', 'category-id-3', 'board-id-4', 1672889246832, 1672889246832, 0, false),
('id-5', 'user-id-3', 'category-id-4', 'board-id-5', 1672889246832, 1672889246832, 0, false);
INSERT INTO Preferences VALUES
('user-id-1', 'focalboard', 'hiddenBoardIDs', '["board-id-1"]'),
('user-id-2', 'focalboard', 'hiddenBoardIDs', '["board-id-3", "board-id-4"]');

Просмотреть файл

@@ -0,0 +1,6 @@
INSERT INTO focalboard_category_boards VALUES
('id-1', 'user-id-1', 'category-id-1', 'board-id-1', 1672889246832, 1672889246832, 0, false),
('id-2', 'user-id-1', 'category-id-2', 'board-id-2', 1672889246832, 1672889246832, 0, false),
('id-3', 'user-id-2', 'category-id-3', 'board-id-3', 1672889246832, 1672889246832, 0, false),
('id-4', 'user-id-2', 'category-id-3', 'board-id-4', 1672889246832, 1672889246832, 0, false),
('id-5', 'user-id-3', 'category-id-4', 'board-id-5', 1672889246832, 1672889246832, 0, false);

Просмотреть файл

@@ -0,0 +1,10 @@
INSERT INTO focalboard_category_boards VALUES
('id-1', 'user-id-1', 'category-id-1', 'board-id-1', 1672889246832, 1672889246832, 0, false),
('id-2', 'user-id-1', 'category-id-2', 'board-id-2', 1672889246832, 1672889246832, 0, false),
('id-3', 'user-id-2', 'category-id-3', 'board-id-3', 1672889246832, 1672889246832, 0, false),
('id-4', 'user-id-2', 'category-id-3', 'board-id-4', 1672889246832, 1672889246832, 0, false),
('id-5', 'user-id-3', 'category-id-4', 'board-id-5', 1672889246832, 1672889246832, 0, false);
INSERT INTO Preferences VALUES
('user-id-1', 'focalboard', 'hiddenBoardIDs', ''),
('user-id-2', 'focalboard', 'hiddenBoardIDs', '');

Просмотреть файл

@@ -0,0 +1,5 @@
INSERT INTO Preferences VALUES
('user-id-1', 'focalboard', 'hiddenBoardIDs', '["board-id-1"]'),
('user-id-2', 'focalboard', 'hiddenBoardIDs', '["board-id-3", "board-id-4"]'),
('user-id-3', 'lorem', 'lorem', ''),
('user-id-4', 'ipsum', 'ipsum', '');

Просмотреть файл

@@ -0,0 +1,33 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package migrationstests
import (
"testing"
"github.com/mgdelacroix/foundation"
)
type TestHelper struct {
t *testing.T
f *foundation.Foundation
}
func (th *TestHelper) IsPostgres() bool {
return th.f.DB().DriverName() == "postgres"
}
func (th *TestHelper) IsMySQL() bool {
return th.f.DB().DriverName() == "mysql"
}
func SetupTestHelper(t *testing.T, f *foundation.Foundation) (*TestHelper, func()) {
th := &TestHelper{t, f}
tearDown := func() {
th.f.TearDown()
}
return th, tearDown
}

Просмотреть файл

@@ -0,0 +1,60 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package migrationstests
import (
"testing"
"github.com/mattermost/mattermost-server/v6/server/boards/services/store/sqlstore"
"github.com/mgdelacroix/foundation"
"github.com/stretchr/testify/require"
)
func Test34DropDeleteAtColumn(t *testing.T) {
sqlstore.RunStoreTestsWithFoundation(t, func(t *testing.T, f *foundation.Foundation) {
t.Run("column exists", func(t *testing.T) {
th, tearDown := SetupTestHelper(t, f)
defer tearDown()
th.f.MigrateToStep(34)
// migration 34 only works for MySQL and PostgreSQL
if th.IsMySQL() {
var count int
query := "SELECT COUNT(column_name) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'focalboard_category_boards' AND column_name = 'delete_at'"
th.f.DB().Get(&count, query)
require.Equal(t, 0, count)
} else if th.IsPostgres() {
var count int
query := "select count(*) from information_schema.columns where table_name = 'focalboard_category_boards' and column_name = 'delete_at'"
th.f.DB().Get(&count, query)
require.Equal(t, 0, count)
}
})
})
sqlstore.RunStoreTestsWithFoundation(t, func(t *testing.T, f *foundation.Foundation) {
t.Run("column already deleted", func(t *testing.T) {
th, tearDown := SetupTestHelper(t, f)
defer tearDown()
th.f.MigrateToStep(33).
ExecFile("./fixtures/test34_drop_delete_at_column.sql")
th.f.MigrateToStep(34)
if th.IsMySQL() {
var count int
query := "SELECT COUNT(column_name) FROM INFORMATION_SCHEMA.COLUMNS WHERE WHERE table_schema = DATABASE() table_name = 'focalboard_category_boards' AND column_name = 'delete_at'"
th.f.DB().Get(&count, query)
require.Equal(t, 0, count)
} else if th.IsPostgres() {
var count int
query := "select count(*) from information_schema.columns where table_name = 'focalboard_category_boards' and column_name = 'delete_at'"
th.f.DB().Get(&count, query)
require.Equal(t, 0, count)
}
})
})
}

Просмотреть файл

@@ -0,0 +1,33 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package migrationstests
import (
"testing"
"github.com/mattermost/mattermost-server/v6/server/boards/services/store/sqlstore"
"github.com/mgdelacroix/foundation"
)
func Test35AddHiddenColumnToCategoryBoards(t *testing.T) {
sqlstore.RunStoreTestsWithFoundation(t, func(t *testing.T, f *foundation.Foundation) {
t.Run("base case - column doesn't already exist", func(t *testing.T) {
th, tearDown := SetupTestHelper(t, f)
defer tearDown()
th.f.MigrateToStep(35)
})
})
sqlstore.RunStoreTestsWithFoundation(t, func(t *testing.T, f *foundation.Foundation) {
t.Run("column already exist", func(t *testing.T) {
th, tearDown := SetupTestHelper(t, f)
defer tearDown()
th.f.MigrateToStep(34).
ExecFile("./fixtures/test35_add_hidden_column.sql")
th.f.MigrateToStep(35)
})
})
}

Просмотреть файл

@@ -0,0 +1,76 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package migrationstests
import (
"testing"
"github.com/mattermost/mattermost-server/v6/server/boards/services/store/sqlstore"
"github.com/mgdelacroix/foundation"
"github.com/stretchr/testify/require"
)
func Test36AddUniqueConstraintToCategoryBoards(t *testing.T) {
sqlstore.RunStoreTestsWithFoundation(t, func(t *testing.T, f *foundation.Foundation) {
t.Run("constraint doesn't alreadt exists", func(t *testing.T) {
th, tearDown := SetupTestHelper(t, f)
defer tearDown()
th.f.MigrateToStep(36)
// verifying if constraint has been added
var schema string
if th.IsMySQL() {
schema = "DATABASE()"
} else if th.IsPostgres() {
schema = "'public'"
}
var count int
query := "SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS " +
"WHERE constraint_schema = " + schema + " " +
"AND constraint_name = 'unique_user_category_board' " +
"AND constraint_type = 'UNIQUE' " +
"AND table_name = 'focalboard_category_boards'"
th.f.DB().Get(&count, query)
require.Equal(t, 1, count)
})
})
sqlstore.RunStoreTestsWithFoundation(t, func(t *testing.T, f *foundation.Foundation) {
t.Run("constraint already exists", func(t *testing.T) {
th, tearDown := SetupTestHelper(t, f)
defer tearDown()
th.f.MigrateToStep(35)
if th.IsMySQL() {
th.f.DB().Exec("alter table focalboard_category_boards add constraint unique_user_category_board UNIQUE(user_id, board_id);")
} else if th.IsPostgres() {
th.f.DB().Exec("ALTER TABLE focalboard_category_boards ADD CONSTRAINT unique_user_category_board UNIQUE(user_id, board_id);")
}
th.f.MigrateToStep(36)
var schema string
if th.IsMySQL() {
schema = "DATABASE()"
} else if th.IsPostgres() {
schema = "'public'"
}
var count int
query := "SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS " +
"WHERE constraint_schema = " + schema + " " +
"AND constraint_name = 'unique_user_category_board' " +
"AND constraint_type = 'UNIQUE' " +
"AND table_name = 'focalboard_category_boards'"
th.f.DB().Get(&count, query)
require.Equal(t, 1, count)
})
})
}

Просмотреть файл

@@ -0,0 +1,87 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package migrationstests
import (
"testing"
"github.com/mattermost/mattermost-server/v6/server/boards/services/store/sqlstore"
"github.com/mgdelacroix/foundation"
"github.com/stretchr/testify/require"
)
func Test37MigrateHiddenBoardIDTest(t *testing.T) {
sqlstore.RunStoreTestsWithFoundation(t, func(t *testing.T, f *foundation.Foundation) {
t.Run("no existing hidden boards exist", func(t *testing.T) {
th, tearDown := SetupTestHelper(t, f)
defer tearDown()
th.f.MigrateToStep(37)
})
})
sqlstore.RunStoreTestsWithFoundation(t, func(t *testing.T, f *foundation.Foundation) {
t.Run("existsing category boards with some hidden boards", func(t *testing.T) {
th, tearDown := SetupTestHelper(t, f)
defer tearDown()
th.f.MigrateToStep(36).
ExecFile("./fixtures/test37_valid_data.sql")
th.f.MigrateToStep(37)
type categoryBoard struct {
User_ID string
Category_ID string
Board_ID string
Hidden bool
}
var hiddenCategoryBoards []categoryBoard
query := "SELECT user_id, category_id, board_id, hidden FROM focalboard_category_boards WHERE hidden = true"
err := th.f.DB().Select(&hiddenCategoryBoards, query)
require.NoError(t, err)
require.Equal(t, 3, len(hiddenCategoryBoards))
require.Contains(t, hiddenCategoryBoards, categoryBoard{User_ID: "user-id-1", Category_ID: "category-id-1", Board_ID: "board-id-1", Hidden: true})
require.Contains(t, hiddenCategoryBoards, categoryBoard{User_ID: "user-id-2", Category_ID: "category-id-3", Board_ID: "board-id-3", Hidden: true})
require.Contains(t, hiddenCategoryBoards, categoryBoard{User_ID: "user-id-2", Category_ID: "category-id-3", Board_ID: "board-id-4", Hidden: true})
})
})
sqlstore.RunStoreTestsWithFoundation(t, func(t *testing.T, f *foundation.Foundation) {
t.Run("no hidden boards", func(t *testing.T) {
th, tearDown := SetupTestHelper(t, f)
defer tearDown()
th.f.MigrateToStep(36).
ExecFile("./fixtures/test37_valid_data_no_hidden_boards.sql")
th.f.MigrateToStep(37)
var count int
query := "SELECT count(*) FROM focalboard_category_boards WHERE hidden = true"
err := th.f.DB().Get(&count, query)
require.NoError(t, err)
require.Equal(t, 0, count)
})
})
sqlstore.RunStoreTestsWithFoundation(t, func(t *testing.T, f *foundation.Foundation) {
t.Run("preference but no hidden board", func(t *testing.T) {
th, tearDown := SetupTestHelper(t, f)
defer tearDown()
th.f.MigrateToStep(36).
ExecFile("./fixtures/test37_valid_data_preference_but_no_hidden_board.sql")
th.f.MigrateToStep(37)
var count int
query := "SELECT count(*) FROM focalboard_category_boards WHERE hidden = true"
err := th.f.DB().Get(&count, query)
require.NoError(t, err)
require.Equal(t, 0, count)
})
})
}

Просмотреть файл

@@ -0,0 +1,45 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package migrationstests
import (
"testing"
"github.com/mattermost/mattermost-server/v6/server/boards/services/store/sqlstore"
"github.com/mgdelacroix/foundation"
"github.com/stretchr/testify/require"
)
func Test38RemoveHiddenBoardIDsFromPreferences(t *testing.T) {
sqlstore.RunStoreTestsWithFoundation(t, func(t *testing.T, f *foundation.Foundation) {
t.Run("no data exist", func(t *testing.T) {
th, tearDown := SetupTestHelper(t, f)
defer tearDown()
th.f.MigrateToStep(38)
})
})
sqlstore.RunStoreTestsWithFoundation(t, func(t *testing.T, f *foundation.Foundation) {
t.Run("some data exist", func(t *testing.T) {
th, tearDown := SetupTestHelper(t, f)
defer tearDown()
th.f.MigrateToStep(37).
ExecFile("./fixtures/test38_add_preferences.sql")
// verify existing data count
var count int
countQuery := "SELECT COUNT(*) FROM Preferences"
err := th.f.DB().Get(&count, countQuery)
require.NoError(t, err)
require.Equal(t, 4, count)
th.f.MigrateToStep(38)
// now the count should be 0
err = th.f.DB().Get(&count, countQuery)
require.NoError(t, err)
require.Equal(t, 2, count)
})
})
}

Просмотреть файл

@@ -0,0 +1,113 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package migrationstests
import (
"encoding/json"
"testing"
"github.com/mattermost/mattermost-server/v6/server/boards/services/store/sqlstore"
"github.com/mgdelacroix/foundation"
"github.com/stretchr/testify/require"
)
func Test18AddTeamsAndBoardsSQLMigration(t *testing.T) {
sqlstore.RunStoreTestsWithFoundation(t, func(t *testing.T, f *foundation.Foundation) {
t.Run("should migrate a block of type board to the boards table", func(t *testing.T) {
th, tearDown := SetupTestHelper(t, f)
defer tearDown()
th.f.MigrateToStep(17).
ExecFile("./fixtures/test18AddTeamsAndBoardsSQLMigrationFixtures.sql")
board := struct {
ID string
Title string
Type string
Fields string
Description string
Show_Description bool
Is_Template bool
Template_Version int
}{}
// we check first that the board is inside the blocks table as
// a block of board type and columnCalculations exists if Fields
err := th.f.DB().Get(&board, "SELECT id, title, type, fields FROM focalboard_blocks WHERE id = 'board-id'")
require.NoError(t, err)
require.Equal(t, "My Board", board.Title)
require.Equal(t, "board", board.Type)
require.Contains(t, board.Fields, "columnCalculations")
// we check another board is inside the blocks table as
// a block of board type and has several different properties in boards
err = th.f.DB().Get(&board, "SELECT id, title, type, fields FROM focalboard_blocks WHERE id = 'board-id2'")
require.NoError(t, err)
require.Equal(t, "My Board Two", board.Title)
require.Equal(t, "board", board.Type)
require.Contains(t, board.Fields, "description")
require.Contains(t, board.Fields, "showDescription")
require.Contains(t, board.Fields, "isTemplate")
require.Contains(t, board.Fields, "templateVer")
// then we run the migration
th.f.MigrateToStep(18)
// we assert that the board is now in the boards table
bErr := th.f.DB().Get(&board, "SELECT id, title, type FROM focalboard_boards WHERE id = 'board-id'")
require.NoError(t, bErr)
require.Equal(t, "My Board", board.Title)
require.Equal(t, "O", board.Type)
card := struct {
Title string
Type string
Parent_ID string
Board_ID string
}{}
// we fetch the card to ensure that the card is still in the blocks table
cErr := th.f.DB().Get(&card, "SELECT title, type, parent_id, board_id FROM focalboard_blocks WHERE id = 'card-id'")
require.NoError(t, cErr)
require.Equal(t, "A card", card.Title)
require.Equal(t, "card", card.Type)
require.Equal(t, board.ID, card.Parent_ID)
require.Equal(t, board.ID, card.Board_ID)
// we assert that the board is now a board and properties from JSON Fields
dErr := th.f.DB().Get(&board, "SELECT id, title, type, description, show_description, is_template, template_version FROM focalboard_boards WHERE id = 'board-id2'")
require.NoError(t, dErr)
require.Equal(t, "My Board Two", board.Title)
require.Equal(t, "O", board.Type)
require.Equal(t, "My Description", board.Description)
require.Equal(t, true, board.Show_Description)
require.Equal(t, true, board.Is_Template)
require.Equal(t, 1, board.Template_Version)
view := struct {
Title string
Type string
Parent_ID string
Board_ID string
Fields string
}{}
// we fetch the views to ensure that the calculation columns exist on views
eErr := th.f.DB().Get(&view, "SELECT title, type, parent_id, board_id, fields FROM focalboard_blocks WHERE id = 'view-id'")
require.NoError(t, eErr)
require.Contains(t, view.Fields, "columnCalculations")
var fields map[string]interface{}
// Make sure a valid JSON object
json.Unmarshal([]byte(view.Fields), &fields)
require.NotNil(t, fields["columnCalculations"])
require.NotEmpty(t, fields["columnCalculations"])
// Board View should not have columnCalculations
fErr := th.f.DB().Get(&view, "SELECT title, type, parent_id, board_id, fields FROM focalboard_blocks WHERE id = 'view-id2'")
require.NoError(t, fErr)
require.NotContains(t, view.Fields, "columnCalculations")
})
})
}

Просмотреть файл

@@ -0,0 +1,62 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package migrationstests
import (
"testing"
"github.com/mattermost/mattermost-server/v6/server/boards/services/store/sqlstore"
"github.com/mgdelacroix/foundation"
"github.com/stretchr/testify/require"
)
func Test28RemoveTemplateChannelLink(t *testing.T) {
sqlstore.RunStoreTestsWithFoundation(t, func(t *testing.T, f *foundation.Foundation) {
t.Run("should correctly remove the channel link from templates", func(t *testing.T) {
th, tearDown := SetupTestHelper(t, f)
defer tearDown()
th.f.MigrateToStep(27).
ExecFile("./fixtures/test28RemoveTemplateChannelLink.sql")
// first we check that the data has the expected shape
board := struct {
ID string
Is_template bool
Channel_id string
}{}
template := struct {
ID string
Is_template bool
Channel_id string
}{}
bErr := th.f.DB().Get(&board, "SELECT id, is_template, channel_id FROM focalboard_boards WHERE id = 'board-id'")
require.NoError(t, bErr)
require.False(t, board.Is_template)
require.Equal(t, "linked-channel", board.Channel_id)
tErr := th.f.DB().Get(&template, "SELECT id, is_template, channel_id FROM focalboard_boards WHERE id = 'template-id'")
require.NoError(t, tErr)
require.True(t, template.Is_template)
require.Equal(t, "linked-channel", template.Channel_id)
// we apply the migration
th.f.MigrateToStep(28)
// then we reuse the structs to load again the data and check
// that the changes were correctly applied
bErr = th.f.DB().Get(&board, "SELECT id, is_template, channel_id FROM focalboard_boards WHERE id = 'board-id'")
require.NoError(t, bErr)
require.False(t, board.Is_template)
require.Equal(t, "linked-channel", board.Channel_id)
tErr = th.f.DB().Get(&template, "SELECT id, is_template, channel_id FROM focalboard_boards WHERE id = 'template-id'")
require.NoError(t, tErr)
require.True(t, template.Is_template)
require.Empty(t, template.Channel_id)
})
})
}

Просмотреть файл

@@ -0,0 +1,75 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package migrationstests
import (
"testing"
"github.com/mgdelacroix/foundation"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/v6/server/boards/services/store/sqlstore"
)
func Test33RemoveDeletedCategoryBoards(t *testing.T) {
sqlstore.RunStoreTestsWithFoundation(t, func(t *testing.T, f *foundation.Foundation) {
t.Run("base case - no data in table", func(t *testing.T) {
th, tearDown := SetupTestHelper(t, f)
defer tearDown()
th.f.MigrateToStep(33)
})
})
sqlstore.RunStoreTestsWithFoundation(t, func(t *testing.T, f *foundation.Foundation) {
t.Run("existing data - 2 soft deleted records", func(t *testing.T) {
th, tearDown := SetupTestHelper(t, f)
defer tearDown()
th.f.MigrateToStep(32).
ExecFile("./fixtures/test33_with_deleted_data.sql")
// cound total records
var count int
err := th.f.DB().Get(&count, "SELECT COUNT(*) FROM focalboard_category_boards")
require.NoError(t, err)
require.Equal(t, 5, count)
// now we run the migration
th.f.MigrateToStep(33)
// and verify record count again.
// The soft deleted records should have been removed from the DB now
err = th.f.DB().Get(&count, "SELECT COUNT(*) FROM focalboard_category_boards")
require.NoError(t, err)
require.Equal(t, 3, count)
})
})
sqlstore.RunStoreTestsWithFoundation(t, func(t *testing.T, f *foundation.Foundation) {
t.Run("existing data - no soft deleted records", func(t *testing.T) {
th, tearDown := SetupTestHelper(t, f)
defer tearDown()
th.f.MigrateToStep(32).
ExecFile("./fixtures/test33_with_no_deleted_data.sql")
// cound total records
var count int
err := th.f.DB().Get(&count, "SELECT COUNT(*) FROM focalboard_category_boards")
require.NoError(t, err)
require.Equal(t, 5, count)
// now we run the migration
th.f.MigrateToStep(33)
// and verify record count again.
// Since there were no soft-deleted records, nothing should have been
// deleted from the database.
err = th.f.DB().Get(&count, "SELECT COUNT(*) FROM focalboard_category_boards")
require.NoError(t, err)
require.Equal(t, 5, count)
})
})
}