Filter by templated schema name for postgres queries (#21635)

There were certain queries which did not filter
by the current schema, but hardcoded public schema.

Apart from that, we always filter with the current schema
which allows connection proxies to run multiple MM within
a single DB.
```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2022-11-11 13:03:28 +05:30
коммит произвёл GitHub
родитель f07de38cc5
Коммит 91f7eb0957
32 изменённых файлов: 46 добавлений и 5 удалений

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

@@ -35,6 +35,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'teams'
AND table_schema = current_schema()
AND column_name = 'alloweddomains'
AND NOT data_type = 'varchar(1000)';
IF column_exist THEN
@@ -49,6 +50,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'teams'
AND table_schema = current_schema()
AND column_name = 'groupconstrained'
AND NOT data_type = 'boolean';
IF column_exist THEN
@@ -63,6 +65,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'teams'
AND table_schema = current_schema()
AND column_name = 'type'
AND NOT data_type = 'varchar(255)';
IF column_exist THEN
@@ -77,6 +80,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'teams'
AND table_schema = current_schema()
AND column_name = 'schemeid'
AND NOT data_type = 'varchar(26)';
IF column_exist THEN

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

@@ -63,6 +63,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'incomingwebhooks'
AND table_schema = current_schema()
AND column_name = 'description'
AND NOT data_type = 'VARCHAR(500)';
IF column_exist THEN

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

@@ -30,6 +30,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'outgoingwebhooks'
AND table_schema = current_schema()
AND column_name = 'description'
AND NOT data_type = 'VARCHAR(500)';
IF column_exist THEN
@@ -44,6 +45,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'outgoingwebhooks'
AND table_schema = current_schema()
AND column_name = 'iconurl'
AND NOT data_type = 'VARCHAR(1024)';
IF column_exist THEN
@@ -56,7 +58,7 @@ BEGIN
IF (
SELECT column_default::bigint
FROM information_schema.columns
WHERE table_schema='public'
WHERE table_schema=current_schema()
AND table_name='outgoingwebhooks'
AND column_name='username'
) = 0 THEN
@@ -69,7 +71,7 @@ BEGIN
IF (
SELECT column_default::bigint
FROM information_schema.columns
WHERE table_schema='public'
WHERE table_schema=current_schema()
AND table_name='outgoingwebhooks'
AND column_name='iconurl'
) = 0 THEN

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

@@ -42,6 +42,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'posts'
AND table_schema = current_schema()
AND column_name = 'fileids'
AND NOT data_type = 'varchar(300)';
IF column_exist THEN

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

@@ -18,11 +18,13 @@ BEGIN
SELECT count(*) != 0 INTO col_exists
FROM information_schema.columns
WHERE table_name = 'preferences'
AND table_schema = current_schema()
AND column_name = 'value';
SELECT count(*) != 0 INTO type_exists
FROM information_schema.columns
WHERE table_name = 'preferences'
AND table_schema = current_schema()
AND column_name = 'value'
AND data_type = 'character varying'
AND character_maximum_length = 2000;

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

@@ -16,11 +16,13 @@ BEGIN
SELECT count(*) != 0 INTO col_exists
FROM information_schema.columns
WHERE table_name = 'tokens'
AND table_schema = current_schema()
AND column_name = 'extra';
SELECT count(*) != 0 INTO type_exists
FROM information_schema.columns
WHERE table_name = 'tokens'
AND table_schema = current_schema()
AND column_name = 'extra'
AND data_type = 'character varying'
AND character_maximum_length = 2048;

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

@@ -6,6 +6,7 @@ BEGIN
SELECT count(*) != 0 INTO col_exist_and_type_different
FROM information_schema.columns
WHERE table_name = 'sidebarchannels'
AND table_schema = current_schema()
AND column_name = 'categoryid'
AND data_type = 'character varying'
AND NOT character_maximum_length = 26;

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

@@ -14,6 +14,7 @@ BEGIN
SELECT count(*) != 0 INTO col_exist_and_type_different
FROM information_schema.columns
WHERE table_name = 'sidebarchannels'
AND table_schema = current_schema()
AND column_name = 'categoryid'
AND data_type = 'character varying'
AND NOT character_maximum_length = 128;

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

@@ -19,11 +19,13 @@ BEGIN
SELECT count(*) != 0 INTO col_exists
FROM information_schema.columns
WHERE table_name = 'oauthauthdata'
AND table_schema = current_schema()
AND column_name = 'state';
SELECT count(*) != 0 INTO type_exists
FROM information_schema.columns
WHERE table_name = 'oauthauthdata'
AND table_schema = current_schema()
AND column_name = 'state'
AND data_type = 'character varying'
AND character_maximum_length = 1024;

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

@@ -9,6 +9,7 @@ BEGIN
SELECT count(*) != 0 INTO col_exist_and_type_different
FROM information_schema.columns
WHERE table_name = 'sidebarcategories'
AND table_schema = current_schema()
AND column_name = 'id'
AND data_type = 'character varying'
AND NOT character_maximum_length = 26;

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

@@ -17,6 +17,7 @@ BEGIN
SELECT count(*) != 0 INTO col_exist_and_type_different
FROM information_schema.columns
WHERE table_name = 'sidebarcategories'
AND table_schema = current_schema()
AND column_name = 'id'
AND data_type = 'character varying'
AND NOT character_maximum_length = 128;

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

@@ -2,7 +2,7 @@ DO $$BEGIN
IF (
SELECT column_default::bigint
FROM information_schema.columns
WHERE table_schema='public'
WHERE table_schema=current_schema()
AND table_name='pluginkeyvaluestore'
AND column_name='expireat'
) IS NULL THEN

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

@@ -11,7 +11,7 @@ DO $$BEGIN
IF (
SELECT column_default::bigint
FROM information_schema.columns
WHERE table_schema='public'
WHERE table_schema=current_schema()
AND table_name='pluginkeyvaluestore'
AND column_name='expireat'
) = 0 THEN

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

@@ -54,6 +54,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'users'
AND table_schema = current_schema()
AND column_name = 'roles'
AND NOT data_type = 'varchar(256)';
IF column_exist THEN

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

@@ -12,6 +12,7 @@ BEGIN
SELECT count(*) != 0 INTO col_exist_and_type_different
FROM information_schema.columns
WHERE table_name = 'channels'
AND table_schema = current_schema()
AND column_name = 'groupconstrained'
AND NOT data_type = 'boolean';
@@ -36,6 +37,7 @@ BEGIN
SELECT count(*) != 0 INTO col_exist_and_type_different
FROM information_schema.columns
WHERE table_name = 'channels'
AND table_schema = current_schema()
AND column_name = 'purpose'
AND data_type = 'character varying'
AND NOT character_maximum_length = 64;

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

@@ -35,6 +35,7 @@ BEGIN
SELECT count(*) != 0 INTO col_exist_and_type_different
FROM information_schema.columns
WHERE table_name = 'channels'
AND table_schema = current_schema()
AND column_name = 'purpose'
AND data_type = 'character varying'
AND NOT character_maximum_length = 250;
@@ -60,6 +61,7 @@ BEGIN
SELECT count(*) != 0 INTO col_exist_and_type_different
FROM information_schema.columns
WHERE table_name = 'channels'
AND table_schema = current_schema()
AND column_name = 'groupconstrained'
AND NOT data_type = 'boolean';

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

@@ -10,11 +10,13 @@ BEGIN
SELECT count(*) != 0 INTO msg_count_root_exist
FROM information_schema.columns
WHERE table_name = 'channels'
AND table_schema = current_schema()
AND column_name = 'totalmsgcountroot';
SELECT count(*) != 0 INTO mention_count_root_exist
FROM information_schema.columns
WHERE table_name = 'channelmembers'
AND table_schema = current_schema()
AND column_name = 'mentioncountroot';
IF mention_count_root_exist THEN

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

@@ -6,6 +6,7 @@ BEGIN
SELECT count(*) != 0 INTO parentid_exist
FROM information_schema.columns
WHERE table_name = 'commandwebhooks'
AND table_schema = current_schema()
AND column_name = 'parentid';
IF parentid_exist THEN
UPDATE commandwebhooks SET rootid = parentid WHERE rootid = '' AND rootid != parentid;

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

@@ -8,16 +8,19 @@ BEGIN
SELECT count(*) != 0 INTO parentid_exist
FROM information_schema.columns
WHERE table_name = 'posts'
AND table_schema = current_schema()
AND column_name = 'parentid';
SELECT count(*) != 0 INTO alter_fileids
FROM information_schema.columns
WHERE table_name = 'posts'
AND table_schema = current_schema()
AND column_name = 'fileids'
AND data_type = 'character varying'
AND character_maximum_length != 300;
SELECT count(*) != 0 INTO alter_props
FROM information_schema.columns
WHERE table_name = 'posts'
AND table_schema = current_schema()
AND column_name = 'props'
AND data_type != 'jsonb';
IF alter_fileids OR alter_props THEN

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

@@ -5,6 +5,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'channelmembers'
AND table_schema = current_schema()
AND column_name = 'roles'
AND NOT data_type = 'varchar(64)';
IF column_exist THEN

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

@@ -5,6 +5,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'channelmembers'
AND table_schema = current_schema()
AND column_name = 'roles'
AND NOT data_type = 'varchar(256)';
IF column_exist THEN

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

@@ -5,6 +5,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'teammembers'
AND table_schema = current_schema()
AND column_name = 'roles'
AND NOT data_type = 'varchar(64)';
IF column_exist THEN

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

@@ -5,6 +5,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'teammembers'
AND table_schema = current_schema()
AND column_name = 'roles'
AND NOT data_type = 'varchar(256)';
IF column_exist THEN

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

@@ -9,6 +9,7 @@ BEGIN
information_schema.columns
WHERE
table_name = 'channels'
AND table_schema = current_schema()
AND column_name = 'lastrootpostat';
IF NOT column_exist THEN
ALTER TABLE channels ADD COLUMN lastrootpostat bigint DEFAULT '0'::bigint;

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

@@ -5,6 +5,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'sessions'
AND table_schema = current_schema()
AND column_name = 'roles'
AND NOT data_type = 'varchar(64)';
IF column_exist THEN

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

@@ -5,6 +5,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'sessions'
AND table_schema = current_schema()
AND column_name = 'roles'
AND NOT data_type = 'varchar(256)';
IF column_exist THEN

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

@@ -5,6 +5,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'pluginkeyvaluestore'
AND table_schema = current_schema()
AND column_name = 'pkey'
AND NOT data_type = 'varchar(50)';
IF column_exist THEN

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

@@ -5,6 +5,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'pluginkeyvaluestore'
AND table_schema = current_schema()
AND column_name = 'pkey'
AND NOT data_type = 'varchar(150)';
IF column_exist THEN

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

@@ -3,7 +3,7 @@ BEGIN
IF (
SELECT count(*)
FROM information_schema.columns
WHERE table_schema='public'
WHERE table_schema=current_schema()
AND table_name='channels'
AND column_name='lastrootpostat'
AND (column_default IS NULL OR column_default != '''0''::bigint')

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

@@ -5,6 +5,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'oauthapps'
AND table_schema = current_schema()
AND column_name = 'mattermostappid';
IF column_exist THEN
ALTER TABLE OAuthApps ALTER COLUMN MattermostAppID DROP NOT NULL;

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

@@ -5,6 +5,7 @@ BEGIN
SELECT count(*) != 0 INTO column_exist
FROM information_schema.columns
WHERE table_name = 'oauthapps'
AND table_schema = current_schema()
AND column_name = 'mattermostappid';
IF column_exist THEN
UPDATE OAuthApps SET MattermostAppID = '' WHERE MattermostAppID IS NULL;

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

@@ -10,6 +10,7 @@ BEGIN
SELECT count(*) != 0 INTO col_exist
FROM information_schema.columns
WHERE table_name = 'users'
AND table_schema = current_schema()
AND column_name = 'themeprops';
IF col_exist THEN