[MM-29217] Remove Posts.ParentId (#17923)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
757dc96461
Коммит
d181ae9262
@@ -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)
|
||||
|
||||
Ссылка в новой задаче
Block a user