mirror of
https://github.com/mattermost/mattermost.git
synced 2026-05-28 04:35:04 -04:00
[MM-52288] Oauth2 postgres migration issue (#23036)
* fixing migrations that caused some oauth2 issues
This commit is contained in:
parent
3ba75afa08
commit
5adbf6c612
6 changed files with 41 additions and 2 deletions
|
|
@ -214,6 +214,8 @@ channels/db/migrations/mysql/000106_fileinfo_channelid.down.sql
|
|||
channels/db/migrations/mysql/000106_fileinfo_channelid.up.sql
|
||||
channels/db/migrations/mysql/000107_threadmemberships_cleanup.down.sql
|
||||
channels/db/migrations/mysql/000107_threadmemberships_cleanup.up.sql
|
||||
channels/db/migrations/mysql/000108_remove_orphaned_oauth_preferences.down.sql
|
||||
channels/db/migrations/mysql/000108_remove_orphaned_oauth_preferences.up.sql
|
||||
channels/db/migrations/postgres/000001_create_teams.down.sql
|
||||
channels/db/migrations/postgres/000001_create_teams.up.sql
|
||||
channels/db/migrations/postgres/000002_create_team_members.down.sql
|
||||
|
|
@ -428,3 +430,5 @@ channels/db/migrations/postgres/000106_fileinfo_channelid.down.sql
|
|||
channels/db/migrations/postgres/000106_fileinfo_channelid.up.sql
|
||||
channels/db/migrations/postgres/000107_threadmemberships_cleanup.down.sql
|
||||
channels/db/migrations/postgres/000107_threadmemberships_cleanup.up.sql
|
||||
channels/db/migrations/postgres/000108_remove_orphaned_oauth_preferences.down.sql
|
||||
channels/db/migrations/postgres/000108_remove_orphaned_oauth_preferences.up.sql
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
-- Migration only applied to postgres
|
||||
|
|
@ -0,0 +1 @@
|
|||
-- Migration only applied to postgres
|
||||
|
|
@ -4,8 +4,7 @@ WITH oauthDelete AS (
|
|||
DELETE FROM oauthaccessdata o
|
||||
WHERE NOT EXISTS (
|
||||
SELECT p.* FROM preferences p
|
||||
WHERE o.clientid = p.name AND o.userid = p.userid AND p.category = 'oauth_app'
|
||||
and p.name IS NULL
|
||||
WHERE o.clientid = p.name AND o.userid = p.userid AND p.category = 'oauth_app'
|
||||
)
|
||||
RETURNING o.token
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
-- Skipping it because the forward migrations are destructive
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
DO $$
|
||||
DECLARE
|
||||
preferences_exist boolean := false;
|
||||
BEGIN
|
||||
SELECT count(p.*) != 0 INTO preferences_exist FROM preferences p
|
||||
WHERE (
|
||||
(NOT EXISTS (
|
||||
SELECT o.* FROM oauthaccessdata o
|
||||
WHERE o.clientid = p.name AND o.userid = p.userid AND p.category = 'oauth_app'
|
||||
))
|
||||
AND
|
||||
(NOT EXISTS (
|
||||
SELECT oa.* FROM oauthauthdata oa
|
||||
WHERE oa.clientid = p.name AND oa.userid = p.userid AND p.category = 'oauth_app'
|
||||
))
|
||||
)
|
||||
AND p.category = 'oauth_app';
|
||||
IF preferences_exist THEN
|
||||
DELETE FROM preferences p
|
||||
WHERE (
|
||||
(NOT EXISTS (
|
||||
SELECT o.* FROM oauthaccessdata o
|
||||
WHERE o.clientid = p.name AND o.userid = p.userid AND p.category = 'oauth_app'
|
||||
))
|
||||
AND
|
||||
(NOT EXISTS (
|
||||
SELECT oa.* FROM oauthauthdata oa
|
||||
WHERE oa.clientid = p.name AND oa.userid = p.userid AND p.category = 'oauth_app'
|
||||
))
|
||||
)
|
||||
AND p.category = 'oauth_app';
|
||||
END IF;
|
||||
END $$;
|
||||
Loading…
Reference in a new issue