[MM-29217] Remove Posts.ParentId (#17923)

Этот коммит содержится в:
Claudio Costa
2021-08-17 10:25:22 +02:00
коммит произвёл GitHub
родитель 757dc96461
Коммит d181ae9262
34 изменённых файлов: 22 добавлений и 211 удалений

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

@@ -414,7 +414,6 @@ func listCommandAutocompleteSuggestions(c *Context, w http.ResponseWriter, r *ht
ChannelId: query.Get("channel_id"),
TeamId: c.Params.TeamId,
RootId: query.Get("root_id"),
ParentId: query.Get("parent_id"),
UserId: c.AppContext.Session().UserId,
T: c.AppContext.T,
Session: *c.AppContext.Session(),

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

@@ -47,7 +47,6 @@ func TestCreatePost(t *testing.T) {
require.Nil(t, rpost.GetProp(model.PropsAddChannelMember), "newly created post shouldn't have Props['add_channel_member'] set")
post.RootId = rpost.Id
post.ParentId = rpost.Id
_, _, err2 = client.CreatePost(post)
require.NoError(t, err2)
@@ -56,12 +55,6 @@ func TestCreatePost(t *testing.T) {
require.Error(t, err2)
CheckBadRequestStatus(t, resp)
post.RootId = rpost.Id
post.ParentId = "junk"
_, resp, err2 = client.CreatePost(post)
require.Error(t, err2)
CheckBadRequestStatus(t, resp)
post2 := &model.Post{ChannelId: th.BasicChannel2.Id, Message: "zz" + model.NewId() + "a", CreateAt: 123}
rpost2, _, _ := client.CreatePost(post2)
require.NotEqual(t, post2.CreateAt, rpost2.CreateAt, "create at should not match")
@@ -130,7 +123,6 @@ func TestCreatePost(t *testing.T) {
th.RemovePermissionFromRole(model.PermissionUseChannelMentions.Id, model.ChannelUserRoleId)
post.RootId = rpost.Id
post.ParentId = rpost.Id
post.Message = "a post with no channel mentions"
_, _, err = client.CreatePost(post)
require.NoError(t, err)
@@ -148,19 +140,16 @@ func TestCreatePost(t *testing.T) {
}
post.RootId = rpost.Id
post.ParentId = rpost.Id
post.Message = "a post with @channel"
_, _, err = client.CreatePost(post)
require.NoError(t, err)
post.RootId = rpost.Id
post.ParentId = rpost.Id
post.Message = "a post with @all"
_, _, err = client.CreatePost(post)
require.NoError(t, err)
post.RootId = rpost.Id
post.ParentId = rpost.Id
post.Message = "a post with @here"
_, _, err = client.CreatePost(post)
require.NoError(t, err)
@@ -182,7 +171,6 @@ func TestCreatePost(t *testing.T) {
})
post.RootId = ""
post.ParentId = ""
post.Type = model.PostTypeSystemGeneric
_, resp, err := client.CreatePost(post)
require.Error(t, err)
@@ -190,13 +178,11 @@ func TestCreatePost(t *testing.T) {
post.Type = ""
post.RootId = rpost2.Id
post.ParentId = rpost2.Id
_, resp, err = client.CreatePost(post)
require.Error(t, err)
CheckBadRequestStatus(t, resp)
post.RootId = ""
post.ParentId = ""
post.ChannelId = "junk"
_, resp, err = client.CreatePost(post)
require.Error(t, err)
@@ -1703,7 +1689,7 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
post3 := th.CreatePost()
post4 := th.CreatePost()
post5 := th.CreatePost()
replyPost := &model.Post{ChannelId: channelId, Message: model.NewId(), RootId: post4.Id, ParentId: post4.Id}
replyPost := &model.Post{ChannelId: channelId, Message: model.NewId(), RootId: post4.Id}
post6, _, err := client.CreatePost(replyPost)
require.NoError(t, err)
post7, _, err := client.CreatePost(replyPost)
@@ -1907,7 +1893,6 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
ChannelId: channelId,
Message: model.NewId(),
RootId: post4.Id,
ParentId: post4.Id,
})
require.NoError(t, err)
post13 := th.CreatePost()

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

@@ -271,7 +271,6 @@ func TestSendAutoResponseSuccess(t *testing.T) {
if post.Type == model.PostTypeAutoResponder {
autoResponderPostFound = true
assert.Equal(t, savedPost.Id, post.RootId)
assert.Equal(t, savedPost.Id, post.ParentId)
}
}
assert.True(t, autoResponderPostFound)
@@ -304,7 +303,7 @@ func TestSendAutoResponseSuccessOnThread(t *testing.T) {
Message: "zz" + model.NewId() + "a",
UserId: th.BasicUser.Id,
RootId: parentPost.Id,
ParentId: parentPost.Id},
},
th.BasicChannel,
false, true)
@@ -321,7 +320,6 @@ func TestSendAutoResponseSuccessOnThread(t *testing.T) {
if post.Type == model.PostTypeAutoResponder {
autoResponderPostFound = true
assert.Equal(t, savedPost.RootId, post.RootId)
assert.Equal(t, savedPost.ParentId, post.ParentId)
}
}
assert.True(t, autoResponderPostFound)

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

@@ -74,7 +74,6 @@ func (a *App) CreateCommandPost(c *request.Context, post *model.Post, teamID str
}
if (response.ResponseType == "" || response.ResponseType == model.CommandResponseTypeEphemeral) && (response.Text != "" || response.Attachments != nil) {
post.ParentId = ""
a.SendEphemeralPost(post.UserId, post)
}
@@ -570,7 +569,6 @@ func (a *App) HandleCommandResponsePost(c *request.Context, command *model.Comma
post := &model.Post{}
post.ChannelId = args.ChannelId
post.RootId = args.RootId
post.ParentId = args.ParentId
post.UserId = args.UserId
post.Type = response.Type
post.SetProps(response.Props)

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

@@ -267,7 +267,6 @@ func (a *App) getDynamicListArgument(c *request.Context, commandArgs *model.Comm
params.Add("channel_id", commandArgs.ChannelId)
params.Add("team_id", commandArgs.TeamId)
params.Add("root_id", commandArgs.RootId)
params.Add("parent_id", commandArgs.ParentId)
params.Add("user_id", commandArgs.UserId)
params.Add("site_url", commandArgs.SiteURL)

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

@@ -1093,7 +1093,6 @@ func (a *App) importReplies(c *request.Context, data []ReplyImportData, post *mo
}
reply.UserId = user.Id
reply.ChannelId = post.ChannelId
reply.ParentId = post.Id
reply.RootId = post.Id
reply.Message = *replyData.Message
reply.CreateAt = *replyData.CreateAt

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

@@ -569,7 +569,6 @@ func (a *App) sendNoUsersNotifiedByGroupInChannel(sender *model.User, post *mode
ephemeralPost := &model.Post{
UserId: sender.Id,
RootId: post.RootId,
ParentId: post.ParentId,
ChannelId: channel.Id,
Message: T("api.post.check_for_out_of_channel_group_users.message.none", model.StringInterface{"GroupName": group.Name}),
}

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

@@ -53,8 +53,7 @@ func (a *App) CreatePostAsUser(c *request.Context, post *model.Post, currentSess
rp, err := a.CreatePost(c, post, channel, true, setOnline)
if err != nil {
if err.Id == "api.post.create_post.root_id.app_error" ||
err.Id == "api.post.create_post.channel_root_id.app_error" ||
err.Id == "api.post.create_post.parent_id.app_error" {
err.Id == "api.post.create_post.channel_root_id.app_error" {
err.StatusCode = http.StatusBadRequest
}
@@ -75,7 +74,6 @@ func (a *App) CreatePostAsUser(c *request.Context, post *model.Post, currentSess
post.UserId,
&model.Post{
ChannelId: channel.Id,
ParentId: post.ParentId,
RootId: post.RootId,
UserId: post.UserId,
Message: T("api.post.create_post.town_square_read_only"),
@@ -230,7 +228,6 @@ func (a *App) CreatePost(c *request.Context, post *model.Post, channel *model.Ch
ephemeralPost = &model.Post{
UserId: user.Id,
RootId: post.RootId,
ParentId: post.ParentId,
ChannelId: channel.Id,
Message: T("model.post.channel_notifications_disabled_in_channel.message", model.StringInterface{"ChannelName": channel.Name, "Mention": mention}),
Props: model.StringInterface{model.PostPropsMentionHighlightDisabled: true},
@@ -254,17 +251,6 @@ func (a *App) CreatePost(c *request.Context, post *model.Post, channel *model.Ch
if rootPost.RootId != "" {
return nil, model.NewAppError("createPost", "api.post.create_post.root_id.app_error", nil, "", http.StatusBadRequest)
}
if post.ParentId == "" {
post.ParentId = post.RootId
}
if post.RootId != post.ParentId {
parent := parentPostList.Posts[post.ParentId]
if parent == nil {
return nil, model.NewAppError("createPost", "api.post.create_post.parent_id.app_error", nil, "", http.StatusInternalServerError)
}
}
}
post.Hashtags, _ = model.ParseHashtags(post.Message)

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

@@ -346,7 +346,6 @@ func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) {
Message: "asd",
ChannelId: channel.Id,
RootId: rootPost.Id,
ParentId: rootPost.Id,
PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()),
UserId: userInChannel.Id,
CreateAt: 0,
@@ -368,7 +367,6 @@ func TestPostAttachPostToChildPost(t *testing.T) {
Message: "reply one",
ChannelId: channel.Id,
RootId: rootPost.Id,
ParentId: rootPost.Id,
PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()),
UserId: user.Id,
CreateAt: 0,
@@ -381,7 +379,6 @@ func TestPostAttachPostToChildPost(t *testing.T) {
Message: "reply two",
ChannelId: channel.Id,
RootId: res1.Id,
ParentId: res1.Id,
PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()),
UserId: user.Id,
CreateAt: 0,
@@ -394,7 +391,6 @@ func TestPostAttachPostToChildPost(t *testing.T) {
Message: "reply three",
ChannelId: channel.Id,
RootId: rootPost.Id,
ParentId: rootPost.Id,
PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()),
UserId: user.Id,
CreateAt: 0,
@@ -2313,7 +2309,6 @@ func TestReplyToPostWithLag(t *testing.T) {
UserId: th.BasicUser2.Id,
ChannelId: th.BasicChannel.Id,
RootId: root.Id,
ParentId: root.Id,
Message: fmt.Sprintf("@%s", th.BasicUser2.Username),
}, th.BasicChannel, false, true)
require.Nil(t, appErr)

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

@@ -70,10 +70,10 @@ func (cfg *AutoPostCreator) UploadTestFile(c *request.Context) ([]string, error)
}
func (cfg *AutoPostCreator) CreateRandomPost(c *request.Context) (*model.Post, error) {
return cfg.CreateRandomPostNested(c, "", "")
return cfg.CreateRandomPostNested(c, "")
}
func (cfg *AutoPostCreator) CreateRandomPostNested(c *request.Context, parentId, rootId string) (*model.Post, error) {
func (cfg *AutoPostCreator) CreateRandomPostNested(c *request.Context, rootId string) (*model.Post, error) {
var fileIDs []string
if cfg.HasImage {
var err error
@@ -93,7 +93,6 @@ func (cfg *AutoPostCreator) CreateRandomPostNested(c *request.Context, parentId,
post := &model.Post{
ChannelId: cfg.channelid,
UserId: cfg.userid,
ParentId: parentId,
RootId: rootId,
Message: postText,
FileIds: fileIDs,

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

@@ -84,7 +84,6 @@ func (*EchoProvider) DoCommand(a *app.App, c *request.Context, args *model.Comma
post := &model.Post{}
post.ChannelId = args.ChannelId
post.RootId = args.RootId
post.ParentId = args.ParentId
post.Message = message
post.UserId = args.UserId

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

@@ -352,7 +352,7 @@ func (*LoadTestProvider) ThreadedPostCommand(a *app.App, c *request.Context, arg
return &model.CommandResponse{Text: "Failed to create a post", ResponseType: model.CommandResponseTypeEphemeral}, err2
}
for i := 0; i < 1000; i++ {
testPoster.CreateRandomPostNested(c, rpost.Id, rpost.Id)
testPoster.CreateRandomPostNested(c, rpost.Id)
}
return &model.CommandResponse{Text: "Added threaded post", ResponseType: model.CommandResponseTypeEphemeral}, nil

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

@@ -145,7 +145,6 @@ func TestHandleCommandResponsePost(t *testing.T) {
TeamId: th.BasicTeam.Id,
UserId: th.BasicUser.Id,
RootId: "",
ParentId: "",
}
resp := &model.CommandResponse{
@@ -161,7 +160,6 @@ func TestHandleCommandResponsePost(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, args.ChannelId, post.ChannelId)
assert.Equal(t, args.RootId, post.RootId)
assert.Equal(t, args.ParentId, post.ParentId)
assert.Equal(t, args.UserId, post.UserId)
assert.Equal(t, resp.Type, post.Type)
assert.Equal(t, resp.Props, post.GetProps())

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

@@ -792,7 +792,6 @@ func (a *App) CreateCommandWebhook(commandID string, args *model.CommandArgs) (*
UserId: args.UserId,
ChannelId: args.ChannelId,
RootId: args.RootId,
ParentId: args.ParentId,
}
savedHook, err := a.Srv().Store.CommandWebhook().Save(hook)
@@ -844,7 +843,6 @@ func (a *App) HandleCommandWebhook(c *request.Context, hookID string, response *
ChannelId: hook.ChannelId,
TeamId: cmd.TeamId,
RootId: hook.RootId,
ParentId: hook.ParentId,
}
if nErr := a.Srv().Store.CommandWebhook().TryUse(hook.Id, 5); nErr != nil {

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

@@ -2148,10 +2148,6 @@
"id": "api.post.create_post.channel_root_id.app_error",
"translation": "Invalid ChannelId for RootId parameter."
},
{
"id": "api.post.create_post.parent_id.app_error",
"translation": "Invalid ParentId parameter."
},
{
"id": "api.post.create_post.root_id.app_error",
"translation": "Invalid RootId parameter."
@@ -7822,10 +7818,6 @@
"id": "model.command_hook.id.app_error",
"translation": "Invalid command hook id."
},
{
"id": "model.command_hook.parent_id.app_error",
"translation": "Invalid parent id."
},
{
"id": "model.command_hook.root_id.app_error",
"translation": "Invalid root id."
@@ -8618,10 +8610,6 @@
"id": "model.post.is_valid.original_id.app_error",
"translation": "Invalid original id."
},
{
"id": "model.post.is_valid.parent_id.app_error",
"translation": "Invalid parent id."
},
{
"id": "model.post.is_valid.props.app_error",
"translation": "Invalid props."
@@ -8630,10 +8618,6 @@
"id": "model.post.is_valid.root_id.app_error",
"translation": "Invalid root id."
},
{
"id": "model.post.is_valid.root_parent.app_error",
"translation": "Invalid root ID must be set if parent ID set."
},
{
"id": "model.post.is_valid.type.app_error",
"translation": "Invalid type."

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

@@ -14,7 +14,6 @@ type CommandWebhook struct {
UserId string
ChannelId string
RootId string
ParentId string
UseCount int
}
@@ -57,9 +56,5 @@ func (o *CommandWebhook) IsValid() *AppError {
return NewAppError("CommandWebhook.IsValid", "model.command_hook.root_id.app_error", nil, "", http.StatusBadRequest)
}
if o.ParentId != "" && !IsValidId(o.ParentId) {
return NewAppError("CommandWebhook.IsValid", "model.command_hook.parent_id.app_error", nil, "", http.StatusBadRequest)
}
return nil
}

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

@@ -43,8 +43,6 @@ func TestCommandWebhookIsValid(t *testing.T) {
{func() { h.ChannelId = NewId() }, ""},
{func() { h.RootId = "asd" }, "model.command_hook.root_id.app_error"},
{func() { h.RootId = NewId() }, ""},
{func() { h.ParentId = "asd" }, "model.command_hook.parent_id.app_error"},
{func() { h.ParentId = NewId() }, ""},
} {
tmp := h
test.Transform()

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

@@ -30,7 +30,6 @@ type CompliancePost struct {
PostUpdateAt int64
PostDeleteAt int64
PostRootId string
PostParentId string
PostOriginalId string
PostMessage string
PostType string
@@ -60,7 +59,6 @@ func CompliancePostHeader() []string {
"PostUpdateAt",
"PostDeleteAt",
"PostRootId",
"PostParentId",
"PostOriginalId",
"PostMessage",
"PostType",
@@ -113,7 +111,6 @@ func (cp *CompliancePost) Row() []string {
postDeleteAt,
cp.PostRootId,
cp.PostParentId,
cp.PostOriginalId,
cleanComplianceStrings(cp.PostMessage),
cp.PostType,

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

@@ -81,7 +81,6 @@ type Post struct {
UserId string `json:"user_id"`
ChannelId string `json:"channel_id"`
RootId string `json:"root_id"`
ParentId string `json:"parent_id"`
OriginalId string `json:"original_id"`
Message string `json:"message"`
@@ -194,7 +193,6 @@ func (o *Post) ShallowCopy(dst *Post) error {
dst.UserId = o.UserId
dst.ChannelId = o.ChannelId
dst.RootId = o.RootId
dst.ParentId = o.ParentId
dst.OriginalId = o.OriginalId
dst.Message = o.Message
dst.MessageSource = o.MessageSource
@@ -302,14 +300,6 @@ func (o *Post) IsValid(maxPostSize int) *AppError {
return NewAppError("Post.IsValid", "model.post.is_valid.root_id.app_error", nil, "", http.StatusBadRequest)
}
if !(IsValidId(o.ParentId) || o.ParentId == "") {
return NewAppError("Post.IsValid", "model.post.is_valid.parent_id.app_error", nil, "", http.StatusBadRequest)
}
if len(o.ParentId) == 26 && o.RootId == "" {
return NewAppError("Post.IsValid", "model.post.is_valid.root_parent.app_error", nil, "", http.StatusBadRequest)
}
if !(len(o.OriginalId) == 26 || o.OriginalId == "") {
return NewAppError("Post.IsValid", "model.post.is_valid.original_id.app_error", nil, "", http.StatusBadRequest)
}

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

@@ -56,16 +56,7 @@ func TestPostIsValid(t *testing.T) {
require.NotNil(t, err)
o.RootId = ""
o.ParentId = "123"
err = o.IsValid(maxPostSize)
require.NotNil(t, err)
o.ParentId = NewId()
o.RootId = ""
err = o.IsValid(maxPostSize)
require.NotNil(t, err)
o.ParentId = ""
o.Message = strings.Repeat("0", maxPostSize+1)
err = o.IsValid(maxPostSize)
require.NotNil(t, err)

2
services/cache/lru_test.go поставляемый
Просмотреть файл

@@ -139,7 +139,6 @@ func TestLRUMarshalUnMarshal(t *testing.T) {
UserId: "UserId",
ChannelId: "ChannelId",
RootId: "RootId",
ParentId: "ParentId",
OriginalId: "OriginalId",
Message: "OriginalId",
MessageSource: "MessageSource",
@@ -487,7 +486,6 @@ func BenchmarkLRU(b *testing.B) {
UserId: "UserId",
ChannelId: "ChannelId",
RootId: "RootId",
ParentId: "ParentId",
OriginalId: "OriginalId",
Message: "OriginalId",
MessageSource: "MessageSource",

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

@@ -330,7 +330,6 @@ func (si *SlackImporter) slackAddPosts(teamId string, channel *model.Channel, po
// If post in thread
if sPost.ThreadTS != "" && sPost.ThreadTS != sPost.TimeStamp {
newPost.RootId = threads[sPost.ThreadTS]
newPost.ParentId = threads[sPost.ThreadTS]
}
postId := si.oldImportPost(&newPost)
// If post is thread starter
@@ -631,8 +630,8 @@ func (si *SlackImporter) oldImportPost(post *model.Post) string {
// Workaround for empty messages, which may be the case if they are webhook posts.
firstIteration := true
firstPostId := ""
if post.ParentId != "" {
firstPostId = post.ParentId
if post.RootId != "" {
firstPostId = post.RootId
}
maxPostSize := si.actions.MaxPostSize()
for messageRuneCount := utf8.RuneCountInString(post.Message); messageRuneCount > 0 || firstIteration; messageRuneCount = utf8.RuneCountInString(post.Message) {
@@ -647,7 +646,6 @@ func (si *SlackImporter) oldImportPost(post *model.Post) string {
post.Hashtags, _ = model.ParseHashtags(post.Message)
post.RootId = firstPostId
post.ParentId = firstPostId
_, err := si.store.Post().Save(post)
if err != nil {

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

@@ -384,7 +384,6 @@ func (th *SearchTestHelper) createFileInfo(creatorID, postID, name, content, ext
func (th *SearchTestHelper) createReply(userID, message, hashtags string, parent *model.Post, createAt int64, pinned bool) (*model.Post, error) {
replyModel := th.createPostModel(userID, parent.ChannelId, message, hashtags, parent.Type, createAt, pinned)
replyModel.ParentId = parent.Id
replyModel.RootId = parent.Id
return th.Store.Post().Save(replyModel)
}

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

@@ -28,7 +28,6 @@ func newSqlCommandWebhookStore(sqlStore *SqlStore) store.CommandWebhookStore {
tablec.ColMap("UserId").SetMaxSize(26)
tablec.ColMap("ChannelId").SetMaxSize(26)
tablec.ColMap("RootId").SetMaxSize(26)
tablec.ColMap("ParentId").SetMaxSize(26)
}
return s

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

@@ -137,7 +137,6 @@ func (s SqlComplianceStore) ComplianceExport(job *model.Compliance, cursor model
Posts.UpdateAt AS PostUpdateAt,
Posts.DeleteAt AS PostDeleteAt,
Posts.RootId AS PostRootId,
Posts.ParentId AS PostParentId,
Posts.OriginalId AS PostOriginalId,
Posts.Message AS PostMessage,
Posts.Type AS PostType,
@@ -200,7 +199,6 @@ func (s SqlComplianceStore) ComplianceExport(job *model.Compliance, cursor model
Posts.UpdateAt AS PostUpdateAt,
Posts.DeleteAt AS PostDeleteAt,
Posts.RootId AS PostRootId,
Posts.ParentId AS PostParentId,
Posts.OriginalId AS PostOriginalId,
Posts.Message AS PostMessage,
Posts.Type AS PostType,

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

@@ -150,16 +150,6 @@ func checkPostsFileInfoIntegrity(ss *SqlStore) model.IntegrityCheckResult {
})
}
func checkPostsPostsParentIdIntegrity(ss *SqlStore) model.IntegrityCheckResult {
return checkParentChildIntegrity(ss, relationalCheckConfig{
parentName: "Posts",
parentIdAttr: "ParentId",
childName: "Posts",
childIdAttr: "Id",
canParentIdBeEmpty: true,
})
}
func checkPostsPostsRootIdIntegrity(ss *SqlStore) model.IntegrityCheckResult {
return checkParentChildIntegrity(ss, relationalCheckConfig{
parentName: "Posts",
@@ -474,7 +464,6 @@ func checkCommandsIntegrity(ss *SqlStore, results chan<- model.IntegrityCheckRes
func checkPostsIntegrity(ss *SqlStore, results chan<- model.IntegrityCheckResult) {
results <- checkPostsFileInfoIntegrity(ss)
results <- checkPostsPostsParentIdIntegrity(ss)
results <- checkPostsPostsRootIdIntegrity(ss)
results <- checkPostsReactionsIntegrity(ss)
}

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

@@ -181,7 +181,6 @@ func createPost(ss store.Store, channelId, userId, rootId, parentId string) *mod
m.ChannelId = channelId
m.UserId = userId
m.RootId = rootId
m.ParentId = parentId
m.Message = "zz" + model.NewId() + "b"
p, _ := ss.Post().Save(&m)
return p
@@ -604,51 +603,6 @@ func TestCheckPostsFileInfoIntegrity(t *testing.T) {
})
}
func TestCheckPostsPostsParentIdIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMaster()
t.Run("should generate a report with no records", func(t *testing.T) {
result := checkPostsPostsParentIdIntegrity(store)
require.NoError(t, result.Err)
data := result.Data.(model.RelationalIntegrityCheckData)
require.Empty(t, data.Records)
})
t.Run("should generate a report with no records", func(t *testing.T) {
root := createPost(ss, model.NewId(), model.NewId(), "", "")
parent := createPost(ss, model.NewId(), model.NewId(), root.Id, root.Id)
post := createPost(ss, model.NewId(), model.NewId(), root.Id, parent.Id)
result := checkPostsPostsParentIdIntegrity(store)
require.NoError(t, result.Err)
data := result.Data.(model.RelationalIntegrityCheckData)
require.Empty(t, data.Records)
dbmap.Delete(parent)
dbmap.Delete(root)
dbmap.Delete(post)
})
t.Run("should generate a report with one record", func(t *testing.T) {
root := createPost(ss, model.NewId(), model.NewId(), "", "")
parent := createPost(ss, model.NewId(), model.NewId(), root.Id, root.Id)
parentId := parent.Id
post := createPost(ss, model.NewId(), model.NewId(), root.Id, parent.Id)
dbmap.Delete(parent)
result := checkPostsPostsParentIdIntegrity(store)
require.NoError(t, result.Err)
data := result.Data.(model.RelationalIntegrityCheckData)
require.Len(t, data.Records, 1)
require.Equal(t, model.OrphanedRecord{
ParentId: &parentId,
ChildId: &post.Id,
}, data.Records[0])
dbmap.Delete(root)
dbmap.Delete(post)
})
})
}
func TestCheckPostsPostsRootIdIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
store := ss.(*SqlStore)

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

@@ -60,7 +60,6 @@ func postSliceColumnsWithTypes() []struct {
{"UserId", reflect.String},
{"ChannelId", reflect.String},
{"RootId", reflect.String},
{"ParentId", reflect.String},
{"OriginalId", reflect.String},
{"Message", reflect.String},
{"Type", reflect.String},
@@ -84,7 +83,6 @@ func postToSlice(post *model.Post) []interface{} {
post.UserId,
post.ChannelId,
post.RootId,
post.ParentId,
post.OriginalId,
post.Message,
post.Type,
@@ -141,7 +139,6 @@ func newSqlPostStore(sqlStore *SqlStore, metrics einterfaces.MetricsInterface) s
table.ColMap("UserId").SetMaxSize(26)
table.ColMap("ChannelId").SetMaxSize(26)
table.ColMap("RootId").SetMaxSize(26)
table.ColMap("ParentId").SetMaxSize(26)
table.ColMap("OriginalId").SetMaxSize(26)
table.ColMap("Message").SetMaxSize(model.PostMessageMaxBytesV2)
table.ColMap("Type").SetMaxSize(26)
@@ -2229,7 +2226,7 @@ func (s *SqlPostStore) GetDirectPostParentsForExportAfter(limit int, afterId str
Join("Users ON p.UserId = Users.Id").
Where(sq.And{
sq.Gt{"p.Id": afterId},
sq.Eq{"p.ParentId": string("")},
sq.Eq{"p.RootId": string("")},
sq.Eq{"p.DeleteAt": int(0)},
sq.Eq{"Channels.DeleteAt": int(0)},
sq.Eq{"Users.DeleteAt": int(0)},

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

@@ -1311,6 +1311,11 @@ func upgradeDatabaseToVersion600(sqlStore *SqlStore) {
sqlStore.AlterColumnTypeIfExists("Users", "NotifyProps", "JSON", "jsonb")
sqlStore.AlterColumnTypeIfExists("Users", "Timezone", "JSON", "jsonb")
sqlStore.GetMaster().ExecNoTimeout("UPDATE Posts SET RootId = ParentId WHERE RootId = '' AND RootId != ParentId")
sqlStore.RemoveColumnIfExists("Posts", "ParentId")
sqlStore.GetMaster().ExecNoTimeout("UPDATE CommandWebhooks SET RootId = ParentId WHERE RootId = '' AND RootId != ParentId")
sqlStore.RemoveColumnIfExists("CommandWebhooks", "ParentId")
// saveSchemaVersion(sqlStore, Version600)
// }
}

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

@@ -125,13 +125,12 @@ func createChannelMemberWithLastViewAt(ss store.Store, channelId, userId string,
cm, _ := ss.Channel().SaveMember(&m)
return cm
}
func createPostWithTimestamp(ss store.Store, channelId, userId, rootId, parentId string, timestamp int64) *model.Post {
func createPostWithTimestamp(ss store.Store, channelId, userId, rootId string, timestamp int64) *model.Post {
m := model.Post{}
m.CreateAt = timestamp
m.ChannelId = channelId
m.UserId = userId
m.RootId = rootId
m.ParentId = parentId
m.Message = "zz" + model.NewId() + "b"
p, _ := ss.Post().Save(&m)
return p
@@ -225,10 +224,10 @@ func TestMsgCountRootMigration(t *testing.T) {
}
for i, pt := range testChannel.PostTimes {
rt := testChannel.ReplyTimes[i]
post := createPostWithTimestamp(ss, channel.Id, model.NewId(), "", "", pt)
post := createPostWithTimestamp(ss, channel.Id, model.NewId(), "", pt)
require.NotNil(t, post)
if rt > 0 {
reply := createPostWithTimestamp(ss, channel.Id, model.NewId(), post.Id, post.Id, rt)
reply := createPostWithTimestamp(ss, channel.Id, model.NewId(), post.Id, rt)
require.NotNil(t, reply)
}
}
@@ -276,12 +275,12 @@ func TestFixCRTCountsAndUnreads(t *testing.T) {
// - user2: reply 2 to root post 1
// - user1: reply 3 to root post 1
// - user2: reply 4 to root post 1
rootPost1 := createPostWithTimestamp(ss, c1.Id, uId2, "", "", 1)
rootPost1 := createPostWithTimestamp(ss, c1.Id, uId2, "", 1)
lastReplyAt := int64(40)
_ = createPostWithTimestamp(ss, c1.Id, uId1, rootPost1.Id, rootPost1.Id, 10)
_ = createPostWithTimestamp(ss, c1.Id, uId2, rootPost1.Id, rootPost1.Id, 20)
_ = createPostWithTimestamp(ss, c1.Id, uId1, rootPost1.Id, rootPost1.Id, 30)
_ = createPostWithTimestamp(ss, c1.Id, uId2, rootPost1.Id, rootPost1.Id, lastReplyAt)
_ = createPostWithTimestamp(ss, c1.Id, uId1, rootPost1.Id, 10)
_ = createPostWithTimestamp(ss, c1.Id, uId2, rootPost1.Id, 20)
_ = createPostWithTimestamp(ss, c1.Id, uId1, rootPost1.Id, 30)
_ = createPostWithTimestamp(ss, c1.Id, uId2, rootPost1.Id, lastReplyAt)
// Check created thread is good
goodThread1, err := ss.Thread().Get(rootPost1.Id)

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

@@ -5952,7 +5952,6 @@ func testChannelStoreGetPinnedPosts(t *testing.T, ss store.Store) {
post3, err := ss.Post().Save(&model.Post{
ChannelId: channelId,
UserId: userId,
ParentId: post1.Id,
RootId: post1.Id,
Message: "message",
IsPinned: true,

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

@@ -658,7 +658,6 @@ func testFileInfoStoreGetFilesBatchForIndexing(t *testing.T, ss store.Store) {
o3 := &model.Post{}
o3.ChannelId = c1.Id
o3.UserId = model.NewId()
o3.ParentId = o1.Id
o3.RootId = o1.Id
o3.Message = "zz" + model.NewId() + "QQQQQQQQQQ"
o3, err = ss.Post().Save(o3)

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

@@ -525,7 +525,6 @@ func testPostStoreUpdate(t *testing.T, ss store.Store) {
o2.ChannelId = o1.ChannelId
o2.UserId = model.NewId()
o2.Message = "zz" + model.NewId() + "CCCCCCCCC"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2, err = ss.Post().Save(o2)
require.NoError(t, err)
@@ -657,7 +656,6 @@ func testPostStoreDelete1Level(t *testing.T, ss store.Store) {
o2.ChannelId = o1.ChannelId
o2.UserId = model.NewId()
o2.Message = "zz" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2, err = ss.Post().Save(o2)
require.NoError(t, err)
@@ -684,7 +682,6 @@ func testPostStoreDelete2Level(t *testing.T, ss store.Store) {
o2.ChannelId = o1.ChannelId
o2.UserId = model.NewId()
o2.Message = "zz" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2, err = ss.Post().Save(o2)
require.NoError(t, err)
@@ -693,7 +690,6 @@ func testPostStoreDelete2Level(t *testing.T, ss store.Store) {
o3.ChannelId = o1.ChannelId
o3.UserId = model.NewId()
o3.Message = "zz" + model.NewId() + "b"
o3.ParentId = o2.Id
o3.RootId = o1.Id
o3, err = ss.Post().Save(o3)
require.NoError(t, err)
@@ -733,7 +729,6 @@ func testPostStorePermDelete1Level(t *testing.T, ss store.Store) {
o2.ChannelId = o1.ChannelId
o2.UserId = model.NewId()
o2.Message = "zz" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2, err = ss.Post().Save(o2)
require.NoError(t, err)
@@ -773,7 +768,6 @@ func testPostStorePermDelete1Level2(t *testing.T, ss store.Store) {
o2.ChannelId = o1.ChannelId
o2.UserId = model.NewId()
o2.Message = "zz" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2, err = ss.Post().Save(o2)
require.NoError(t, err)
@@ -810,7 +804,6 @@ func testPostStoreGetWithChildren(t *testing.T, ss store.Store) {
o2.ChannelId = o1.ChannelId
o2.UserId = model.NewId()
o2.Message = "zz" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2, err = ss.Post().Save(o2)
require.NoError(t, err)
@@ -819,7 +812,6 @@ func testPostStoreGetWithChildren(t *testing.T, ss store.Store) {
o3.ChannelId = o1.ChannelId
o3.UserId = model.NewId()
o3.Message = "zz" + model.NewId() + "b"
o3.ParentId = o2.Id
o3.RootId = o1.Id
o3, err = ss.Post().Save(o3)
require.NoError(t, err)
@@ -859,7 +851,6 @@ func testPostStoreGetPostsWithDetails(t *testing.T, ss store.Store) {
o2.ChannelId = o1.ChannelId
o2.UserId = model.NewId()
o2.Message = "zz" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
_, err = ss.Post().Save(o2)
require.NoError(t, err)
@@ -869,7 +860,6 @@ func testPostStoreGetPostsWithDetails(t *testing.T, ss store.Store) {
o2a.ChannelId = o1.ChannelId
o2a.UserId = model.NewId()
o2a.Message = "zz" + model.NewId() + "b"
o2a.ParentId = o1.Id
o2a.RootId = o1.Id
o2a, err = ss.Post().Save(o2a)
require.NoError(t, err)
@@ -879,7 +869,6 @@ func testPostStoreGetPostsWithDetails(t *testing.T, ss store.Store) {
o3.ChannelId = o1.ChannelId
o3.UserId = model.NewId()
o3.Message = "zz" + model.NewId() + "b"
o3.ParentId = o1.Id
o3.RootId = o1.Id
o3, err = ss.Post().Save(o3)
require.NoError(t, err)
@@ -897,7 +886,6 @@ func testPostStoreGetPostsWithDetails(t *testing.T, ss store.Store) {
o5.ChannelId = o1.ChannelId
o5.UserId = model.NewId()
o5.Message = "zz" + model.NewId() + "b"
o5.ParentId = o4.Id
o5.RootId = o4.Id
o5, err = ss.Post().Save(o5)
require.NoError(t, err)
@@ -1073,7 +1061,6 @@ func testPostStoreGetPostsBeforeAfter(t *testing.T, ss store.Store) {
post3, err := ss.Post().Save(&model.Post{
ChannelId: channelId,
UserId: userId,
ParentId: post1.Id,
RootId: post1.Id,
Message: "message",
})
@@ -1085,7 +1072,6 @@ func testPostStoreGetPostsBeforeAfter(t *testing.T, ss store.Store) {
ChannelId: channelId,
UserId: userId,
RootId: post2.Id,
ParentId: post2.Id,
Message: "message",
})
require.NoError(t, err)
@@ -1103,7 +1089,6 @@ func testPostStoreGetPostsBeforeAfter(t *testing.T, ss store.Store) {
post6, err := ss.Post().Save(&model.Post{
ChannelId: channelId,
UserId: userId,
ParentId: post2.Id,
RootId: post2.Id,
Message: "message",
})
@@ -1174,7 +1159,6 @@ func testPostStoreGetPostsBeforeAfter(t *testing.T, ss store.Store) {
post3, err := ss.Post().Save(&model.Post{
ChannelId: channelId,
UserId: userId,
ParentId: post1.Id,
RootId: post1.Id,
Message: "post3",
})
@@ -1186,7 +1170,6 @@ func testPostStoreGetPostsBeforeAfter(t *testing.T, ss store.Store) {
ChannelId: channelId,
UserId: userId,
RootId: post2.Id,
ParentId: post2.Id,
Message: "post4",
})
require.NoError(t, err)
@@ -1204,7 +1187,6 @@ func testPostStoreGetPostsBeforeAfter(t *testing.T, ss store.Store) {
post6, err := ss.Post().Save(&model.Post{
ChannelId: channelId,
UserId: userId,
ParentId: post2.Id,
RootId: post2.Id,
Message: "post6",
})
@@ -1283,7 +1265,6 @@ func testPostStoreGetPostsBeforeAfter(t *testing.T, ss store.Store) {
post3, err := ss.Post().Save(&model.Post{
ChannelId: channelId,
UserId: userId,
ParentId: post1.Id,
RootId: post1.Id,
Message: "post3",
})
@@ -1295,7 +1276,6 @@ func testPostStoreGetPostsBeforeAfter(t *testing.T, ss store.Store) {
ChannelId: channelId,
UserId: userId,
RootId: post2.Id,
ParentId: post2.Id,
Message: "post4",
})
require.NoError(t, err)
@@ -1313,7 +1293,6 @@ func testPostStoreGetPostsBeforeAfter(t *testing.T, ss store.Store) {
post6, err := ss.Post().Save(&model.Post{
ChannelId: channelId,
UserId: userId,
ParentId: post2.Id,
RootId: post2.Id,
Message: "post6",
})
@@ -1606,7 +1585,6 @@ func testPostStoreGetPostBeforeAfter(t *testing.T, ss store.Store) {
o0a.ChannelId = channelId
o0a.UserId = model.NewId()
o0a.Message = "zz" + model.NewId() + "b"
o0a.ParentId = o1.Id
o0a.RootId = o1.Id
_, err = ss.Post().Save(o0a)
require.NoError(t, err)
@@ -1616,7 +1594,6 @@ func testPostStoreGetPostBeforeAfter(t *testing.T, ss store.Store) {
o0b.ChannelId = channelId
o0b.UserId = model.NewId()
o0b.Message = "deleted message"
o0b.ParentId = o1.Id
o0b.RootId = o1.Id
o0b.DeleteAt = 1
_, err = ss.Post().Save(o0b)
@@ -1643,7 +1620,6 @@ func testPostStoreGetPostBeforeAfter(t *testing.T, ss store.Store) {
o2a.ChannelId = channelId
o2a.UserId = model.NewId()
o2a.Message = "zz" + model.NewId() + "b"
o2a.ParentId = o2.Id
o2a.RootId = o2.Id
_, err = ss.Post().Save(o2a)
require.NoError(t, err)
@@ -2252,7 +2228,6 @@ func testPostStoreGetPostsCreatedAt(t *testing.T, ss store.Store) {
o2.ChannelId = o1.ChannelId
o2.UserId = model.NewId()
o2.Message = "zz" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2.CreateAt = createTime + 1
_, err = ss.Post().Save(o2)
@@ -2282,7 +2257,6 @@ func testPostStoreOverwriteMultiple(t *testing.T, ss store.Store) {
o2.ChannelId = o1.ChannelId
o2.UserId = model.NewId()
o2.Message = "zz" + model.NewId() + "CCCCCCCCC"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2, err = ss.Post().Save(o2)
require.NoError(t, err)
@@ -2409,7 +2383,6 @@ func testPostStoreOverwrite(t *testing.T, ss store.Store) {
o2.ChannelId = o1.ChannelId
o2.UserId = model.NewId()
o2.Message = "zz" + model.NewId() + "CCCCCCCCC"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2, err = ss.Post().Save(o2)
require.NoError(t, err)
@@ -2583,7 +2556,6 @@ func testPostStoreGetPostsBatchForIndexing(t *testing.T, ss store.Store) {
o3 := &model.Post{}
o3.ChannelId = c1.Id
o3.UserId = model.NewId()
o3.ParentId = o1.Id
o3.RootId = o1.Id
o3.Message = "zz" + model.NewId() + "QQQQQQQQQQ"
o3, err = ss.Post().Save(o3)
@@ -2935,7 +2907,6 @@ func testPostStoreGetRepliesForExport(t *testing.T, ss store.Store) {
p2.UserId = u1.Id
p2.Message = "zz" + model.NewId() + "AAAAAAAAAAA"
p2.CreateAt = 1001
p2.ParentId = p1.Id
p2.RootId = p1.Id
p2, nErr = ss.Post().Save(p2)
require.NoError(t, nErr)

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

@@ -455,7 +455,6 @@ func threadStoreCreateReply(t *testing.T, ss store.Store, channelID, postID stri
UserId: model.NewId(),
CreateAt: createAt,
RootId: postID,
ParentId: postID,
})
require.NoError(t, err)
return reply