[MM-45868] Replace TeamId column with ThreadTeamId (#21505)
* Replace TeamId column with TreadTeamId * make migrations-extract
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
82096a8cbb
Коммит
96c8dc1281
@@ -190,6 +190,8 @@ db/migrations/mysql/000094_threads_teamid.down.sql
|
||||
db/migrations/mysql/000094_threads_teamid.up.sql
|
||||
db/migrations/mysql/000095_remove_posts_parentid.down.sql
|
||||
db/migrations/mysql/000095_remove_posts_parentid.up.sql
|
||||
db/migrations/mysql/000096_threads_threadteamid.down.sql
|
||||
db/migrations/mysql/000096_threads_threadteamid.up.sql
|
||||
db/migrations/postgres/000001_create_teams.down.sql
|
||||
db/migrations/postgres/000001_create_teams.up.sql
|
||||
db/migrations/postgres/000002_create_team_members.down.sql
|
||||
@@ -380,3 +382,5 @@ db/migrations/postgres/000094_threads_teamid.down.sql
|
||||
db/migrations/postgres/000094_threads_teamid.up.sql
|
||||
db/migrations/postgres/000095_remove_posts_parentid.down.sql
|
||||
db/migrations/postgres/000095_remove_posts_parentid.up.sql
|
||||
db/migrations/postgres/000096_threads_threadteamid.down.sql
|
||||
db/migrations/postgres/000096_threads_threadteamid.up.sql
|
||||
|
||||
@@ -1,14 +1 @@
|
||||
SET @preparedStatement = (SELECT IF(
|
||||
EXISTS(
|
||||
SELECT 1 FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE table_name = 'Threads'
|
||||
AND table_schema = DATABASE()
|
||||
AND column_name = 'TeamId'
|
||||
),
|
||||
'ALTER TABLE Threads DROP COLUMN TeamId;',
|
||||
'SELECT 1;'
|
||||
));
|
||||
|
||||
PREPARE removeColumnIfExists FROM @preparedStatement;
|
||||
EXECUTE removeColumnIfExists;
|
||||
DEALLOCATE PREPARE removeColumnIfExists;
|
||||
-- Replaced by 000096_threads_threadteamid.down.sql
|
||||
|
||||
@@ -1,19 +1 @@
|
||||
SET @preparedStatement = (SELECT IF(
|
||||
NOT EXISTS(
|
||||
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE table_name = 'Threads'
|
||||
AND table_schema = DATABASE()
|
||||
AND column_name = 'TeamId'
|
||||
),
|
||||
'ALTER TABLE Threads ADD COLUMN TeamId varchar(26) DEFAULT NULL;',
|
||||
'SELECT 1;'
|
||||
));
|
||||
|
||||
PREPARE addColumnIfNotExists FROM @preparedStatement;
|
||||
EXECUTE addColumnIfNotExists;
|
||||
DEALLOCATE PREPARE addColumnIfNotExists;
|
||||
|
||||
UPDATE Threads, Channels
|
||||
SET Threads.TeamId = Channels.TeamId
|
||||
WHERE Channels.Id = Threads.ChannelId
|
||||
AND Threads.TeamId IS NULL;
|
||||
-- Replaced by 000096_threads_threadteamid.up.sql
|
||||
|
||||
14
db/migrations/mysql/000096_threads_threadteamid.down.sql
Обычный файл
14
db/migrations/mysql/000096_threads_threadteamid.down.sql
Обычный файл
@@ -0,0 +1,14 @@
|
||||
SET @preparedStatement = (SELECT IF(
|
||||
EXISTS(
|
||||
SELECT 1 FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE table_name = 'Threads'
|
||||
AND table_schema = DATABASE()
|
||||
AND column_name = 'ThreadTeamId'
|
||||
),
|
||||
'ALTER TABLE Threads DROP COLUMN ThreadTeamId;',
|
||||
'SELECT 1;'
|
||||
));
|
||||
|
||||
PREPARE removeColumnIfExists FROM @preparedStatement;
|
||||
EXECUTE removeColumnIfExists;
|
||||
DEALLOCATE PREPARE removeColumnIfExists;
|
||||
35
db/migrations/mysql/000096_threads_threadteamid.up.sql
Обычный файл
35
db/migrations/mysql/000096_threads_threadteamid.up.sql
Обычный файл
@@ -0,0 +1,35 @@
|
||||
-- Drop any existing TeamId column from 000094_threads_teamid.up.sql
|
||||
SET @preparedStatement = (SELECT IF(
|
||||
EXISTS(
|
||||
SELECT 1 FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE table_name = 'Threads'
|
||||
AND table_schema = DATABASE()
|
||||
AND column_name = 'TeamId'
|
||||
) > 0,
|
||||
'ALTER TABLE Threads DROP COLUMN TeamId;',
|
||||
'SELECT 1;'
|
||||
));
|
||||
|
||||
PREPARE removeColumnIfExists FROM @preparedStatement;
|
||||
EXECUTE removeColumnIfExists;
|
||||
DEALLOCATE PREPARE removeColumnIfExists;
|
||||
|
||||
SET @preparedStatement = (SELECT IF(
|
||||
NOT EXISTS(
|
||||
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE table_name = 'Threads'
|
||||
AND table_schema = DATABASE()
|
||||
AND column_name = 'ThreadTeamId'
|
||||
),
|
||||
'ALTER TABLE Threads ADD COLUMN ThreadTeamId varchar(26) DEFAULT NULL;',
|
||||
'SELECT 1;'
|
||||
));
|
||||
|
||||
PREPARE addColumnIfNotExists FROM @preparedStatement;
|
||||
EXECUTE addColumnIfNotExists;
|
||||
DEALLOCATE PREPARE addColumnIfNotExists;
|
||||
|
||||
UPDATE Threads, Channels
|
||||
SET Threads.ThreadTeamId = Channels.TeamId
|
||||
WHERE Channels.Id = Threads.ChannelId
|
||||
AND Threads.ThreadTeamId IS NULL;
|
||||
@@ -1 +1 @@
|
||||
ALTER TABLE threads DROP COLUMN IF EXISTS teamid;
|
||||
-- Replaced by 000096_threads_threadteamid.down.sql
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
ALTER TABLE threads ADD COLUMN IF NOT EXISTS teamid VARCHAR(26);
|
||||
UPDATE threads SET teamid = channels.teamid FROM channels WHERE threads.teamid IS NULL AND channels.id = threads.channelid;
|
||||
-- Replaced by 000096_threads_threadteamid.up.sql
|
||||
|
||||
1
db/migrations/postgres/000096_threads_threadteamid.down.sql
Обычный файл
1
db/migrations/postgres/000096_threads_threadteamid.down.sql
Обычный файл
@@ -0,0 +1 @@
|
||||
ALTER TABLE threads DROP COLUMN IF EXISTS threadteamid;
|
||||
5
db/migrations/postgres/000096_threads_threadteamid.up.sql
Обычный файл
5
db/migrations/postgres/000096_threads_threadteamid.up.sql
Обычный файл
@@ -0,0 +1,5 @@
|
||||
-- Drop any existing TeamId column from 000094_threads_teamid.up.sql
|
||||
ALTER TABLE threads DROP COLUMN IF EXISTS teamid;
|
||||
|
||||
ALTER TABLE threads ADD COLUMN IF NOT EXISTS threadteamid VARCHAR(26);
|
||||
UPDATE threads SET threadteamid = channels.teamid FROM channels WHERE threads.threadteamid IS NULL AND channels.id = threads.channelid;
|
||||
@@ -27,7 +27,8 @@ type Thread struct {
|
||||
// named ThreadDeleteAt to avoid introducing a query conflict with older server versions.
|
||||
DeleteAt int64 `json:"delete_at"`
|
||||
|
||||
// TeamId is a denormalized copy of the Channel's teamId.
|
||||
// TeamId is a denormalized copy of the Channel's teamId. In the database, it's
|
||||
// named ThreadTeamId to avoid introducing a query conflict with older server versions.
|
||||
TeamId string `json:"team_id"`
|
||||
}
|
||||
|
||||
|
||||
@@ -515,7 +515,7 @@ func checkUsersIntegrity(ss *SqlStore, results chan<- model.IntegrityCheckResult
|
||||
func checkThreadsTeamsIntegrity(ss *SqlStore) model.IntegrityCheckResult {
|
||||
return checkParentChildIntegrity(ss, relationalCheckConfig{
|
||||
parentName: "Teams",
|
||||
parentIdAttr: "TeamId",
|
||||
parentIdAttr: "ThreadTeamId",
|
||||
childName: "Threads",
|
||||
childIdAttr: "PostId",
|
||||
canParentIdBeEmpty: false,
|
||||
|
||||
@@ -3004,7 +3004,7 @@ func (s *SqlPostStore) updateThreadsFromPosts(transaction *sqlxTxWrapper, posts
|
||||
}
|
||||
// no metadata entry, create one
|
||||
if _, err := transaction.NamedExec(`INSERT INTO Threads
|
||||
(PostId, ChannelId, ReplyCount, LastReplyAt, Participants, TeamId)
|
||||
(PostId, ChannelId, ReplyCount, LastReplyAt, Participants, ThreadTeamId)
|
||||
VALUES
|
||||
(:PostId, :ChannelId, :ReplyCount, :LastReplyAt, :Participants, :TeamId)`, &model.Thread{
|
||||
PostId: rootId,
|
||||
|
||||
@@ -51,7 +51,7 @@ func (s *SqlThreadStore) initializeQueries() {
|
||||
"Threads.LastReplyAt",
|
||||
"Threads.Participants",
|
||||
"COALESCE(Threads.ThreadDeleteAt, 0) AS DeleteAt",
|
||||
"COALESCE(Threads.TeamId, '') AS TeamId",
|
||||
"COALESCE(Threads.ThreadTeamId, '') AS TeamId",
|
||||
).
|
||||
From("Threads")
|
||||
|
||||
@@ -63,7 +63,7 @@ func (s *SqlThreadStore) initializeQueries() {
|
||||
"Threads.LastReplyAt",
|
||||
"Threads.Participants",
|
||||
"COALESCE(Threads.ThreadDeleteAt, 0) AS ThreadDeleteAt",
|
||||
"COALESCE(Threads.TeamId, '') AS TeamId",
|
||||
"COALESCE(Threads.ThreadTeamId, '') AS TeamId",
|
||||
).
|
||||
From("Threads")
|
||||
}
|
||||
@@ -98,8 +98,8 @@ func (s *SqlThreadStore) getTotalThreadsQuery(userId, teamId string, opts model.
|
||||
if teamId != "" {
|
||||
query = query.
|
||||
Where(sq.Or{
|
||||
sq.Eq{"Threads.TeamId": teamId},
|
||||
sq.Eq{"Threads.TeamId": ""},
|
||||
sq.Eq{"Threads.ThreadTeamId": teamId},
|
||||
sq.Eq{"Threads.ThreadTeamId": ""},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -160,8 +160,8 @@ func (s *SqlThreadStore) GetTotalUnreadMentions(userId, teamId string, opts mode
|
||||
if teamId != "" {
|
||||
query = query.
|
||||
Where(sq.Or{
|
||||
sq.Eq{"Threads.TeamId": teamId},
|
||||
sq.Eq{"Threads.TeamId": ""},
|
||||
sq.Eq{"Threads.ThreadTeamId": teamId},
|
||||
sq.Eq{"Threads.ThreadTeamId": ""},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -225,8 +225,8 @@ func (s *SqlThreadStore) GetThreadsForUser(userId, teamId string, opts model.Get
|
||||
if teamId != "" {
|
||||
query = query.
|
||||
Where(sq.Or{
|
||||
sq.Eq{"Threads.TeamId": teamId},
|
||||
sq.Eq{"Threads.TeamId": ""},
|
||||
sq.Eq{"Threads.ThreadTeamId": teamId},
|
||||
sq.Eq{"Threads.ThreadTeamId": ""},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ func (s *SqlThreadStore) GetTeamsUnreadForUser(userID string, teamIDs []string)
|
||||
fetchConditions := sq.And{
|
||||
sq.Eq{"ThreadMemberships.UserId": userID},
|
||||
sq.Eq{"ThreadMemberships.Following": true},
|
||||
sq.Eq{"Threads.TeamId": teamIDs},
|
||||
sq.Eq{"Threads.ThreadTeamId": teamIDs},
|
||||
sq.Eq{"COALESCE(Threads.ThreadDeleteAt, 0)": 0},
|
||||
}
|
||||
|
||||
@@ -345,12 +345,12 @@ func (s *SqlThreadStore) GetTeamsUnreadForUser(userID string, teamIDs []string)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
repliesQuery := s.getQueryBuilder().
|
||||
Select("COUNT(Threads.PostId) AS Count, TeamId").
|
||||
Select("COUNT(Threads.PostId) AS Count, ThreadTeamId AS TeamId").
|
||||
From("Threads").
|
||||
LeftJoin("ThreadMemberships ON Threads.PostId = ThreadMemberships.PostId").
|
||||
Where(fetchConditions).
|
||||
Where("Threads.LastReplyAt > ThreadMemberships.LastViewed").
|
||||
GroupBy("Threads.TeamId")
|
||||
GroupBy("Threads.ThreadTeamId")
|
||||
|
||||
err := s.GetReplicaX().SelectBuilder(&unreadThreads, repliesQuery)
|
||||
if err != nil {
|
||||
@@ -362,11 +362,11 @@ func (s *SqlThreadStore) GetTeamsUnreadForUser(userID string, teamIDs []string)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
mentionsQuery := s.getQueryBuilder().
|
||||
Select("COALESCE(SUM(ThreadMemberships.UnreadMentions),0) AS Count, TeamId").
|
||||
Select("COALESCE(SUM(ThreadMemberships.UnreadMentions),0) AS Count, ThreadTeamId AS TeamId").
|
||||
From("ThreadMemberships").
|
||||
LeftJoin("Threads ON Threads.PostId = ThreadMemberships.PostId").
|
||||
Where(fetchConditions).
|
||||
GroupBy("Threads.TeamId")
|
||||
GroupBy("Threads.ThreadTeamId")
|
||||
|
||||
err := s.GetReplicaX().SelectBuilder(&unreadMentions, mentionsQuery)
|
||||
if err != nil {
|
||||
@@ -461,7 +461,7 @@ func (s *SqlThreadStore) GetThreadForUser(teamId string, threadMembership *model
|
||||
})
|
||||
|
||||
fetchConditions := sq.And{
|
||||
sq.Or{sq.Eq{"Threads.TeamId": teamId}, sq.Eq{"Threads.TeamId": ""}},
|
||||
sq.Or{sq.Eq{"Threads.ThreadTeamId": teamId}, sq.Eq{"Threads.ThreadTeamId": ""}},
|
||||
sq.Eq{"Threads.PostId": threadMembership.PostId},
|
||||
}
|
||||
|
||||
@@ -670,7 +670,7 @@ func (s *SqlThreadStore) GetMembershipsForUser(userId, teamId string) ([]*model.
|
||||
Select("ThreadMemberships.*").
|
||||
Join("Threads ON Threads.PostId = ThreadMemberships.PostId").
|
||||
From("ThreadMemberships").
|
||||
Where(sq.Or{sq.Eq{"Threads.TeamId": teamId}, sq.Eq{"Threads.TeamId": ""}}).
|
||||
Where(sq.Or{sq.Eq{"Threads.ThreadTeamId": teamId}, sq.Eq{"Threads.ThreadTeamId": ""}}).
|
||||
Where(sq.Eq{"ThreadMemberships.UserId": userId})
|
||||
|
||||
err := s.GetReplicaX().SelectBuilder(&memberships, query)
|
||||
|
||||
Ссылка в новой задаче
Block a user