Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(authentication_service): refresh token speed (#961)

Will Hutchinsonebf59e69011e
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 71cf23d474..8b589aeb57 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -4902,6 +4902,7 @@ dependencies = [
"jsonwebtoken",
"macro_env",
"macro_env_var",
+ "macro_user_id",
"rand 0.9.0",
"remote_env_var",
"serde",
diff --git a/rust/cloud-storage/authentication_service/src/api/jwt/refresh.rs b/rust/cloud-storage/authentication_service/src/api/jwt/refresh.rs
index 66d18fc421..4fa24303a7 100644
--- a/rust/cloud-storage/authentication_service/src/api/jwt/refresh.rs
+++ b/rust/cloud-storage/authentication_service/src/api/jwt/refresh.rs
@@ -11,11 +11,41 @@ use axum::{
http::StatusCode,
response::{IntoResponse, Response},
};
-use macro_auth::{error::MacroAuthError, middleware::decode_jwt::JwtValidationArgs};
+use macro_auth::{
+ error::MacroAuthError,
+ middleware::decode_jwt::{JwtValidationArgs, decode_macro_access_token_allow_expired},
+};
+use macro_db_client::advisory_lock::try_acquire_user_refresh_xact_lock;
use model::response::UserTokensResponse;
+use sqlx::PgPool;
use std::sync::Arc;
use tower_cookies::Cookies;
+#[derive(Debug, thiserror::Error)]
+pub enum RefreshError {
+ #[error("internal server error")]
+ InternalServerError,
+ #[error("refresh in progress")]
+ RefreshInProgress,
+ #[error("invalid refresh token")]
+ InvalidRefreshToken,
+ #[error("unauthorized")]
+ Unauthorized,
+}
+
+impl IntoResponse for RefreshError {
+ fn into_response(self) -> Response {
+ let status_code = match self {
+ RefreshError::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR,
+ RefreshError::InvalidRefreshToken => StatusCode::BAD_REQUEST,
+ RefreshError::RefreshInProgress => StatusCode::TOO_MANY_REQUESTS,
+ RefreshError::Unauthorized => StatusCode::UNAUTHORIZED,
+ };
+
+ (status_code, self.to_string()).into_response()
+ }
+}
+
/// Refreshes a JWT token
/// You can either have your access token and refresh token in the cookies or in the request
/// headers
@@ -30,63 +60,82 @@ use tower_cookies::Cookies;
(status = 200, body = UserTokensResponse),
(status = 400, body=String),
(status = 401, body=String),
+ (status = 429, body=String, description = "Refresh already in progress for this user"),
(status = 500, body=String),
)
)]
-#[tracing::instrument(skip(auth_client, jwt, token_context, cookies))]
+#[tracing::instrument(skip(auth_client, db, jwt, token_context, cookies))]
pub async fn handler(
State(auth_client): State<Arc<FusionAuthClient>>,
+ State(db): State<PgPool>,
State(jwt): State<JwtValidationArgs>,
token_context: Extension<TokenContext>,
cookies: Cookies,
-) -> Result<Response, Response> {
+) -> Result<Json<UserTokensResponse>, RefreshError> {
match macro_auth::middleware::decode_jwt::validate_macro_access_token(
&token_context.access_token,
&jwt,
) {
Ok(_) => {
// jwt is valid, return back original tokens
- return Ok((
- StatusCode::OK,
- Json(UserTokensResponse {
- access_token: token_context.access_token.clone(),
- refresh_token: token_context.refresh_token.clone(),
- }),
- )
- .into_response());
+ tracing::trace!("jwt still valid");
+ return Ok(Json(UserTokensResponse {
+ access_token: token_context.access_token.clone(),
+ refresh_token: token_context.refresh_token.clone(),
+ }));
}
Err(e) => match e {
// We only want to refresh the token if it's expired
MacroAuthError::JwtExpired => {}
_ => {
tracing::error!(error=?e, "unable to decode jwt");
- return Err((StatusCode::UNAUTHORIZED, "unauthorized").into_response());
+ return Err(RefreshError::Unauthorized);
}
},
}
+ // Decode the JWT (allowing expired) to get the user ID for the advisory lock
+ let user_id = decode_macro_access_token_allow_expired(&token_context.access_token, &jwt)
+ .map_err(|e| {
+ // Keeping this log in here to see why we couldn't decode the jwt
+ tracing::error!(error=?e, "unable to decode jwt for user id");
+ RefreshError::Unauthorized
+ })?;
+
+ // Acquire advisory lock to prevent concurrent refresh requests for the same user
+ let mut txn = db.begin().await.map_err(|e| {
+ tracing::error!(error=?e, "unable to start transaction");
+ RefreshError::InternalServerError
+ })?;
+
+ let lock_acquired = try_acquire_user_refresh_xact_lock(&mut txn, &user_id)
+ .await
+ .map_err(|e| {
+ tracing::error!(error=?e, "unable to acquire advisory lock");
+ RefreshError::InternalServerError
+ })?;
+
+ if !lock_acquired {
+ return Err(RefreshError::RefreshInProgress);
+ }
+
let (access_token, refresh_token) = auth_client
.refresh_token(&token_context.access_token, &token_context.refresh_token)
.await
.map_err(|e| match e {
- FusionAuthClientError::InvalidRefreshToken => {
- (StatusCode::BAD_REQUEST, "invalid refresh token").into_response()
- }
+ FusionAuthClientError::InvalidRefreshToken => RefreshError::InvalidRefreshToken,
_ => {
tracing::error!(error=?e, "unable to refresh token");
- (StatusCode::INTERNAL_SERVER_ERROR).into_response()
+ RefreshError::InternalServerError
}
})?;
+ // Add in cookies to response
cookies.add(create_access_token_cookie(&access_token));
cookies.add(create_refresh_token_cookie(&refresh_token));
- Ok((
- StatusCode::OK,
- Json(UserTokensResponse {
- access_token,
- refresh_token,
- }),
- )
- .into_response())
+ Ok(Json(UserTokensResponse {
+ access_token,
+ refresh_token,
+ }))
}
diff --git a/rust/cloud-storage/macro_auth/Cargo.toml b/rust/cloud-storage/macro_auth/Cargo.toml
index 4a6dd44d21..1ee3fa6d60 100644
--- a/rust/cloud-storage/macro_auth/Cargo.toml
+++ b/rust/cloud-storage/macro_auth/Cargo.toml
@@ -15,6 +15,7 @@ cookie = { workspace = true }
jsonwebtoken = { workspace = true }
macro_env = { path = "../macro_env" }
macro_env_var = { path = "../macro_env_var" }
+macro_user_id = { path = "../macro_user_id" }
rand = { workspace = true }
remote_env_var = { path = "../remote_env_var" }
serde = { workspace = true }
diff --git a/rust/cloud-storage/macro_auth/src/middleware/decode_jwt.rs b/rust/cloud-storage/macro_auth/src/middleware/decode_jwt.rs
index 29a0188c59..45ee768c0a 100644
--- a/rust/cloud-storage/macro_auth/src/middleware/decode_jwt.rs
+++ b/rust/cloud-storage/macro_auth/src/middleware/decode_jwt.rs
@@ -2,6 +2,7 @@ use anyhow::Context;
use jsonwebtoken::{Algorithm, DecodingKey, Validation, decode};
use macro_env::Environment;
use macro_env_var::{VarNameErr, env_var};
+use macro_user_id::{cowlike::CowLike, lowercased::Lowercase, user_id::MacroUserId};
use remote_env_var::{LocalOrRemoteSecret, SecretManager};
use thiserror::Error;
@@ -128,6 +129,37 @@ pub fn validate_macro_access_token(
)
}
+/// Decodes a macro access token without validating expiry and the macro user id.
+/// This is useful for extracting the user ID from an expired token
+/// (e.g., for advisory lock acquisition during token refresh).
+/// The signature is still validated.
+pub fn decode_macro_access_token_allow_expired(
+ macro_access_token: &str,
+ args: &JwtValidationArgs,
+) -> Result<MacroUserId<Lowercase<'static>>, MacroAuthError> {
+ let mut validation = Validation::new(Algorithm::HS256);
+ validation.set_audience(&[args.audience.as_ref()]);
+ validation.set_issuer(&[args.issuer.as_ref()]);
+ validation.validate_exp = false;
+
+ let decoded_jwt: MacroAccessToken = decode::<MacroAccessToken>(
+ macro_access_token,
+ &DecodingKey::from_secret(args.jwt_secret.as_ref().as_bytes()),
+ &validation,
+ )
+ .map_err(|e| MacroAuthError::JwtValidationFailed {
+ details: e.to_string(),
+ })?
+ .claims;
+
+ let macro_user_id = MacroUserId::parse_from_str(&decoded_jwt.macro_user_id)
+ .map_err(|_| MacroAuthError::from(anyhow::anyhow!("invalid macro user id in token")))?
+ .lowercase()
+ .into_owned();
+
+ Ok(macro_user_id)
+}
+
fn validate_macro_access_token_inner(
macro_access_token: &str,
jwt_secret: &LocalOrRemoteSecret<JwtSecretKey>,
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-0e124775055015b822196bac04d7421635befe41752d32bceaf5ab66e9215cc8.json b/rust/cloud-storage/macro_db_client/.sqlx/query-0e124775055015b822196bac04d7421635befe41752d32bceaf5ab66e9215cc8.json
index aa9502aa59..a1c4c0d402 100644
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-0e124775055015b822196bac04d7421635befe41752d32bceaf5ab66e9215cc8.json
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-0e124775055015b822196bac04d7421635befe41752d32bceaf5ab66e9215cc8.json
@@ -37,9 +37,9 @@
"kind": {
"Enum": [
"view",
+ "comment",
"edit",
- "owner",
- "comment"
+ "owner"
]
}
}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-12a8e0cf51f4192305347c6be6f54282949286944da44b9f779b351e5e84d164.json b/rust/cloud-storage/macro_db_client/.sqlx/query-12a8e0cf51f4192305347c6be6f54282949286944da44b9f779b351e5e84d164.json
deleted file mode 100644
index d2f7d74d0a..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-12a8e0cf51f4192305347c6be6f54282949286944da44b9f779b351e5e84d164.json
+++ /dev/null
@@ -1,77 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT \n id,\n \"userId\" as user_id,\n \"threadsProcessedCount\" as threads_processed_count,\n \"insightsGeneratedCount\" as insights_generated_count,\n status as \"status: InsightsBackfillJobStatus\",\n \"completedAt\"::timestamptz as completed_at,\n \"createdAt\"::timestamptz as \"created_at!\",\n \"updatedAt\"::timestamptz as \"updated_at!\"\n FROM \"EmailInsightsBackfillJob\"\n WHERE id = $1\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "threads_processed_count",
- "type_info": "Int4"
- },
- {
- "ordinal": 3,
- "name": "insights_generated_count",
- "type_info": "Int4"
- },
- {
- "ordinal": 4,
- "name": "status: InsightsBackfillJobStatus",
- "type_info": {
- "Custom": {
- "name": "insights_backfill_job_status",
- "kind": {
- "Enum": [
- "Init",
- "InProgress",
- "Complete",
- "Cancelled",
- "Failed"
- ]
- }
- }
- }
- },
- {
- "ordinal": 5,
- "name": "completed_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 6,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 7,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- false,
- null,
- null,
- null
- ]
- },
- "hash": "12a8e0cf51f4192305347c6be6f54282949286944da44b9f779b351e5e84d164"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-1305807f9cc4251bd612a2f47f310119e5e37b433fa6c8333c19d4b777c74924.json b/rust/cloud-storage/macro_db_client/.sqlx/query-1305807f9cc4251bd612a2f47f310119e5e37b433fa6c8333c19d4b777c74924.json
deleted file mode 100644
index 6808b7f809..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-1305807f9cc4251bd612a2f47f310119e5e37b433fa6c8333c19d4b777c74924.json
+++ /dev/null
@@ -1,42 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT \n \"id\",\n \"providerSource\" as provider_source, \n \"userId\" as user_id,\n \"resourceId\" as resource_id\n FROM \"InsightContext\"\n WHERE\n \"userId\" = $1\n AND\n \"providerSource\" = $2\n AND\n \"consumed\" = false\n ORDER BY\n \"createdAt\" DESC\n LIMIT\n $3\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "provider_source",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "resource_id",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text",
- "Int8"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false
- ]
- },
- "hash": "1305807f9cc4251bd612a2f47f310119e5e37b433fa6c8333c19d4b777c74924"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75.json b/rust/cloud-storage/macro_db_client/.sqlx/query-1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75.json
deleted file mode 100644
index d2b084cf10..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO entity_properties (id, entity_id, entity_type, property_definition_id, values)\n SELECT \n u.id,\n u.entity_id,\n 'TASK'::property_entity_type,\n u.property_definition_id,\n u.values\n FROM UNNEST(\n $1::UUID[],\n $2::TEXT[],\n $3::UUID[],\n $4::JSONB[]\n ) AS u(id, entity_id, property_definition_id, values)\n ON CONFLICT (entity_id, entity_type, property_definition_id)\n DO UPDATE SET \n values = EXCLUDED.values,\n updated_at = NOW()\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "UuidArray",
- "TextArray",
- "UuidArray",
- "JsonbArray"
- ]
- },
- "nullable": []
- },
- "hash": "1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-1514983363d7a71b57b4f4dee4b47a5091a45a17b31ead1f87bb9b556986ec8e.json b/rust/cloud-storage/macro_db_client/.sqlx/query-1514983363d7a71b57b4f4dee4b47a5091a45a17b31ead1f87bb9b556986ec8e.json
deleted file mode 100644
index 7b79922d1f..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-1514983363d7a71b57b4f4dee4b47a5091a45a17b31ead1f87bb9b556986ec8e.json
+++ /dev/null
@@ -1,96 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT \n \"id\",\n \"userId\" as \"user_id\",\n \"content\",\n \"source\", \n \"sourceLocation\" as \"source_location: Json<SourceLocation>\",\n \"generated\",\n \"createdAt\"::timestamptz as \"created_at!\",\n \"updatedAt\"::timestamptz as \"updated_at!\",\n \"spanStart\"::timestamptz as \"span_start\",\n \"spanEnd\"::timestamptz as \"span_end\",\n \"confidence\",\n \"insightType\" as \"insight_type: InsightType\",\n \"relevanceKeywords\" as \"relevance_keywords\"\n FROM\n \"UserInsights\"\n WHERE\n \"userId\" = $1 \n ORDER BY \n \"updatedAt\" DESC\n LIMIT \n $2\n OFFSET\n $3\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "content",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "source",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "source_location: Json<SourceLocation>",
- "type_info": "Jsonb"
- },
- {
- "ordinal": 5,
- "name": "generated",
- "type_info": "Bool"
- },
- {
- "ordinal": 6,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 7,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 8,
- "name": "span_start",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 9,
- "name": "span_end",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 10,
- "name": "confidence",
- "type_info": "Int4"
- },
- {
- "ordinal": 11,
- "name": "insight_type: InsightType",
- "type_info": "Text"
- },
- {
- "ordinal": 12,
- "name": "relevance_keywords",
- "type_info": "TextArray"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Int8",
- "Int8"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- true,
- false,
- null,
- null,
- null,
- null,
- true,
- true,
- true
- ]
- },
- "hash": "1514983363d7a71b57b4f4dee4b47a5091a45a17b31ead1f87bb9b556986ec8e"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-15d0de62c1b856181f4263b8ba43424a41e718199ca502a49ccfc1cd167bf72b.json b/rust/cloud-storage/macro_db_client/.sqlx/query-15d0de62c1b856181f4263b8ba43424a41e718199ca502a49ccfc1cd167bf72b.json
deleted file mode 100644
index 09c3b2a2a0..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-15d0de62c1b856181f4263b8ba43424a41e718199ca502a49ccfc1cd167bf72b.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n DELETE FROM\n \"UserInsights\"\n WHERE\n id = ANY($1)\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "TextArray"
- ]
- },
- "nullable": []
- },
- "hash": "15d0de62c1b856181f4263b8ba43424a41e718199ca502a49ccfc1cd167bf72b"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-18d2885f4c7a6ffd835a5d661ec5e81dd143cd4a51873e92050a0beedbbb86cb.json b/rust/cloud-storage/macro_db_client/.sqlx/query-18d2885f4c7a6ffd835a5d661ec5e81dd143cd4a51873e92050a0beedbbb86cb.json
index 4860ae3ec1..6c17e2c89d 100644
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-18d2885f4c7a6ffd835a5d661ec5e81dd143cd4a51873e92050a0beedbbb86cb.json
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-18d2885f4c7a6ffd835a5d661ec5e81dd143cd4a51873e92050a0beedbbb86cb.json
@@ -22,9 +22,9 @@
"kind": {
"Enum": [
"view",
+ "comment",
"edit",
- "owner",
- "comment"
+ "owner"
]
}
}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-1c9beb8a6be94cbf27a4bb37f987c50a4663132683114b65862ea6c2985d5f7e.json b/rust/cloud-storage/macro_db_client/.sqlx/query-1c9beb8a6be94cbf27a4bb37f987c50a4663132683114b65862ea6c2985d5f7e.json
deleted file mode 100644
index 1f5181230a..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-1c9beb8a6be94cbf27a4bb37f987c50a4663132683114b65862ea6c2985d5f7e.json
+++ /dev/null
@@ -1,31 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n UPDATE \"UserInsights\" ui\n SET\n content = d.content,\n generated = d.generated,\n \"updatedAt\" = $10,\n \"createdAt\" = d.created_at,\n \"spanStart\" = d.span_start,\n \"spanEnd\" = d.span_end,\n source = d.source,\n confidence = d.confidence\n FROM (\n SELECT \n UNNEST($1::TEXT[]) as id, \n UNNEST($2::TEXT[]) as content,\n UNNEST($3::BOOLEAN[]) as generated,\n UNNEST($4::TIMESTAMP[]) as created_at,\n UNNEST($5::TIMESTAMP[]) as span_start,\n UNNEST($6::TIMESTAMP[]) as span_end,\n UNNEST($7::INT[]) as confidence,\n UNNEST($8::TEXT[]) as source\n ) AS d\n WHERE \n ui.id = d.id \n AND \n ui.\"userId\" = $9\n RETURNING\n ui.id\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "TextArray",
- "TextArray",
- "BoolArray",
- "TimestampArray",
- "TimestampArray",
- "TimestampArray",
- "Int4Array",
- "TextArray",
- "Text",
- "Timestamp"
- ]
- },
- "nullable": [
- false
- ]
- },
- "hash": "1c9beb8a6be94cbf27a4bb37f987c50a4663132683114b65862ea6c2985d5f7e"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-2520a37468ab2cc6b065770204ae54cff27a629c58e728248c6f6f4709080850.json b/rust/cloud-storage/macro_db_client/.sqlx/query-2520a37468ab2cc6b065770204ae54cff27a629c58e728248c6f6f4709080850.json
deleted file mode 100644
index 1c64130636..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-2520a37468ab2cc6b065770204ae54cff27a629c58e728248c6f6f4709080850.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n UPDATE \"InsightContext\"\n SET consumed=true\n WHERE id = ANY($1)\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "TextArray"
- ]
- },
- "nullable": []
- },
- "hash": "2520a37468ab2cc6b065770204ae54cff27a629c58e728248c6f6f4709080850"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-270c1f7ab00df1095282625b0766522d883948bc3589eb9a70fffa7787710bbf.json b/rust/cloud-storage/macro_db_client/.sqlx/query-270c1f7ab00df1095282625b0766522d883948bc3589eb9a70fffa7787710bbf.json
index 69cb81d4c7..602ce4228d 100644
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-270c1f7ab00df1095282625b0766522d883948bc3589eb9a70fffa7787710bbf.json
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-270c1f7ab00df1095282625b0766522d883948bc3589eb9a70fffa7787710bbf.json
@@ -15,9 +15,9 @@
"kind": {
"Enum": [
"view",
+ "comment",
"edit",
- "owner",
- "comment"
+ "owner"
]
}
}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-38bcd793812c154a030d2395ba89c8f8adc7e9bbc367ea4d85fa64457adb5093.json b/rust/cloud-storage/macro_db_client/.sqlx/query-38bcd793812c154a030d2395ba89c8f8adc7e9bbc367ea4d85fa64457adb5093.json
deleted file mode 100644
index 92130fa356..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-38bcd793812c154a030d2395ba89c8f8adc7e9bbc367ea4d85fa64457adb5093.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO \"EmailInsightsBackfillBatch\" (\n id, \n \"insightsBackfillJobId\", \n \"sqsMessageId\",\n \"threadIds\", \n \"totalThreads\", \n status,\n \"queuedAt\",\n \"createdAt\",\n \"updatedAt\"\n ) VALUES (\n $1, $2, $3, $4, $5, 'Queued'::\"insights_backfill_batch_status\", NOW(), NOW(), NOW()\n )\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text",
- "Text",
- "Text",
- "TextArray",
- "Int4"
- ]
- },
- "nullable": []
- },
- "hash": "38bcd793812c154a030d2395ba89c8f8adc7e9bbc367ea4d85fa64457adb5093"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-3c3526612a289e3264514c0e5b3d448f8456725ea3cc7d3d33019b75f0807ba7.json b/rust/cloud-storage/macro_db_client/.sqlx/query-3c3526612a289e3264514c0e5b3d448f8456725ea3cc7d3d33019b75f0807ba7.json
deleted file mode 100644
index a0c861ddd9..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-3c3526612a289e3264514c0e5b3d448f8456725ea3cc7d3d33019b75f0807ba7.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n DELETE FROM \"UserInsights\"\n WHERE \n \"userId\" = $1\n AND\n \"id\" = ANY($2)\n RETURNING\n \"id\"\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "TextArray"
- ]
- },
- "nullable": [
- false
- ]
- },
- "hash": "3c3526612a289e3264514c0e5b3d448f8456725ea3cc7d3d33019b75f0807ba7"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-525a4d2d25f82184315ad5a3171ae877ea14dea08cba19b8e8f8e7cc1fab4835.json b/rust/cloud-storage/macro_db_client/.sqlx/query-525a4d2d25f82184315ad5a3171ae877ea14dea08cba19b8e8f8e7cc1fab4835.json
deleted file mode 100644
index dc17c63b3d..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-525a4d2d25f82184315ad5a3171ae877ea14dea08cba19b8e8f8e7cc1fab4835.json
+++ /dev/null
@@ -1,96 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT \n \"id\",\n \"userId\" as \"user_id\",\n \"content\",\n \"source\", \n \"sourceLocation\" as \"source_location: Json<SourceLocation>\",\n \"generated\",\n \"createdAt\"::timestamptz as \"created_at!\",\n \"updatedAt\"::timestamptz as \"updated_at!\",\n \"spanStart\"::timestamptz as \"span_start\",\n \"spanEnd\"::timestamptz as \"span_end\",\n \"confidence\",\n \"insightType\" as \"insight_type: InsightType\",\n \"relevanceKeywords\" as \"relevance_keywords\"\n FROM \n \"UserInsights\" u\n WHERE \n u.\"userId\" = $1\n AND\n u.\"source\" = $2\n ORDER BY \n u.\"createdAt\" DESC\n LIMIT $3\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "content",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "source",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "source_location: Json<SourceLocation>",
- "type_info": "Jsonb"
- },
- {
- "ordinal": 5,
- "name": "generated",
- "type_info": "Bool"
- },
- {
- "ordinal": 6,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 7,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 8,
- "name": "span_start",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 9,
- "name": "span_end",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 10,
- "name": "confidence",
- "type_info": "Int4"
- },
- {
- "ordinal": 11,
- "name": "insight_type: InsightType",
- "type_info": "Text"
- },
- {
- "ordinal": 12,
- "name": "relevance_keywords",
- "type_info": "TextArray"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text",
- "Int8"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- true,
- false,
- null,
- null,
- null,
- null,
- true,
- true,
- true
- ]
- },
- "hash": "525a4d2d25f82184315ad5a3171ae877ea14dea08cba19b8e8f8e7cc1fab4835"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-530ba9c14f6f9e857023f66fa06cf632d4f2122183631ee8ae15902cd870cac3.json b/rust/cloud-storage/macro_db_client/.sqlx/query-530ba9c14f6f9e857023f66fa06cf632d4f2122183631ee8ae15902cd870cac3.json
index daf0b4f790..51a42b64cb 100644
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-530ba9c14f6f9e857023f66fa06cf632d4f2122183631ee8ae15902cd870cac3.json
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-530ba9c14f6f9e857023f66fa06cf632d4f2122183631ee8ae15902cd870cac3.json
@@ -37,9 +37,9 @@
"kind": {
"Enum": [
"view",
+ "comment",
"edit",
- "owner",
- "comment"
+ "owner"
]
}
}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-59282bf7aef3d189bdede3680ba378d60075ee1bae28149db3d5eadd855f6cc7.json b/rust/cloud-storage/macro_db_client/.sqlx/query-59282bf7aef3d189bdede3680ba378d60075ee1bae28149db3d5eadd855f6cc7.json
deleted file mode 100644
index d2032bce39..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-59282bf7aef3d189bdede3680ba378d60075ee1bae28149db3d5eadd855f6cc7.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO \"EmailInsightsBackfillJob\" (\n id, \"userId\", status, \"createdAt\", \"updatedAt\"\n ) VALUES (\n $1, $2, 'InProgress'::\"insights_backfill_job_status\", NOW(), NOW()\n )\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text",
- "Text"
- ]
- },
- "nullable": []
- },
- "hash": "59282bf7aef3d189bdede3680ba378d60075ee1bae28149db3d5eadd855f6cc7"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c.json b/rust/cloud-storage/macro_db_client/.sqlx/query-63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c.json
deleted file mode 100644
index 6d97183829..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO entity_properties (id, entity_id, entity_type, property_definition_id, values)\n SELECT \n u.id,\n u.entity_id,\n 'TASK'::property_entity_type,\n u.property_definition_id,\n NULL\n FROM UNNEST(\n $1::UUID[],\n $2::TEXT[],\n $3::UUID[]\n ) AS u(id, entity_id, property_definition_id)\n ON CONFLICT (entity_id, entity_type, property_definition_id)\n DO NOTHING\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "UuidArray",
- "TextArray",
- "UuidArray"
- ]
- },
- "nullable": []
- },
- "hash": "63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-68c3fd0dca67ebc52afaf8a1ebca21f70a35a36e43b9f3124f1be0507c4c9f28.json b/rust/cloud-storage/macro_db_client/.sqlx/query-68c3fd0dca67ebc52afaf8a1ebca21f70a35a36e43b9f3124f1be0507c4c9f28.json
deleted file mode 100644
index 29fc0347ab..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-68c3fd0dca67ebc52afaf8a1ebca21f70a35a36e43b9f3124f1be0507c4c9f28.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n UPDATE \"EmailInsightsBackfillBatch\"\n SET \n \"insightsGeneratedCount\" = $2,\n \"insightIds\" = $3,\n \"updatedAt\" = $4\n WHERE id = $1\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text",
- "Int4",
- "TextArray",
- "Timestamp"
- ]
- },
- "nullable": []
- },
- "hash": "68c3fd0dca67ebc52afaf8a1ebca21f70a35a36e43b9f3124f1be0507c4c9f28"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-6b56c6a7b38085081264b04cc4f37441c32249d20e9b6244387a31910b70cc45.json b/rust/cloud-storage/macro_db_client/.sqlx/query-6b56c6a7b38085081264b04cc4f37441c32249d20e9b6244387a31910b70cc45.json
deleted file mode 100644
index 8654071ee1..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-6b56c6a7b38085081264b04cc4f37441c32249d20e9b6244387a31910b70cc45.json
+++ /dev/null
@@ -1,27 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO \"UserInsightBatch\" (\n \"userId\", \n \"insightIds\", \n \"totalChars\", \n \"estimatedTokens\", \n \"expiresAt\",\n \"rankingContext\"\n )\n VALUES ($1, $2, $3, $4, $5, $6)\n ON CONFLICT (\"userId\") \n DO UPDATE SET\n \"insightIds\" = EXCLUDED.\"insightIds\",\n \"totalChars\" = EXCLUDED.\"totalChars\",\n \"estimatedTokens\" = EXCLUDED.\"estimatedTokens\",\n \"expiresAt\" = EXCLUDED.\"expiresAt\",\n \"rankingContext\" = EXCLUDED.\"rankingContext\",\n \"version\" = \"UserInsightBatch\".\"version\" + 1,\n \"createdAt\" = NOW()\n RETURNING \"id\"\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "TextArray",
- "Int4",
- "Int4",
- "Timestamp",
- "Jsonb"
- ]
- },
- "nullable": [
- false
- ]
- },
- "hash": "6b56c6a7b38085081264b04cc4f37441c32249d20e9b6244387a31910b70cc45"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-715dbd2005cf827f430c9f1365554541bbd5d375c76c9d8ef022750bb306b9d8.json b/rust/cloud-storage/macro_db_client/.sqlx/query-715dbd2005cf827f430c9f1365554541bbd5d375c76c9d8ef022750bb306b9d8.json
deleted file mode 100644
index 87c3c136f3..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-715dbd2005cf827f430c9f1365554541bbd5d375c76c9d8ef022750bb306b9d8.json
+++ /dev/null
@@ -1,112 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT \n id,\n \"insightsBackfillJobId\" as insights_backfill_job_id,\n \"sqsMessageId\" as sqs_message_id,\n \"threadIds\" as thread_ids,\n \"totalThreads\" as total_threads,\n status as \"status!: InsightsBackfillBatchStatus\",\n \"insightsGeneratedCount\" as insights_generated_count,\n \"insightIds\" as insight_ids,\n \"errorMessage\" as error_message,\n \"queuedAt\"::timestamptz as queued_at,\n \"startedAt\"::timestamptz as started_at,\n \"completedAt\"::timestamptz as completed_at,\n \"createdAt\"::timestamptz as \"created_at!\",\n \"updatedAt\"::timestamptz as \"updated_at!\"\n FROM \"EmailInsightsBackfillBatch\"\n WHERE id = $1\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "insights_backfill_job_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "sqs_message_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "thread_ids",
- "type_info": "TextArray"
- },
- {
- "ordinal": 4,
- "name": "total_threads",
- "type_info": "Int4"
- },
- {
- "ordinal": 5,
- "name": "status!: InsightsBackfillBatchStatus",
- "type_info": {
- "Custom": {
- "name": "insights_backfill_batch_status",
- "kind": {
- "Enum": [
- "Queued",
- "InProgress",
- "Complete",
- "Failed"
- ]
- }
- }
- }
- },
- {
- "ordinal": 6,
- "name": "insights_generated_count",
- "type_info": "Int4"
- },
- {
- "ordinal": 7,
- "name": "insight_ids",
- "type_info": "TextArray"
- },
- {
- "ordinal": 8,
- "name": "error_message",
- "type_info": "Text"
- },
- {
- "ordinal": 9,
- "name": "queued_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 10,
- "name": "started_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 11,
- "name": "completed_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 12,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 13,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false,
- false,
- true,
- true,
- false,
- false,
- false,
- true,
- true,
- null,
- null,
- null,
- null,
- null
- ]
- },
- "hash": "715dbd2005cf827f430c9f1365554541bbd5d375c76c9d8ef022750bb306b9d8"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-7ac12a2efeec0505ac3b4c04459cd29700b18bcb12c81118c1a13b5c8a58a104.json b/rust/cloud-storage/macro_db_client/.sqlx/query-7ac12a2efeec0505ac3b4c04459cd29700b18bcb12c81118c1a13b5c8a58a104.json
deleted file mode 100644
index 9b2fc455bc..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-7ac12a2efeec0505ac3b4c04459cd29700b18bcb12c81118c1a13b5c8a58a104.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT COUNT(*) as \"count!\"\n FROM \"UserInsights\"\n WHERE \"userId\" = $1\n AND \"createdAt\" > $2\n AND \"generated\" = true\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "count!",
- "type_info": "Int8"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Timestamp"
- ]
- },
- "nullable": [
- null
- ]
- },
- "hash": "7ac12a2efeec0505ac3b4c04459cd29700b18bcb12c81118c1a13b5c8a58a104"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-7cf3466b91ebd6cac2a24f566c4a95d63161e8787db7d7552b42a7a0b7e341ea.json b/rust/cloud-storage/macro_db_client/.sqlx/query-7cf3466b91ebd6cac2a24f566c4a95d63161e8787db7d7552b42a7a0b7e341ea.json
deleted file mode 100644
index aa65b05f11..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-7cf3466b91ebd6cac2a24f566c4a95d63161e8787db7d7552b42a7a0b7e341ea.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT \n COUNT(id) as count\n FROM \n \"UserInsights\" i\n WHERE\n i.\"userId\" = $1\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "count",
- "type_info": "Int8"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- null
- ]
- },
- "hash": "7cf3466b91ebd6cac2a24f566c4a95d63161e8787db7d7552b42a7a0b7e341ea"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-80bdc9137502be2a226585bf56f640ea79e47aabf113c821e2abdfaa94005506.json b/rust/cloud-storage/macro_db_client/.sqlx/query-80bdc9137502be2a226585bf56f640ea79e47aabf113c821e2abdfaa94005506.json
deleted file mode 100644
index c8cd96236d..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-80bdc9137502be2a226585bf56f640ea79e47aabf113c821e2abdfaa94005506.json
+++ /dev/null
@@ -1,95 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT \n \"id\",\n \"userId\" as \"user_id\",\n \"content\",\n \"source\", \n \"sourceLocation\" as \"source_location: Json<SourceLocation>\",\n \"generated\",\n \"createdAt\"::timestamptz as \"created_at!\",\n \"updatedAt\"::timestamptz as \"updated_at!\",\n \"spanStart\"::timestamptz as \"span_start\",\n \"spanEnd\"::timestamptz as \"span_end\",\n \"confidence\",\n \"insightType\" as \"insight_type: InsightType\",\n \"relevanceKeywords\" as \"relevance_keywords\"\n FROM\n \"UserInsights\"\n WHERE\n \"userId\" = $1 \n AND\n \"id\" = $2\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "content",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "source",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "source_location: Json<SourceLocation>",
- "type_info": "Jsonb"
- },
- {
- "ordinal": 5,
- "name": "generated",
- "type_info": "Bool"
- },
- {
- "ordinal": 6,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 7,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 8,
- "name": "span_start",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 9,
- "name": "span_end",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 10,
- "name": "confidence",
- "type_info": "Int4"
- },
- {
- "ordinal": 11,
- "name": "insight_type: InsightType",
- "type_info": "Text"
- },
- {
- "ordinal": 12,
- "name": "relevance_keywords",
- "type_info": "TextArray"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- true,
- false,
- null,
- null,
- null,
- null,
- true,
- true,
- true
- ]
- },
- "hash": "80bdc9137502be2a226585bf56f640ea79e47aabf113c821e2abdfaa94005506"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-85c9d9605877ccafd562ac4a30e6cb7733416c77fbcb0086396777b65e0857af.json b/rust/cloud-storage/macro_db_client/.sqlx/query-85c9d9605877ccafd562ac4a30e6cb7733416c77fbcb0086396777b65e0857af.json
deleted file mode 100644
index fd6a4f9e46..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-85c9d9605877ccafd562ac4a30e6cb7733416c77fbcb0086396777b65e0857af.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n DELETE FROM \"DocumentSummary\" WHERE id = ANY($1)\n RETURNING id\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "TextArray"
- ]
- },
- "nullable": [
- false
- ]
- },
- "hash": "85c9d9605877ccafd562ac4a30e6cb7733416c77fbcb0086396777b65e0857af"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-9c006241d51a2d4bdedf1cf4000c705b20db30df5bf7f541d0b01d224f1505df.json b/rust/cloud-storage/macro_db_client/.sqlx/query-9c006241d51a2d4bdedf1cf4000c705b20db30df5bf7f541d0b01d224f1505df.json
deleted file mode 100644
index 8ba1abbaa5..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-9c006241d51a2d4bdedf1cf4000c705b20db30df5bf7f541d0b01d224f1505df.json
+++ /dev/null
@@ -1,82 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT\n m.\"id\" as message_id,\n m.\"content\",\n m.\"createdAt\" as \"date!: DateTime<Utc>\",\n c.\"name\" as conversation_title,\n a.\"attachmentId\" as \"attachment_id?\",\n d.\"summary\" as \"ds_summary?\",\n d.\"version_id\" as \"ds_version_id?\",\n d.\"createdAt\" as \"ds_created_at?: DateTime<Utc>\",\n d.\"document_id\" as \"ds_document_id?\",\n d.\"id\" as \"ds_id?\",\n m.\"chatId\" as \"chat_id\"\n FROM \"ChatMessage\" m\n LEFT JOIN \"Chat\" c\n ON c.\"id\" = m.\"chatId\"\n LEFT JOIN \"ChatAttachment\" a\n ON m.id = a.\"messageId\"\n LEFT JOIN LATERAL (\n SELECT DISTINCT ON (ds.\"document_id\")\n ds.*\n FROM \"DocumentSummary\" ds\n WHERE ds.\"document_id\" = a.\"attachmentId\"\n ORDER BY ds.\"document_id\", ds.\"createdAt\" DESC\n ) d ON true\n WHERE\n m.\"chatId\" = $1\n ORDER BY m.\"createdAt\" DESC;\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "message_id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "content",
- "type_info": "Jsonb"
- },
- {
- "ordinal": 2,
- "name": "date!: DateTime<Utc>",
- "type_info": "Timestamp"
- },
- {
- "ordinal": 3,
- "name": "conversation_title",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "attachment_id?",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
- "name": "ds_summary?",
- "type_info": "Text"
- },
- {
- "ordinal": 6,
- "name": "ds_version_id?",
- "type_info": "Text"
- },
- {
- "ordinal": 7,
- "name": "ds_created_at?: DateTime<Utc>",
- "type_info": "Timestamp"
- },
- {
- "ordinal": 8,
- "name": "ds_document_id?",
- "type_info": "Text"
- },
- {
- "ordinal": 9,
- "name": "ds_id?",
- "type_info": "Text"
- },
- {
- "ordinal": 10,
- "name": "chat_id",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- false,
- false,
- false,
- false,
- false,
- false,
- false
- ]
- },
- "hash": "9c006241d51a2d4bdedf1cf4000c705b20db30df5bf7f541d0b01d224f1505df"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4.json b/rust/cloud-storage/macro_db_client/.sqlx/query-9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4.json
deleted file mode 100644
index 9d717fa5f9..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4.json
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT property_definition_id, values\n FROM entity_properties\n WHERE entity_id = $1\n AND entity_type = 'TASK'\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "property_definition_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "values",
- "type_info": "Jsonb"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false,
- true
- ]
- },
- "hash": "9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-a1a771d0bf1cec19cb50f9e0cf26f412a7a9f7f4e88cbe8470a11664934c61d5.json b/rust/cloud-storage/macro_db_client/.sqlx/query-a1a771d0bf1cec19cb50f9e0cf26f412a7a9f7f4e88cbe8470a11664934c61d5.json
deleted file mode 100644
index 3136125618..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-a1a771d0bf1cec19cb50f9e0cf26f412a7a9f7f4e88cbe8470a11664934c61d5.json
+++ /dev/null
@@ -1,82 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT\n m.\"id\" as message_id,\n m.\"content\",\n m.\"createdAt\" as \"date!: DateTime<Utc>\",\n c.\"name\" as conversation_title,\n a.\"attachmentId\" as \"attachment_id?\",\n d.\"summary\" as \"ds_summary?\",\n d.\"version_id\" as \"ds_version_id?\",\n d.\"createdAt\" as \"ds_created_at?: DateTime<Utc>\",\n d.\"document_id\" as \"ds_document_id?\",\n d.\"id\" as \"ds_id?\",\n m.\"chatId\" as \"chat_id\"\n FROM \"ChatMessage\" m\n LEFT JOIN \"Chat\" c\n ON c.\"id\" = m.\"chatId\"\n LEFT JOIN \"ChatAttachment\" a\n ON m.id = a.\"messageId\"\n LEFT JOIN LATERAL (\n SELECT DISTINCT ON (ds.\"document_id\")\n ds.*\n FROM \"DocumentSummary\" ds\n WHERE ds.\"document_id\" = a.\"attachmentId\"\n ORDER BY ds.\"document_id\", ds.\"createdAt\" DESC\n ) d ON true\n WHERE\n m.\"id\" = ANY($1)\n ORDER BY m.\"createdAt\" DESC;\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "message_id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "content",
- "type_info": "Jsonb"
- },
- {
- "ordinal": 2,
- "name": "date!: DateTime<Utc>",
- "type_info": "Timestamp"
- },
- {
- "ordinal": 3,
- "name": "conversation_title",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "attachment_id?",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
- "name": "ds_summary?",
- "type_info": "Text"
- },
- {
- "ordinal": 6,
- "name": "ds_version_id?",
- "type_info": "Text"
- },
- {
- "ordinal": 7,
- "name": "ds_created_at?: DateTime<Utc>",
- "type_info": "Timestamp"
- },
- {
- "ordinal": 8,
- "name": "ds_document_id?",
- "type_info": "Text"
- },
- {
- "ordinal": 9,
- "name": "ds_id?",
- "type_info": "Text"
- },
- {
- "ordinal": 10,
- "name": "chat_id",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "TextArray"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- false,
- false,
- false,
- false,
- false,
- false,
- false
- ]
- },
- "hash": "a1a771d0bf1cec19cb50f9e0cf26f412a7a9f7f4e88cbe8470a11664934c61d5"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-ad38f25dbef83e91f225a7a8ec390faa2c11cce3824757aaf19fafcbc909b725.json b/rust/cloud-storage/macro_db_client/.sqlx/query-ad38f25dbef83e91f225a7a8ec390faa2c11cce3824757aaf19fafcbc909b725.json
deleted file mode 100644
index 6c32b207e6..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-ad38f25dbef83e91f225a7a8ec390faa2c11cce3824757aaf19fafcbc909b725.json
+++ /dev/null
@@ -1,12 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n DELETE FROM \"UserInsightBatch\"\n WHERE \"expiresAt\" <= NOW()\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": []
- },
- "nullable": []
- },
- "hash": "ad38f25dbef83e91f225a7a8ec390faa2c11cce3824757aaf19fafcbc909b725"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-b4edf0877afce79c1811f30b172520e11c357ef671da3ae1a651be27d01984a3.json b/rust/cloud-storage/macro_db_client/.sqlx/query-b4edf0877afce79c1811f30b172520e11c357ef671da3ae1a651be27d01984a3.json
index 78eac67010..4235a97747 100644
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-b4edf0877afce79c1811f30b172520e11c357ef671da3ae1a651be27d01984a3.json
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-b4edf0877afce79c1811f30b172520e11c357ef671da3ae1a651be27d01984a3.json
@@ -37,9 +37,9 @@
"kind": {
"Enum": [
"view",
+ "comment",
"edit",
- "owner",
- "comment"
+ "owner"
]
}
}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-c2fdddfd2d07ccb82539a834a9c564f79bb1c6862ac65929ad3268a74b0e8cfd.json b/rust/cloud-storage/macro_db_client/.sqlx/query-c2fdddfd2d07ccb82539a834a9c564f79bb1c6862ac65929ad3268a74b0e8cfd.json
deleted file mode 100644
index d298ce4ad1..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-c2fdddfd2d07ccb82539a834a9c564f79bb1c6862ac65929ad3268a74b0e8cfd.json
+++ /dev/null
@@ -1,70 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT \n \"id\",\n \"userId\" as \"user_id\",\n \"insightIds\" as \"insight_ids\",\n \"totalChars\" as \"total_chars\",\n \"estimatedTokens\" as \"estimated_tokens\",\n \"rankingContext\" as \"ranking_context\",\n \"createdAt\"::timestamptz as \"created_at!\",\n \"expiresAt\"::timestamptz as \"expires_at!\",\n \"version\"\n FROM \n \"UserInsightBatch\"\n WHERE \n \"userId\" = $1\n AND \n \"expiresAt\" > NOW()\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "insight_ids",
- "type_info": "TextArray"
- },
- {
- "ordinal": 3,
- "name": "total_chars",
- "type_info": "Int4"
- },
- {
- "ordinal": 4,
- "name": "estimated_tokens",
- "type_info": "Int4"
- },
- {
- "ordinal": 5,
- "name": "ranking_context",
- "type_info": "Jsonb"
- },
- {
- "ordinal": 6,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 7,
- "name": "expires_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 8,
- "name": "version",
- "type_info": "Int4"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false,
- false,
- true,
- false,
- false,
- true,
- null,
- null,
- false
- ]
- },
- "hash": "c2fdddfd2d07ccb82539a834a9c564f79bb1c6862ac65929ad3268a74b0e8cfd"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-c578035fe707a542b4d4836ba2cf62d20bec24f04957422f3066b39c9a02ec44.json b/rust/cloud-storage/macro_db_client/.sqlx/query-c578035fe707a542b4d4836ba2cf62d20bec24f04957422f3066b39c9a02ec44.json
deleted file mode 100644
index 437231eea0..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-c578035fe707a542b4d4836ba2cf62d20bec24f04957422f3066b39c9a02ec44.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n UPDATE \"EmailInsightsBackfillJob\"\n SET \n \"threadsProcessedCount\" = \"threadsProcessedCount\" + $2,\n \"insightsGeneratedCount\" = \"insightsGeneratedCount\" + $3,\n \"updatedAt\" = $4\n WHERE id = $1\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text",
- "Int4",
- "Int4",
- "Timestamp"
- ]
- },
- "nullable": []
- },
- "hash": "c578035fe707a542b4d4836ba2cf62d20bec24f04957422f3066b39c9a02ec44"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-ca6bca52697da1ef1b6bb702496b1dea573d8eb020c8f005dd620d1c334549b3.json b/rust/cloud-storage/macro_db_client/.sqlx/query-ca6bca52697da1ef1b6bb702496b1dea573d8eb020c8f005dd620d1c334549b3.json
deleted file mode 100644
index 385d5459b9..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-ca6bca52697da1ef1b6bb702496b1dea573d8eb020c8f005dd620d1c334549b3.json
+++ /dev/null
@@ -1,48 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO \"DocumentSummary\" (\n document_id, \n version_id, \n summary\n )\n SELECT \n u.document_id, u.version_id, u.summary\n FROM \n UNNEST($1::text[], $2::text[], $3::text[])\n AS u(document_id, version_id, summary)\n RETURNING \n id as \"id?\", \n \"createdAt\" as \"created_at?: DateTime<Utc>\",\n document_id,\n version_id, \n summary\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id?",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "created_at?: DateTime<Utc>",
- "type_info": "Timestamp"
- },
- {
- "ordinal": 2,
- "name": "document_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "version_id",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "summary",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "TextArray",
- "TextArray",
- "TextArray"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- false
- ]
- },
- "hash": "ca6bca52697da1ef1b6bb702496b1dea573d8eb020c8f005dd620d1c334549b3"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-cd39c593bdca8f628570365a8aa6787d34173da3b114c61b2cddc69b7d197819.json b/rust/cloud-storage/macro_db_client/.sqlx/query-cd39c593bdca8f628570365a8aa6787d34173da3b114c61b2cddc69b7d197819.json
new file mode 100644
index 0000000000..a140edbf63
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-cd39c593bdca8f628570365a8aa6787d34173da3b114c61b2cddc69b7d197819.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT pg_try_advisory_xact_lock($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "pg_try_advisory_xact_lock",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "cd39c593bdca8f628570365a8aa6787d34173da3b114c61b2cddc69b7d197819"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-ce3155fe8b0b0c44b0e20c06db015fc4ce088c97401b4d5264077bd4852c95a4.json b/rust/cloud-storage/macro_db_client/.sqlx/query-ce3155fe8b0b0c44b0e20c06db015fc4ce088c97401b4d5264077bd4852c95a4.json
deleted file mode 100644
index a0a28cabb6..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-ce3155fe8b0b0c44b0e20c06db015fc4ce088c97401b4d5264077bd4852c95a4.json
+++ /dev/null
@@ -1,95 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT \n \"id\",\n \"userId\" as \"user_id\",\n \"content\",\n \"source\", \n \"sourceLocation\" as \"source_location: Json<SourceLocation>\",\n \"generated\",\n \"createdAt\"::timestamptz as \"created_at!\",\n \"updatedAt\"::timestamptz as \"updated_at!\",\n \"spanStart\"::timestamptz as \"span_start\",\n \"spanEnd\"::timestamptz as \"span_end\",\n \"confidence\",\n \"insightType\" as \"insight_type: InsightType\",\n \"relevanceKeywords\" as \"relevance_keywords\"\n FROM \n \"UserInsights\"\n WHERE \n \"userId\" = $1\n AND \n \"id\" = ANY($2)\n ORDER BY \n array_position($2, \"id\")\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "content",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "source",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "source_location: Json<SourceLocation>",
- "type_info": "Jsonb"
- },
- {
- "ordinal": 5,
- "name": "generated",
- "type_info": "Bool"
- },
- {
- "ordinal": 6,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 7,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 8,
- "name": "span_start",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 9,
- "name": "span_end",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 10,
- "name": "confidence",
- "type_info": "Int4"
- },
- {
- "ordinal": 11,
- "name": "insight_type: InsightType",
- "type_info": "Text"
- },
- {
- "ordinal": 12,
- "name": "relevance_keywords",
- "type_info": "TextArray"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "TextArray"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- true,
- false,
- null,
- null,
- null,
- null,
- true,
- true,
- true
- ]
- },
- "hash": "ce3155fe8b0b0c44b0e20c06db015fc4ce088c97401b4d5264077bd4852c95a4"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-cfbec090ff3b62415ec0c215aa52bdafe162fb8c8fd217a8fcaf613e39525b0f.json b/rust/cloud-storage/macro_db_client/.sqlx/query-cfbec090ff3b62415ec0c215aa52bdafe162fb8c8fd217a8fcaf613e39525b0f.json
index 56f1ffeb77..e17bd1ee56 100644
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-cfbec090ff3b62415ec0c215aa52bdafe162fb8c8fd217a8fcaf613e39525b0f.json
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-cfbec090ff3b62415ec0c215aa52bdafe162fb8c8fd217a8fcaf613e39525b0f.json
@@ -56,12 +56,12 @@
]
},
"nullable": [
+ false,
+ false,
true,
- true,
- true,
- true,
- null,
false,
+ null,
+ true,
null
]
},
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-d1d1519e0bdb30ddcbaa6d602bc04617613bb21df0e7728150e74b4125d28a59.json b/rust/cloud-storage/macro_db_client/.sqlx/query-d1d1519e0bdb30ddcbaa6d602bc04617613bb21df0e7728150e74b4125d28a59.json
index a427d7bdea..12ed677b43 100644
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-d1d1519e0bdb30ddcbaa6d602bc04617613bb21df0e7728150e74b4125d28a59.json
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-d1d1519e0bdb30ddcbaa6d602bc04617613bb21df0e7728150e74b4125d28a59.json
@@ -13,9 +13,9 @@
"kind": {
"Enum": [
"view",
+ "comment",
"edit",
- "owner",
- "comment"
+ "owner"
]
}
}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-d67b71dadd6c5d7467fd2c5e49065f998ba9f364b2d5c8d5d6fca37d03990b3a.json b/rust/cloud-storage/macro_db_client/.sqlx/query-d67b71dadd6c5d7467fd2c5e49065f998ba9f364b2d5c8d5d6fca37d03990b3a.json
deleted file mode 100644
index b20cca7030..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-d67b71dadd6c5d7467fd2c5e49065f998ba9f364b2d5c8d5d6fca37d03990b3a.json
+++ /dev/null
@@ -1,97 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT \n \"id\",\n \"userId\" as \"user_id\",\n \"content\",\n \"source\", \n \"sourceLocation\" as \"source_location: Json<SourceLocation>\",\n \"generated\",\n \"createdAt\"::timestamptz as \"created_at!\",\n \"updatedAt\"::timestamptz as \"updated_at!\",\n \"spanStart\"::timestamptz as \"span_start\",\n \"spanEnd\"::timestamptz as \"span_end\",\n \"confidence\",\n \"insightType\" as \"insight_type: InsightType\",\n \"relevanceKeywords\" as \"relevance_keywords\"\n FROM\n \"UserInsights\"\n WHERE\n \"userId\" = $1 \n AND\n generated = $2\n ORDER BY \n \"updatedAt\" DESC\n LIMIT \n $3\n OFFSET\n $4\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "content",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "source",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "source_location: Json<SourceLocation>",
- "type_info": "Jsonb"
- },
- {
- "ordinal": 5,
- "name": "generated",
- "type_info": "Bool"
- },
- {
- "ordinal": 6,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 7,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 8,
- "name": "span_start",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 9,
- "name": "span_end",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 10,
- "name": "confidence",
- "type_info": "Int4"
- },
- {
- "ordinal": 11,
- "name": "insight_type: InsightType",
- "type_info": "Text"
- },
- {
- "ordinal": 12,
- "name": "relevance_keywords",
- "type_info": "TextArray"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Bool",
- "Int8",
- "Int8"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- true,
- false,
- null,
- null,
- null,
- null,
- true,
- true,
- true
- ]
- },
- "hash": "d67b71dadd6c5d7467fd2c5e49065f998ba9f364b2d5c8d5d6fca37d03990b3a"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-de9cdba9742afd09f855fb6b9326acf99fd35ea8b93c5e5b0f8ca3eb6f0d6e73.json b/rust/cloud-storage/macro_db_client/.sqlx/query-de9cdba9742afd09f855fb6b9326acf99fd35ea8b93c5e5b0f8ca3eb6f0d6e73.json
deleted file mode 100644
index a262bb11ab..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-de9cdba9742afd09f855fb6b9326acf99fd35ea8b93c5e5b0f8ca3eb6f0d6e73.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO \"InsightContext\" (\"providerSource\", \"userId\", \"resourceId\")\n VALUES ($1, $2, $3)\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text",
- "Text",
- "Text"
- ]
- },
- "nullable": []
- },
- "hash": "de9cdba9742afd09f855fb6b9326acf99fd35ea8b93c5e5b0f8ca3eb6f0d6e73"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-e4fe26b8ea99777cb6a64d01d33a5d55d73accfb22345d129d012703e65488d3.json b/rust/cloud-storage/macro_db_client/.sqlx/query-e4fe26b8ea99777cb6a64d01d33a5d55d73accfb22345d129d012703e65488d3.json
deleted file mode 100644
index 6434746394..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-e4fe26b8ea99777cb6a64d01d33a5d55d73accfb22345d129d012703e65488d3.json
+++ /dev/null
@@ -1,46 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT DISTINCT ON(\"document_id\") \n \"id\" as \"id?\",\n \"document_id\",\n \"version_id\",\n \"createdAt\" as \"created_at?: DateTime<Utc>\",\n \"summary\"\n FROM \"DocumentSummary\"\n WHERE document_id = ANY($1)\n ORDER BY \"document_id\", \"createdAt\" DESC\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id?",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "document_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "version_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "created_at?: DateTime<Utc>",
- "type_info": "Timestamp"
- },
- {
- "ordinal": 4,
- "name": "summary",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "TextArray"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- false
- ]
- },
- "hash": "e4fe26b8ea99777cb6a64d01d33a5d55d73accfb22345d129d012703e65488d3"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-ea8ca1cc2c2685b94ff8138dbf7c02b4f24ed69045afabdea66a759c5e0e32c4.json b/rust/cloud-storage/macro_db_client/.sqlx/query-ea8ca1cc2c2685b94ff8138dbf7c02b4f24ed69045afabdea66a759c5e0e32c4.json
deleted file mode 100644
index 42b099670b..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-ea8ca1cc2c2685b94ff8138dbf7c02b4f24ed69045afabdea66a759c5e0e32c4.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT \n COUNT(id) as count\n FROM \n \"UserInsights\" i\n WHERE\n i.\"userId\" = $1\n AND\n i.\"generated\" = $2\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "count",
- "type_info": "Int8"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Bool"
- ]
- },
- "nullable": [
- null
- ]
- },
- "hash": "ea8ca1cc2c2685b94ff8138dbf7c02b4f24ed69045afabdea66a759c5e0e32c4"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069.json b/rust/cloud-storage/macro_db_client/.sqlx/query-f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069.json
deleted file mode 100644
index 182e0858ba..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO entity_properties (id, entity_id, entity_type, property_definition_id, values)\n SELECT \n u.id,\n u.entity_id,\n u.entity_type::property_entity_type,\n u.property_definition_id,\n u.values\n FROM UNNEST(\n $1::UUID[],\n $2::TEXT[],\n $3::TEXT[],\n $4::UUID[],\n $5::JSONB[]\n ) AS u(id, entity_id, entity_type, property_definition_id, values)\n ON CONFLICT (entity_id, entity_type, property_definition_id)\n DO UPDATE SET \n values = EXCLUDED.values,\n updated_at = NOW()\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "UuidArray",
- "TextArray",
- "TextArray",
- "UuidArray",
- "JsonbArray"
- ]
- },
- "nullable": []
- },
- "hash": "f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-f7bfffb9ab023321ee3ceb8b86196bd279eec8c695dec232b06823fe017edd83.json b/rust/cloud-storage/macro_db_client/.sqlx/query-f7bfffb9ab023321ee3ceb8b86196bd279eec8c695dec232b06823fe017edd83.json
deleted file mode 100644
index a024ff9b44..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-f7bfffb9ab023321ee3ceb8b86196bd279eec8c695dec232b06823fe017edd83.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n DELETE FROM \"UserInsightBatch\"\n WHERE \"userId\" = $1\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": []
- },
- "hash": "f7bfffb9ab023321ee3ceb8b86196bd279eec8c695dec232b06823fe017edd83"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-f8d2e1308363b6d79f351d8b03a0bc80c22da3074b2ce909d51cec1f8f5db0f1.json b/rust/cloud-storage/macro_db_client/.sqlx/query-f8d2e1308363b6d79f351d8b03a0bc80c22da3074b2ce909d51cec1f8f5db0f1.json
deleted file mode 100644
index af9f86721b..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-f8d2e1308363b6d79f351d8b03a0bc80c22da3074b2ce909d51cec1f8f5db0f1.json
+++ /dev/null
@@ -1,30 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n UPDATE \"EmailInsightsBackfillJob\"\n SET \n status = $2::\"insights_backfill_job_status\",\n \"completedAt\" = $3,\n \"updatedAt\" = $4\n WHERE id = $1\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text",
- {
- "Custom": {
- "name": "insights_backfill_job_status",
- "kind": {
- "Enum": [
- "Init",
- "InProgress",
- "Complete",
- "Cancelled",
- "Failed"
- ]
- }
- }
- },
- "Timestamp",
- "Timestamp"
- ]
- },
- "nullable": []
- },
- "hash": "f8d2e1308363b6d79f351d8b03a0bc80c22da3074b2ce909d51cec1f8f5db0f1"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-fa73020f419314824e047eb67bd8dc94a443790ba5ec74410e1ca5e0aa98b577.json b/rust/cloud-storage/macro_db_client/.sqlx/query-fa73020f419314824e047eb67bd8dc94a443790ba5ec74410e1ca5e0aa98b577.json
deleted file mode 100644
index 7b37bd3deb..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-fa73020f419314824e047eb67bd8dc94a443790ba5ec74410e1ca5e0aa98b577.json
+++ /dev/null
@@ -1,32 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n UPDATE \"EmailInsightsBackfillBatch\"\n SET \n status = $2::\"insights_backfill_batch_status\",\n \"errorMessage\" = $3,\n \"sqsMessageId\" = COALESCE(\"sqsMessageId\", $4),\n \"startedAt\" = COALESCE(\"startedAt\", $5),\n \"completedAt\" = $6,\n \"updatedAt\" = $7\n WHERE id = $1\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text",
- {
- "Custom": {
- "name": "insights_backfill_batch_status",
- "kind": {
- "Enum": [
- "Queued",
- "InProgress",
- "Complete",
- "Failed"
- ]
- }
- }
- },
- "Text",
- "Text",
- "Timestamp",
- "Timestamp",
- "Timestamp"
- ]
- },
- "nullable": []
- },
- "hash": "fa73020f419314824e047eb67bd8dc94a443790ba5ec74410e1ca5e0aa98b577"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-fab2fcdcfa7c81426ffddfb934b7c5eade3811d3ec8b5ab962c3dc9fd7886e9b.json b/rust/cloud-storage/macro_db_client/.sqlx/query-fab2fcdcfa7c81426ffddfb934b7c5eade3811d3ec8b5ab962c3dc9fd7886e9b.json
index 6c9131a493..02598512d9 100644
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-fab2fcdcfa7c81426ffddfb934b7c5eade3811d3ec8b5ab962c3dc9fd7886e9b.json
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-fab2fcdcfa7c81426ffddfb934b7c5eade3811d3ec8b5ab962c3dc9fd7886e9b.json
@@ -37,9 +37,9 @@
"kind": {
"Enum": [
"view",
+ "comment",
"edit",
- "owner",
- "comment"
+ "owner"
]
}
}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-fc8f1f0f54cc0cd5e2ed8071c36c5eb3e42857a64e07b78e66e0e044516512d4.json b/rust/cloud-storage/macro_db_client/.sqlx/query-fc8f1f0f54cc0cd5e2ed8071c36c5eb3e42857a64e07b78e66e0e044516512d4.json
deleted file mode 100644
index 3372afaa05..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-fc8f1f0f54cc0cd5e2ed8071c36c5eb3e42857a64e07b78e66e0e044516512d4.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT DISTINCT u.\"id\" as \"user_id\"\n FROM \"User\" u\n INNER JOIN \"UserInsights\" ui ON u.\"id\" = ui.\"userId\"\n LEFT JOIN \"UserInsightBatch\" uib ON u.\"id\" = uib.\"userId\"\n WHERE \n ui.\"generated\" = true\n AND ui.\"createdAt\" > COALESCE(uib.\"createdAt\", '1970-01-01'::timestamptz)\n OR \n uib.\"expiresAt\" <= NOW()\n ORDER BY u.\"id\"\n LIMIT $1\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "user_id",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Int8"
- ]
- },
- "nullable": [
- false
- ]
- },
- "hash": "fc8f1f0f54cc0cd5e2ed8071c36c5eb3e42857a64e07b78e66e0e044516512d4"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-fef80a0b809980ea8efbf49087aff2dd8c12edd081ad759855474fd9a4d1916d.json b/rust/cloud-storage/macro_db_client/.sqlx/query-fef80a0b809980ea8efbf49087aff2dd8c12edd081ad759855474fd9a4d1916d.json
index a3c1720287..055f08f556 100644
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-fef80a0b809980ea8efbf49087aff2dd8c12edd081ad759855474fd9a4d1916d.json
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-fef80a0b809980ea8efbf49087aff2dd8c12edd081ad759855474fd9a4d1916d.json
@@ -13,9 +13,9 @@
"kind": {
"Enum": [
"view",
+ "comment",
"edit",
- "owner",
- "comment"
+ "owner"
]
}
}
diff --git a/rust/cloud-storage/macro_db_client/src/advisory_lock/mod.rs b/rust/cloud-storage/macro_db_client/src/advisory_lock/mod.rs
new file mode 100644
index 0000000000..038719bace
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/src/advisory_lock/mod.rs
@@ -0,0 +1,48 @@
+use std::{
+ collections::hash_map::DefaultHasher,
+ hash::{Hash, Hasher},
+};
+
+use macro_user_id::{lowercased::Lowercase, user_id::MacroUserId};
+use sqlx::{Postgres, Transaction};
+
+#[cfg(test)]
+mod test;
+
+/// Namespace constant for refresh token locks to avoid collisions with other advisory locks
+const REFRESH_TOKEN_LOCK_NAMESPACE: i64 = 1_000_000_000;
+
+/// Computes an advisory lock key from a user ID string.
+/// Combines a namespace constant with a hash of the user ID.
+fn compute_lock_key<'a>(user_id: &MacroUserId<Lowercase<'a>>) -> i64 {
+ let mut hasher = DefaultHasher::new();
+ user_id.as_ref().hash(&mut hasher);
+ let hash = hasher.finish();
+ // Use the lower 32 bits of the hash combined with the namespace
+ // to create a unique lock key
+ REFRESH_TOKEN_LOCK_NAMESPACE + (hash as i64 & 0x7FFFFFFF)
+}
+
+/// Attempts to acquire a transaction-level advisory lock for the given user ID.
+/// Returns `true` if the lock was acquired, `false` if another transaction holds the lock.
+///
+/// The lock is automatically released when the transaction commits or rolls back.
+/// This is the preferred method over session-level locks as it prevents lock leaks.
+#[tracing::instrument(skip(transaction))]
+pub async fn try_acquire_user_refresh_xact_lock<'a>(
+ transaction: &mut Transaction<'_, Postgres>,
+ user_id: &MacroUserId<Lowercase<'a>>,
+) -> anyhow::Result<bool> {
+ let lock_key = compute_lock_key(user_id);
+
+ let result = sqlx::query_scalar!(
+ r#"
+ SELECT pg_try_advisory_xact_lock($1)
+ "#,
+ lock_key
+ )
+ .fetch_one(transaction.as_mut())
+ .await?;
+
+ Ok(result.unwrap_or(false))
+}
diff --git a/rust/cloud-storage/macro_db_client/src/advisory_lock/test.rs b/rust/cloud-storage/macro_db_client/src/advisory_lock/test.rs
new file mode 100644
index 0000000000..31b45417f9
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/src/advisory_lock/test.rs
@@ -0,0 +1,153 @@
+use super::*;
+use sqlx::{Pool, Postgres};
+
+#[sqlx::test]
+async fn test_xact_lock_acquired_in_transaction(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserId::parse_from_str("macro|[email protected]")
+ .unwrap()
+ .lowercase();
+
+ let mut txn = pool.begin().await?;
+
+ // Should acquire lock successfully within transaction
+ let acquired = try_acquire_user_refresh_xact_lock(&mut txn, &user_id).await?;
+ assert!(acquired, "Should acquire lock on first attempt");
+
+ txn.commit().await?;
+
+ Ok(())
+}
+
+#[sqlx::test]
+async fn test_xact_lock_blocks_concurrent_transaction(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserId::parse_from_str("macro|[email protected]")
+ .unwrap()
+ .lowercase();
+
+ // First transaction acquires the lock
+ let mut txn1 = pool.begin().await?;
+ let acquired1 = try_acquire_user_refresh_xact_lock(&mut txn1, &user_id).await?;
+ assert!(acquired1, "First transaction should acquire lock");
+
+ // Second transaction should fail to acquire the same lock
+ let mut txn2 = pool.begin().await?;
+ let acquired2 = try_acquire_user_refresh_xact_lock(&mut txn2, &user_id).await?;
+ assert!(
+ !acquired2,
+ "Second transaction should NOT acquire lock while first holds it"
+ );
+
+ // After first transaction commits, second should be able to acquire
+ txn1.commit().await?;
+
+ let acquired3 = try_acquire_user_refresh_xact_lock(&mut txn2, &user_id).await?;
+ assert!(
+ acquired3,
+ "Second transaction should acquire lock after first commits"
+ );
+
+ txn2.commit().await?;
+
+ Ok(())
+}
+
+#[sqlx::test]
+async fn test_xact_lock_released_on_commit(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserId::parse_from_str("macro|[email protected]")
+ .unwrap()
+ .lowercase();
+
+ // Acquire and commit in first transaction
+ {
+ let mut txn = pool.begin().await?;
+ let acquired = try_acquire_user_refresh_xact_lock(&mut txn, &user_id).await?;
+ assert!(acquired, "Should acquire lock");
+ txn.commit().await?;
+ }
+
+ // Should be able to acquire again in new transaction (lock was released)
+ {
+ let mut txn = pool.begin().await?;
+ let acquired = try_acquire_user_refresh_xact_lock(&mut txn, &user_id).await?;
+ assert!(acquired, "Should acquire lock again after previous commit");
+ txn.commit().await?;
+ }
+
+ Ok(())
+}
+
+#[sqlx::test]
+async fn test_xact_lock_released_on_rollback(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserId::parse_from_str("macro|[email protected]")
+ .unwrap()
+ .lowercase();
+
+ // Acquire and rollback in first transaction
+ {
+ let mut txn = pool.begin().await?;
+ let acquired = try_acquire_user_refresh_xact_lock(&mut txn, &user_id).await?;
+ assert!(acquired, "Should acquire lock");
+ txn.rollback().await?;
+ }
+
+ // Should be able to acquire again in new transaction (lock was released on rollback)
+ {
+ let mut txn = pool.begin().await?;
+ let acquired = try_acquire_user_refresh_xact_lock(&mut txn, &user_id).await?;
+ assert!(
+ acquired,
+ "Should acquire lock again after previous rollback"
+ );
+ txn.commit().await?;
+ }
+
+ Ok(())
+}
+
+#[sqlx::test]
+async fn test_xact_lock_released_on_drop(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = MacroUserId::parse_from_str("macro|[email protected]")
+ .unwrap()
+ .lowercase();
+
+ // Acquire and drop transaction without explicit commit/rollback
+ {
+ let mut txn = pool.begin().await?;
+ let acquired = try_acquire_user_refresh_xact_lock(&mut txn, &user_id).await?;
+ assert!(acquired, "Should acquire lock");
+ // txn is dropped here without explicit commit/rollback
+ }
+
+ // Should be able to acquire again in new transaction (lock was released on drop)
+ {
+ let mut txn = pool.begin().await?;
+ let acquired = try_acquire_user_refresh_xact_lock(&mut txn, &user_id).await?;
+ assert!(acquired, "Should acquire lock again after previous drop");
+ txn.commit().await?;
+ }
+
+ Ok(())
+}
+
+#[sqlx::test]
+async fn test_xact_lock_different_users(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id_1 = MacroUserId::parse_from_str("macro|[email protected]")
+ .unwrap()
+ .lowercase();
+ let user_id_2 = MacroUserId::parse_from_str("macro|[email protected]")
+ .unwrap()
+ .lowercase();
+
+ let mut txn = pool.begin().await?;
+
+ // Both users should be able to acquire their own locks in the same transaction
+ let acquired1 = try_acquire_user_refresh_xact_lock(&mut txn, &user_id_1).await?;
+ let acquired2 = try_acquire_user_refresh_xact_lock(&mut txn, &user_id_2).await?;
+
+ assert!(acquired1, "User 1 should acquire lock");
+ assert!(acquired2, "User 2 should acquire lock");
+
+ txn.commit().await?;
+
+ Ok(())
+}
diff --git a/rust/cloud-storage/macro_db_client/src/lib.rs b/rust/cloud-storage/macro_db_client/src/lib.rs
index 4e3e95179b..1cfa88dda4 100644
--- a/rust/cloud-storage/macro_db_client/src/lib.rs
+++ b/rust/cloud-storage/macro_db_client/src/lib.rs
@@ -1,6 +1,7 @@
#[cfg(feature = "account_merge_request")]
pub mod account_merge_request;
pub mod activity;
+pub mod advisory_lock;
pub mod annotations;
pub mod blocked_email;
pub mod chat;