diff --git a/crates/storage-pg/.sqlx/query-623097fc45ffa5d6e09fedfbdbe5e42662e9854430bcd9e53598debf99c9ca37.json b/crates/storage-pg/.sqlx/query-623097fc45ffa5d6e09fedfbdbe5e42662e9854430bcd9e53598debf99c9ca37.json new file mode 100644 index 000000000..27b69adf4 --- /dev/null +++ b/crates/storage-pg/.sqlx/query-623097fc45ffa5d6e09fedfbdbe5e42662e9854430bcd9e53598debf99c9ca37.json @@ -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" +} diff --git a/crates/storage-pg/.sqlx/query-67b4a124ea3e12902dc4256cf95950508f7eb24f4c9d62b34815c8e8940e4676.json b/crates/storage-pg/.sqlx/query-67b4a124ea3e12902dc4256cf95950508f7eb24f4c9d62b34815c8e8940e4676.json deleted file mode 100644 index b9a82c629..000000000 --- a/crates/storage-pg/.sqlx/query-67b4a124ea3e12902dc4256cf95950508f7eb24f4c9d62b34815c8e8940e4676.json +++ /dev/null @@ -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" -} diff --git a/crates/storage-pg/src/upstream_oauth2/link.rs b/crates/storage-pg/src/upstream_oauth2/link.rs index 720d0f251..ca01dc97d 100644 --- a/crates/storage-pg/src/upstream_oauth2/link.rs +++ b/crates/storage-pg/src/upstream_oauth2/link.rs @@ -466,7 +466,8 @@ impl UpstreamOAuthLinkRepository for PgUpstreamOAuthLinkRepository<'_> { // `MAX(uuid)` isn't a thing in Postgres, so we aggregate on the client side. let res = sqlx::query_scalar!( r#" - WITH to_delete AS ( + WITH + to_delete AS ( SELECT upstream_oauth_link_id FROM upstream_oauth_links WHERE user_id IS NULL @@ -474,7 +475,12 @@ impl UpstreamOAuthLinkRepository for PgUpstreamOAuthLinkRepository<'_> { AND upstream_oauth_link_id <= $2 ORDER BY upstream_oauth_link_id 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 USING to_delete WHERE upstream_oauth_links.upstream_oauth_link_id = to_delete.upstream_oauth_link_id