Fix foreign key constraint when cleaning up upstream OAuth 2.0 links
https://sentry.tools.element.io/organizations/element/issues/11222736/
This commit is contained in:
24
crates/storage-pg/.sqlx/query-623097fc45ffa5d6e09fedfbdbe5e42662e9854430bcd9e53598debf99c9ca37.json
generated
Normal file
24
crates/storage-pg/.sqlx/query-623097fc45ffa5d6e09fedfbdbe5e42662e9854430bcd9e53598debf99c9ca37.json
generated
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "\n WITH\n to_delete AS (\n SELECT upstream_oauth_link_id\n FROM upstream_oauth_links\n WHERE user_id IS NULL\n AND ($1::uuid IS NULL OR upstream_oauth_link_id > $1)\n AND upstream_oauth_link_id <= $2\n ORDER BY upstream_oauth_link_id\n LIMIT $3\n ),\n deleted_sessions AS (\n DELETE FROM upstream_oauth_authorization_sessions\n USING to_delete\n WHERE upstream_oauth_authorization_sessions.upstream_oauth_link_id = to_delete.upstream_oauth_link_id\n )\n DELETE FROM upstream_oauth_links\n USING to_delete\n WHERE upstream_oauth_links.upstream_oauth_link_id = to_delete.upstream_oauth_link_id\n RETURNING upstream_oauth_links.upstream_oauth_link_id\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"ordinal": 0,
|
||||||
|
"name": "upstream_oauth_link_id",
|
||||||
|
"type_info": "Uuid"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Uuid",
|
||||||
|
"Uuid",
|
||||||
|
"Int8"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "623097fc45ffa5d6e09fedfbdbe5e42662e9854430bcd9e53598debf99c9ca37"
|
||||||
|
}
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "\n WITH to_delete AS (\n SELECT upstream_oauth_link_id\n FROM upstream_oauth_links\n WHERE user_id IS NULL\n AND ($1::uuid IS NULL OR upstream_oauth_link_id > $1)\n AND upstream_oauth_link_id <= $2\n ORDER BY upstream_oauth_link_id\n LIMIT $3\n )\n DELETE FROM upstream_oauth_links\n USING to_delete\n WHERE upstream_oauth_links.upstream_oauth_link_id = to_delete.upstream_oauth_link_id\n RETURNING upstream_oauth_links.upstream_oauth_link_id\n ",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "upstream_oauth_link_id",
|
|
||||||
"type_info": "Uuid"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Uuid",
|
|
||||||
"Uuid",
|
|
||||||
"Int8"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "67b4a124ea3e12902dc4256cf95950508f7eb24f4c9d62b34815c8e8940e4676"
|
|
||||||
}
|
|
||||||
@@ -466,7 +466,8 @@ impl UpstreamOAuthLinkRepository for PgUpstreamOAuthLinkRepository<'_> {
|
|||||||
// `MAX(uuid)` isn't a thing in Postgres, so we aggregate on the client side.
|
// `MAX(uuid)` isn't a thing in Postgres, so we aggregate on the client side.
|
||||||
let res = sqlx::query_scalar!(
|
let res = sqlx::query_scalar!(
|
||||||
r#"
|
r#"
|
||||||
WITH to_delete AS (
|
WITH
|
||||||
|
to_delete AS (
|
||||||
SELECT upstream_oauth_link_id
|
SELECT upstream_oauth_link_id
|
||||||
FROM upstream_oauth_links
|
FROM upstream_oauth_links
|
||||||
WHERE user_id IS NULL
|
WHERE user_id IS NULL
|
||||||
@@ -474,7 +475,12 @@ impl UpstreamOAuthLinkRepository for PgUpstreamOAuthLinkRepository<'_> {
|
|||||||
AND upstream_oauth_link_id <= $2
|
AND upstream_oauth_link_id <= $2
|
||||||
ORDER BY upstream_oauth_link_id
|
ORDER BY upstream_oauth_link_id
|
||||||
LIMIT $3
|
LIMIT $3
|
||||||
)
|
),
|
||||||
|
deleted_sessions AS (
|
||||||
|
DELETE FROM upstream_oauth_authorization_sessions
|
||||||
|
USING to_delete
|
||||||
|
WHERE upstream_oauth_authorization_sessions.upstream_oauth_link_id = to_delete.upstream_oauth_link_id
|
||||||
|
)
|
||||||
DELETE FROM upstream_oauth_links
|
DELETE FROM upstream_oauth_links
|
||||||
USING to_delete
|
USING to_delete
|
||||||
WHERE upstream_oauth_links.upstream_oauth_link_id = to_delete.upstream_oauth_link_id
|
WHERE upstream_oauth_links.upstream_oauth_link_id = to_delete.upstream_oauth_link_id
|
||||||
|
|||||||
Reference in New Issue
Block a user