From f5ca71e7013cb30a6f22373e9a300633395befdd Mon Sep 17 00:00:00 2001 From: Bartosz Sypytkowski Date: Mon, 15 Jul 2024 19:09:26 +0200 Subject: [PATCH] chore: remove pg advisory lock --- ...dcc9d963cc033582bf2e945e8bf3a301b4247.json | 22 ---------------- ...fb1e2e0aab6f3a1ac9c2fc99b4cdee9e58cbe.json | 25 ------------------- ...e4befa495bb6438ef88be860fa1e557bf9281.json | 25 +++++++++++++++++++ libs/database/src/user.rs | 9 ++++--- src/biz/user/user_verify.rs | 16 ------------ 5 files changed, 30 insertions(+), 67 deletions(-) delete mode 100644 .sqlx/query-a06e1d9f6f95e4c4c2b98310ebddcc9d963cc033582bf2e945e8bf3a301b4247.json delete mode 100644 .sqlx/query-b4fa2e732c975fbb23c346981c4fb1e2e0aab6f3a1ac9c2fc99b4cdee9e58cbe.json create mode 100644 .sqlx/query-ce3b2a3ddee0f420166719e39e0e4befa495bb6438ef88be860fa1e557bf9281.json diff --git a/.sqlx/query-a06e1d9f6f95e4c4c2b98310ebddcc9d963cc033582bf2e945e8bf3a301b4247.json b/.sqlx/query-a06e1d9f6f95e4c4c2b98310ebddcc9d963cc033582bf2e945e8bf3a301b4247.json deleted file mode 100644 index 909e6ad4..00000000 --- a/.sqlx/query-a06e1d9f6f95e4c4c2b98310ebddcc9d963cc033582bf2e945e8bf3a301b4247.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "SELECT pg_advisory_xact_lock($1)", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "pg_advisory_xact_lock", - "type_info": "Void" - } - ], - "parameters": { - "Left": [ - "Int8" - ] - }, - "nullable": [ - null - ] - }, - "hash": "a06e1d9f6f95e4c4c2b98310ebddcc9d963cc033582bf2e945e8bf3a301b4247" -} diff --git a/.sqlx/query-b4fa2e732c975fbb23c346981c4fb1e2e0aab6f3a1ac9c2fc99b4cdee9e58cbe.json b/.sqlx/query-b4fa2e732c975fbb23c346981c4fb1e2e0aab6f3a1ac9c2fc99b4cdee9e58cbe.json deleted file mode 100644 index 437a2167..00000000 --- a/.sqlx/query-b4fa2e732c975fbb23c346981c4fb1e2e0aab6f3a1ac9c2fc99b4cdee9e58cbe.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n WITH ins_user AS (\n INSERT INTO af_user (uid, uuid, email, name)\n VALUES ($1, $2, $3, $4)\n ON CONFLICT(email) DO NOTHING\n RETURNING uid\n ),\n owner_role AS (\n SELECT id FROM af_roles WHERE name = 'Owner'\n ),\n ins_workspace AS (\n INSERT INTO af_workspace (owner_uid)\n SELECT uid FROM ins_user\n RETURNING workspace_id, owner_uid\n ),\n ins_collab_member AS (\n INSERT INTO af_collab_member (uid, oid, permission_id)\n SELECT ins_workspace.owner_uid,\n ins_workspace.workspace_id::TEXT,\n (SELECT permission_id FROM af_role_permissions WHERE role_id = owner_role.id)\n FROM ins_workspace, owner_role\n )\n SELECT workspace_id FROM ins_workspace;\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "workspace_id", - "type_info": "Uuid" - } - ], - "parameters": { - "Left": [ - "Int8", - "Uuid", - "Text", - "Text" - ] - }, - "nullable": [ - false - ] - }, - "hash": "b4fa2e732c975fbb23c346981c4fb1e2e0aab6f3a1ac9c2fc99b4cdee9e58cbe" -} diff --git a/.sqlx/query-ce3b2a3ddee0f420166719e39e0e4befa495bb6438ef88be860fa1e557bf9281.json b/.sqlx/query-ce3b2a3ddee0f420166719e39e0e4befa495bb6438ef88be860fa1e557bf9281.json new file mode 100644 index 00000000..9411bc4d --- /dev/null +++ b/.sqlx/query-ce3b2a3ddee0f420166719e39e0e4befa495bb6438ef88be860fa1e557bf9281.json @@ -0,0 +1,25 @@ +{ + "db_name": "PostgreSQL", + "query": "\n WITH ins_user AS (\n INSERT INTO af_user (uid, uuid, email, name)\n VALUES ($1, $2, $3, $4)\n RETURNING uid\n ),\n owner_role AS (\n SELECT id FROM af_roles WHERE name = 'Owner'\n ),\n ins_workspace AS (\n INSERT INTO af_workspace (owner_uid)\n SELECT uid FROM ins_user\n RETURNING workspace_id, owner_uid\n ),\n ins_collab_member AS (\n INSERT INTO af_collab_member (uid, oid, permission_id)\n SELECT ins_workspace.owner_uid,\n ins_workspace.workspace_id::TEXT,\n (SELECT permission_id FROM af_role_permissions WHERE role_id = owner_role.id)\n FROM ins_workspace, owner_role\n )\n SELECT workspace_id FROM ins_workspace;\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "workspace_id", + "type_info": "Uuid" + } + ], + "parameters": { + "Left": [ + "Int8", + "Uuid", + "Text", + "Text" + ] + }, + "nullable": [ + false + ] + }, + "hash": "ce3b2a3ddee0f420166719e39e0e4befa495bb6438ef88be860fa1e557bf9281" +} diff --git a/libs/database/src/user.rs b/libs/database/src/user.rs index f84c25d2..05f201c4 100644 --- a/libs/database/src/user.rs +++ b/libs/database/src/user.rs @@ -1,12 +1,14 @@ -use crate::pg_row::AFUserIdRow; -use app_error::AppError; use futures_util::stream::BoxStream; +use sqlx::{Arguments, Executor, PgPool, Postgres}; use sqlx::postgres::PgArguments; use sqlx::types::JsonValue; -use sqlx::{Arguments, Executor, PgPool, Postgres}; use tracing::{instrument, warn}; use uuid::Uuid; +use app_error::AppError; + +use crate::pg_row::AFUserIdRow; + /// Updates the user's details in the `af_user` table. /// /// This function allows for updating the user's name, email, and metadata based on the provided UUID. @@ -104,7 +106,6 @@ pub async fn create_user<'a, E: Executor<'a, Database = Postgres>>( WITH ins_user AS ( INSERT INTO af_user (uid, uuid, email, name) VALUES ($1, $2, $3, $4) - ON CONFLICT(email) DO NOTHING RETURNING uid ), owner_role AS ( diff --git a/src/biz/user/user_verify.rs b/src/biz/user/user_verify.rs index 4a35173a..6107a12e 100644 --- a/src/biz/user/user_verify.rs +++ b/src/biz/user/user_verify.rs @@ -23,28 +23,12 @@ pub async fn verify_token(access_token: &str, state: &AppState) -> Result