migrations: Fix typos/errors and add missing migrations (#19316)
* fix public channels creation script for mysql * fix several remaining migrations
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
4a1a0863c4
Коммит
d0724d8b00
@@ -27,3 +27,59 @@ ALTER TABLE teams ADD COLUMN IF NOT EXISTS description VARCHAR(255);
|
||||
ALTER TABLE teams ADD COLUMN IF NOT EXISTS groupconstrained boolean;
|
||||
|
||||
DROP INDEX IF EXISTS idx_teams_name;
|
||||
|
||||
DO $$
|
||||
DECLARE
|
||||
column_exist boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO column_exist
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'teams'
|
||||
AND column_name = 'alloweddomains'
|
||||
AND NOT data_type = 'varchar(1000)';
|
||||
IF column_exist THEN
|
||||
ALTER TABLE teams ALTER COLUMN alloweddomains TYPE VARCHAR(1000);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
DO $$
|
||||
DECLARE
|
||||
column_exist boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO column_exist
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'teams'
|
||||
AND column_name = 'groupconstrained'
|
||||
AND NOT data_type = 'boolean';
|
||||
IF column_exist THEN
|
||||
ALTER TABLE teams ALTER COLUMN groupconstrained TYPE boolean;
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
DO $$
|
||||
DECLARE
|
||||
column_exist boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO column_exist
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'teams'
|
||||
AND column_name = 'type'
|
||||
AND NOT data_type = 'varchar(255)';
|
||||
IF column_exist THEN
|
||||
ALTER TABLE teams ALTER COLUMN type TYPE VARCHAR(255);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
DO $$
|
||||
DECLARE
|
||||
column_exist boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO column_exist
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'teams'
|
||||
AND column_name = 'schemeid'
|
||||
AND NOT data_type = 'varchar(26)';
|
||||
IF column_exist THEN
|
||||
ALTER TABLE teams ALTER COLUMN schemeid TYPE varchar(26);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
@@ -55,3 +55,17 @@ BEGIN
|
||||
RAISE EXCEPTION 'IncomingWebhooks column IconURL has data larger that 1024 characters';
|
||||
END IF;
|
||||
END checks $$;
|
||||
|
||||
DO $$
|
||||
DECLARE
|
||||
column_exist boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO column_exist
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'incomingwebhooks'
|
||||
AND column_name = 'description'
|
||||
AND NOT data_type = 'VARCHAR(500)';
|
||||
IF column_exist THEN
|
||||
ALTER TABLE incomingwebhooks ALTER COLUMN description TYPE VARCHAR(500);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
@@ -22,3 +22,57 @@ CREATE INDEX IF NOT EXISTS idx_outgoing_webhook_team_id ON outgoingwebhooks (tea
|
||||
CREATE INDEX IF NOT EXISTS idx_outgoing_webhook_update_at ON outgoingwebhooks (updateat);
|
||||
CREATE INDEX IF NOT EXISTS idx_outgoing_webhook_create_at ON outgoingwebhooks (createat);
|
||||
CREATE INDEX IF NOT EXISTS idx_outgoing_webhook_delete_at ON outgoingwebhooks (deleteat);
|
||||
|
||||
DO $$
|
||||
DECLARE
|
||||
column_exist boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO column_exist
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'outgoingwebhooks'
|
||||
AND column_name = 'description'
|
||||
AND NOT data_type = 'VARCHAR(500)';
|
||||
IF column_exist THEN
|
||||
ALTER TABLE outgoingwebhooks ALTER COLUMN description TYPE VARCHAR(500);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
DO $$
|
||||
DECLARE
|
||||
column_exist boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO column_exist
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'outgoingwebhooks'
|
||||
AND column_name = 'iconurl'
|
||||
AND NOT data_type = 'VARCHAR(1024)';
|
||||
IF column_exist THEN
|
||||
ALTER TABLE outgoingwebhooks ALTER COLUMN iconurl TYPE VARCHAR(1024);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF (
|
||||
SELECT column_default::bigint
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema='public'
|
||||
AND table_name='outgoingwebhooks'
|
||||
AND column_name='username'
|
||||
) = 0 THEN
|
||||
ALTER TABLE outgoingwebhooks ALTER COLUMN username SET DEFAULT NULL;
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF (
|
||||
SELECT column_default::bigint
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema='public'
|
||||
AND table_name='outgoingwebhooks'
|
||||
AND column_name='iconurl'
|
||||
) = 0 THEN
|
||||
ALTER TABLE outgoingwebhooks ALTER COLUMN iconurl SET DEFAULT NULL;
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
@@ -13,7 +13,19 @@ CREATE TABLE IF NOT EXISTS roles (
|
||||
|
||||
ALTER TABLE roles ADD COLUMN IF NOT EXISTS builtin boolean;
|
||||
|
||||
UPDATE Roles SET SchemeManaged = false
|
||||
WHERE Name NOT IN ('system_user', 'system_admin', 'team_user', 'team_admin', 'channel_user', 'channel_admin');
|
||||
DO $$
|
||||
<< migrate_roles >>
|
||||
BEGIN
|
||||
IF((
|
||||
SELECT
|
||||
value
|
||||
FROM systems
|
||||
WHERE
|
||||
Name = 'Version') = '4.10.0') THEN
|
||||
UPDATE Roles SET SchemeManaged = false
|
||||
WHERE Name NOT IN ('system_user', 'system_admin', 'team_user', 'team_admin', 'channel_user', 'channel_admin');
|
||||
END IF;
|
||||
END migrate_roles
|
||||
$$;
|
||||
|
||||
ALTER TABLE roles ALTER COLUMN permissions TYPE TEXT;
|
||||
|
||||
@@ -34,3 +34,17 @@ CREATE INDEX IF NOT EXISTS idx_posts_hashtags_txt ON posts USING gin(to_tsvector
|
||||
ALTER TABLE posts ADD COLUMN IF NOT EXISTS remoteid VARCHAR(26);
|
||||
|
||||
DROP INDEX IF EXISTS idx_posts_channel_id;
|
||||
|
||||
DO $$
|
||||
DECLARE
|
||||
column_exist boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO column_exist
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'posts'
|
||||
AND column_name = 'fileids'
|
||||
AND NOT data_type = 'varchar(300)';
|
||||
IF column_exist THEN
|
||||
ALTER TABLE posts ALTER COLUMN fileids TYPE varchar(300);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
@@ -16,3 +16,17 @@ CREATE INDEX IF NOT EXISTS idx_uploadsessions_type ON uploadsessions(type);
|
||||
|
||||
ALTER TABLE uploadsessions ADD COLUMN IF NOT EXISTS remoteid VARCHAR(26);
|
||||
ALTER TABLE uploadsessions ADD COLUMN IF NOT EXISTS reqfileid VARCHAR(26);
|
||||
|
||||
DO $$
|
||||
<< shared_channel_support >>
|
||||
BEGIN
|
||||
IF((
|
||||
SELECT
|
||||
value
|
||||
FROM systems
|
||||
WHERE
|
||||
Name = 'Version') = '5.34.0') THEN
|
||||
UPDATE UploadSessions SET RemoteId='', ReqFileId='' WHERE RemoteId IS NULL;
|
||||
END IF;
|
||||
END shared_channel_support
|
||||
$$;
|
||||
|
||||
@@ -4,6 +4,8 @@ DECLARE
|
||||
mention_count_root_exist boolean := false;
|
||||
DECLARE
|
||||
msg_count_root_exist boolean := false;
|
||||
DECLARE
|
||||
tmp_count_root integer := 0;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO msg_count_root_exist
|
||||
FROM information_schema.columns
|
||||
@@ -15,8 +17,13 @@ SELECT count(*) != 0 INTO msg_count_root_exist
|
||||
WHERE table_name = 'channelmembers'
|
||||
AND column_name = 'mentioncountroot';
|
||||
|
||||
IF mention_count_root_exist THEN
|
||||
tmp_count_root := (SELECT count(*) FROM channelmembers WHERE msgcountroot = NULL OR mentioncountroot = NULL);
|
||||
END IF;
|
||||
|
||||
ALTER TABLE channelmembers ADD COLUMN IF NOT EXISTS mentioncountroot bigint;
|
||||
|
||||
IF (tmp_count_root > 0) THEN
|
||||
WITH q AS (
|
||||
SELECT ChannelId, COALESCE(SUM(UnreadMentions), 0) AS UnreadMentions, UserId
|
||||
FROM ThreadMemberships
|
||||
@@ -30,9 +37,10 @@ ALTER TABLE channelmembers ADD COLUMN IF NOT EXISTS mentioncountroot bigint;
|
||||
q.ChannelId = ChannelMembers.ChannelId AND
|
||||
q.UserId = ChannelMembers.UserId AND
|
||||
ChannelMembers.MentionCount > 0;
|
||||
END IF;
|
||||
|
||||
ALTER TABLE channels ADD COLUMN IF NOT EXISTS totalmsgcountroot bigint;
|
||||
ALTER TABLE channels ADD COLUMN IF NOT EXISTS lastrootpostat bigint;
|
||||
ALTER TABLE channels ADD COLUMN IF NOT EXISTS lastrootat bigint;
|
||||
|
||||
ALTER TABLE channelmembers ADD COLUMN IF NOT EXISTS msgcountroot bigint;
|
||||
|
||||
@@ -44,16 +52,16 @@ IF NOT msg_count_root_exist THEN
|
||||
WHERE Posts.RootId = ''
|
||||
GROUP BY Channels.Id
|
||||
)
|
||||
UPDATE Channels SET TotalMsgCountRoot = q.newcount, LastRootPostAt=q.lastpost
|
||||
UPDATE Channels SET TotalMsgCountRoot = q.newcount, LastRootAt=q.lastpost
|
||||
FROM q where q.channelid=Channels.Id;
|
||||
END IF;
|
||||
|
||||
IF NOT mention_count_root_exist THEN
|
||||
WITH q as (SELECT TotalMsgCountRoot, Id, LastRootPostAt from Channels)
|
||||
WITH q as (SELECT TotalMsgCountRoot, Id, LastRootAt from Channels)
|
||||
UPDATE ChannelMembers CM SET MsgCountRoot=TotalMsgCountRoot
|
||||
FROM q WHERE q.id=CM.ChannelId AND LastViewedAt >= q.lastrootpostat;
|
||||
FROM q WHERE q.id=CM.ChannelId AND LastViewedAt >= q.lastrootat;
|
||||
END IF;
|
||||
|
||||
ALTER TABLE channels DROP COLUMN IF EXISTS lastrootpostat;
|
||||
ALTER TABLE channels DROP COLUMN IF EXISTS lastrootat;
|
||||
|
||||
END migrate_root_mention_count $$;
|
||||
|
||||
@@ -11,7 +11,7 @@ BEGIN
|
||||
table_name = 'channels'
|
||||
AND column_name = 'lastrootpostat';
|
||||
IF NOT column_exist THEN
|
||||
ALTER TABLE channels ADD COLUMN lastrootpostat bigint;
|
||||
ALTER TABLE channels ADD COLUMN lastrootpostat bigint DEFAULT '0'::bigint;
|
||||
WITH q AS (
|
||||
SELECT
|
||||
Channels.Id channelid,
|
||||
|
||||
Ссылка в новой задаче
Block a user