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

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

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

@@ -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