[MM-53428] Delete empty drafts on upsert (#24046)

* [MM-53428] Delete empty drafts on upsert

* Add migrations to fix existing drafts

* Fix CI

* Delete empty drafts entirely from the DB

* Fix lint

* Implement batch migration for deleting drafts

* Missing store layers

* Add updated mock

* Remove unnecessary test

* PR feedback

* Add check for cluster migration

* Fix MySQL

* Don't check for len<2

* Bit of PR feedback

* Use query builder for parameters

* PR feedback

* More PR feedback

* Merge'd

* unit test GetLastCreateAtAndUserIdValuesForEmptyDraftsMigration

* simplified builder interface

* fix DeleteEmptyDraftsByCreateAtAndUserId for MySQL

* rework as batch migration worker

* fix typo

* log ip address on version mismatches too

* simplify reset semantics

* remove trace log in favour of low spam

* document parameters for clarity

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>
Этот коммит содержится в:
Devin Binnie
2023-10-12 10:52:10 -04:00
коммит произвёл GitHub
родитель 760dfe41f9
Коммит 89492a6a46
22 изменённых файлов: 1573 добавлений и 26 удалений

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

@@ -600,6 +600,27 @@ func (s *Server) doCloudS3PathMigrations(c *request.Context) {
}
}
func (s *Server) doDeleteEmptyDraftsMigration(c *request.Context) {
// If the migration is already marked as completed, don't do it again.
if _, err := s.Store().System().GetByName(model.MigrationKeyDeleteEmptyDrafts); err == nil {
return
}
jobs, err := s.Store().Job().GetAllByTypeAndStatus(c, model.JobTypeDeleteEmptyDraftsMigration, model.JobStatusPending)
if err != nil {
mlog.Fatal("failed to get jobs by type and status", mlog.Err(err))
return
}
if len(jobs) > 0 {
return
}
if _, appErr := s.Jobs.CreateJobOnce(c, model.JobTypeDeleteEmptyDraftsMigration, nil); appErr != nil {
mlog.Fatal("failed to start job for deleting empty drafts", mlog.Err(appErr))
return
}
}
func (a *App) DoAppMigrations() {
a.Srv().doAppMigrations()
}
@@ -625,4 +646,5 @@ func (s *Server) doAppMigrations() {
s.doPostPriorityConfigDefaultTrueMigration()
s.doElasticsearchFixChannelIndex(c)
s.doCloudS3PathMigrations(c)
s.doDeleteEmptyDraftsMigration(c)
}