Files
mostlymatter/db/migrations/postgres/000034_create_oauthauthdata.up.sql
Agniva De Sarker 91f7eb0957 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
```
2022-11-11 13:03:28 +05:30

39 строки
1.1 KiB
SQL

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 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;
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;