Replace go-migrate with morph (#19116)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c8198fbefe
Коммит
6595b31f23
@@ -1,3 +1,5 @@
|
||||
CREATE INDEX IF NOT EXISTS idx_teams_name ON teams (name);
|
||||
|
||||
ALTER TABLE teams DROP COLUMN IF EXISTS allowopeninvite;
|
||||
ALTER TABLE teams DROP COLUMN IF EXISTS lastteamiconupdate;
|
||||
ALTER TABLE teams DROP COLUMN IF EXISTS description;
|
||||
|
||||
@@ -25,3 +25,5 @@ ALTER TABLE teams ADD COLUMN IF NOT EXISTS allowopeninvite boolean;
|
||||
ALTER TABLE teams ADD COLUMN IF NOT EXISTS lastteamiconupdate bigint;
|
||||
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;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
CREATE INDEX IF NOT EXISTS idx_teammembers_team_id ON teammembers (teamid);
|
||||
|
||||
ALTER TABLE teammembers DROP COLUMN IF EXISTS schemeuser;
|
||||
ALTER TABLE teammembers DROP COLUMN IF EXISTS schemeadmin;
|
||||
ALTER TABLE teammembers DROP COLUMN IF EXISTS schemeguest;
|
||||
@@ -6,4 +8,4 @@ ALTER TABLE teammembers DROP COLUMN IF EXISTS deleteat;
|
||||
DROP INDEX IF EXISTS idx_teammembers_user_id;
|
||||
DROP INDEX IF EXISTS idx_teammembers_delete_at;
|
||||
|
||||
DROP TABLE IF EXISTS TeamMembers;
|
||||
DROP TABLE IF EXISTS teammembers;
|
||||
|
||||
@@ -13,3 +13,5 @@ ALTER TABLE teammembers ADD COLUMN IF NOT EXISTS schemeuser boolean;
|
||||
ALTER TABLE teammembers ADD COLUMN IF NOT EXISTS schemeadmin boolean;
|
||||
ALTER TABLE teammembers ADD COLUMN IF NOT EXISTS schemeguest boolean;
|
||||
ALTER TABLE teammembers ADD COLUMN IF NOT EXISTS deleteat bigint;
|
||||
|
||||
DROP INDEX IF EXISTS idx_teammembers_team_id;
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
DO $$
|
||||
<<modify_column_type_if_type_is_different>>
|
||||
DECLARE
|
||||
col_exist_and_type_different boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO col_exist_and_type_different
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'teammembers'
|
||||
AND column_name = 'roles'
|
||||
AND data_type = 'character varying'
|
||||
AND NOT character_maximum_length = 256;
|
||||
|
||||
IF col_exist_and_type_different THEN
|
||||
ALTER TABLE teammembers ALTER COLUMN roles TYPE varchar(256);
|
||||
END IF;
|
||||
END modify_column_type_if_type_is_different $$
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS clusterdiscovery;
|
||||
10
db/migrations/postgres/000003_create_cluster_discovery.up.sql
Обычный файл
10
db/migrations/postgres/000003_create_cluster_discovery.up.sql
Обычный файл
@@ -0,0 +1,10 @@
|
||||
CREATE TABLE IF NOT EXISTS clusterdiscovery (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
type VARCHAR(64),
|
||||
clustername VARCHAR(64),
|
||||
hostname VARCHAR(512),
|
||||
gossipport integer,
|
||||
port integer,
|
||||
createat bigint,
|
||||
lastpingat bigint
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS commandwebhooks;
|
||||
12
db/migrations/postgres/000004_create_command_webhooks.up.sql
Обычный файл
12
db/migrations/postgres/000004_create_command_webhooks.up.sql
Обычный файл
@@ -0,0 +1,12 @@
|
||||
CREATE TABLE IF NOT EXISTS commandwebhooks (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
createat bigint,
|
||||
commandid VARCHAR(26),
|
||||
userid VARCHAR(26),
|
||||
channelid VARCHAR(26),
|
||||
rootid VARCHAR(26),
|
||||
parentid VARCHAR(26),
|
||||
usecount integer
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_command_webhook_create_at ON commandwebhooks (createat);
|
||||
1
db/migrations/postgres/000005_create_compliances.down.sql
Обычный файл
1
db/migrations/postgres/000005_create_compliances.down.sql
Обычный файл
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS compliances;
|
||||
14
db/migrations/postgres/000005_create_compliances.up.sql
Обычный файл
14
db/migrations/postgres/000005_create_compliances.up.sql
Обычный файл
@@ -0,0 +1,14 @@
|
||||
CREATE TABLE IF NOT EXISTS compliances (
|
||||
id VARCHAR(26) NOT NULL,
|
||||
createat bigint,
|
||||
userid VARCHAR(26),
|
||||
status VARCHAR(64),
|
||||
count integer,
|
||||
"desc" VARCHAR(512),
|
||||
type VARCHAR(64),
|
||||
startat bigint,
|
||||
endat bigint,
|
||||
keywords VARCHAR(512),
|
||||
emails VARCHAR(1024),
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
3
db/migrations/postgres/000006_create_emojis.down.sql
Обычный файл
3
db/migrations/postgres/000006_create_emojis.down.sql
Обычный файл
@@ -0,0 +1,3 @@
|
||||
CREATE INDEX IF NOT EXISTS idx_emoji_name ON emoji (name);
|
||||
|
||||
DROP TABLE IF EXISTS emoji;
|
||||
17
db/migrations/postgres/000006_create_emojis.up.sql
Обычный файл
17
db/migrations/postgres/000006_create_emojis.up.sql
Обычный файл
@@ -0,0 +1,17 @@
|
||||
CREATE TABLE IF NOT EXISTS emoji (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
createat bigint,
|
||||
updateat bigint,
|
||||
deleteat bigint,
|
||||
creatorid VARCHAR(26),
|
||||
name VARCHAR(64),
|
||||
UNIQUE(name, deleteat)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_emoji_update_at ON emoji (updateat);
|
||||
CREATE INDEX IF NOT EXISTS idx_emoji_create_at ON emoji (createat);
|
||||
CREATE INDEX IF NOT EXISTS idx_emoji_delete_at ON emoji (deleteat);
|
||||
|
||||
DROP INDEX IF EXISTS Name_2;
|
||||
|
||||
DROP INDEX IF EXISTS idx_emoji_name;
|
||||
3
db/migrations/postgres/000007_create_user_groups.down.sql
Обычный файл
3
db/migrations/postgres/000007_create_user_groups.down.sql
Обычный файл
@@ -0,0 +1,3 @@
|
||||
DROP INDEX IF EXISTS idx_usergroups_remote_id;
|
||||
DROP INDEX IF EXISTS idx_usergroups_delete_at;
|
||||
DROP TABLE IF EXISTS usergroups;
|
||||
18
db/migrations/postgres/000007_create_user_groups.up.sql
Обычный файл
18
db/migrations/postgres/000007_create_user_groups.up.sql
Обычный файл
@@ -0,0 +1,18 @@
|
||||
CREATE TABLE IF NOT EXISTS usergroups (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
name VARCHAR(64),
|
||||
displayname VARCHAR(128),
|
||||
description VARCHAR(1024),
|
||||
source VARCHAR(64),
|
||||
remoteid VARCHAR(48),
|
||||
createat bigint,
|
||||
updateat bigint,
|
||||
deleteat bigint,
|
||||
allowreference bool,
|
||||
UNIQUE(name),
|
||||
UNIQUE(source, remoteid)
|
||||
);
|
||||
|
||||
ALTER TABLE usergroups ADD COLUMN IF NOT EXISTS allowreference bool;
|
||||
CREATE INDEX IF NOT EXISTS idx_usergroups_remote_id ON usergroups (remoteid);
|
||||
CREATE INDEX IF NOT EXISTS idx_usergroups_delete_at ON usergroups (deleteat);
|
||||
1
db/migrations/postgres/000008_create_group_members.down.sql
Обычный файл
1
db/migrations/postgres/000008_create_group_members.down.sql
Обычный файл
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS groupmembers;
|
||||
9
db/migrations/postgres/000008_create_group_members.up.sql
Обычный файл
9
db/migrations/postgres/000008_create_group_members.up.sql
Обычный файл
@@ -0,0 +1,9 @@
|
||||
CREATE TABLE IF NOT EXISTS groupmembers (
|
||||
groupid VARCHAR(26),
|
||||
userid VARCHAR(26),
|
||||
createat bigint,
|
||||
deleteat bigint,
|
||||
PRIMARY KEY(groupid, userid)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_groupmembers_create_at ON groupmembers (createat);
|
||||
1
db/migrations/postgres/000009_create_group_teams.down.sql
Обычный файл
1
db/migrations/postgres/000009_create_group_teams.down.sql
Обычный файл
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS groupteams;
|
||||
15
db/migrations/postgres/000009_create_group_teams.up.sql
Обычный файл
15
db/migrations/postgres/000009_create_group_teams.up.sql
Обычный файл
@@ -0,0 +1,15 @@
|
||||
CREATE TABLE IF NOT EXISTS groupteams (
|
||||
groupid VARCHAR(26),
|
||||
autoadd boolean,
|
||||
schemeadmin boolean,
|
||||
createat bigint,
|
||||
deleteat bigint,
|
||||
updateat bigint,
|
||||
teamid VARCHAR(26),
|
||||
PRIMARY KEY(groupid, teamid)
|
||||
);
|
||||
|
||||
ALTER TABLE groupteams ADD COLUMN IF NOT EXISTS schemeadmin boolean default false;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_groupteams_schemeadmin ON groupteams (schemeadmin);
|
||||
CREATE INDEX IF NOT EXISTS idx_groupteams_teamid ON groupteams (teamid);
|
||||
1
db/migrations/postgres/000010_create_group_channels.down.sql
Обычный файл
1
db/migrations/postgres/000010_create_group_channels.down.sql
Обычный файл
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS groupchanels;
|
||||
15
db/migrations/postgres/000010_create_group_channels.up.sql
Обычный файл
15
db/migrations/postgres/000010_create_group_channels.up.sql
Обычный файл
@@ -0,0 +1,15 @@
|
||||
CREATE TABLE IF NOT EXISTS groupchannels (
|
||||
groupid VARCHAR(26),
|
||||
autoadd boolean,
|
||||
schemeadmin boolean,
|
||||
createat bigint,
|
||||
deleteat bigint,
|
||||
updateat bigint,
|
||||
channelid VARCHAR(26),
|
||||
PRIMARY KEY(groupid, channelid)
|
||||
);
|
||||
|
||||
ALTER TABLE groupchannels ADD COLUMN IF NOT EXISTS schemeadmin boolean;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_groupteams_schemeadmin ON groupchannels (schemeadmin);
|
||||
CREATE INDEX IF NOT EXISTS idx_groupchannels_channelid ON groupchannels (channelid);
|
||||
3
db/migrations/postgres/000011_create_link_metadata.down.sql
Обычный файл
3
db/migrations/postgres/000011_create_link_metadata.down.sql
Обычный файл
@@ -0,0 +1,3 @@
|
||||
DROP INDEX IF EXISTS idx_link_metadata_url_timestamp;
|
||||
|
||||
DROP TABLE IF EXISTS linkmetadata;
|
||||
10
db/migrations/postgres/000011_create_link_metadata.up.sql
Обычный файл
10
db/migrations/postgres/000011_create_link_metadata.up.sql
Обычный файл
@@ -0,0 +1,10 @@
|
||||
CREATE TABLE IF NOT EXISTS linkmetadata (
|
||||
hash bigint NOT NULL,
|
||||
url VARCHAR(2048),
|
||||
"timestamp" bigint,
|
||||
type VARCHAR(16),
|
||||
data VARCHAR(4096),
|
||||
PRIMARY KEY (hash)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_link_metadata_url_timestamp ON linkmetadata (url, "timestamp");
|
||||
8
db/migrations/postgres/000012_create_commands.down.sql
Обычный файл
8
db/migrations/postgres/000012_create_commands.down.sql
Обычный файл
@@ -0,0 +1,8 @@
|
||||
DROP INDEX IF EXISTS idx_commands_team_id;
|
||||
DROP INDEX IF EXISTS idx_commands_update_at;
|
||||
DROP INDEX IF EXISTS idx_commands_create_at;
|
||||
DROP INDEX IF EXISTS idx_commands_delete_at;
|
||||
|
||||
ALTER TABLE commands DROP COLUMN IF EXISTS pluginid;
|
||||
|
||||
DROP TABLE IF EXISTS commands;
|
||||
28
db/migrations/postgres/000012_create_commands.up.sql
Обычный файл
28
db/migrations/postgres/000012_create_commands.up.sql
Обычный файл
@@ -0,0 +1,28 @@
|
||||
CREATE TABLE IF NOT EXISTS commands (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
token VARCHAR(26),
|
||||
createat bigint,
|
||||
updateat bigint,
|
||||
deleteat bigint,
|
||||
creatorid VARCHAR(26),
|
||||
teamid VARCHAR(26),
|
||||
trigger VARCHAR(128),
|
||||
method VARCHAR(1),
|
||||
username VARCHAR(64),
|
||||
iconurl VARCHAR(1024),
|
||||
autocomplete bool,
|
||||
autocompletedesc VARCHAR(1024),
|
||||
autocompletehint VARCHAR(1024),
|
||||
displayname VARCHAR(64),
|
||||
description VARCHAR(128),
|
||||
url VARCHAR(1024)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_command_team_id ON commands (teamid);
|
||||
CREATE INDEX IF NOT EXISTS idx_command_update_at ON commands (updateat);
|
||||
CREATE INDEX IF NOT EXISTS idx_command_create_at ON commands (createat);
|
||||
CREATE INDEX IF NOT EXISTS idx_command_delete_at ON commands (deleteat);
|
||||
|
||||
ALTER TABLE commands ADD COLUMN IF NOT EXISTS pluginid VARCHAR(190);
|
||||
|
||||
UPDATE commands SET pluginid = '' WHERE pluginid IS NULL;
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS incomingwebhooks;
|
||||
57
db/migrations/postgres/000013_create_incoming_webhooks.up.sql
Обычный файл
57
db/migrations/postgres/000013_create_incoming_webhooks.up.sql
Обычный файл
@@ -0,0 +1,57 @@
|
||||
CREATE TABLE IF NOT EXISTS incomingwebhooks (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
createat bigint,
|
||||
updateat bigint,
|
||||
deleteat bigint,
|
||||
userid VARCHAR(26),
|
||||
channelid VARCHAR(26),
|
||||
teamid VARCHAR(26),
|
||||
displayname VARCHAR(64),
|
||||
description VARCHAR(128)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_incoming_webhook_user_id ON incomingwebhooks (userid);
|
||||
CREATE INDEX IF NOT EXISTS idx_incoming_webhook_team_id ON incomingwebhooks (teamid);
|
||||
CREATE INDEX IF NOT EXISTS idx_incoming_webhook_update_at ON incomingwebhooks (updateat);
|
||||
CREATE INDEX IF NOT EXISTS idx_incoming_webhook_create_at ON incomingwebhooks (createat);
|
||||
CREATE INDEX IF NOT EXISTS idx_incoming_webhook_delete_at ON incomingwebhooks (deleteat);
|
||||
|
||||
ALTER TABLE incomingwebhooks ADD COLUMN IF NOT EXISTS username VARCHAR(255);
|
||||
ALTER TABLE incomingwebhooks ADD COLUMN IF NOT EXISTS iconurl VARCHAR(1024);
|
||||
ALTER TABLE incomingwebhooks ADD COLUMN IF NOT EXISTS channellocked boolean;
|
||||
ALTER TABLE incomingwebhooks ALTER COLUMN description TYPE VARCHAR(500);
|
||||
|
||||
DO $$
|
||||
<<checks>>
|
||||
DECLARE
|
||||
wrong_usernames_count integer := 0;
|
||||
wrong_icon_urls_count integer := 0;
|
||||
BEGIN
|
||||
SELECT COALESCE(
|
||||
SUM(
|
||||
CASE
|
||||
WHEN CHAR_LENGTH(username) > 255 THEN 1
|
||||
ELSE 0
|
||||
END
|
||||
),
|
||||
0) INTO wrong_usernames_count
|
||||
FROM incomingwebhooks;
|
||||
|
||||
SELECT COALESCE(
|
||||
SUM(
|
||||
CASE
|
||||
WHEN CHAR_LENGTH(iconurl) > 1024 THEN 1
|
||||
ELSE 0
|
||||
END
|
||||
),
|
||||
0) INTO wrong_icon_urls_count
|
||||
FROM incomingwebhooks;
|
||||
|
||||
IF wrong_usernames_count > 0 THEN
|
||||
RAISE EXCEPTION 'IncomingWebhooks column Username has data larger that 255 characters';
|
||||
END IF;
|
||||
|
||||
IF wrong_icon_urls_count > 0 THEN
|
||||
RAISE EXCEPTION 'IncomingWebhooks column IconURL has data larger that 1024 characters';
|
||||
END IF;
|
||||
END checks $$;
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS outgoingwebhooks;
|
||||
24
db/migrations/postgres/000014_create_outgoing_webhooks.up.sql
Обычный файл
24
db/migrations/postgres/000014_create_outgoing_webhooks.up.sql
Обычный файл
@@ -0,0 +1,24 @@
|
||||
CREATE TABLE IF NOT EXISTS outgoingwebhooks (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
token VARCHAR(26),
|
||||
createat bigint,
|
||||
updateat bigint,
|
||||
deleteat bigint,
|
||||
creatorid VARCHAR(26),
|
||||
channelid VARCHAR(26),
|
||||
teamid VARCHAR(26),
|
||||
triggerwords VARCHAR(1024),
|
||||
callbackurls VARCHAR(1024),
|
||||
displayname VARCHAR(64)
|
||||
);
|
||||
|
||||
ALTER TABLE outgoingwebhooks ADD COLUMN IF NOT EXISTS contenttype VARCHAR(128);
|
||||
ALTER TABLE outgoingwebhooks ADD COLUMN IF NOT EXISTS triggerwhen integer;
|
||||
ALTER TABLE outgoingwebhooks ADD COLUMN IF NOT EXISTS username VARCHAR(64);
|
||||
ALTER TABLE outgoingwebhooks ADD COLUMN IF NOT EXISTS iconurl VARCHAR(1024);
|
||||
ALTER TABLE outgoingwebhooks ADD COLUMN IF NOT EXISTS description VARCHAR(500);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_outgoing_webhook_team_id ON outgoingwebhooks (teamid);
|
||||
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);
|
||||
5
db/migrations/postgres/000015_create_systems.up.sql
Обычный файл
5
db/migrations/postgres/000015_create_systems.up.sql
Обычный файл
@@ -0,0 +1,5 @@
|
||||
CREATE TABLE IF NOT EXISTS systems (
|
||||
name VARCHAR(64),
|
||||
value VARCHAR(1024),
|
||||
PRIMARY KEY (name)
|
||||
);
|
||||
1
db/migrations/postgres/000016_create_reactions.down.sql
Обычный файл
1
db/migrations/postgres/000016_create_reactions.down.sql
Обычный файл
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS reactions;
|
||||
31
db/migrations/postgres/000016_create_reactions.up.sql
Обычный файл
31
db/migrations/postgres/000016_create_reactions.up.sql
Обычный файл
@@ -0,0 +1,31 @@
|
||||
CREATE TABLE IF NOT EXISTS reactions(
|
||||
userid VARCHAR(26) NOT NULL,
|
||||
postid VARCHAR(26) NOT NULL,
|
||||
emojiname VARCHAR(64) NOT NULL,
|
||||
createat bigint
|
||||
);
|
||||
|
||||
ALTER TABLE reactions ADD COLUMN IF NOT EXISTS updateat bigint;
|
||||
ALTER TABLE reactions ADD COLUMN IF NOT EXISTS deleteat bigint;
|
||||
|
||||
DO $$
|
||||
<<alter_pk>>
|
||||
DECLARE
|
||||
existing_index text;
|
||||
BEGIN
|
||||
SELECT string_agg(a.attname, ',') INTO existing_index
|
||||
FROM pg_constraint AS c
|
||||
CROSS JOIN
|
||||
(SELECT unnest(conkey) FROM pg_constraint WHERE conrelid = 'reactions'::regclass AND contype='p') AS cols(colnum)
|
||||
INNER JOIN pg_attribute AS a ON a.attrelid = c.conrelid AND cols.colnum = a.attnum
|
||||
WHERE c.contype = 'p'
|
||||
AND c.conrelid = 'reactions'::regclass;
|
||||
|
||||
IF COALESCE (existing_index, '') <> text('postid,userid,emojiname') THEN
|
||||
ALTER TABLE reactions
|
||||
DROP CONSTRAINT IF EXISTS reactions_pkey,
|
||||
ADD PRIMARY KEY (postid, userid, emojiname);
|
||||
END IF;
|
||||
END alter_pk $$;
|
||||
|
||||
ALTER TABLE reactions ADD COLUMN IF NOT EXISTS remoteid VARCHAR(26);
|
||||
1
db/migrations/postgres/000017_create_roles.down.sql
Обычный файл
1
db/migrations/postgres/000017_create_roles.down.sql
Обычный файл
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS roles;
|
||||
19
db/migrations/postgres/000017_create_roles.up.sql
Обычный файл
19
db/migrations/postgres/000017_create_roles.up.sql
Обычный файл
@@ -0,0 +1,19 @@
|
||||
CREATE TABLE IF NOT EXISTS roles (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
name VARCHAR(64),
|
||||
displayname VARCHAR(128),
|
||||
description VARCHAR(1024),
|
||||
createat bigint,
|
||||
updateat bigint,
|
||||
deleteat bigint,
|
||||
permissions VARCHAR(4096),
|
||||
schememanaged boolean,
|
||||
UNIQUE(name)
|
||||
);
|
||||
|
||||
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');
|
||||
|
||||
ALTER TABLE roles ALTER COLUMN permissions TYPE TEXT;
|
||||
1
db/migrations/postgres/000018_create_schemes.down.sql
Обычный файл
1
db/migrations/postgres/000018_create_schemes.down.sql
Обычный файл
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS schemes;
|
||||
25
db/migrations/postgres/000018_create_schemes.up.sql
Обычный файл
25
db/migrations/postgres/000018_create_schemes.up.sql
Обычный файл
@@ -0,0 +1,25 @@
|
||||
CREATE TABLE IF NOT EXISTS schemes (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
name VARCHAR(64),
|
||||
displayname VARCHAR(128),
|
||||
description VARCHAR(1024),
|
||||
createat bigint,
|
||||
updateat bigint,
|
||||
deleteat bigint,
|
||||
scope VARCHAR(32),
|
||||
defaultteamadminrole VARCHAR(64),
|
||||
defaultteamuserrole VARCHAR(64),
|
||||
defaultchanneladminrole VARCHAR(64),
|
||||
defaultchanneluserrole VARCHAR(64),
|
||||
UNIQUE(name)
|
||||
);
|
||||
|
||||
ALTER TABLE schemes ADD COLUMN IF NOT EXISTS defaultteamguestrole VARCHAR(64);
|
||||
ALTER TABLE schemes ADD COLUMN IF NOT EXISTS defaultchannelguestrole VARCHAR(64);
|
||||
|
||||
ALTER TABLE schemes ALTER COLUMN defaultteamguestrole TYPE VARCHAR(64);
|
||||
ALTER TABLE schemes ALTER COLUMN defaultchannelguestrole TYPE VARCHAR(64);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_schemes_channel_guest_role ON schemes (defaultchannelguestrole);
|
||||
CREATE INDEX IF NOT EXISTS idx_schemes_channel_user_role ON schemes (defaultchanneluserrole);
|
||||
CREATE INDEX IF NOT EXISTS idx_schemes_channel_admin_role ON schemes (defaultchanneladminrole);
|
||||
1
db/migrations/postgres/000019_create_licenses.down.sql
Обычный файл
1
db/migrations/postgres/000019_create_licenses.down.sql
Обычный файл
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS licenses;
|
||||
6
db/migrations/postgres/000019_create_licenses.up.sql
Обычный файл
6
db/migrations/postgres/000019_create_licenses.up.sql
Обычный файл
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE IF NOT EXISTS licenses (
|
||||
id VARCHAR(26) NOT NULL,
|
||||
createat bigint,
|
||||
bytes VARCHAR(10000),
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
3
db/migrations/postgres/000020_create_posts.down.sql
Обычный файл
3
db/migrations/postgres/000020_create_posts.down.sql
Обычный файл
@@ -0,0 +1,3 @@
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_channel_id ON posts (channelid);
|
||||
|
||||
DROP TABLE IF EXISTS posts;
|
||||
36
db/migrations/postgres/000020_create_posts.up.sql
Обычный файл
36
db/migrations/postgres/000020_create_posts.up.sql
Обычный файл
@@ -0,0 +1,36 @@
|
||||
CREATE TABLE IF NOT EXISTS posts (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
createat bigint,
|
||||
updateat bigint,
|
||||
deleteat bigint,
|
||||
userid VARCHAR(26),
|
||||
channelid VARCHAR(26),
|
||||
rootid VARCHAR(26),
|
||||
parentid VARCHAR(26),
|
||||
originalid VARCHAR(26),
|
||||
message VARCHAR(65535),
|
||||
type VARCHAR(26),
|
||||
props VARCHAR(8000),
|
||||
hashtags VARCHAR(1000),
|
||||
filenames VARCHAR(4000)
|
||||
);
|
||||
|
||||
ALTER TABLE posts ADD COLUMN IF NOT EXISTS fileids VARCHAR(300);
|
||||
ALTER TABLE posts ADD COLUMN IF NOT EXISTS hasreactions boolean;
|
||||
ALTER TABLE posts ADD COLUMN IF NOT EXISTS editat bigint;
|
||||
ALTER TABLE posts ADD COLUMN IF NOT EXISTS ispinned boolean;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_update_at ON posts(updateat);
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_create_at ON posts(createat);
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_delete_at ON posts(deleteat);
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_root_id ON posts(rootid);
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_user_id ON posts(userid);
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_is_pinned ON posts(ispinned);
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_channel_id_update_at ON posts(channelid, updateat);
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_channel_id_delete_at_create_at ON posts(channelid, deleteat, createat);
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_message_txt ON posts USING gin(to_tsvector('english', message));
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_hashtags_txt ON posts USING gin(to_tsvector('english', hashtags));
|
||||
|
||||
ALTER TABLE posts ADD COLUMN IF NOT EXISTS remoteid VARCHAR(26);
|
||||
|
||||
DROP INDEX IF EXISTS idx_posts_channel_id;
|
||||
@@ -0,0 +1,4 @@
|
||||
CREATE INDEX IF NOT EXISTS idx_notice_views_user_notice ON productnoticeviewstate (userid, noticeid);
|
||||
CREATE INDEX IF NOT EXISTS idx_notice_views_user_id ON productnoticeviewstate (userid);
|
||||
|
||||
DROP TABLE IF EXISTS productnoticeviewstate;
|
||||
@@ -0,0 +1,13 @@
|
||||
CREATE TABLE IF NOT EXISTS productnoticeviewstate (
|
||||
userid VARCHAR(26),
|
||||
noticeid VARCHAR(26),
|
||||
viewed integer,
|
||||
"timestamp" bigint,
|
||||
PRIMARY KEY (userid, noticeid)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_notice_views_notice_id ON productnoticeviewstate(noticeid);
|
||||
CREATE INDEX IF NOT EXISTS idx_notice_views_timestamp ON productnoticeviewstate("timestamp");
|
||||
|
||||
DROP INDEX IF EXISTS idx_notice_views_user_id;
|
||||
DROP INDEX IF EXISTS idx_notice_views_user_notice;
|
||||
1
db/migrations/postgres/000022_create_sessions.down.sql
Обычный файл
1
db/migrations/postgres/000022_create_sessions.down.sql
Обычный файл
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS sessions;
|
||||
22
db/migrations/postgres/000022_create_sessions.up.sql
Обычный файл
22
db/migrations/postgres/000022_create_sessions.up.sql
Обычный файл
@@ -0,0 +1,22 @@
|
||||
CREATE TABLE IF NOT EXISTS sessions (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
token VARCHAR(26),
|
||||
createat bigint,
|
||||
expiresat bigint,
|
||||
lastactivityat bigint,
|
||||
userid VARCHAR(26),
|
||||
deviceid VARCHAR(512),
|
||||
roles VARCHAR(64),
|
||||
isoauth boolean,
|
||||
props VARCHAR(1000)
|
||||
);
|
||||
|
||||
ALTER TABLE sessions ADD COLUMN IF NOT EXISTS expirednotify boolean;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_sessions_user_id ON sessions (userid);
|
||||
CREATE INDEX IF NOT EXISTS idx_sessions_token ON sessions (token);
|
||||
CREATE INDEX IF NOT EXISTS idx_sessions_expires_at ON sessions (expiresat);
|
||||
CREATE INDEX IF NOT EXISTS idx_sessions_create_at ON sessions (createat);
|
||||
CREATE INDEX IF NOT EXISTS idx_sessions_last_activity_at ON sessions (lastactivityat);
|
||||
|
||||
DELETE FROM sessions where expiresat > 3000000000000;
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS termsofservice;
|
||||
6
db/migrations/postgres/000023_create_terms_of_service.up.sql
Обычный файл
6
db/migrations/postgres/000023_create_terms_of_service.up.sql
Обычный файл
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE IF NOT EXISTS termsofservice (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
createat bigint,
|
||||
userid VARCHAR(26),
|
||||
text VARCHAR(65535)
|
||||
);
|
||||
3
db/migrations/postgres/000024_create_audits.down.sql
Обычный файл
3
db/migrations/postgres/000024_create_audits.down.sql
Обычный файл
@@ -0,0 +1,3 @@
|
||||
DROP INDEX IF EXISTS idx_audits_user_id;
|
||||
|
||||
DROP TABLE IF EXISTS audits;
|
||||
11
db/migrations/postgres/000024_create_audits.up.sql
Обычный файл
11
db/migrations/postgres/000024_create_audits.up.sql
Обычный файл
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS audits (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
createat bigint,
|
||||
userid VARCHAR(26),
|
||||
action VARCHAR(512),
|
||||
extrainfo VARCHAR(1024),
|
||||
ipaddress VARCHAR(64),
|
||||
sessionid VARCHAR(26)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_audits_user_id ON audits (userid);
|
||||
@@ -0,0 +1,3 @@
|
||||
CREATE INDEX IF NOT EXISTS idx_oauthaccessdata_client_id ON oauthaccessdata (clientid);
|
||||
|
||||
DROP TABLE IF EXISTS oauthaccessdata;
|
||||
36
db/migrations/postgres/000025_create_oauth_access_data.up.sql
Обычный файл
36
db/migrations/postgres/000025_create_oauth_access_data.up.sql
Обычный файл
@@ -0,0 +1,36 @@
|
||||
CREATE TABLE IF NOT EXISTS oauthaccessdata (
|
||||
token VARCHAR(26) NOT NULL,
|
||||
refreshtoken VARCHAR(26),
|
||||
redirecturi VARCHAR(256),
|
||||
PRIMARY KEY (token)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_oauthaccessdata_refresh_token ON oauthaccessdata (refreshtoken);
|
||||
|
||||
ALTER TABLE oauthaccessdata ADD COLUMN IF NOT EXISTS clientid VARCHAR(26);
|
||||
|
||||
ALTER TABLE oauthaccessdata ADD COLUMN IF NOT EXISTS userid VARCHAR(26);
|
||||
CREATE INDEX IF NOT EXISTS idx_oauthaccessdata_user_id ON oauthaccessdata (userid);
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT conname
|
||||
FROM pg_constraint
|
||||
WHERE conname = 'oauthaccessdata_clientid_userid_key'
|
||||
)
|
||||
THEN
|
||||
ALTER TABLE oauthaccessdata ADD CONSTRAINT oauthaccessdata_clientid_userid_key UNIQUE (clientid, userid);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
ALTER TABLE oauthaccessdata ADD COLUMN IF NOT EXISTS expiresat bigint;
|
||||
|
||||
DROP INDEX IF EXISTS idx_oauthaccessdata_auth_code;
|
||||
ALTER TABLE oauthaccessdata DROP COLUMN IF EXISTS authcode;
|
||||
|
||||
ALTER TABLE oauthaccessdata ADD COLUMN IF NOT EXISTS scope VARCHAR(128);
|
||||
|
||||
DROP INDEX IF EXISTS clientid_2;
|
||||
|
||||
DROP INDEX IF EXISTS idx_oauthaccessdata_client_id;
|
||||
3
db/migrations/postgres/000026_create_preferences.down.sql
Обычный файл
3
db/migrations/postgres/000026_create_preferences.down.sql
Обычный файл
@@ -0,0 +1,3 @@
|
||||
CREATE INDEX IF NOT EXISTS idx_preferences_user_id ON preferences (userid);
|
||||
|
||||
DROP TABLE IF EXISTS preferences;
|
||||
51
db/migrations/postgres/000026_create_preferences.up.sql
Обычный файл
51
db/migrations/postgres/000026_create_preferences.up.sql
Обычный файл
@@ -0,0 +1,51 @@
|
||||
CREATE TABLE IF NOT EXISTS preferences (
|
||||
userid varchar(26) NOT NULL,
|
||||
category varchar(32) NOT NULL,
|
||||
name varchar(32) NOT NULL,
|
||||
value varchar(2000),
|
||||
PRIMARY KEY (userid, category, name)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_preferences_category ON preferences(category);
|
||||
CREATE INDEX IF NOT EXISTS idx_preferences_name ON preferences(name);
|
||||
|
||||
DO $$
|
||||
<<modify_column_type_if_type_is_different>>
|
||||
DECLARE
|
||||
type_exists boolean := false;
|
||||
col_exists boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO col_exists
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'preferences'
|
||||
AND column_name = 'value';
|
||||
|
||||
SELECT count(*) != 0 INTO type_exists
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'preferences'
|
||||
AND column_name = 'value'
|
||||
AND data_type = 'character varying'
|
||||
AND character_maximum_length = 2000;
|
||||
|
||||
IF col_exists AND NOT type_exists THEN
|
||||
ALTER TABLE preferences ALTER COLUMN value TYPE varchar(2000);
|
||||
END IF;
|
||||
END modify_column_type_if_type_is_different $$;
|
||||
|
||||
DO $$
|
||||
<<rename_solarized_theme>>
|
||||
DECLARE
|
||||
preference record;
|
||||
BEGIN
|
||||
FOR preference IN
|
||||
SELECT * FROM preferences WHERE category = 'theme' AND value LIKE '%solarized_%'
|
||||
LOOP
|
||||
UPDATE preferences
|
||||
SET value = replace(preference.value, 'solarized_', 'solarized-')
|
||||
WHERE userid = preference.userid
|
||||
AND category = preference.category
|
||||
AND name = preference.name;
|
||||
END LOOP;
|
||||
END rename_solarized_theme $$;
|
||||
|
||||
DROP INDEX IF EXISTS idx_preferences_user_id;
|
||||
3
db/migrations/postgres/000027_create_status.down.sql
Обычный файл
3
db/migrations/postgres/000027_create_status.down.sql
Обычный файл
@@ -0,0 +1,3 @@
|
||||
CREATE INDEX IF NOT EXISTS idx_status_user_id ON status (userid);
|
||||
|
||||
DROP TABLE IF EXISTS status;
|
||||
15
db/migrations/postgres/000027_create_status.up.sql
Обычный файл
15
db/migrations/postgres/000027_create_status.up.sql
Обычный файл
@@ -0,0 +1,15 @@
|
||||
CREATE TABLE IF NOT EXISTS status (
|
||||
userid VARCHAR(26) PRIMARY KEY,
|
||||
status VARCHAR(32),
|
||||
manual boolean,
|
||||
lastactivityat bigint
|
||||
);
|
||||
|
||||
ALTER TABLE status DROP COLUMN IF EXISTS activechannel;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_status_status ON status(status);
|
||||
|
||||
ALTER TABLE status ADD COLUMN IF NOT EXISTS dndendtime bigint;
|
||||
ALTER TABLE status ADD COLUMN IF NOT EXISTS prevstatus VARCHAR(32);
|
||||
|
||||
DROP INDEX IF EXISTS idx_status_user_id;
|
||||
1
db/migrations/postgres/000028_create_tokens.down.sql
Обычный файл
1
db/migrations/postgres/000028_create_tokens.down.sql
Обычный файл
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS tokens;
|
||||
31
db/migrations/postgres/000028_create_tokens.up.sql
Обычный файл
31
db/migrations/postgres/000028_create_tokens.up.sql
Обычный файл
@@ -0,0 +1,31 @@
|
||||
CREATE TABLE IF NOT EXISTS tokens (
|
||||
token VARCHAR(64) PRIMARY KEY,
|
||||
createat bigint,
|
||||
type VARCHAR(64),
|
||||
extra VARCHAR(2048)
|
||||
);
|
||||
|
||||
ALTER TABLE tokens ALTER COLUMN extra TYPE VARCHAR(2048);
|
||||
|
||||
DO $$
|
||||
<<modify_column_type_if_type_is_different>>
|
||||
DECLARE
|
||||
type_exists boolean := false;
|
||||
col_exists boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO col_exists
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'tokens'
|
||||
AND column_name = 'extra';
|
||||
|
||||
SELECT count(*) != 0 INTO type_exists
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'tokens'
|
||||
AND column_name = 'extra'
|
||||
AND data_type = 'character varying'
|
||||
AND character_maximum_length = 2048;
|
||||
|
||||
IF col_exists AND NOT type_exists THEN
|
||||
ALTER TABLE tokens ALTER COLUMN extra TYPE VARCHAR(2048);
|
||||
END IF;
|
||||
END modify_column_type_if_type_is_different $$;
|
||||
3
db/migrations/postgres/000029_create_bots.down.sql
Обычный файл
3
db/migrations/postgres/000029_create_bots.down.sql
Обычный файл
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE bots DROP COLUMN IF EXISTS lasticonupdate;
|
||||
|
||||
DROP TABLE IF EXISTS bots;
|
||||
10
db/migrations/postgres/000029_create_bots.up.sql
Обычный файл
10
db/migrations/postgres/000029_create_bots.up.sql
Обычный файл
@@ -0,0 +1,10 @@
|
||||
CREATE TABLE IF NOT EXISTS bots (
|
||||
userid VARCHAR(26) PRIMARY KEY,
|
||||
description VARCHAR(1024),
|
||||
ownerid VARCHAR(190),
|
||||
createat bigint,
|
||||
updateat bigint,
|
||||
deleteat bigint
|
||||
);
|
||||
|
||||
ALTER TABLE bots ADD COLUMN IF NOT EXISTS lasticonupdate bigint;
|
||||
@@ -0,0 +1,3 @@
|
||||
CREATE INDEX IF NOT EXISTS idx_user_access_tokens_token ON useraccesstokens (token);
|
||||
|
||||
DROP TABLE IF EXISTS useraccesstokens;
|
||||
11
db/migrations/postgres/000030_create_user_access_tokens.up.sql
Обычный файл
11
db/migrations/postgres/000030_create_user_access_tokens.up.sql
Обычный файл
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS useraccesstokens (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
token VARCHAR(26) UNIQUE,
|
||||
userid VARCHAR(26),
|
||||
description VARCHAR(512)
|
||||
);
|
||||
|
||||
ALTER TABLE useraccesstokens ADD COLUMN IF NOT EXISTS isactive boolean;
|
||||
CREATE INDEX IF NOT EXISTS idx_user_access_tokens_user_id ON useraccesstokens(userid);
|
||||
|
||||
DROP INDEX IF EXISTS idx_user_access_tokens_token;
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS remoteclusters;
|
||||
16
db/migrations/postgres/000031_create_remote_clusters.up.sql
Обычный файл
16
db/migrations/postgres/000031_create_remote_clusters.up.sql
Обычный файл
@@ -0,0 +1,16 @@
|
||||
CREATE TABLE IF NOT EXISTS remoteclusters (
|
||||
remoteid VARCHAR(26) NOT NULL,
|
||||
remoteteamid VARCHAR(26),
|
||||
name VARCHAR(64) NOT NULL,
|
||||
displayname VARCHAR(64),
|
||||
siteurl VARCHAR(512),
|
||||
createat bigint,
|
||||
lastpingat bigint,
|
||||
token VARCHAR(26),
|
||||
remotetoken VARCHAR(26),
|
||||
topics VARCHAR(512),
|
||||
creatorid VARCHAR(26),
|
||||
PRIMARY KEY (remoteid, name)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS remote_clusters_site_url_unique ON remoteclusters (siteurl, remoteteamid);
|
||||
1
db/migrations/postgres/000032_create_sharedchannels.down.sql
Обычный файл
1
db/migrations/postgres/000032_create_sharedchannels.down.sql
Обычный файл
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS sharedchannels;
|
||||
16
db/migrations/postgres/000032_create_sharedchannels.up.sql
Обычный файл
16
db/migrations/postgres/000032_create_sharedchannels.up.sql
Обычный файл
@@ -0,0 +1,16 @@
|
||||
CREATE TABLE IF NOT EXISTS sharedchannels (
|
||||
channelid character varying(26) NOT NULL,
|
||||
teamid character varying(26),
|
||||
home boolean,
|
||||
readonly boolean,
|
||||
sharename character varying(64),
|
||||
sharedisplayname character varying(64),
|
||||
sharepurpose character varying(250),
|
||||
shareheader character varying(1024),
|
||||
creatorid character varying(26),
|
||||
createat bigint,
|
||||
updateat bigint,
|
||||
remoteid character varying(26),
|
||||
PRIMARY KEY (channelid),
|
||||
UNIQUE (sharename, teamid)
|
||||
);
|
||||
@@ -5,12 +5,14 @@ DECLARE
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO col_exist_and_type_different
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'teammembers'
|
||||
AND column_name = 'roles'
|
||||
WHERE table_name = 'sidebarchannels'
|
||||
AND column_name = 'categoryid'
|
||||
AND data_type = 'character varying'
|
||||
AND NOT character_maximum_length = 64;
|
||||
AND NOT character_maximum_length = 26;
|
||||
|
||||
IF col_exist_and_type_different THEN
|
||||
ALTER TABLE teammembers ALTER COLUMN roles TYPE varchar(64);
|
||||
ALTER TABLE sidebarchannels ALTER COLUMN categoryid TYPE varchar(26);
|
||||
END IF;
|
||||
END modify_column_type_if_type_is_different $$
|
||||
END modify_column_type_if_type_is_different $$;
|
||||
|
||||
DROP TABLE IF EXISTS sidebarchannels;
|
||||
24
db/migrations/postgres/000033_create_sidebar_channels.up.sql
Обычный файл
24
db/migrations/postgres/000033_create_sidebar_channels.up.sql
Обычный файл
@@ -0,0 +1,24 @@
|
||||
CREATE TABLE IF NOT EXISTS sidebarchannels (
|
||||
channelid VARCHAR(26),
|
||||
userid VARCHAR(26),
|
||||
categoryid VARCHAR(26),
|
||||
sortorder bigint,
|
||||
PRIMARY KEY (channelid, userid, categoryid)
|
||||
);
|
||||
|
||||
DO $$
|
||||
<<modify_column_type_if_type_is_different>>
|
||||
DECLARE
|
||||
col_exist_and_type_different boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO col_exist_and_type_different
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'sidebarchannels'
|
||||
AND column_name = 'categoryid'
|
||||
AND data_type = 'character varying'
|
||||
AND NOT character_maximum_length = 128;
|
||||
|
||||
IF col_exist_and_type_different THEN
|
||||
ALTER TABLE sidebarchannels ALTER COLUMN categoryid TYPE varchar(128);
|
||||
END IF;
|
||||
END modify_column_type_if_type_is_different $$
|
||||
3
db/migrations/postgres/000034_create_oauthauthdata.down.sql
Обычный файл
3
db/migrations/postgres/000034_create_oauthauthdata.down.sql
Обычный файл
@@ -0,0 +1,3 @@
|
||||
CREATE INDEX IF NOT EXISTS idx_oauthauthdata_client_id ON oauthauthdata (code);
|
||||
|
||||
DROP TABLE IF EXISTS oauthauthdata;
|
||||
36
db/migrations/postgres/000034_create_oauthauthdata.up.sql
Обычный файл
36
db/migrations/postgres/000034_create_oauthauthdata.up.sql
Обычный файл
@@ -0,0 +1,36 @@
|
||||
CREATE TABLE IF NOT EXISTS oauthauthdata (
|
||||
clientid varchar(26),
|
||||
userid varchar(26),
|
||||
code varchar(128) NOT NULL,
|
||||
expiresin integer,
|
||||
createat bigint,
|
||||
redirecturi varchar(256),
|
||||
state varchar(1024),
|
||||
scope varchar(128),
|
||||
PRIMARY KEY (code)
|
||||
);
|
||||
|
||||
DO $$
|
||||
<<modify_column_type_if_type_is_different>>
|
||||
DECLARE
|
||||
type_exists boolean := false;
|
||||
col_exists boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO col_exists
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'oauthauthdata'
|
||||
AND column_name = 'state';
|
||||
|
||||
SELECT count(*) != 0 INTO type_exists
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'oauthauthdata'
|
||||
AND column_name = 'state'
|
||||
AND data_type = 'character varying'
|
||||
AND character_maximum_length = 1024;
|
||||
|
||||
IF col_exists AND NOT type_exists THEN
|
||||
ALTER TABLE oauthauthdata ALTER COLUMN state TYPE varchar(1024);
|
||||
END IF;
|
||||
END modify_column_type_if_type_is_different $$;
|
||||
|
||||
DROP INDEX IF EXISTS idx_oauthauthdata_client_id;
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS sharedchannelattachments;
|
||||
@@ -0,0 +1,9 @@
|
||||
CREATE TABLE IF NOT EXISTS sharedchannelattachments (
|
||||
id varchar(26) NOT NULL,
|
||||
fileid varchar(26),
|
||||
remoteid varchar(26),
|
||||
createat bigint,
|
||||
lastsyncat bigint,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE (fileid, remoteid)
|
||||
);
|
||||
@@ -0,0 +1,5 @@
|
||||
CREATE INDEX IF NOT EXISTS idx_sharedchannelusers_user_id ON sharedchannelusers (userid);
|
||||
|
||||
ALTER TABLE sharedchannelusers DROP COLUMN IF EXISTS channelid;
|
||||
|
||||
DROP TABLE IF EXISTS sharedchannelusers;
|
||||
26
db/migrations/postgres/000036_create_sharedchannelusers.up.sql
Обычный файл
26
db/migrations/postgres/000036_create_sharedchannelusers.up.sql
Обычный файл
@@ -0,0 +1,26 @@
|
||||
CREATE TABLE IF NOT EXISTS sharedchannelusers (
|
||||
id varchar(26) NOT NULL,
|
||||
userid varchar(26),
|
||||
remoteid varchar(26),
|
||||
createat bigint,
|
||||
lastsyncat bigint,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
ALTER TABLE sharedchannelusers ADD COLUMN IF NOT EXISTS channelid varchar(26);
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT conname
|
||||
FROM pg_constraint
|
||||
WHERE conname = 'sharedchannelusers_userid_channelid_remoteid_key'
|
||||
)
|
||||
THEN
|
||||
ALTER TABLE sharedchannelusers ADD CONSTRAINT sharedchannelusers_userid_channelid_remoteid_key UNIQUE (userid, channelid, remoteid);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
DROP INDEX IF EXISTS idx_sharedchannelusers_user_id;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_sharedchannelusers_remote_id ON sharedchannelusers(remoteid);
|
||||
@@ -0,0 +1,4 @@
|
||||
ALTER TABLE sharedchannelremotes DROP COLUMN IF EXISTS LastPostId;
|
||||
ALTER TABLE sharedchannelremotes DROP COLUMN IF EXISTS LastPostUpdateAt;
|
||||
|
||||
DROP TABLE IF EXISTS sharedchannelremotes;
|
||||
15
db/migrations/postgres/000037_create_sharedchannelremotes.up.sql
Обычный файл
15
db/migrations/postgres/000037_create_sharedchannelremotes.up.sql
Обычный файл
@@ -0,0 +1,15 @@
|
||||
CREATE TABLE IF NOT EXISTS sharedchannelremotes (
|
||||
id character varying(26) NOT NULL,
|
||||
channelid character varying(26) NOT NULL,
|
||||
creatorid character varying(26),
|
||||
createat bigint,
|
||||
updateat bigint,
|
||||
isinviteaccepted boolean,
|
||||
isinviteconfirmed boolean,
|
||||
remoteid character varying(26),
|
||||
PRIMARY KEY(id, channelid),
|
||||
UNIQUE(channelid, remoteid)
|
||||
);
|
||||
|
||||
ALTER TABLE sharedchannelremotes ADD COLUMN IF NOT EXISTS LastPostUpdateAt bigint;
|
||||
ALTER TABLE sharedchannelremotes ADD COLUMN IF NOT EXISTS LastPostId character varying(26);
|
||||
3
db/migrations/postgres/000038_create_jobs.down.sql
Обычный файл
3
db/migrations/postgres/000038_create_jobs.down.sql
Обычный файл
@@ -0,0 +1,3 @@
|
||||
DROP INDEX IF EXISTS idx_jobs_type;
|
||||
|
||||
DROP TABLE IF EXISTS jobs;
|
||||
13
db/migrations/postgres/000038_create_jobs.up.sql
Обычный файл
13
db/migrations/postgres/000038_create_jobs.up.sql
Обычный файл
@@ -0,0 +1,13 @@
|
||||
CREATE TABLE IF NOT EXISTS jobs (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
type VARCHAR(32),
|
||||
priority bigint,
|
||||
createat bigint,
|
||||
startat bigint,
|
||||
lastactivityat bigint,
|
||||
status VARCHAR(32),
|
||||
progress bigint,
|
||||
data VARCHAR(1024)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_jobs_type ON jobs (type);
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS channelmemberhistory;
|
||||
@@ -0,0 +1,10 @@
|
||||
CREATE TABLE IF NOT EXISTS channelmemberhistory (
|
||||
channelid VARCHAR(26) NOT NULL,
|
||||
userid VARCHAR(26) NOT NULL,
|
||||
jointime bigint NOT NULL,
|
||||
leavetime bigint,
|
||||
PRIMARY KEY (channelid, userid, jointime)
|
||||
);
|
||||
|
||||
ALTER TABLE channelmemberhistory DROP COLUMN IF EXISTS email;
|
||||
ALTER TABLE channelmemberhistory DROP COLUMN IF EXISTS username;
|
||||
21
db/migrations/postgres/000040_create_sidebar_categories.down.sql
Обычный файл
21
db/migrations/postgres/000040_create_sidebar_categories.down.sql
Обычный файл
@@ -0,0 +1,21 @@
|
||||
ALTER TABLE sidebarcategories DROP COLUMN IF EXISTS collapsed;
|
||||
ALTER TABLE sidebarcategories DROP COLUMN IF EXISTS muted;
|
||||
|
||||
DO $$
|
||||
<<modify_column_type_if_type_is_different>>
|
||||
DECLARE
|
||||
col_exist_and_type_different boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO col_exist_and_type_different
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'sidebarcategories'
|
||||
AND column_name = 'id'
|
||||
AND data_type = 'character varying'
|
||||
AND NOT character_maximum_length = 26;
|
||||
|
||||
IF col_exist_and_type_different THEN
|
||||
ALTER TABLE sidebarcategories ALTER COLUMN id TYPE varchar(26);
|
||||
END IF;
|
||||
END modify_column_type_if_type_is_different $$;
|
||||
|
||||
DROP TABLE IF EXISTS sidebarcategories;
|
||||
30
db/migrations/postgres/000040_create_sidebar_categories.up.sql
Обычный файл
30
db/migrations/postgres/000040_create_sidebar_categories.up.sql
Обычный файл
@@ -0,0 +1,30 @@
|
||||
CREATE TABLE IF NOT EXISTS sidebarcategories (
|
||||
id VARCHAR(26),
|
||||
userid VARCHAR(26),
|
||||
teamid VARCHAR(26),
|
||||
sortorder bigint,
|
||||
sorting VARCHAR(64),
|
||||
type VARCHAR(64),
|
||||
displayname VARCHAR(64),
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
DO $$
|
||||
<<modify_column_type_if_type_is_different>>
|
||||
DECLARE
|
||||
col_exist_and_type_different boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO col_exist_and_type_different
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'sidebarcategories'
|
||||
AND column_name = 'id'
|
||||
AND data_type = 'character varying'
|
||||
AND NOT character_maximum_length = 128;
|
||||
|
||||
IF col_exist_and_type_different THEN
|
||||
ALTER TABLE sidebarcategories ALTER COLUMN id TYPE varchar(128);
|
||||
END IF;
|
||||
END modify_column_type_if_type_is_different $$;
|
||||
|
||||
ALTER TABLE sidebarcategories ADD COLUMN IF NOT EXISTS muted boolean;
|
||||
ALTER TABLE sidebarcategories ADD COLUMN IF NOT EXISTS collapsed boolean;
|
||||
@@ -0,0 +1,4 @@
|
||||
ALTER TABLE uploadsessions DROP COLUMN IF EXISTS reqfileid;
|
||||
ALTER TABLE uploadsessions DROP COLUMN IF EXISTS remoteid;
|
||||
|
||||
DROP TABLE IF EXISTS uploadsessions;
|
||||
18
db/migrations/postgres/000041_create_upload_sessions.up.sql
Обычный файл
18
db/migrations/postgres/000041_create_upload_sessions.up.sql
Обычный файл
@@ -0,0 +1,18 @@
|
||||
CREATE TABLE IF NOT EXISTS uploadsessions (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
type VARCHAR(32),
|
||||
createat bigint,
|
||||
userid VARCHAR(26),
|
||||
channelid VARCHAR(26),
|
||||
filename VARCHAR(256),
|
||||
path VARCHAR(512),
|
||||
filesize bigint,
|
||||
fileoffset bigint
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_uploadsessions_user_id ON uploadsessions(userid);
|
||||
CREATE INDEX IF NOT EXISTS idx_uploadsessions_create_at ON uploadsessions(createat);
|
||||
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);
|
||||
5
db/migrations/postgres/000042_create_threads.down.sql
Обычный файл
5
db/migrations/postgres/000042_create_threads.down.sql
Обычный файл
@@ -0,0 +1,5 @@
|
||||
DROP INDEX IF EXISTS idx_threads_channel_id;
|
||||
|
||||
ALTER TABLE threads DROP COLUMN IF EXISTS channelid;
|
||||
|
||||
DROP TABLE IF EXISTS threads;
|
||||
16
db/migrations/postgres/000042_create_threads.up.sql
Обычный файл
16
db/migrations/postgres/000042_create_threads.up.sql
Обычный файл
@@ -0,0 +1,16 @@
|
||||
CREATE TABLE IF NOT EXISTS threads (
|
||||
postid VARCHAR(26) PRIMARY KEY,
|
||||
replycount bigint,
|
||||
lastreplyat bigint,
|
||||
participants text
|
||||
);
|
||||
|
||||
ALTER TABLE threads ADD COLUMN IF NOT EXISTS channelid VARCHAR(26);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_threads_channel_id ON threads (channelid);
|
||||
|
||||
UPDATE threads
|
||||
SET channelId=posts.channelid
|
||||
FROM posts
|
||||
WHERE posts.id=threads.postid
|
||||
AND threads.channelid IS NULL;
|
||||
7
db/migrations/postgres/000043_thread_memberships.down.sql
Обычный файл
7
db/migrations/postgres/000043_thread_memberships.down.sql
Обычный файл
@@ -0,0 +1,7 @@
|
||||
DROP INDEX IF EXISTS idx_thread_memberships_user_id;
|
||||
DROP INDEX IF EXISTS idx_thread_memberships_last_view_at;
|
||||
DROP INDEX IF EXISTS idx_thread_memberships_last_update_at;
|
||||
|
||||
ALTER TABLE threadmemberships DROP COLUMN IF EXISTS unreadmentions;
|
||||
|
||||
DROP TABLE IF EXISTS theadmemberships;
|
||||
14
db/migrations/postgres/000043_thread_memberships.up.sql
Обычный файл
14
db/migrations/postgres/000043_thread_memberships.up.sql
Обычный файл
@@ -0,0 +1,14 @@
|
||||
CREATE TABLE IF NOT EXISTS threadmemberships(
|
||||
postid VARCHAR(26) NOT NULL,
|
||||
userid VARCHAR(26) NOT NULL,
|
||||
following boolean,
|
||||
lastviewed bigint,
|
||||
lastupdated bigint,
|
||||
PRIMARY KEY (postid, userid)
|
||||
);
|
||||
|
||||
ALTER TABLE threadmemberships ADD COLUMN IF NOT EXISTS unreadmentions bigint;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_thread_memberships_last_update_at ON threadmemberships(lastupdated);
|
||||
CREATE INDEX IF NOT EXISTS idx_thread_memberships_last_view_at ON threadmemberships(lastviewed);
|
||||
CREATE INDEX IF NOT EXISTS idx_thread_memberships_user_id ON threadmemberships(userid);
|
||||
@@ -0,0 +1,3 @@
|
||||
CREATE INDEX IF NOT EXISTS idx_user_terms_of_service_user_id ON usertermsofservice (userid);
|
||||
|
||||
DROP TABLE IF EXISTS usertermsofservice;
|
||||
@@ -0,0 +1,27 @@
|
||||
-- This migration depends on users table
|
||||
CREATE TABLE IF NOT EXISTS usertermsofservice (
|
||||
userid VARCHAR(26) PRIMARY KEY,
|
||||
termsofserviceid VARCHAR(26),
|
||||
createat bigint
|
||||
);
|
||||
|
||||
DO $$
|
||||
<<do_migrate_to_usertermsofservice_table>>
|
||||
DECLARE
|
||||
col_exist boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO col_exist
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'users'
|
||||
AND column_name = 'acceptedtermsofserviceid';
|
||||
|
||||
IF col_exist THEN
|
||||
INSERT INTO usertermsofservice
|
||||
SELECT id, acceptedtermsofserviceid as termsofserviceid, (extract(epoch from now()) * 1000)
|
||||
FROM users
|
||||
WHERE acceptedtermsofserviceid != ''
|
||||
AND acceptedtermsofserviceid IS NOT NULL;
|
||||
END IF;
|
||||
END do_migrate_to_usertermsofservice_table $$;
|
||||
|
||||
DROP INDEX IF EXISTS idx_user_terms_of_service_user_id;
|
||||
@@ -0,0 +1,15 @@
|
||||
DO $$BEGIN
|
||||
IF (
|
||||
SELECT column_default::bigint
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema='public'
|
||||
AND table_name='pluginkeyvaluestore'
|
||||
AND column_name='expireat'
|
||||
) IS NULL THEN
|
||||
ALTER TABLE pluginkeyvaluestore ALTER COLUMN expireat SET DEFAULT 0;
|
||||
END IF;
|
||||
END$$;
|
||||
|
||||
ALTER TABLE pluginkeyvaluestore DROP COLUMN IF EXISTS expireat;
|
||||
|
||||
DROP TABLE IF EXISTS pluginkeyvaluestore;
|
||||
@@ -0,0 +1,20 @@
|
||||
CREATE TABLE IF NOT EXISTS pluginkeyvaluestore (
|
||||
pluginid VARCHAR(190) NOT NULL,
|
||||
pkey VARCHAR(50) NOT NULL,
|
||||
pvalue bytea,
|
||||
PRIMARY KEY (pluginid, pkey)
|
||||
);
|
||||
|
||||
ALTER TABLE pluginkeyvaluestore ADD COLUMN IF NOT EXISTS expireat bigint DEFAULT 0;
|
||||
|
||||
DO $$BEGIN
|
||||
IF (
|
||||
SELECT column_default::bigint
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema='public'
|
||||
AND table_name='pluginkeyvaluestore'
|
||||
AND column_name='expireat'
|
||||
) = 0 THEN
|
||||
ALTER TABLE pluginkeyvaluestore ALTER COLUMN expireat SET DEFAULT NULL;
|
||||
END IF;
|
||||
END$$;
|
||||
5
db/migrations/postgres/000046_create_users.down.sql
Обычный файл
5
db/migrations/postgres/000046_create_users.down.sql
Обычный файл
@@ -0,0 +1,5 @@
|
||||
CREATE INDEX IF NOT EXISTS idx_users_email ON users (email);
|
||||
|
||||
ALTER TABLE users DROP COLUMN IF EXISTS remoteid;
|
||||
|
||||
DROP TABLE IF EXISTS users;
|
||||
58
db/migrations/postgres/000046_create_users.up.sql
Обычный файл
58
db/migrations/postgres/000046_create_users.up.sql
Обычный файл
@@ -0,0 +1,58 @@
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
createat bigint,
|
||||
updateat bigint,
|
||||
deleteat bigint,
|
||||
username VARCHAR(64) UNIQUE,
|
||||
password VARCHAR(128),
|
||||
authdata VARCHAR(128) UNIQUE,
|
||||
authservice VARCHAR(32),
|
||||
email VARCHAR(128) UNIQUE,
|
||||
emailverified boolean,
|
||||
nickname VARCHAR(64),
|
||||
firstname VARCHAR(64),
|
||||
lastname VARCHAR(64),
|
||||
roles VARCHAR(256),
|
||||
allowmarketing boolean,
|
||||
props VARCHAR(4000),
|
||||
notifyprops VARCHAR(2000),
|
||||
lastpasswordupdate bigint,
|
||||
lastpictureupdate bigint,
|
||||
failedattempts integer,
|
||||
locale VARCHAR(5),
|
||||
mfaactive boolean,
|
||||
mfasecret VARCHAR(128)
|
||||
);
|
||||
|
||||
ALTER TABLE users DROP COLUMN IF EXISTS lastactivityat;
|
||||
ALTER TABLE users DROP COLUMN IF EXISTS lastpingat;
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS position VARCHAR(128);
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS timezone VARCHAR(256) DEFAULT '{"automaticTimezone":"","manualTimezone":"","useAutomaticTimezone":"true"}';
|
||||
ALTER TABLE users ALTER COLUMN position TYPE VARCHAR(128);
|
||||
UPDATE Users SET AuthData=LOWER(AuthData) WHERE AuthService = 'saml';
|
||||
ALTER TABLE users ALTER COLUMN roles TYPE VARCHAR(256);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_users_update_at ON users (updateat);
|
||||
CREATE INDEX IF NOT EXISTS idx_users_create_at ON users (createat);
|
||||
CREATE INDEX IF NOT EXISTS idx_users_delete_at ON users (deleteat);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_users_email_lower_textpattern ON users (lower(email) text_pattern_ops);
|
||||
CREATE INDEX IF NOT EXISTS idx_users_username_lower_textpattern ON users (lower(username) text_pattern_ops);
|
||||
CREATE INDEX IF NOT EXISTS idx_users_nickname_lower_textpattern ON users (lower(nickname) text_pattern_ops);
|
||||
CREATE INDEX IF NOT EXISTS idx_users_firstname_lower_textpattern ON users (lower(firstname) text_pattern_ops);
|
||||
CREATE INDEX IF NOT EXISTS idx_users_lastname_lower_textpattern ON users (lower(lastname) text_pattern_ops);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_users_all_txt ON users USING gin(to_tsvector('english', username || ' ' || firstname || ' ' || lastname || ' ' || nickname || ' ' || email));
|
||||
CREATE INDEX IF NOT EXISTS idx_users_all_no_full_name_txt ON users USING gin(to_tsvector('english', username || ' ' || nickname || ' ' || email));
|
||||
CREATE INDEX IF NOT EXISTS idx_users_names_txt ON users USING gin(to_tsvector('english', username || ' ' || firstname || ' ' || lastname || ' ' || nickname));
|
||||
CREATE INDEX IF NOT EXISTS idx_users_names_no_full_name_txt ON users USING gin(to_tsvector('english', username || ' ' || nickname));
|
||||
|
||||
DROP INDEX IF EXISTS idx_users_email_lower;
|
||||
DROP INDEX IF EXISTS idx_users_username_lower;
|
||||
DROP INDEX IF EXISTS idx_users_nickname_lower;
|
||||
DROP INDEX IF EXISTS idx_users_firstname_lower;
|
||||
DROP INDEX IF EXISTS idx_users_lastname_lower;
|
||||
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS remoteid VARCHAR(26);
|
||||
|
||||
DROP INDEX IF EXISTS idx_users_email;
|
||||
14
db/migrations/postgres/000047_create_file_info.down.sql
Обычный файл
14
db/migrations/postgres/000047_create_file_info.down.sql
Обычный файл
@@ -0,0 +1,14 @@
|
||||
ALTER TABLE fileinfo DROP COLUMN IF EXISTS remoteid;
|
||||
|
||||
DROP INDEX IF EXISTS idx_fileinfo_content_txt;
|
||||
ALTER TABLE fileinfo DROP COLUMN IF EXISTS content;
|
||||
ALTER TABLE fileinfo DROP COLUMN IF EXISTS minipreview;
|
||||
|
||||
DROP INDEX IF EXISTS idx_fileinfo_name_txt;
|
||||
DROP INDEX IF EXISTS idx_fileinfo_extension_at;
|
||||
DROP INDEX IF EXISTS idx_fileinfo_postid_at;
|
||||
DROP INDEX IF EXISTS idx_fileinfo_delete_at;
|
||||
DROP INDEX IF EXISTS idx_fileinfo_create_at;
|
||||
DROP INDEX IF EXISTS idx_fileinfo_update_at;
|
||||
|
||||
DROP TABLE IF EXISTS fileinfo;
|
||||
33
db/migrations/postgres/000047_create_file_info.up.sql
Обычный файл
33
db/migrations/postgres/000047_create_file_info.up.sql
Обычный файл
@@ -0,0 +1,33 @@
|
||||
CREATE TABLE IF NOT EXISTS fileinfo (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
creatorid VARCHAR(26),
|
||||
postid VARCHAR(26),
|
||||
createat bigint,
|
||||
updateat bigint,
|
||||
deleteat bigint,
|
||||
path VARCHAR(512),
|
||||
thumbnailpath VARCHAR(512),
|
||||
previewpath VARCHAR(512),
|
||||
name VARCHAR(256),
|
||||
extension VARCHAR(64),
|
||||
size bigint,
|
||||
mimetype VARCHAR(256),
|
||||
width integer,
|
||||
height integer,
|
||||
haspreviewimage boolean
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_fileinfo_update_at ON fileinfo (updateat);
|
||||
CREATE INDEX IF NOT EXISTS idx_fileinfo_create_at ON fileinfo (createat);
|
||||
CREATE INDEX IF NOT EXISTS idx_fileinfo_delete_at ON fileinfo (deleteat);
|
||||
CREATE INDEX IF NOT EXISTS idx_fileinfo_postid_at ON fileinfo (postid);
|
||||
CREATE INDEX IF NOT EXISTS idx_fileinfo_extension_at ON fileinfo (extension);
|
||||
CREATE INDEX IF NOT EXISTS idx_fileinfo_name_txt ON fileinfo USING gin(to_tsvector('english', name));
|
||||
|
||||
ALTER TABLE fileinfo ADD COLUMN IF NOT EXISTS minipreview bytea;
|
||||
ALTER TABLE fileinfo ADD COLUMN IF NOT EXISTS content text;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_fileinfo_content_txt ON fileinfo USING gin(to_tsvector('english', content));
|
||||
CREATE INDEX IF NOT EXISTS idx_fileinfo_name_splitted ON fileinfo USING gin (to_tsvector('english'::regconfig, translate((name)::text, '.,-'::text, ' '::text)));
|
||||
|
||||
ALTER TABLE fileinfo ADD COLUMN IF NOT EXISTS remoteid varchar(26);
|
||||
6
db/migrations/postgres/000048_create_oauth_apps.down.sql
Обычный файл
6
db/migrations/postgres/000048_create_oauth_apps.down.sql
Обычный файл
@@ -0,0 +1,6 @@
|
||||
ALTER TABLE oauthapps DROP COLUMN IF EXISTS iconurl;
|
||||
ALTER TABLE oauthapps DROP COLUMN IF EXISTS istrusted;
|
||||
|
||||
DROP INDEX IF EXISTS idx_oauthapps_creator_id;
|
||||
|
||||
DROP TABLE IF EXISTS oauthapps;
|
||||
16
db/migrations/postgres/000048_create_oauth_apps.up.sql
Обычный файл
16
db/migrations/postgres/000048_create_oauth_apps.up.sql
Обычный файл
@@ -0,0 +1,16 @@
|
||||
CREATE TABLE IF NOT EXISTS oauthapps (
|
||||
id VARCHAR(26) PRIMARY KEY,
|
||||
creatorid VARCHAR(26),
|
||||
createat bigint,
|
||||
updateat bigint,
|
||||
clientsecret VARCHAR(128),
|
||||
name VARCHAR(64),
|
||||
description VARCHAR(512),
|
||||
callbackurls VARCHAR(1024),
|
||||
homepage VARCHAR(256)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_oauthapps_creator_id ON oauthapps (creatorid);
|
||||
|
||||
ALTER TABLE oauthapps ADD COLUMN IF NOT EXISTS istrusted boolean;
|
||||
ALTER TABLE oauthapps ADD COLUMN IF NOT EXISTS iconurl VARCHAR(512);
|
||||
59
db/migrations/postgres/000049_create_channels.down.sql
Обычный файл
59
db/migrations/postgres/000049_create_channels.down.sql
Обычный файл
@@ -0,0 +1,59 @@
|
||||
CREATE INDEX IF NOT EXISTS idx_channels_name ON channels (name);
|
||||
|
||||
ALTER TABLE channels DROP COLUMN IF EXISTS shared;
|
||||
|
||||
DROP INDEX IF EXISTS idx_channels_scheme_id;
|
||||
|
||||
DO $$
|
||||
<<modify_column_type_if_type_is_different>>
|
||||
DECLARE
|
||||
col_exist_and_type_different boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO col_exist_and_type_different
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'channels'
|
||||
AND column_name = 'groupconstrained'
|
||||
AND NOT data_type = 'boolean';
|
||||
|
||||
IF col_exist_and_type_different THEN
|
||||
ALTER TABLE channels ALTER COLUMN groupconstrained TYPE boolean;
|
||||
END IF;
|
||||
END modify_column_type_if_type_is_different $$;
|
||||
|
||||
ALTER TABLE channels DROP COLUMN IF EXISTS groupconstrained;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_channels_txt ON channels (name,displayname);
|
||||
|
||||
ALTER TABLE channels DROP COLUMN IF EXISTS schemeid;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_channels_displayname ON channels (displayname);
|
||||
|
||||
DO $$
|
||||
<<modify_column_type_if_type_is_different>>
|
||||
DECLARE
|
||||
col_exist_and_type_different boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO col_exist_and_type_different
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'channels'
|
||||
AND column_name = 'purpose'
|
||||
AND data_type = 'character varying'
|
||||
AND NOT character_maximum_length = 64;
|
||||
|
||||
IF col_exist_and_type_different THEN
|
||||
ALTER TABLE channels ALTER COLUMN purpose TYPE varchar(64);
|
||||
END IF;
|
||||
END modify_column_type_if_type_is_different $$;
|
||||
|
||||
DROP INDEX IF EXISTS idx_channels_displayname;
|
||||
DROP INDEX IF EXISTS idx_channels_txt;
|
||||
DROP INDEX IF EXISTS idx_channels_displayname_lower;
|
||||
DROP INDEX IF EXISTS idx_channels_name_lower;
|
||||
DROP INDEX IF EXISTS idx_channels_name;
|
||||
DROP INDEX IF EXISTS idx_channels_update_at;
|
||||
DROP INDEX IF EXISTS idx_channels_team_id;
|
||||
DROP INDEX IF EXISTS idx_channels_delete_at;
|
||||
DROP INDEX IF EXISTS idx_channels_create_at;
|
||||
DROP INDEX IF EXISTS idx_channel_search_txt;
|
||||
|
||||
DROP TABLE IF EXISTS channels;
|
||||
76
db/migrations/postgres/000049_create_channels.up.sql
Обычный файл
76
db/migrations/postgres/000049_create_channels.up.sql
Обычный файл
@@ -0,0 +1,76 @@
|
||||
CREATE TABLE IF NOT EXISTS channels (
|
||||
id varchar(26) PRIMARY KEY,
|
||||
createat bigint,
|
||||
updateat bigint,
|
||||
deleteat bigint,
|
||||
teamid varchar(26),
|
||||
type varchar(1),
|
||||
displayname varchar(64),
|
||||
name varchar(64),
|
||||
header varchar(1024),
|
||||
purpose varchar(128),
|
||||
lastpostat bigint,
|
||||
totalmsgcount bigint,
|
||||
extraupdateat bigint,
|
||||
creatorid varchar(26),
|
||||
UNIQUE(name, teamid)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_channels_displayname ON channels (displayname);
|
||||
CREATE INDEX IF NOT EXISTS idx_channels_txt ON channels (name, displayname);
|
||||
CREATE INDEX IF NOT EXISTS idx_channels_displayname_lower ON channels (lower(displayname));
|
||||
CREATE INDEX IF NOT EXISTS idx_channels_name_lower ON channels (lower(name));
|
||||
CREATE INDEX IF NOT EXISTS idx_channels_name ON channels (name);
|
||||
CREATE INDEX IF NOT EXISTS idx_channels_update_at ON channels (updateat);
|
||||
CREATE INDEX IF NOT EXISTS idx_channels_team_id ON channels (teamid);
|
||||
CREATE INDEX IF NOT EXISTS idx_channels_delete_at ON channels (deleteat);
|
||||
CREATE INDEX IF NOT EXISTS idx_channels_create_at ON channels (createat);
|
||||
CREATE INDEX IF NOT EXISTS idx_channel_search_txt ON channels using gin (to_tsvector('english'::regconfig, (((((name)::text || ' '::text) || (displayname)::text) || ' '::text) || (purpose)::text)));
|
||||
|
||||
DO $$
|
||||
<<modify_column_type_if_type_is_different>>
|
||||
DECLARE
|
||||
col_exist_and_type_different boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO col_exist_and_type_different
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'channels'
|
||||
AND column_name = 'purpose'
|
||||
AND data_type = 'character varying'
|
||||
AND NOT character_maximum_length = 250;
|
||||
|
||||
IF col_exist_and_type_different THEN
|
||||
ALTER TABLE channels ALTER COLUMN purpose TYPE varchar(250);
|
||||
END IF;
|
||||
END modify_column_type_if_type_is_different $$;
|
||||
|
||||
DROP INDEX IF EXISTS idx_channels_displayname;
|
||||
|
||||
ALTER TABLE channels ADD COLUMN IF NOT EXISTS schemeid varchar(26);
|
||||
|
||||
DROP INDEX IF EXISTS idx_channels_txt;
|
||||
|
||||
ALTER TABLE channels ADD COLUMN IF NOT EXISTS groupconstrained boolean;
|
||||
|
||||
DO $$
|
||||
<<modify_column_type_if_type_is_different>>
|
||||
DECLARE
|
||||
col_exist_and_type_different boolean := false;
|
||||
BEGIN
|
||||
SELECT count(*) != 0 INTO col_exist_and_type_different
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'channels'
|
||||
AND column_name = 'groupconstrained'
|
||||
AND NOT data_type = 'boolean';
|
||||
|
||||
IF col_exist_and_type_different THEN
|
||||
ALTER TABLE channels ALTER COLUMN groupconstrained TYPE boolean;
|
||||
END IF;
|
||||
END modify_column_type_if_type_is_different $$;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_channels_scheme_id ON channels (schemeid);
|
||||
|
||||
ALTER TABLE channels ADD COLUMN IF NOT EXISTS shared boolean;
|
||||
|
||||
DROP INDEX IF EXISTS idx_channels_name;
|
||||
|
||||
10
db/migrations/postgres/000050_create_channelmembers.down.sql
Обычный файл
10
db/migrations/postgres/000050_create_channelmembers.down.sql
Обычный файл
@@ -0,0 +1,10 @@
|
||||
CREATE INDEX IF NOT EXISTS idx_channelmembers_channel_id ON channelmembers(channelid);
|
||||
|
||||
ALTER TABLE channelmembers DROP COLUMN IF EXISTS schemeguest;
|
||||
|
||||
ALTER TABLE channelmembers DROP COLUMN IF EXISTS schemeadmin;
|
||||
ALTER TABLE channelmembers DROP COLUMN IF EXISTS schemeuser;
|
||||
|
||||
DROP INDEX IF EXISTS idx_channelmembers_user_id;
|
||||
|
||||
DROP TABLE IF EXISTS channelmembers;
|
||||
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Ссылка в новой задаче
Block a user