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.

feat entity access (#2418)

Will Hutchinsonb4a6458d380c
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/editCallRecordRequest.ts b/js/app/packages/service-clients/service-storage/generated/schemas/editCallRecordRequest.ts
new file mode 100644
index 0000000000..7ca9050682
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/editCallRecordRequest.ts
@@ -0,0 +1,14 @@
+/**
+ * Generated by orval v7.13.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { EditCallRecordRequestSharePermission } from './editCallRecordRequestSharePermission';
+
+/**
+ * Edit call request
+ */
+export interface EditCallRecordRequest {
+ sharePermission?: EditCallRecordRequestSharePermission;
+}
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/editCallRecordRequestSharePermission.ts b/js/app/packages/service-clients/service-storage/generated/schemas/editCallRecordRequestSharePermission.ts
new file mode 100644
index 0000000000..f254ddc80f
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/editCallRecordRequestSharePermission.ts
@@ -0,0 +1,10 @@
+/**
+ * Generated by orval v7.13.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { UpdateSharePermissionRequestV2 } from './updateSharePermissionRequestV2';
+
+export type EditCallRecordRequestSharePermission =
+ null | UpdateSharePermissionRequestV2;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
index 7a000c3fe6..c4d900e722 100644
--- a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
@@ -257,6 +257,8 @@ export * from './editAnchorRequestOneOfAllOf';
export * from './editAnchorRequestOneOfAllOfFileType';
export * from './editAnchorResponse';
export * from './editAnchorResponseAllOf';
+export * from './editCallRecordRequest';
+export * from './editCallRecordRequestSharePermission';
export * from './editCommentRequest';
export * from './editCommentRequestMentions';
export * from './editCommentRequestText';
diff --git a/js/app/packages/service-clients/service-storage/generated/zod.ts b/js/app/packages/service-clients/service-storage/generated/zod.ts
index 3b5048dca8..091456e950 100644
--- a/js/app/packages/service-clients/service-storage/generated/zod.ts
+++ b/js/app/packages/service-clients/service-storage/generated/zod.ts
@@ -916,6 +916,71 @@ export const deleteCallRecordParams = zod.object({
call_id: zod.string().uuid().describe('Call ID'),
});
+/**
+ * Edits a call record — currently supports updating the record's share
+permissions. Access is validated via channel membership
+ * @summary Handler for `PATCH /call/record/{call_id}`.
+ */
+export const editCallRecordParams = zod.object({
+ call_id: zod.string().uuid().describe('Call ID'),
+});
+
+export const editCallRecordBody = zod
+ .object({
+ sharePermission: zod
+ .union([
+ zod.null(),
+ zod.object({
+ channelSharePermissions: zod
+ .array(
+ zod.object({
+ accessLevel: zod
+ .union([
+ zod.null(),
+ zod
+ .enum(['view', 'comment', 'edit', 'owner'])
+ .describe(
+ 'Ordered from least to most access top -> bottom'
+ ),
+ ])
+ .optional(),
+ channelId: zod.string().describe('The channel id'),
+ operation: zod.enum(['add', 'remove', 'replace']),
+ })
+ )
+ .nullish()
+ .describe(
+ 'Any channel share permissions to be created/updated/removed'
+ ),
+ isPublic: zod
+ .boolean()
+ .nullish()
+ .describe('If the item is publicly accessible'),
+ publicAccessLevel: zod
+ .union([
+ zod.null(),
+ zod
+ .enum(['view', 'comment', 'edit', 'owner'])
+ .describe('Ordered from least to most access top -> bottom'),
+ ])
+ .optional(),
+ }),
+ ])
+ .optional(),
+ })
+ .describe('Edit call request');
+
+/**
+ * Toggles the `share_with_team` flag on the active call. Returns the new
+value as the JSON body.
+ * @summary Handler for `POST /call/record/{call_id}/share-with-team/toggle`.
+ */
+export const toggleShareWithTeamParams = zod.object({
+ call_id: zod.string().uuid().describe('Call ID'),
+});
+
+export const toggleShareWithTeamResponse = zod.boolean();
+
/**
* Gets or creates a call for the channel. If a call already exists, joins it;
otherwise creates a new one. Always returns a join token.
@@ -8199,6 +8264,7 @@ export const createProjectHandlerBody = zod.object({
name: zod.string().describe('The name of the project.'),
projectParentId: zod
.string()
+ .uuid()
.nullish()
.describe('The project that the new project will belong to.'),
});
@@ -9787,6 +9853,67 @@ export const patchViewHandlerBody = zod.object({
name: zod.string().nullish(),
});
+/**
+ * @summary Edits the share permissions of a thread.
+ */
+export const editThreadV2Params = zod.object({
+ thread_id: zod.string().describe('thread ID'),
+});
+
+export const editThreadV2Body = zod.object({
+ projectId: zod
+ .string()
+ .nullish()
+ .describe('The new project that the thread will belong to.'),
+ sharePermission: zod
+ .union([
+ zod.null(),
+ zod.object({
+ channelSharePermissions: zod
+ .array(
+ zod.object({
+ accessLevel: zod
+ .union([
+ zod.null(),
+ zod
+ .enum(['view', 'comment', 'edit', 'owner'])
+ .describe(
+ 'Ordered from least to most access top -> bottom'
+ ),
+ ])
+ .optional(),
+ channelId: zod.string().describe('The channel id'),
+ operation: zod.enum(['add', 'remove', 'replace']),
+ })
+ )
+ .nullish()
+ .describe(
+ 'Any channel share permissions to be created/updated/removed'
+ ),
+ isPublic: zod
+ .boolean()
+ .nullish()
+ .describe('If the item is publicly accessible'),
+ publicAccessLevel: zod
+ .union([
+ zod.null(),
+ zod
+ .enum(['view', 'comment', 'edit', 'owner'])
+ .describe('Ordered from least to most access top -> bottom'),
+ ])
+ .optional(),
+ }),
+ ])
+ .optional(),
+});
+
+export const editThreadV2Response = zod.object({
+ data: zod.object({
+ success: zod.boolean().describe('Indicates if the request was successful'),
+ }),
+ error: zod.boolean().describe('Indicates if an error occurred'),
+});
+
/**
* @summary Gets a UserPdfDocumentLocation entry
*/
@@ -9922,64 +10049,3 @@ export const editProjectV2Response = zod.object({
}),
error: zod.boolean().describe('Indicates if an error occurred'),
});
-
-/**
- * @summary Edits the share permissions of a thread.
- */
-export const editThreadV2Params = zod.object({
- thread_id: zod.string().describe('thread ID'),
-});
-
-export const editThreadV2Body = zod.object({
- projectId: zod
- .string()
- .nullish()
- .describe('The new project that the thread will belong to.'),
- sharePermission: zod
- .union([
- zod.null(),
- zod.object({
- channelSharePermissions: zod
- .array(
- zod.object({
- accessLevel: zod
- .union([
- zod.null(),
- zod
- .enum(['view', 'comment', 'edit', 'owner'])
- .describe(
- 'Ordered from least to most access top -> bottom'
- ),
- ])
- .optional(),
- channelId: zod.string().describe('The channel id'),
- operation: zod.enum(['add', 'remove', 'replace']),
- })
- )
- .nullish()
- .describe(
- 'Any channel share permissions to be created/updated/removed'
- ),
- isPublic: zod
- .boolean()
- .nullish()
- .describe('If the item is publicly accessible'),
- publicAccessLevel: zod
- .union([
- zod.null(),
- zod
- .enum(['view', 'comment', 'edit', 'owner'])
- .describe('Ordered from least to most access top -> bottom'),
- ])
- .optional(),
- }),
- ])
- .optional(),
-});
-
-export const editThreadV2Response = zod.object({
- data: zod.object({
- success: zod.boolean().describe('Indicates if the request was successful'),
- }),
- error: zod.boolean().describe('Indicates if an error occurred'),
-});
diff --git a/js/app/packages/service-clients/service-storage/openapi.json b/js/app/packages/service-clients/service-storage/openapi.json
index fb0277b015..27d55930a2 100644
--- a/js/app/packages/service-clients/service-storage/openapi.json
+++ b/js/app/packages/service-clients/service-storage/openapi.json
@@ -707,6 +707,131 @@
}
}
}
+ },
+ "patch": {
+ "tags": ["call::inbound::axum_router"],
+ "summary": "Handler for `PATCH /call/record/{call_id}`.",
+ "description": "Edits a call record — currently supports updating the record's share\npermissions. Access is validated via channel membership",
+ "operationId": "edit_call_record",
+ "parameters": [
+ {
+ "name": "call_id",
+ "in": "path",
+ "description": "Call ID",
+ "required": true,
+ "schema": {
+ "type": "string",
+ "format": "uuid"
+ }
+ }
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/EditCallRecordRequest"
+ }
+ }
+ },
+ "required": true
+ },
+ "responses": {
+ "204": {
+ "description": "Call record updated"
+ },
+ "401": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ },
+ "404": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ },
+ "500": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "/call/record/{call_id}/share-with-team/toggle": {
+ "post": {
+ "tags": ["call::inbound::axum_router"],
+ "summary": "Handler for `POST /call/record/{call_id}/share-with-team/toggle`.",
+ "description": "Toggles the `share_with_team` flag on the active call. Returns the new\nvalue as the JSON body.",
+ "operationId": "toggle_share_with_team",
+ "parameters": [
+ {
+ "name": "call_id",
+ "in": "path",
+ "description": "Call ID",
+ "required": true,
+ "schema": {
+ "type": "string",
+ "format": "uuid"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "New value of share_with_team after toggle",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "boolean"
+ }
+ }
+ }
+ },
+ "401": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ },
+ "404": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ },
+ "500": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ }
+ }
}
},
"/call/webhook": {
@@ -4814,6 +4939,66 @@
}
}
},
+ "/threads/{thread_id}": {
+ "patch": {
+ "tags": ["threads"],
+ "summary": "Edits the share permissions of a thread.",
+ "operationId": "edit_thread_v2",
+ "parameters": [
+ {
+ "name": "thread_id",
+ "in": "path",
+ "description": "thread ID",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ }
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/PatchThreadRequestV2"
+ }
+ }
+ },
+ "required": true
+ },
+ "responses": {
+ "200": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/SuccessResponse"
+ }
+ }
+ }
+ },
+ "401": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/GenericErrorResponse"
+ }
+ }
+ }
+ },
+ "500": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/GenericErrorResponse"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
"/user_document_view_location/{document_id}": {
"get": {
"tags": [
@@ -5094,66 +5279,6 @@
}
}
}
- },
- "/v2/threads/{thread_id}": {
- "patch": {
- "tags": ["threads"],
- "summary": "Edits the share permissions of a thread.",
- "operationId": "edit_thread_v2",
- "parameters": [
- {
- "name": "thread_id",
- "in": "path",
- "description": "thread ID",
- "required": true,
- "schema": {
- "type": "string"
- }
- }
- ],
- "requestBody": {
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/PatchThreadRequestV2"
- }
- }
- },
- "required": true
- },
- "responses": {
- "200": {
- "description": "",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/SuccessResponse"
- }
- }
- }
- },
- "401": {
- "description": "",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/GenericErrorResponse"
- }
- }
- }
- },
- "500": {
- "description": "",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/GenericErrorResponse"
- }
- }
- }
- }
- }
- }
}
},
"components": {
@@ -6686,6 +6811,7 @@
},
"projectParentId": {
"type": ["string", "null"],
+ "format": "uuid",
"description": "The project that the new project will belong to."
}
}
@@ -7397,6 +7523,23 @@
}
]
},
+ "EditCallRecordRequest": {
+ "type": "object",
+ "description": "Edit call request",
+ "properties": {
+ "sharePermission": {
+ "oneOf": [
+ {
+ "type": "null"
+ },
+ {
+ "$ref": "#/components/schemas/UpdateSharePermissionRequestV2",
+ "description": "Updated share permissions."
+ }
+ ]
+ }
+ }
+ },
"EditCommentRequest": {
"type": "object",
"required": ["threadId"],
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 046c89f76f..a93e1707f2 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -107,6 +107,7 @@ dependencies = [
"email",
"email_service_client",
"entity_access",
+ "entity_access_management",
"frecency",
"item_filters",
"lazy_static",
@@ -1465,11 +1466,9 @@ name = "backfill_entity_access"
version = "0.1.0"
dependencies = [
"anyhow",
- "futures",
"macro_entrypoint",
"macro_env_var",
"macro_uuid",
- "models_permissions",
"sqlx",
"tokio",
"tracing",
@@ -1762,6 +1761,7 @@ dependencies = [
"chrono",
"connection",
"entity_access",
+ "entity_access_db_utils",
"filter_ast",
"item_filters",
"livekit-api",
@@ -1769,6 +1769,7 @@ dependencies = [
"macro_aws_config",
"macro_db_migrator",
"macro_user_id",
+ "macro_uuid",
"mockall",
"model-entity",
"model-error-response",
@@ -1887,13 +1888,16 @@ dependencies = [
"axum",
"chrono",
"entity_access",
+ "entity_access_db_utils",
+ "entity_access_management",
"http-body-util",
"macro_db_migrator",
- "macro_share_permissions",
"macro_user_id",
"macro_uuid",
"model",
+ "model-entity",
"model_user",
+ "models_entity_access_management",
"models_permissions",
"roles_and_permissions",
"serde",
@@ -1905,6 +1909,7 @@ dependencies = [
"tracing",
"unicode-segmentation",
"utoipa",
+ "uuid",
]
[[package]]
@@ -2111,6 +2116,7 @@ dependencies = [
"connection_gateway_client",
"doppleganger",
"entity_access",
+ "entity_access_db_utils",
"frecency",
"futures",
"http-body-util",
@@ -2859,6 +2865,7 @@ dependencies = [
"aws_lambda_events",
"lambda_runtime",
"macro_entrypoint",
+ "macro_uuid",
"openssl",
"sqlx",
"tokio",
@@ -3041,6 +3048,7 @@ dependencies = [
"email",
"email_service_client",
"entity_access",
+ "entity_access_management",
"frecency",
"futures",
"http 1.3.1",
@@ -3059,7 +3067,6 @@ dependencies = [
"macro_env_var",
"macro_middleware",
"macro_project_utils",
- "macro_share_permissions",
"macro_user_id",
"macro_uuid",
"memory",
@@ -3149,6 +3156,7 @@ dependencies = [
"dynamodb_client",
"email",
"entity_access",
+ "entity_access_management",
"frecency",
"futures",
"github",
@@ -3168,7 +3176,6 @@ dependencies = [
"macro_middleware",
"macro_project_utils",
"macro_sha_count_client",
- "macro_share_permissions",
"macro_user_id",
"macro_uuid",
"mockall",
@@ -3290,6 +3297,8 @@ dependencies = [
"document_sub_type",
"dotenvy",
"entity_access",
+ "entity_access_db_utils",
+ "entity_access_management",
"futures",
"hex",
"http-body-util",
@@ -3300,6 +3309,7 @@ dependencies = [
"macro_uuid",
"mockall",
"model",
+ "model-entity",
"model-error-response",
"model_file_type",
"model_user",
@@ -3874,7 +3884,9 @@ dependencies = [
"anyhow",
"axum",
"axum-extra",
+ "cached",
"cool_asserts",
+ "macro_db_migrator",
"macro_user_id",
"mockall",
"model",
@@ -3892,16 +3904,35 @@ dependencies = [
"uuid",
]
+[[package]]
+name = "entity_access_db_utils"
+version = "0.1.0"
+dependencies = [
+ "anyhow",
+ "macro_db_migrator",
+ "macro_user_id",
+ "macro_uuid",
+ "model-entity",
+ "models_entity_access_management",
+ "models_permissions",
+ "serde",
+ "sqlx",
+ "tokio",
+ "tracing",
+]
+
[[package]]
name = "entity_access_management"
version = "0.1.0"
dependencies = [
"anyhow",
"cool_asserts",
+ "entity_access_db_utils",
"macro_db_migrator",
"macro_user_id",
"mockall",
"model-entity",
+ "models_entity_access_management",
"models_permissions",
"serde",
"serde_json",
@@ -6040,6 +6071,7 @@ dependencies = [
"cached",
"chrono",
"document_sub_type",
+ "entity_access_db_utils",
"futures",
"macro_user_id",
"macro_uuid",
@@ -6048,6 +6080,7 @@ dependencies = [
"model-entity",
"model_file_type",
"models_dcs",
+ "models_entity_access_management",
"models_opensearch",
"models_pagination",
"models_permissions",
@@ -6118,13 +6151,13 @@ dependencies = [
"axum",
"axum-extra",
"decode_jwt",
+ "entity_access_db_utils",
"http-body-util",
"ip_extractor",
"macro_auth",
"macro_db_client",
"macro_env",
"macro_env_var",
- "macro_share_permissions",
"macro_user_id",
"macro_uuid",
"model",
@@ -6193,24 +6226,6 @@ dependencies = [
"tracing",
]
-[[package]]
-name = "macro_share_permissions"
-version = "0.1.0"
-dependencies = [
- "anyhow",
- "comms_db_client",
- "macro_db_client",
- "macro_user_id",
- "model",
- "model-entity",
- "model_notifications",
- "models_permissions",
- "serde",
- "serde_json",
- "sqlx",
- "tracing",
-]
-
[[package]]
name = "macro_tower_layers"
version = "0.1.0"
@@ -6419,6 +6434,7 @@ dependencies = [
"email",
"email_service_client",
"entity_access",
+ "entity_access_management",
"frecency",
"fusionauth",
"http 1.3.1",
@@ -6474,7 +6490,17 @@ dependencies = [
"anyhow",
"axum",
"chrono",
+ "comms",
+ "document_storage_service_client",
+ "documents",
+ "email",
+ "email_service_client",
+ "entity_access",
+ "entity_access_management",
+ "frecency",
"futures",
+ "lexical_client",
+ "macro_aws_config",
"macro_db_migrator",
"macro_entrypoint",
"macro_env",
@@ -6482,9 +6508,17 @@ dependencies = [
"macro_user_id",
"macro_uuid",
"model_user",
+ "properties",
+ "readonly_pool",
+ "scribe",
+ "search_service_client",
"serde",
"serde_json",
+ "soup",
"sqlx",
+ "sqs_client",
+ "static_file_service_client",
+ "sync_service_client",
"thiserror 2.0.17",
"tokio",
"tracing",
@@ -6779,6 +6813,14 @@ dependencies = [
"uuid",
]
+[[package]]
+name = "models_entity_access_management"
+version = "0.1.0"
+dependencies = [
+ "serde",
+ "sqlx",
+]
+
[[package]]
name = "models_opensearch"
version = "0.1.0"
@@ -8282,6 +8324,7 @@ dependencies = [
"chrono",
"email_db_client",
"entity_access",
+ "entity_access_db_utils",
"futures",
"macro_db_client",
"macro_db_migrator",
@@ -9727,6 +9770,7 @@ dependencies = [
"clap",
"comms_db_client",
"email_db_client",
+ "entity_access_db_utils",
"fusionauth",
"futures",
"macro_aws_config",
@@ -9735,8 +9779,10 @@ dependencies = [
"macro_env",
"macro_env_var",
"macro_user_id",
+ "macro_uuid",
"mockall",
"model",
+ "model-entity",
"models_email",
"models_permissions",
"rand 0.9.3",
diff --git a/rust/cloud-storage/Cargo.toml b/rust/cloud-storage/Cargo.toml
index f07f353163..cd67ed8c7a 100644
--- a/rust/cloud-storage/Cargo.toml
+++ b/rust/cloud-storage/Cargo.toml
@@ -47,6 +47,7 @@ members = [
"email_utils",
"email_validator",
"entity_access",
+ "entity_access_db_utils",
"entity_access_management",
"frecency",
"fusionauth",
@@ -70,7 +71,6 @@ members = [
"macro_redis",
"macro_service_client",
"macro_sha_count_client",
- "macro_share_permissions",
"macro_uuid",
"mcp_auth_proxy",
"mcp_service",
diff --git a/rust/cloud-storage/ai_tools/Cargo.toml b/rust/cloud-storage/ai_tools/Cargo.toml
index e12626f78c..282d321f9d 100644
--- a/rust/cloud-storage/ai_tools/Cargo.toml
+++ b/rust/cloud-storage/ai_tools/Cargo.toml
@@ -28,6 +28,7 @@ documents = { path = "../documents", features = ["ai_tools"] }
email = { path = "../email", features = ["ai_schema", "ai_tools", "axum", "outbound"] }
email_service_client = { path = "../email_service_client" }
entity_access = { path = "../entity_access" }
+entity_access_management = { path = "../entity_access_management" }
frecency = { path = "../frecency", features = ["outbound", "postgres"] }
item_filters = { path = "../item_filters" }
lazy_static.workspace = true
diff --git a/rust/cloud-storage/ai_tools/src/build_context.rs b/rust/cloud-storage/ai_tools/src/build_context.rs
index c3b2c1d012..d8ce3f7215 100644
--- a/rust/cloud-storage/ai_tools/src/build_context.rs
+++ b/rust/cloud-storage/ai_tools/src/build_context.rs
@@ -213,6 +213,9 @@ pub async fn build_tool_service_context_from_env(
s3_upload_adapter,
NoOpTaskProperties,
NoOpConnectionService,
+ entity_access_management::domain::service::EntityAccessManagementServiceImpl::new(
+ entity_access_management::outbound::PgRepository::new(pool.clone()),
+ ),
);
let entity_access_service = Arc::new(EntityAccessServiceImpl::new(PgAccessRepository::new(
pool.clone(),
diff --git a/rust/cloud-storage/ai_tools/src/tool_context.rs b/rust/cloud-storage/ai_tools/src/tool_context.rs
index 46e6b04925..dad133bc5f 100644
--- a/rust/cloud-storage/ai_tools/src/tool_context.rs
+++ b/rust/cloud-storage/ai_tools/src/tool_context.rs
@@ -88,12 +88,19 @@ impl ConnectionService for NoOpConnectionService {
}
}
+/// Type alias for the entity access management service implementation used by AI tools
+pub type ToolEntityAccessManagementService =
+ entity_access_management::domain::service::EntityAccessManagementServiceImpl<
+ entity_access_management::outbound::PgRepository,
+ >;
+
/// Type alias for the document service implementation used by AI tools
pub type ToolDocumentService = documents::domain::service::DocumentServiceImpl<
documents::outbound::pg_document_repo::PgDocumentRepo,
documents::outbound::s3_upload_url::S3UploadUrlAdapter,
NoOpTaskProperties,
NoOpConnectionService,
+ ToolEntityAccessManagementService,
>;
/// Type alias for the entity access service implementation
diff --git a/rust/cloud-storage/backfill_entity_access/.sqlx/query-523fb6716f505d7b81cb8e5ad596435cc4ffabcef4743d9cb1a3a2b6423bf07e.json b/rust/cloud-storage/backfill_entity_access/.sqlx/query-523fb6716f505d7b81cb8e5ad596435cc4ffabcef4743d9cb1a3a2b6423bf07e.json
deleted file mode 100644
index d1771823eb..0000000000
--- a/rust/cloud-storage/backfill_entity_access/.sqlx/query-523fb6716f505d7b81cb8e5ad596435cc4ffabcef4743d9cb1a3a2b6423bf07e.json
+++ /dev/null
@@ -1,59 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT DISTINCT\n \"item_id\",\n \"item_type\",\n \"user_id\",\n access_level AS \"access_level: AccessLevel\",\n \"created_at\"\n FROM \"UserItemAccess\"\n WHERE \"granted_from_channel_id\" IS NULL\n AND \"granted_from_team_id\" IS NULL\n ORDER BY created_at ASC\n LIMIT $1\n OFFSET $2\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "item_id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "item_type",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "access_level: AccessLevel",
- "type_info": {
- "Custom": {
- "name": "\"AccessLevel\"",
- "kind": {
- "Enum": [
- "view",
- "comment",
- "edit",
- "owner"
- ]
- }
- }
- }
- },
- {
- "ordinal": 4,
- "name": "created_at",
- "type_info": "Timestamp"
- }
- ],
- "parameters": {
- "Left": [
- "Int8",
- "Int8"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- false
- ]
- },
- "hash": "523fb6716f505d7b81cb8e5ad596435cc4ffabcef4743d9cb1a3a2b6423bf07e"
-}
diff --git a/rust/cloud-storage/backfill_entity_access/.sqlx/query-52b5ddf40ae25392846729a85efd8880beea0876c5b3851ae431aa8618a56eef.json b/rust/cloud-storage/backfill_entity_access/.sqlx/query-52b5ddf40ae25392846729a85efd8880beea0876c5b3851ae431aa8618a56eef.json
deleted file mode 100644
index 634ff2611a..0000000000
--- a/rust/cloud-storage/backfill_entity_access/.sqlx/query-52b5ddf40ae25392846729a85efd8880beea0876c5b3851ae431aa8618a56eef.json
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE project_tree AS (\n SELECT id FROM \"Project\" WHERE id = $1\n UNION ALL\n SELECT p.id\n FROM \"Project\" p\n JOIN project_tree pt ON p.\"parentId\" = pt.id\n )\n SELECT id AS \"item_id!\", 'project' AS \"item_type!\" FROM project_tree\n\n UNION ALL\n\n SELECT d.id, 'document' FROM \"Document\" d\n WHERE d.\"projectId\" IN (SELECT id FROM project_tree)\n\n UNION ALL\n\n SELECT c.id, 'chat' FROM \"Chat\" c\n WHERE c.\"projectId\" IN (SELECT id FROM project_tree)\n\n UNION ALL\n\n SELECT et.id::text, 'thread' FROM \"email_threads\" et\n WHERE et.project_id IN (SELECT id FROM project_tree);\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "item_id!",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "item_type!",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- null,
- null
- ]
- },
- "hash": "52b5ddf40ae25392846729a85efd8880beea0876c5b3851ae431aa8618a56eef"
-}
diff --git a/rust/cloud-storage/backfill_entity_access/.sqlx/query-762b1612135674574c474aa8adf106bc49809d375f7ca448a116b43e7ebe1665.json b/rust/cloud-storage/backfill_entity_access/.sqlx/query-762b1612135674574c474aa8adf106bc49809d375f7ca448a116b43e7ebe1665.json
deleted file mode 100644
index 56dd139c3c..0000000000
--- a/rust/cloud-storage/backfill_entity_access/.sqlx/query-762b1612135674574c474aa8adf106bc49809d375f7ca448a116b43e7ebe1665.json
+++ /dev/null
@@ -1,65 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT DISTINCT\n uia.\"item_id\",\n uia.\"item_type\",\n uia.\"granted_from_channel_id\",\n uia.access_level AS \"access_level: AccessLevel\",\n uia.\"created_at\",\n p.\"userId\" as project_owner -- project owner\n FROM \"UserItemAccess\" uia\n JOIN \"Project\" p ON p.id = uia.item_id\n WHERE item_type = 'project'\n ORDER BY created_at ASC\n LIMIT $1\n OFFSET $2\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "item_id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "item_type",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "granted_from_channel_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 3,
- "name": "access_level: AccessLevel",
- "type_info": {
- "Custom": {
- "name": "\"AccessLevel\"",
- "kind": {
- "Enum": [
- "view",
- "comment",
- "edit",
- "owner"
- ]
- }
- }
- }
- },
- {
- "ordinal": 4,
- "name": "created_at",
- "type_info": "Timestamp"
- },
- {
- "ordinal": 5,
- "name": "project_owner",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Int8",
- "Int8"
- ]
- },
- "nullable": [
- false,
- false,
- true,
- false,
- false,
- false
- ]
- },
- "hash": "762b1612135674574c474aa8adf106bc49809d375f7ca448a116b43e7ebe1665"
-}
diff --git a/rust/cloud-storage/backfill_entity_access/.sqlx/query-50751cb761c99ac2efdaf29ebaa69ab0f29873c9cc7fc3957d399a1df603ba92.json b/rust/cloud-storage/backfill_entity_access/.sqlx/query-ba49dfcd0a3ab834f9e61f27a0a80174e549103ee63f03d30fe76857c8803b6a.json
similarity index 57%
rename from rust/cloud-storage/backfill_entity_access/.sqlx/query-50751cb761c99ac2efdaf29ebaa69ab0f29873c9cc7fc3957d399a1df603ba92.json
rename to rust/cloud-storage/backfill_entity_access/.sqlx/query-ba49dfcd0a3ab834f9e61f27a0a80174e549103ee63f03d30fe76857c8803b6a.json
index 4ad67dd157..6dd63ef404 100644
--- a/rust/cloud-storage/backfill_entity_access/.sqlx/query-50751cb761c99ac2efdaf29ebaa69ab0f29873c9cc7fc3957d399a1df603ba92.json
+++ b/rust/cloud-storage/backfill_entity_access/.sqlx/query-ba49dfcd0a3ab834f9e61f27a0a80174e549103ee63f03d30fe76857c8803b6a.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE ProjectHierarchy AS (\n -- Find direct user access to projects first as starting point\n SELECT\n p.id,\n uia.access_level\n FROM \"Project\" p\n JOIN \"UserItemAccess\" uia ON p.id = uia.item_id AND uia.item_type = 'project'\n WHERE uia.user_id = $1 AND p.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Then walk down the project tree and grab child projects, keeping parent's access\n SELECT\n p.id,\n ph.access_level\n FROM \"Project\" p\n JOIN ProjectHierarchy ph ON p.\"parentId\" = ph.id\n WHERE p.\"deletedAt\" IS NULL\n ),\n -- Now build up all the ways a user can have access to stuff\n AllAccessGrants AS (\n -- Explicit access to items via UserItemAccess table\n SELECT uia.item_id, uia.item_type, uia.access_level\n FROM \"UserItemAccess\" uia\n -- We join to each table to check its \"deletedAt\" status.\n -- This is more explicit and robust than using subqueries.\n LEFT JOIN \"Document\" d ON uia.item_type = 'document' AND uia.item_id = d.id\n LEFT JOIN \"Chat\" c ON uia.item_type = 'chat' AND uia.item_id = c.id\n LEFT JOIN \"Project\" p ON uia.item_type = 'project' AND uia.item_id = p.id\n WHERE uia.user_id = $1\n -- Rule: The item must not be deleted.\n AND (\n (uia.item_type = 'document' AND d.\"deletedAt\" IS NULL) OR\n (uia.item_type = 'chat' AND c.\"deletedAt\" IS NULL) OR\n (uia.item_type = 'project' AND p.\"deletedAt\" IS NULL)\n )\n \n -- The rest of the unions are to get implicit access to items via project access\n UNION ALL\n\n -- Access to docs in visible projects \n SELECT\n d.id AS item_id,\n 'document' AS item_type,\n ph.access_level\n FROM \"Document\" d\n JOIN ProjectHierarchy ph ON d.\"projectId\" = ph.id\n WHERE d.\"projectId\" IS NOT NULL AND d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Access to chats in visible projects\n SELECT\n c.id AS item_id,\n 'chat' AS item_type,\n ph.access_level\n FROM \"Chat\" c\n JOIN ProjectHierarchy ph ON c.\"projectId\" = ph.id\n WHERE c.\"projectId\" IS NOT NULL AND c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Include the projects we found earlier\n SELECT\n ph.id AS item_id,\n 'project' AS item_type,\n ph.access_level\n FROM ProjectHierarchy ph\n ),\n UserAccessibleItems AS (\n SELECT\n item_id,\n item_type\n FROM AllAccessGrants\n GROUP BY item_id, item_type\n )\n SELECT item_id as \"item_id!\", item_type as \"item_type!\" FROM UserAccessibleItems\n ",
+ "query": "\n WITH RECURSIVE ProjectHierarchy AS (\n -- Find direct user access to projects first as starting point\n SELECT\n p.id,\n uia.access_level\n FROM \"Project\" p\n JOIN \"UserItemAccess\" uia ON p.id = uia.item_id AND uia.item_type = 'project'\n WHERE uia.user_id = $1 AND p.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Then walk down the project tree and grab child projects, keeping parent's access\n SELECT\n p.id,\n ph.access_level\n FROM \"Project\" p\n JOIN ProjectHierarchy ph ON p.\"parentId\" = ph.id\n WHERE p.\"deletedAt\" IS NULL\n ),\n -- Now build up all the ways a user can have access to stuff\n AllAccessGrants AS (\n -- Explicit access to items via UserItemAccess table\n SELECT uia.item_id, uia.item_type, uia.access_level\n FROM \"UserItemAccess\" uia\n -- We join to each table to check its \"deletedAt\" status.\n -- This is more explicit and robust than using subqueries.\n LEFT JOIN \"Document\" d ON uia.item_type = 'document' AND uia.item_id = d.id\n LEFT JOIN \"Chat\" c ON uia.item_type = 'chat' AND uia.item_id = c.id\n LEFT JOIN \"Project\" p ON uia.item_type = 'project' AND uia.item_id = p.id\n WHERE uia.user_id = $1\n -- Rule: The item must not be deleted.\n AND (\n (uia.item_type = 'document' AND d.\"deletedAt\" IS NULL) OR\n (uia.item_type = 'chat' AND c.\"deletedAt\" IS NULL) OR\n (uia.item_type = 'project' AND p.\"deletedAt\" IS NULL)\n )\n\n -- The rest of the unions are to get implicit access to items via project access\n UNION ALL\n\n -- Access to docs in visible projects\n SELECT\n d.id AS item_id,\n 'document' AS item_type,\n ph.access_level\n FROM \"Document\" d\n JOIN ProjectHierarchy ph ON d.\"projectId\" = ph.id\n WHERE d.\"projectId\" IS NOT NULL AND d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Access to chats in visible projects\n SELECT\n c.id AS item_id,\n 'chat' AS item_type,\n ph.access_level\n FROM \"Chat\" c\n JOIN ProjectHierarchy ph ON c.\"projectId\" = ph.id\n WHERE c.\"projectId\" IS NOT NULL AND c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Include the projects we found earlier\n SELECT\n ph.id AS item_id,\n 'project' AS item_type,\n ph.access_level\n FROM ProjectHierarchy ph\n ),\n UserAccessibleItems AS (\n SELECT\n item_id,\n item_type\n FROM AllAccessGrants\n GROUP BY item_id, item_type\n )\n SELECT item_id as \"item_id!\", item_type as \"item_type!\" FROM UserAccessibleItems\n ",
"describe": {
"columns": [
{
@@ -24,5 +24,5 @@
null
]
},
- "hash": "50751cb761c99ac2efdaf29ebaa69ab0f29873c9cc7fc3957d399a1df603ba92"
+ "hash": "ba49dfcd0a3ab834f9e61f27a0a80174e549103ee63f03d30fe76857c8803b6a"
}
diff --git a/rust/cloud-storage/backfill_entity_access/.sqlx/query-fe80007460f1c5d362aa34f40768096f11cf1b330568742d312a0ab1faeee4b4.json b/rust/cloud-storage/backfill_entity_access/.sqlx/query-fe80007460f1c5d362aa34f40768096f11cf1b330568742d312a0ab1faeee4b4.json
deleted file mode 100644
index 855ffff729..0000000000
--- a/rust/cloud-storage/backfill_entity_access/.sqlx/query-fe80007460f1c5d362aa34f40768096f11cf1b330568742d312a0ab1faeee4b4.json
+++ /dev/null
@@ -1,71 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT DISTINCT\n \"item_id\",\n \"item_type\",\n \"user_id\",\n \"granted_from_channel_id\",\n \"granted_from_team_id\",\n access_level AS \"access_level: AccessLevel\",\n \"created_at\"\n FROM \"UserItemAccess\"\n WHERE \"item_type\" != 'project'\n AND (\"granted_from_channel_id\" IS NOT NULL OR \"granted_from_team_id\" IS NOT NULL)\n ORDER BY created_at ASC\n LIMIT $1\n OFFSET $2\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "item_id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "item_type",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "granted_from_channel_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 4,
- "name": "granted_from_team_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 5,
- "name": "access_level: AccessLevel",
- "type_info": {
- "Custom": {
- "name": "\"AccessLevel\"",
- "kind": {
- "Enum": [
- "view",
- "comment",
- "edit",
- "owner"
- ]
- }
- }
- }
- },
- {
- "ordinal": 6,
- "name": "created_at",
- "type_info": "Timestamp"
- }
- ],
- "parameters": {
- "Left": [
- "Int8",
- "Int8"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- true,
- true,
- false,
- false
- ]
- },
- "hash": "fe80007460f1c5d362aa34f40768096f11cf1b330568742d312a0ab1faeee4b4"
-}
diff --git a/rust/cloud-storage/backfill_entity_access/Cargo.toml b/rust/cloud-storage/backfill_entity_access/Cargo.toml
index 02139a4fb0..4dc53581bf 100644
--- a/rust/cloud-storage/backfill_entity_access/Cargo.toml
+++ b/rust/cloud-storage/backfill_entity_access/Cargo.toml
@@ -6,11 +6,9 @@ version = "0.1.0"
[dependencies]
anyhow = { workspace = true }
-futures = { workspace = true }
macro_entrypoint = { path = "../macro_entrypoint" }
macro_env_var = { path = "../macro_env_var" }
macro_uuid = { path = "../macro_uuid" }
-models_permissions = { path = "../models_permissions" }
sqlx = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
diff --git a/rust/cloud-storage/backfill_entity_access/src/main.rs b/rust/cloud-storage/backfill_entity_access/src/main.rs
index 956b6b1f2b..3c38ad1004 100644
--- a/rust/cloud-storage/backfill_entity_access/src/main.rs
+++ b/rust/cloud-storage/backfill_entity_access/src/main.rs
@@ -2,31 +2,22 @@
mod config;
-use std::sync::atomic::{AtomicUsize, Ordering};
-
use anyhow::Context;
use config::EnvVars;
-use futures::stream::{self, StreamExt};
use macro_entrypoint::MacroEntrypoint;
-use models_permissions::share_permission::access_level::AccessLevel;
-use sqlx::QueryBuilder;
+use macro_uuid::Uuid;
use sqlx::postgres::PgPoolOptions;
use sqlx::{Pool, Postgres};
-/// Max rows per INSERT statement to stay well within Postgres bind parameter limits.
-const WRITE_BATCH_SIZE: usize = 1000;
-
-/// Max concurrent write tasks.
-const WRITE_CONCURRENCY: usize = 10;
+/// Rows of `UserItemAccess` consumed per SQL statement for the 1:1 phases
+/// (owned items, channel/team shares on non-project items). Each batch is a
+/// single `INSERT ... SELECT` in its own autocommit transaction, so lock
+/// windows and WAL size stay bounded.
+const BATCH_SIZE: i64 = 5_000;
-#[derive(Debug, Clone, Copy, sqlx::Type)]
-#[sqlx(type_name = "\"entity_access_source_type\"", rename_all = "lowercase")]
-/// Ordered from least to most access top -> bottom
-pub enum SourceEntityType {
- Channel,
- Team,
- User,
-}
+/// Smaller batch for the project phase, because each `UserItemAccess` row
+/// fans out to every descendant of the shared project tree.
+const PROJECT_BATCH_SIZE: i64 = 500;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
@@ -40,7 +31,7 @@ async fn main() -> anyhow::Result<()> {
let db = PgPoolOptions::new()
.min_connections(1)
- .max_connections(50)
+ .max_connections(4)
.connect(&env_vars.database_url)
.await
.context("could not connect to db")?;
@@ -49,7 +40,7 @@ async fn main() -> anyhow::Result<()> {
"backfill" => {
println!("Starting backfill...");
- backfill_non_projects_channels_and_teams(&db).await?;
+ backfill_non_project_channels_and_teams(&db).await?;
backfill_owned_items(&db).await?;
backfill_project_items(&db).await?;
@@ -70,330 +61,283 @@ async fn main() -> anyhow::Result<()> {
Ok(())
}
-/// Inserts rows into `entity_access` in chunks, running up to [`WRITE_CONCURRENCY`] inserts concurrently.
-async fn bulk_upsert(
+/// Drives a keyset-paginated loop. `sql` must bind `$1 = cursor uuid` and
+/// `$2 = batch_size bigint`, and must return exactly one row
+/// `(Option<Uuid>, i64)` — the maximum `UserItemAccess.id` processed in this
+/// batch (NULL when empty = termination), and the number of source rows
+/// considered in the batch.
+async fn run_keyset(
db: &Pool<Postgres>,
label: &str,
- inserts: Vec<(
- macro_uuid::Uuid,
- String,
- String,
- SourceEntityType,
- AccessLevel,
- )>,
+ sql: &str,
+ batch_size: i64,
) -> anyhow::Result<()> {
- if inserts.is_empty() {
- return Ok(());
+ let start = std::time::Instant::now();
+ let mut cursor: Uuid = Uuid::nil();
+ let mut batches: u64 = 0;
+ let mut total_rows: i64 = 0;
+ loop {
+ let (next_cursor, batch_rows): (Option<Uuid>, i64) = sqlx::query_as(sql)
+ .bind(cursor)
+ .bind(batch_size)
+ .fetch_one(db)
+ .await
+ .with_context(|| format!("[{label}] batch {batches} failed at cursor={cursor}"))?;
+
+ match next_cursor {
+ Some(max_id) => {
+ batches += 1;
+ total_rows += batch_rows;
+ cursor = max_id;
+ if batches.is_multiple_of(50) {
+ println!(
+ "[{label}] {batches} batches, {total_rows} rows, cursor={cursor}, elapsed={:?}",
+ start.elapsed()
+ );
+ }
+ }
+ None => {
+ println!(
+ "[{label}] DONE: {batches} batches, {total_rows} source rows in {:?}",
+ start.elapsed()
+ );
+ return Ok(());
+ }
+ }
}
-
- let total = inserts.len();
- let chunks: Vec<_> = inserts
- .chunks(WRITE_BATCH_SIZE)
- .map(|c| c.to_vec())
- .collect();
- let num_chunks = chunks.len();
- println!("[{label}] writing {total} rows in {num_chunks} chunks");
-
- stream::iter(chunks)
- .map(|chunk| async move {
- let mut qb: QueryBuilder<Postgres> = QueryBuilder::new(
- r#"INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level) "#,
- );
-
- qb.push_values(&chunk, |mut b, row| {
- b.push_bind(row.0)
- .push_bind(&row.1)
- .push_bind(&row.2)
- .push_bind(row.3)
- .push_bind(row.4);
- });
-
- qb.push(" ON CONFLICT DO NOTHING");
- qb.build().execute(db).await?;
-
- Ok::<_, anyhow::Error>(())
- })
- .buffer_unordered(WRITE_CONCURRENCY)
- .collect::<Vec<_>>()
- .await
- .into_iter()
- .collect::<Result<Vec<_>, _>>()?;
-
- println!("[{label}] write complete ({total} rows)");
-
- Ok(())
}
+/// Phase 1: user-owned items — direct grants with `source_type = 'user'`
+/// and `granted_from_project_id IS NULL`.
async fn backfill_owned_items(db: &Pool<Postgres>) -> anyhow::Result<()> {
- let limit = 10000_i64;
- let mut offset = 0_i64;
-
println!("[owned_items] STARTING");
-
- loop {
- println!("[owned_items] BATCH offset={offset}");
-
- let batch = sqlx::query!(
- r#"
- SELECT DISTINCT
- "item_id",
- "item_type",
- "user_id",
- access_level AS "access_level: AccessLevel",
- "created_at"
- FROM "UserItemAccess"
- WHERE "granted_from_channel_id" IS NULL
- AND "granted_from_team_id" IS NULL
- ORDER BY created_at ASC
- LIMIT $1
- OFFSET $2
- "#,
- limit,
- offset
+ run_keyset(
+ db,
+ "owned_items",
+ r#"
+ WITH batch AS (
+ SELECT uia.id, uia.item_id, uia.item_type, uia.user_id, uia.access_level
+ FROM "UserItemAccess" uia
+ WHERE uia.id > $1
+ AND uia.granted_from_channel_id IS NULL
+ AND uia.granted_from_team_id IS NULL
+ ORDER BY uia.id
+ LIMIT $2
+ ),
+ ins AS (
+ INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)
+ SELECT DISTINCT ON (entity_id, entity_type, source_id, source_type)
+ b.item_id::uuid AS entity_id,
+ CASE WHEN b.item_type = 'thread' THEN 'email_thread' ELSE b.item_type END AS entity_type,
+ b.user_id AS source_id,
+ 'user'::entity_access_source_type AS source_type,
+ b.access_level
+ FROM batch b
+ ORDER BY entity_id, entity_type, source_id, source_type, b.access_level DESC
+ ON CONFLICT (entity_id, entity_type, source_id, source_type)
+ WHERE granted_from_project_id IS NULL
+ DO NOTHING
+ RETURNING 1
)
- .fetch_all(db)
- .await?;
-
- if batch.is_empty() {
- break;
- }
-
- println!("[owned_items] read {} rows", batch.len());
-
- let inserts: Vec<_> = batch
- .iter()
- .map(|item| {
- let item_type = if item.item_type.eq("thread") {
- "email_thread".to_string()
- } else {
- item.item_type.to_string()
- };
- (
- item.item_id.parse::<macro_uuid::Uuid>().unwrap(),
- item_type,
- item.user_id.to_string(),
- SourceEntityType::User,
- item.access_level,
- )
- })
- .collect();
-
- bulk_upsert(db, "owned_items", inserts).await?;
-
- offset += limit;
- }
-
+ SELECT
+ (SELECT id FROM batch ORDER BY id DESC LIMIT 1),
+ (SELECT COUNT(*)::bigint FROM batch)
+ "#,
+ BATCH_SIZE,
+ )
+ .await?;
println!("[owned_items] COMPLETED");
-
Ok(())
}
-/// Handles backfilling non-project items for channels and teams
-async fn backfill_non_projects_channels_and_teams(db: &Pool<Postgres>) -> anyhow::Result<()> {
- let limit = 10000_i64;
- let mut offset = 0_i64;
-
+/// Phase 2: non-project items shared via a channel or a team — direct grants
+/// with `source_type = 'channel'` or `'team'` and
+/// `granted_from_project_id IS NULL`.
+async fn backfill_non_project_channels_and_teams(db: &Pool<Postgres>) -> anyhow::Result<()> {
println!("[channels_and_teams] STARTING");
- loop {
- println!("[channels_and_teams] BATCH offset={offset}");
-
- let batch = sqlx::query!(
- r#"
- SELECT DISTINCT
- "item_id",
- "item_type",
- "user_id",
- "granted_from_channel_id",
- "granted_from_team_id",
- access_level AS "access_level: AccessLevel",
- "created_at"
- FROM "UserItemAccess"
- WHERE "item_type" != 'project'
- AND ("granted_from_channel_id" IS NOT NULL OR "granted_from_team_id" IS NOT NULL)
- ORDER BY created_at ASC
- LIMIT $1
- OFFSET $2
- "#,
- limit,
- offset
+ run_keyset(
+ db,
+ "channels_and_teams:channels",
+ r#"
+ WITH batch AS (
+ SELECT uia.id, uia.item_id, uia.item_type, uia.granted_from_channel_id, uia.access_level
+ FROM "UserItemAccess" uia
+ WHERE uia.id > $1
+ AND uia.item_type <> 'project'
+ AND uia.granted_from_channel_id IS NOT NULL
+ ORDER BY uia.id
+ LIMIT $2
+ ),
+ ins AS (
+ INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)
+ SELECT DISTINCT ON (entity_id, entity_type, source_id, source_type)
+ b.item_id::uuid AS entity_id,
+ CASE WHEN b.item_type = 'thread' THEN 'email_thread' ELSE b.item_type END AS entity_type,
+ b.granted_from_channel_id::text AS source_id,
+ 'channel'::entity_access_source_type AS source_type,
+ b.access_level
+ FROM batch b
+ ORDER BY entity_id, entity_type, source_id, source_type, b.access_level DESC
+ ON CONFLICT (entity_id, entity_type, source_id, source_type)
+ WHERE granted_from_project_id IS NULL
+ DO NOTHING
+ RETURNING 1
)
- .fetch_all(db)
- .await?;
-
- if batch.is_empty() {
- break;
- }
-
- println!("[channels_and_teams] read {} rows", batch.len());
-
- let mut inserts = Vec::new();
-
- for item in &batch {
- let item_type = if item.item_type.eq("thread") {
- "email_thread".to_string()
- } else {
- item.item_type.to_string()
- };
- if let Some(channel_id) = &item.granted_from_channel_id {
- inserts.push((
- item.item_id.parse::<macro_uuid::Uuid>().unwrap(),
- item_type.clone(),
- channel_id.to_string(),
- SourceEntityType::Channel,
- item.access_level,
- ));
- }
- if let Some(team_id) = &item.granted_from_team_id {
- inserts.push((
- item.item_id.parse::<macro_uuid::Uuid>().unwrap(),
- item_type.clone(),
- team_id.to_string(),
- SourceEntityType::Team,
- item.access_level,
- ));
- }
- }
-
- bulk_upsert(db, "channels_and_teams", inserts).await?;
+ SELECT
+ (SELECT id FROM batch ORDER BY id DESC LIMIT 1),
+ (SELECT COUNT(*)::bigint FROM batch)
+ "#,
+ BATCH_SIZE,
+ )
+ .await?;
- offset += limit;
- }
+ run_keyset(
+ db,
+ "channels_and_teams:teams",
+ r#"
+ WITH batch AS (
+ SELECT uia.id, uia.item_id, uia.item_type, uia.granted_from_team_id, uia.access_level
+ FROM "UserItemAccess" uia
+ WHERE uia.id > $1
+ AND uia.item_type <> 'project'
+ AND uia.granted_from_team_id IS NOT NULL
+ ORDER BY uia.id
+ LIMIT $2
+ ),
+ ins AS (
+ INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)
+ SELECT DISTINCT ON (entity_id, entity_type, source_id, source_type)
+ b.item_id::uuid AS entity_id,
+ CASE WHEN b.item_type = 'thread' THEN 'email_thread' ELSE b.item_type END AS entity_type,
+ b.granted_from_team_id::text AS source_id,
+ 'team'::entity_access_source_type AS source_type,
+ b.access_level
+ FROM batch b
+ ORDER BY entity_id, entity_type, source_id, source_type, b.access_level DESC
+ ON CONFLICT (entity_id, entity_type, source_id, source_type)
+ WHERE granted_from_project_id IS NULL
+ DO NOTHING
+ RETURNING 1
+ )
+ SELECT
+ (SELECT id FROM batch ORDER BY id DESC LIMIT 1),
+ (SELECT COUNT(*)::bigint FROM batch)
+ "#,
+ BATCH_SIZE,
+ )
+ .await?;
println!("[channels_and_teams] COMPLETED");
-
Ok(())
}
-/// Backfills project shares
+/// Phase 3: project shares — direct grant on the shared project itself, plus
+/// inherited grants on every descendant (child projects, docs, chats, email
+/// threads) keyed to the shared project via `granted_from_project_id`.
+/// Mirrors `entity_access_db_utils::update_entity_access_channel_share_permissions`.
+///
+/// Team-shared projects are intentionally skipped: the product does not
+/// support sharing a project directly with a team.
+///
+/// Both direct and inherited inserts happen in one statement per batch via
+/// two data-modifying CTEs; they target different partial unique indexes, so
+/// they do not compete for locks.
async fn backfill_project_items(db: &Pool<Postgres>) -> anyhow::Result<()> {
- let limit = 500_i64;
- let mut offset = 0_i64;
-
println!("[project_items] STARTING");
-
- loop {
- println!("[project_items] BATCH offset={offset}");
-
- let project_batch = sqlx::query!(
- r#"
- SELECT DISTINCT
- uia."item_id",
- uia."item_type",
- uia."granted_from_channel_id",
- uia.access_level AS "access_level: AccessLevel",
- uia."created_at",
- p."userId" as project_owner -- project owner
+ run_keyset(
+ db,
+ "project_items",
+ r#"
+ WITH RECURSIVE batch AS (
+ SELECT uia.id, uia.item_id, uia.granted_from_channel_id, uia.access_level
FROM "UserItemAccess" uia
- JOIN "Project" p ON p.id = uia.item_id
- WHERE item_type = 'project'
- ORDER BY created_at ASC
- LIMIT $1
- OFFSET $2
- "#,
- limit,
- offset
- )
- .fetch_all(db)
- .await?;
-
- if project_batch.is_empty() {
- break;
- }
-
- let batch_size = project_batch.len();
- println!("[project_items] read {batch_size} projects");
-
- let processed = AtomicUsize::new(0);
-
- // Process projects concurrently
- stream::iter(project_batch)
- .map(|project| {
- let processed = &processed;
- async move {
- let item_ids = sqlx::query!(
- r#"
- WITH RECURSIVE project_tree AS (
- SELECT id FROM "Project" WHERE id = $1
- UNION ALL
- SELECT p.id
- FROM "Project" p
- JOIN project_tree pt ON p."parentId" = pt.id
- )
- SELECT id AS "item_id!", 'project' AS "item_type!" FROM project_tree
-
- UNION ALL
-
- SELECT d.id, 'document' FROM "Document" d
- WHERE d."projectId" IN (SELECT id FROM project_tree)
-
- UNION ALL
-
- SELECT c.id, 'chat' FROM "Chat" c
- WHERE c."projectId" IN (SELECT id FROM project_tree)
-
- UNION ALL
-
- SELECT et.id::text, 'thread' FROM "email_threads" et
- WHERE et.project_id IN (SELECT id FROM project_tree);
- "#,
- project.item_id
- )
- .fetch_all(db)
- .await?;
-
- let (source_id, source_entity_type) =
- if let Some(granted_from_channel_id) = project.granted_from_channel_id {
- (
- granted_from_channel_id.to_string(),
- SourceEntityType::Channel,
- )
- } else {
- (project.project_owner, SourceEntityType::User)
- };
-
- let inserts: Vec<_> = item_ids
- .iter()
- .map(|item| {
- let item_type = if item.item_type.eq("thread") {
- "email_thread".to_string()
- } else {
- item.item_type.to_string()
- };
- (
- item.item_id.parse::<macro_uuid::Uuid>().unwrap(),
- item_type,
- source_id.clone(),
- source_entity_type,
- project.access_level,
- )
- })
- .collect();
-
- let sub_items = inserts.len();
- bulk_upsert(db, "project_items", inserts).await?;
-
- let done = processed.fetch_add(1, Ordering::Relaxed) + 1;
- println!(
- "[project_items] processed {done}/{batch_size} projects \
- (project {} had {sub_items} sub-items)",
- project.item_id
- );
+ WHERE uia.id > $1
+ AND uia.item_type = 'project'
+ AND uia.granted_from_team_id IS NULL
+ ORDER BY uia.id
+ LIMIT $2
+ ),
+ share_sources AS (
+ SELECT DISTINCT ON (project_id, source_id, source_type)
+ b.item_id AS project_id,
+ COALESCE(b.granted_from_channel_id::text, p."userId") AS source_id,
+ CASE WHEN b.granted_from_channel_id IS NOT NULL
+ THEN 'channel' ELSE 'user' END::entity_access_source_type AS source_type,
+ b.access_level
+ FROM batch b
+ JOIN "Project" p ON p.id = b.item_id
+ ORDER BY project_id, source_id, source_type, b.access_level DESC
+ ),
+ direct_ins AS (
+ INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)
+ SELECT DISTINCT ON (entity_id, source_id, source_type)
+ ss.project_id::uuid AS entity_id,
+ 'project' AS entity_type,
+ ss.source_id,
+ ss.source_type,
+ ss.access_level
+ FROM share_sources ss
+ ORDER BY entity_id, source_id, source_type, ss.access_level DESC
+ ON CONFLICT (entity_id, entity_type, source_id, source_type)
+ WHERE granted_from_project_id IS NULL
+ DO NOTHING
+ RETURNING 1
+ ),
+ descendant_projects AS (
+ SELECT ss.project_id AS root_project_id, ss.project_id AS id
+ FROM share_sources ss
+ UNION ALL
+ SELECT dp.root_project_id, p.id
+ FROM "Project" p
+ JOIN descendant_projects dp ON p."parentId" = dp.id
+ ),
+ descendants AS (
+ SELECT dp.root_project_id, dp.id::uuid AS entity_id, 'project' AS entity_type
+ FROM descendant_projects dp
+ WHERE dp.id <> dp.root_project_id
- Ok::<_, anyhow::Error>(())
- }
- })
- .buffer_unordered(WRITE_CONCURRENCY)
- .collect::<Vec<_>>()
- .await
- .into_iter()
- .collect::<Result<Vec<_>, _>>()?;
+ UNION ALL
+ SELECT dp.root_project_id, d.id::uuid, 'document'
+ FROM "Document" d
+ JOIN descendant_projects dp ON d."projectId" = dp.id
- offset += limit;
- }
+ UNION ALL
+ SELECT dp.root_project_id, c.id::uuid, 'chat'
+ FROM "Chat" c
+ JOIN descendant_projects dp ON c."projectId" = dp.id
+ UNION ALL
+ SELECT dp.root_project_id, et.id::uuid, 'email_thread'
+ FROM email_threads et
+ JOIN descendant_projects dp ON et.project_id = dp.id
+ ),
+ inherited_ins AS (
+ INSERT INTO entity_access
+ (entity_id, entity_type, source_id, source_type, access_level, granted_from_project_id)
+ SELECT DISTINCT ON (entity_id, entity_type, source_id, source_type, granted_from_project_id)
+ d.entity_id,
+ d.entity_type,
+ ss.source_id,
+ ss.source_type,
+ ss.access_level,
+ d.root_project_id AS granted_from_project_id
+ FROM descendants d
+ JOIN share_sources ss ON ss.project_id = d.root_project_id
+ ORDER BY entity_id, entity_type, source_id, source_type, granted_from_project_id, ss.access_level DESC
+ ON CONFLICT (entity_id, entity_type, source_id, source_type, granted_from_project_id)
+ WHERE granted_from_project_id IS NOT NULL
+ DO NOTHING
+ RETURNING 1
+ )
+ SELECT
+ (SELECT id FROM batch ORDER BY id DESC LIMIT 1),
+ (SELECT COUNT(*)::bigint FROM batch)
+ "#,
+ PROJECT_BATCH_SIZE,
+ )
+ .await?;
println!("[project_items] COMPLETED");
-
Ok(())
}
@@ -442,11 +386,11 @@ pub async fn get_legacy_user_items(
(uia.item_type = 'chat' AND c."deletedAt" IS NULL) OR
(uia.item_type = 'project' AND p."deletedAt" IS NULL)
)
-
+
-- The rest of the unions are to get implicit access to items via project access
UNION ALL
- -- Access to docs in visible projects
+ -- Access to docs in visible projects
SELECT
d.id AS item_id,
'document' AS item_type,
diff --git a/rust/cloud-storage/call/.sqlx/query-34a70ab661c087eb2c6b97d57099ac2c7ff263b9340003c319475fcafdf0356b.json b/rust/cloud-storage/call/.sqlx/query-34a70ab661c087eb2c6b97d57099ac2c7ff263b9340003c319475fcafdf0356b.json
new file mode 100644
index 0000000000..c92d9c45fc
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-34a70ab661c087eb2c6b97d57099ac2c7ff263b9340003c319475fcafdf0356b.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "34a70ab661c087eb2c6b97d57099ac2c7ff263b9340003c319475fcafdf0356b"
+}
diff --git a/rust/cloud-storage/call/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json b/rust/cloud-storage/call/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json
new file mode 100644
index 0000000000..b75a3a2ff5
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json
@@ -0,0 +1,41 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)\n VALUES ($1, $2, $3, $4, $5)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text",
+ {
+ "Custom": {
+ "name": "entity_access_source_type",
+ "kind": {
+ "Enum": [
+ "channel",
+ "team",
+ "user"
+ ]
+ }
+ }
+ },
+ {
+ "Custom": {
+ "name": "\"AccessLevel\"",
+ "kind": {
+ "Enum": [
+ "view",
+ "comment",
+ "edit",
+ "owner"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132"
+}
diff --git a/rust/cloud-storage/call/.sqlx/query-46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237.json b/rust/cloud-storage/call/.sqlx/query-46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237.json
new file mode 100644
index 0000000000..c91a76ff52
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2\n AND source_id = ANY($3) AND source_type = 'channel'\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237"
+}
diff --git a/rust/cloud-storage/call/.sqlx/query-5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b.json b/rust/cloud-storage/call/.sqlx/query-5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b.json
new file mode 100644
index 0000000000..ac050656e7
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b.json
@@ -0,0 +1,29 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)\n SELECT $1, $2, u.user_id, 'user', $3\n FROM UNNEST($4::text[]) as u(user_id)\n ON CONFLICT (entity_id, entity_type, source_id, source_type)\n WHERE granted_from_project_id IS NULL\n AND access_level != 'owner' -- this prevents us from overriding the owner user\n DO UPDATE SET access_level = EXCLUDED.access_level, updated_at = NOW()\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ {
+ "Custom": {
+ "name": "\"AccessLevel\"",
+ "kind": {
+ "Enum": [
+ "view",
+ "comment",
+ "edit",
+ "owner"
+ ]
+ }
+ }
+ },
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b"
+}
diff --git a/rust/cloud-storage/call/.sqlx/query-7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029.json b/rust/cloud-storage/call/.sqlx/query-7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029.json
new file mode 100644
index 0000000000..b7e5230b4c
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM entity_access\n WHERE (source_id = ANY($1) AND source_type = 'channel')\n AND (entity_id = ANY($2) OR granted_from_project_id = ANY($3))\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "UuidArray",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029"
+}
diff --git a/rust/cloud-storage/call/.sqlx/query-b08f21bc79644b7ae980ef17ea38f60be7749e48143ad40a164b236e977157f3.json b/rust/cloud-storage/call/.sqlx/query-b08f21bc79644b7ae980ef17ea38f60be7749e48143ad40a164b236e977157f3.json
new file mode 100644
index 0000000000..4327d95754
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-b08f21bc79644b7ae980ef17ea38f60be7749e48143ad40a164b236e977157f3.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"ChannelSharePermission\" (\"share_permission_id\", \"channel_id\", \"access_level\")\n SELECT $1, channel_id, access_level::\"AccessLevel\"\n FROM UNNEST($2::text[], $3::text[]) AS t(channel_id, access_level)\n ON CONFLICT (\"share_permission_id\", \"channel_id\")\n DO UPDATE SET \"access_level\" = EXCLUDED.\"access_level\"\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "b08f21bc79644b7ae980ef17ea38f60be7749e48143ad40a164b236e977157f3"
+}
diff --git a/rust/cloud-storage/call/.sqlx/query-b46b2b51f07ec4fc65cd158b210ce262e9ab44f10825969072c01a8fe3022a23.json b/rust/cloud-storage/call/.sqlx/query-b46b2b51f07ec4fc65cd158b210ce262e9ab44f10825969072c01a8fe3022a23.json
new file mode 100644
index 0000000000..93348ea121
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-b46b2b51f07ec4fc65cd158b210ce262e9ab44f10825969072c01a8fe3022a23.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"ChannelSharePermission\"\n WHERE \"share_permission_id\" = $1\n AND \"channel_id\" = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "b46b2b51f07ec4fc65cd158b210ce262e9ab44f10825969072c01a8fe3022a23"
+}
diff --git a/rust/cloud-storage/call/.sqlx/query-eb38775373a5ee3fdb942593936a3231b9303a5cc2fd2198b3ac132cae45024a.json b/rust/cloud-storage/call/.sqlx/query-b514f8481c5d7b865fd3265fd927a9bb5855eb01eb33f90137e7685573b3be8e.json
similarity index 79%
rename from rust/cloud-storage/call/.sqlx/query-eb38775373a5ee3fdb942593936a3231b9303a5cc2fd2198b3ac132cae45024a.json
rename to rust/cloud-storage/call/.sqlx/query-b514f8481c5d7b865fd3265fd927a9bb5855eb01eb33f90137e7685573b3be8e.json
index 20c138ce78..b847a27cd8 100644
--- a/rust/cloud-storage/call/.sqlx/query-eb38775373a5ee3fdb942593936a3231b9303a5cc2fd2198b3ac132cae45024a.json
+++ b/rust/cloud-storage/call/.sqlx/query-b514f8481c5d7b865fd3265fd927a9bb5855eb01eb33f90137e7685573b3be8e.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT id, channel_id, room_name, created_by, created_at, egress_id, recording_key, share_permission_id\n FROM calls\n WHERE id = $1\n FOR UPDATE\n ",
+ "query": "\n SELECT id, channel_id, room_name, created_by, created_at, egress_id, recording_key, share_permission_id, share_with_team\n FROM calls\n WHERE id = $1\n FOR UPDATE\n ",
"describe": {
"columns": [
{
@@ -42,6 +42,11 @@
"ordinal": 7,
"name": "share_permission_id",
"type_info": "Text"
+ },
+ {
+ "ordinal": 8,
+ "name": "share_with_team",
+ "type_info": "Bool"
}
],
"parameters": {
@@ -57,8 +62,9 @@
false,
true,
true,
+ false,
false
]
},
- "hash": "eb38775373a5ee3fdb942593936a3231b9303a5cc2fd2198b3ac132cae45024a"
+ "hash": "b514f8481c5d7b865fd3265fd927a9bb5855eb01eb33f90137e7685573b3be8e"
}
diff --git a/rust/cloud-storage/call/.sqlx/query-c707e1d4017c4ab2983364705b6ea9b62060b16ba2e7714d5690cc8311a5e201.json b/rust/cloud-storage/call/.sqlx/query-c707e1d4017c4ab2983364705b6ea9b62060b16ba2e7714d5690cc8311a5e201.json
new file mode 100644
index 0000000000..2fc62a4bdc
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-c707e1d4017c4ab2983364705b6ea9b62060b16ba2e7714d5690cc8311a5e201.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT share_permission_id as \"share_permission_id!\"\n FROM (\n SELECT share_permission_id FROM calls WHERE id = $1\n UNION ALL\n SELECT share_permission_id FROM call_records WHERE id = $1\n ) t\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "share_permission_id!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "c707e1d4017c4ab2983364705b6ea9b62060b16ba2e7714d5690cc8311a5e201"
+}
diff --git a/rust/cloud-storage/call/.sqlx/query-d913bcfef1a7d318743aca5d1db542ffe191451bf3b578cb3aaedaf754a46a19.json b/rust/cloud-storage/call/.sqlx/query-d913bcfef1a7d318743aca5d1db542ffe191451bf3b578cb3aaedaf754a46a19.json
new file mode 100644
index 0000000000..dd2f916e5e
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-d913bcfef1a7d318743aca5d1db542ffe191451bf3b578cb3aaedaf754a46a19.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE calls\n SET share_with_team = NOT share_with_team\n WHERE id = $1\n RETURNING share_with_team\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "share_with_team",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "d913bcfef1a7d318743aca5d1db542ffe191451bf3b578cb3aaedaf754a46a19"
+}
diff --git a/rust/cloud-storage/call/.sqlx/query-e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2.json b/rust/cloud-storage/call/.sqlx/query-e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2.json
new file mode 100644
index 0000000000..f47413e3dc
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH RECURSIVE parent_projects AS (\n -- Base case: the project itself\n SELECT id, name, \"parentId\"\n FROM \"Project\"\n WHERE id = $1\n\n UNION ALL\n\n -- Recursive case: walk up to the parent\n SELECT p.id, p.name, p.\"parentId\"\n FROM \"Project\" p\n INNER JOIN parent_projects pp ON p.id = pp.\"parentId\"\n )\n SELECT id as \"id!\"\n FROM parent_projects\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2"
+}
diff --git a/rust/cloud-storage/call/.sqlx/query-f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f.json b/rust/cloud-storage/call/.sqlx/query-f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f.json
new file mode 100644
index 0000000000..c718076a09
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH RECURSIVE child_projects AS (\n SELECT id FROM \"Project\" WHERE id = $1\n\n UNION ALL\n\n SELECT p.id FROM \"Project\" p\n INNER JOIN child_projects cp ON p.\"parentId\" = cp.id\n )\n SELECT id as \"entity_id!\", 'project' as \"entity_type!\" FROM child_projects\n\n UNION ALL\n\n SELECT d.id as \"entity_id!\", 'document' as \"entity_type!\" FROM \"Document\" d\n WHERE d.\"projectId\" IN (SELECT id FROM child_projects)\n\n UNION ALL\n\n SELECT c.id as \"entity_id!\", 'chat' as \"entity_type!\" FROM \"Chat\" c\n WHERE c.\"projectId\" IN (SELECT id FROM child_projects)\n\n UNION ALL\n\n SELECT et.id::text as \"entity_id!\", 'email_thread' as \"entity_type!\" FROM email_threads et\n WHERE et.project_id IN (SELECT id FROM child_projects)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "entity_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "entity_type!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null,
+ null
+ ]
+ },
+ "hash": "f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f"
+}
diff --git a/rust/cloud-storage/call/.sqlx/query-fc0744ebeb842c69501102f111cb569a6f2b0c2fc0e62e5243a5857e054e61c7.json b/rust/cloud-storage/call/.sqlx/query-fc0744ebeb842c69501102f111cb569a6f2b0c2fc0e62e5243a5857e054e61c7.json
new file mode 100644
index 0000000000..d9a73c770f
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-fc0744ebeb842c69501102f111cb569a6f2b0c2fc0e62e5243a5857e054e61c7.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT team_id\n FROM team_user\n WHERE user_id = $1\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "team_id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "fc0744ebeb842c69501102f111cb569a6f2b0c2fc0e62e5243a5857e054e61c7"
+}
diff --git a/rust/cloud-storage/call/Cargo.toml b/rust/cloud-storage/call/Cargo.toml
index fe8a7d798c..0404ff6da9 100644
--- a/rust/cloud-storage/call/Cargo.toml
+++ b/rust/cloud-storage/call/Cargo.toml
@@ -16,10 +16,10 @@ inbound = [
]
outbound = [
"dep:aws-sdk-s3",
- "dep:macro_aws_config",
+ "dep:entity_access_db_utils",
"dep:livekit-api",
"dep:livekit-protocol",
- "dep:models_permissions",
+ "dep:macro_aws_config",
"dep:sqlx",
"ports",
]
@@ -36,17 +36,21 @@ connection = { path = "../connection", default-features = false, features = [
entity_access = { path = "../entity_access", optional = true, default-features = false, features = [
"ports",
] }
+entity_access_db_utils = { path = "../entity_access_db_utils", optional = true }
filter_ast = { path = "../filter_ast" }
item_filters = { path = "../item_filters" }
livekit-api = { workspace = true, optional = true }
livekit-protocol = { workspace = true, optional = true }
-macro_aws_config = { path = "../macro_aws_config", optional = true, features = ["s3"] }
+macro_aws_config = { path = "../macro_aws_config", optional = true, features = [
+ "s3",
+] }
macro_user_id = { path = "../macro_user_id" }
-models_pagination = { path = "../models_pagination" }
+macro_uuid = { path = "../macro_uuid" }
model-entity = { path = "../model-entity" }
model-error-response = { path = "../model-error-response", optional = true }
model_user = { path = "../model_user", optional = true, features = ["axum"] }
-models_permissions = { path = "../models_permissions", optional = true }
+models_pagination = { path = "../models_pagination" }
+models_permissions = { path = "../models_permissions" }
notification = { path = "../notification" }
serde = { workspace = true }
serde_json = { workspace = true }
diff --git a/rust/cloud-storage/call/fixtures/call_repo.sql b/rust/cloud-storage/call/fixtures/call_repo.sql
index 43e48bef02..23a2e6d9d3 100644
--- a/rust/cloud-storage/call/fixtures/call_repo.sql
+++ b/rust/cloud-storage/call/fixtures/call_repo.sql
@@ -60,3 +60,13 @@ INSERT INTO call_record_transcripts (call_record_id, segment_id, speaker_id, con
'2024-01-01 10:00:05+00', '2024-01-01 10:00:07+00', 1),
('00000000-0000-0000-0000-0000000ca2ed', 'seg-arch-2', 'macro|[email protected]', 'archived reply',
'2024-01-01 10:00:08+00', '2024-01-01 10:00:10+00', 2);
+
+-- entity_access grants for the active call (owner + channel view).
+INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level) VALUES
+ ('00000000-0000-0000-0000-0000000ca110', 'call', 'macro|[email protected]', 'user', 'owner'),
+ ('00000000-0000-0000-0000-0000000ca110', 'call', '00000000-0000-0000-0000-000000000c01', 'channel', 'view');
+
+-- entity_access grants for the archived call (owner + channel view).
+INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level) VALUES
+ ('00000000-0000-0000-0000-0000000ca2ed', 'call', 'macro|[email protected]', 'user', 'owner'),
+ ('00000000-0000-0000-0000-0000000ca2ed', 'call', '00000000-0000-0000-0000-000000000c01', 'channel', 'view');
diff --git a/rust/cloud-storage/call/src/domain/models.rs b/rust/cloud-storage/call/src/domain/models.rs
index 715d888b9d..96c479fc97 100644
--- a/rust/cloud-storage/call/src/domain/models.rs
+++ b/rust/cloud-storage/call/src/domain/models.rs
@@ -139,6 +139,16 @@ pub struct TranscriptSegmentRequest {
pub is_final: bool,
}
+/// Edit call request
+#[derive(Debug, Clone, serde::Deserialize)]
+#[cfg_attr(feature = "inbound", derive(utoipa::ToSchema))]
+#[serde(rename_all = "camelCase")]
+pub struct EditCallRecordRequest {
+ /// Updated share permissions.
+ pub share_permission:
+ Option<models_permissions::share_permission::UpdateSharePermissionRequestV2>,
+}
+
/// A transcript segment as returned in a [`CallRecord`].
#[derive(Debug, Clone, serde::Serialize)]
#[cfg_attr(feature = "inbound", derive(utoipa::ToSchema))]
diff --git a/rust/cloud-storage/call/src/domain/ports.rs b/rust/cloud-storage/call/src/domain/ports.rs
index e122e25236..66f47c4c5b 100644
--- a/rust/cloud-storage/call/src/domain/ports.rs
+++ b/rust/cloud-storage/call/src/domain/ports.rs
@@ -11,6 +11,8 @@ use uuid::Uuid;
use item_filters::ast::{LiteralTree, call::CallLiteral};
+use crate::domain::models::EditCallRecordRequest;
+
use super::models::{
Call, CallActiveResponse, CallError, CallParticipant, CallRecord, CallTokenResponse,
CallWebhookEvent, EgressS3Config, GetCallRecordsRequest, LeaveCallResponse,
@@ -94,6 +96,12 @@ pub trait CallRepository: Send + Sync + 'static {
egress_id: &str,
) -> impl Future<Output = Result<(), Self::Err>> + Send;
+ /// Flip the `share_with_team` flag on an active call. Returns the new value.
+ fn toggle_share_with_team(
+ &self,
+ call_id: &Uuid,
+ ) -> impl Future<Output = Result<bool, Self::Err>> + Send;
+
/// Archive an active call to the permanent `call_records` and
/// `call_record_participants` tables, then delete the ephemeral rows.
/// Returns the new `call_records` id.
@@ -172,6 +180,13 @@ pub trait CallRepository: Send + Sync + 'static {
&self,
call_record_id: &Uuid,
) -> impl Future<Output = Result<Option<String>, Self::Err>> + Send;
+
+ /// Patches a call record.
+ fn patch_call_record(
+ &self,
+ call_record_id: &Uuid,
+ request: &EditCallRecordRequest,
+ ) -> impl Future<Output = Result<(), Self::Err>> + Send;
}
/// Storage port for generating presigned recording URLs.
@@ -320,6 +335,23 @@ pub trait CallService: Send + Sync + 'static {
&self,
receipt: EntityAccessReceipt<MemberParticipantRole>,
) -> impl Future<Output = Result<(), CallError>> + Send;
+
+ /// Edits a [`CallRecord`].
+ fn edit_call_record(
+ &self,
+ receipt: EntityAccessReceipt<MemberParticipantRole>,
+ request: EditCallRecordRequest,
+ ) -> impl Future<Output = Result<(), CallError>> + Send;
+
+ /// Toggle the `share_with_team` flag on the active call identified by the
+ /// receipt. Authorization is carried in the receipt produced by
+ /// `CallAccessLevelExtractor`; the entity on the receipt must be
+ /// `EntityType::Call` and its `entity_id` must be the call's UUID.
+ /// Returns the new value.
+ fn toggle_share_with_team(
+ &self,
+ receipt: EntityAccessReceipt<MemberParticipantRole>,
+ ) -> impl Future<Output = Result<bool, CallError>> + Send;
}
/// Lightweight read-only port for querying call records in Soup.
diff --git a/rust/cloud-storage/call/src/domain/service.rs b/rust/cloud-storage/call/src/domain/service.rs
index 293cb18770..9f416fe6a4 100644
--- a/rust/cloud-storage/call/src/domain/service.rs
+++ b/rust/cloud-storage/call/src/domain/service.rs
@@ -19,6 +19,8 @@ use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use uuid::Uuid;
+use crate::domain::models::EditCallRecordRequest;
+
use super::models::{
CallActiveResponse, CallError, CallRecord, CallTokenResponse, EgressS3Config,
GetCallRecordsRequest, LeaveCallResponse, TranscriptSegmentRequest,
@@ -713,6 +715,51 @@ impl<
Ok(())
}
+
+ #[tracing::instrument(err, skip(self))]
+ async fn edit_call_record(
+ &self,
+ receipt: EntityAccessReceipt<MemberParticipantRole>,
+ request: EditCallRecordRequest,
+ ) -> Result<(), CallError> {
+ let entity = receipt.entity();
+ if entity.entity_type != EntityType::Call {
+ return Err(CallError::Internal(anyhow::anyhow!(
+ "expected Call entity in receipt, got {:?}",
+ entity.entity_type
+ )));
+ }
+
+ let call_id = macro_uuid::string_to_uuid(&entity.entity_id)
+ .map_err(|_| CallError::Internal(anyhow::anyhow!("invalid call entity receipt")))?;
+
+ self.repo
+ .patch_call_record(&call_id, &request)
+ .await
+ .map_err(|e| CallError::Internal(e.into()))
+ }
+
+ #[tracing::instrument(err, skip(self))]
+ async fn toggle_share_with_team(
+ &self,
+ receipt: EntityAccessReceipt<MemberParticipantRole>,
+ ) -> Result<bool, CallError> {
+ let entity = receipt.entity();
+ if entity.entity_type != EntityType::Call {
+ return Err(CallError::Internal(anyhow::anyhow!(
+ "expected Call entity in receipt, got {:?}",
+ entity.entity_type
+ )));
+ }
+
+ let call_id = macro_uuid::string_to_uuid(&entity.entity_id)
+ .map_err(|_| CallError::Internal(anyhow::anyhow!("invalid call entity receipt")))?;
+
+ self.repo
+ .toggle_share_with_team(&call_id)
+ .await
+ .map_err(|e| CallError::Internal(e.into()))
+ }
}
/// Extract the recording key from a full S3 URL.
diff --git a/rust/cloud-storage/call/src/inbound/axum_router.rs b/rust/cloud-storage/call/src/inbound/axum_router.rs
index 9ef23a14f6..6a76be437f 100644
--- a/rust/cloud-storage/call/src/inbound/axum_router.rs
+++ b/rust/cloud-storage/call/src/inbound/axum_router.rs
@@ -30,8 +30,8 @@ use model_user::axum_extractor::MacroUserExtractor;
use uuid::Uuid;
use crate::domain::models::{
- CallActiveResponse, CallError, CallRecord, CallTokenResponse, LeaveCallResponse,
- TranscriptSegmentRequest,
+ CallActiveResponse, CallError, CallRecord, CallTokenResponse, EditCallRecordRequest,
+ LeaveCallResponse, TranscriptSegmentRequest,
};
use crate::domain::ports::CallService;
@@ -77,7 +77,9 @@ impl<S, Svc> FromRef<CallRouterState<S, Svc>> for Arc<Svc> {
/// - `GET /{channel_id}/active` — check if an active call exists
/// - `DELETE /{channel_id}` — leave or end a call
/// - `GET /record/{call_id}` — get a full call record (transcript + participants)
+/// - `PATCH /record/{call_id}` — edit a call record (e.g. share permissions)
/// - `DELETE /record/{call_id}` — delete a call record
+/// - `POST /record/{call_id}/share-with-team/toggle` — flip the call's share_with_team flag
pub fn call_router<S, Svc, T>(state: CallRouterState<S, Svc>) -> Router<T>
where
S: CallService,
@@ -95,7 +97,13 @@ where
)
.route(
"/record/{call_id}",
- get(get_call_record_handler::<S, Svc>).delete(delete_call_record_handler::<S, Svc>),
+ get(get_call_record_handler::<S, Svc>)
+ .patch(edit_call_record_handler::<S, Svc>)
+ .delete(delete_call_record_handler::<S, Svc>),
+ )
+ .route(
+ "/record/{call_id}/share-with-team/toggle",
+ post(toggle_share_with_team_handler::<S, Svc>),
)
.with_state(state)
}
@@ -349,6 +357,68 @@ pub async fn delete_call_record_handler<S: CallService, Svc: EntityAccessService
Ok(StatusCode::NO_CONTENT)
}
+/// Handler for `PATCH /call/record/{call_id}`.
+///
+/// Edits a call record — currently supports updating the record's share
+/// permissions. Access is validated via channel membership
+#[utoipa::path(
+ patch,
+ operation_id = "edit_call_record",
+ path = "/call/record/{call_id}",
+ params(
+ ("call_id" = Uuid, Path, description = "Call ID"),
+ ),
+ request_body = EditCallRecordRequest,
+ responses(
+ (status = 204, description = "Call record updated"),
+ (status = 401, body = ErrorResponse),
+ (status = 404, body = ErrorResponse),
+ (status = 500, body = ErrorResponse),
+ )
+)]
+#[tracing::instrument(err, skip_all)]
+pub async fn edit_call_record_handler<S: CallService, Svc: EntityAccessService>(
+ State(state): State<CallRouterState<S, Svc>>,
+ access: CallAccessLevelExtractor<MemberParticipantRole, Svc>,
+ Json(request): Json<EditCallRecordRequest>,
+) -> Result<StatusCode, CallError> {
+ state
+ .service
+ .edit_call_record(access.entity_access_receipt, request)
+ .await?;
+ Ok(StatusCode::NO_CONTENT)
+}
+
+/// Handler for `POST /call/record/{call_id}/share-with-team/toggle`.
+///
+/// Toggles the `share_with_team` flag on the active call. Returns the new
+/// value as the JSON body.
+#[utoipa::path(
+ post,
+ operation_id = "toggle_share_with_team",
+ path = "/call/record/{call_id}/share-with-team/toggle",
+ params(
+ ("call_id" = Uuid, Path, description = "Call ID"),
+ ),
+ responses(
+ (status = 200, body = bool, content_type = "application/json", description = "New value of share_with_team after toggle"),
+ (status = 401, body = ErrorResponse),
+ (status = 404, body = ErrorResponse),
+ (status = 500, body = ErrorResponse),
+ )
+)]
+#[tracing::instrument(err, skip_all)]
+pub async fn toggle_share_with_team_handler<S: CallService, Svc: EntityAccessService>(
+ State(state): State<CallRouterState<S, Svc>>,
+ access: CallAccessLevelExtractor<MemberParticipantRole, Svc>,
+) -> Result<Json<bool>, CallError> {
+ let new_value = state
+ .service
+ .toggle_share_with_team(access.entity_access_receipt)
+ .await?;
+ Ok(Json(new_value))
+}
+
/// Handler for `DELETE /call/{channel_id}`.
#[utoipa::path(
delete,
diff --git a/rust/cloud-storage/call/src/outbound/pg_call_repo.rs b/rust/cloud-storage/call/src/outbound/pg_call_repo.rs
index 2d593dcf47..6e4d041acd 100644
--- a/rust/cloud-storage/call/src/outbound/pg_call_repo.rs
+++ b/rust/cloud-storage/call/src/outbound/pg_call_repo.rs
@@ -1,5 +1,7 @@
//! Postgres-backed repository for call state.
+mod edit;
+
#[cfg(test)]
mod test;
@@ -18,7 +20,7 @@ use uuid::Uuid;
use crate::domain::channel_name::{NameLookup, display_name, resolve_channel_name};
use crate::domain::models::{
Call, CallParticipant, CallRecord, CallRecordParticipant, CallRecordTranscriptSegment,
- TranscriptSegmentRequest,
+ EditCallRecordRequest, TranscriptSegmentRequest,
};
use crate::domain::ports::CallRepository;
@@ -129,6 +131,27 @@ impl CallRepository for PgCallRepo {
.execute(tx.as_mut())
.await?;
+ // owner entity access row
+ entity_access_db_utils::insert_entity_access_row(
+ &mut tx,
+ call_id,
+ entity_access_db_utils::EntityType::Call,
+ created_by.as_ref(),
+ entity_access_db_utils::EntityAccessSourceType::User,
+ entity_access_db_utils::AccessLevel::Owner,
+ )
+ .await?;
+
+ entity_access_db_utils::insert_entity_access_row(
+ &mut tx,
+ call_id,
+ entity_access_db_utils::EntityType::Call,
+ &channel_id.to_string(),
+ entity_access_db_utils::EntityAccessSourceType::Channel,
+ entity_access_db_utils::AccessLevel::View,
+ )
+ .await?;
+
let row = sqlx::query!(
r#"
INSERT INTO calls (id, channel_id, room_name, created_by, share_permission_id)
@@ -339,14 +362,25 @@ impl CallRepository for PgCallRepo {
#[tracing::instrument(err, skip(self))]
async fn delete_call(&self, call_id: &Uuid) -> Result<(), Self::Err> {
+ let mut tx = self.pool.begin().await?;
+
sqlx::query!(
r#"
DELETE FROM calls WHERE id = $1
"#,
call_id,
)
- .execute(&self.pool)
+ .execute(tx.as_mut())
.await?;
+
+ entity_access_db_utils::delete_entity_access_rows(
+ &mut tx,
+ call_id,
+ entity_access_db_utils::EntityType::Call,
+ )
+ .await?;
+
+ tx.commit().await?;
Ok(())
}
@@ -364,6 +398,22 @@ impl CallRepository for PgCallRepo {
Ok(())
}
+ #[tracing::instrument(err, skip(self))]
+ async fn toggle_share_with_team(&self, call_id: &Uuid) -> Result<bool, Self::Err> {
+ let row = sqlx::query!(
+ r#"
+ UPDATE calls
+ SET share_with_team = NOT share_with_team
+ WHERE id = $1
+ RETURNING share_with_team
+ "#,
+ call_id,
+ )
+ .fetch_one(&self.pool)
+ .await?;
+ Ok(row.share_with_team)
+ }
+
#[tracing::instrument(err, skip(self))]
async fn archive_call(&self, call_id: &Uuid) -> Result<Uuid, Self::Err> {
let mut tx = self.pool.begin().await?;
@@ -371,7 +421,7 @@ impl CallRepository for PgCallRepo {
// Fetch and lock the active call so concurrent archive_call callers serialize.
let call = sqlx::query!(
r#"
- SELECT id, channel_id, room_name, created_by, created_at, egress_id, recording_key, share_permission_id
+ SELECT id, channel_id, room_name, created_by, created_at, egress_id, recording_key, share_permission_id, share_with_team
FROM calls
WHERE id = $1
FOR UPDATE
@@ -382,6 +432,34 @@ impl CallRepository for PgCallRepo {
.await?
.ok_or(sqlx::Error::RowNotFound)?;
+ // If the call opted in to team sharing, grant the creator's team View
+ // access on the archived call. Silently skip if the creator has no team.
+ if call.share_with_team {
+ let team_id: Option<Uuid> = sqlx::query_scalar!(
+ r#"
+ SELECT team_id
+ FROM team_user
+ WHERE user_id = $1
+ LIMIT 1
+ "#,
+ &call.created_by,
+ )
+ .fetch_optional(tx.as_mut())
+ .await?;
+
+ if let Some(team_id) = team_id {
+ entity_access_db_utils::insert_entity_access_row(
+ &mut tx,
+ call_id,
+ entity_access_db_utils::EntityType::Call,
+ &team_id.to_string(),
+ entity_access_db_utils::EntityAccessSourceType::Team,
+ entity_access_db_utils::AccessLevel::View,
+ )
+ .await?;
+ }
+ }
+
let now = Utc::now();
let duration_ms = now
.signed_duration_since(call.created_at)
@@ -1038,14 +1116,41 @@ impl CallRepository for PgCallRepo {
#[tracing::instrument(err, skip(self))]
async fn delete_call_record(&self, call_record_id: &Uuid) -> Result<Option<String>, Self::Err> {
+ let mut tx = self.pool.begin().await?;
+
let row = sqlx::query!(
r#"
DELETE FROM call_records WHERE id = $1 RETURNING recording_key
"#,
call_record_id,
)
- .fetch_optional(&self.pool)
+ .fetch_optional(tx.as_mut())
+ .await?;
+
+ entity_access_db_utils::delete_entity_access_rows(
+ &mut tx,
+ call_record_id,
+ entity_access_db_utils::EntityType::Call,
+ )
.await?;
+
+ tx.commit().await?;
Ok(row.and_then(|r| r.recording_key))
}
+
+ #[tracing::instrument(skip(self), err)]
+ async fn patch_call_record(
+ &self,
+ call_record_id: &Uuid,
+ request: &EditCallRecordRequest,
+ ) -> Result<(), Self::Err> {
+ let mut tx = self.pool.begin().await?;
+
+ if let Some(share_permission) = request.share_permission.as_ref() {
+ edit::update_share_permission(&mut tx, call_record_id, share_permission).await?;
+ }
+
+ tx.commit().await?;
+ Ok(())
+ }
}
diff --git a/rust/cloud-storage/call/src/outbound/pg_call_repo/edit.rs b/rust/cloud-storage/call/src/outbound/pg_call_repo/edit.rs
new file mode 100644
index 0000000000..23b22bfb6e
--- /dev/null
+++ b/rust/cloud-storage/call/src/outbound/pg_call_repo/edit.rs
@@ -0,0 +1,188 @@
+//! SQL operations for editing call-record share permissions.
+
+use model_entity::EntityType;
+use models_permissions::share_permission::UpdateSharePermissionRequestV2;
+use models_permissions::share_permission::channel_share_permission::UpdateOperation;
+use sqlx::{Postgres, Transaction};
+use uuid::Uuid;
+
+/// Update share permissions for a call record.
+///
+/// Looks up the call's share permission ID from either the active `calls`
+/// table or the archived `call_records` table (both carry `share_permission_id`),
+/// then updates the `SharePermission` and `ChannelSharePermission` tables.
+pub(super) async fn update_share_permission(
+ transaction: &mut Transaction<'_, Postgres>,
+ call_id: &Uuid,
+ share_permission: &UpdateSharePermissionRequestV2,
+) -> Result<(), sqlx::Error> {
+ let share_permission_id = sqlx::query_scalar!(
+ r#"
+ SELECT share_permission_id as "share_permission_id!"
+ FROM (
+ SELECT share_permission_id FROM calls WHERE id = $1
+ UNION ALL
+ SELECT share_permission_id FROM call_records WHERE id = $1
+ ) t
+ LIMIT 1
+ "#,
+ call_id,
+ )
+ .fetch_one(transaction.as_mut())
+ .await?;
+
+ update_share_permission_row(transaction, &share_permission_id, share_permission).await?;
+
+ if let Some(channel_perms) = &share_permission.channel_share_permissions {
+ update_channel_share_permissions(transaction, &share_permission_id, channel_perms).await?;
+
+ entity_access_db_utils::update_entity_access_channel_share_permissions(
+ transaction,
+ call_id,
+ EntityType::Call,
+ channel_perms,
+ )
+ .await?;
+ }
+
+ Ok(())
+}
+
+/// Update the SharePermission row (isPublic, publicAccessLevel).
+async fn update_share_permission_row(
+ transaction: &mut Transaction<'_, Postgres>,
+ share_permission_id: &str,
+ share_permission: &UpdateSharePermissionRequestV2,
+) -> Result<(), sqlx::Error> {
+ let mut set_parts = Vec::new();
+ let mut str_params: Vec<Option<String>> = Vec::new();
+ let mut bool_params: Vec<bool> = Vec::new();
+
+ // Track parameter indices (starting at 2 since $1 is the share_permission_id)
+ let mut param_idx = 2u32;
+ enum ParamType {
+ Bool(usize),
+ Str(usize),
+ }
+ let mut param_order: Vec<ParamType> = Vec::new();
+
+ let mut ignore_public_access_level = false;
+ if let Some(is_public) = share_permission.is_public {
+ set_parts.push(format!("\"isPublic\" = ${param_idx}"));
+ param_idx += 1;
+ bool_params.push(is_public);
+ param_order.push(ParamType::Bool(bool_params.len() - 1));
+
+ if is_public && share_permission.public_access_level.is_none() {
+ set_parts.push(format!("\"publicAccessLevel\" = ${param_idx}"));
+ param_idx += 1;
+ str_params.push(Some("view".to_string()));
+ param_order.push(ParamType::Str(str_params.len() - 1));
+ }
+
+ if !is_public {
+ ignore_public_access_level = true;
+ set_parts.push("\"publicAccessLevel\" = NULL".to_string());
+ }
+ }
+
+ if let Some(public_access_level) = share_permission.public_access_level
+ && !ignore_public_access_level
+ {
+ set_parts.push(format!("\"publicAccessLevel\" = ${param_idx}"));
+ str_params.push(Some(public_access_level.to_string()));
+ param_order.push(ParamType::Str(str_params.len() - 1));
+ }
+
+ if set_parts.is_empty() {
+ sqlx::query(r#"UPDATE "SharePermission" SET "updatedAt" = NOW() WHERE id = $1"#)
+ .bind(share_permission_id)
+ .execute(transaction.as_mut())
+ .await?;
+ return Ok(());
+ }
+
+ let query_str = format!(
+ r#"UPDATE "SharePermission" SET {}, "updatedAt" = NOW() WHERE id = $1"#,
+ set_parts.join(", ")
+ );
+
+ let mut query = sqlx::query(&query_str);
+ query = query.bind(share_permission_id.to_string());
+
+ for param_type in &param_order {
+ match param_type {
+ ParamType::Bool(idx) => {
+ query = query.bind(bool_params[*idx]);
+ }
+ ParamType::Str(idx) => {
+ query = query.bind(str_params[*idx].clone());
+ }
+ }
+ }
+
+ query.execute(transaction.as_mut()).await?;
+ Ok(())
+}
+
+/// Update channel share permissions (add/replace/remove).
+async fn update_channel_share_permissions(
+ transaction: &mut Transaction<'_, Postgres>,
+ share_permission_id: &str,
+ channel_perms: &[models_permissions::share_permission::channel_share_permission::UpdateChannelSharePermission],
+) -> Result<(), sqlx::Error> {
+ let mut upsert_channel_ids = Vec::new();
+ let mut upsert_access_levels = Vec::new();
+ let mut remove_channel_ids = Vec::new();
+
+ for perm in channel_perms {
+ match perm.operation {
+ UpdateOperation::Add | UpdateOperation::Replace => {
+ upsert_channel_ids.push(perm.channel_id.clone());
+ upsert_access_levels.push(
+ perm.access_level
+ .unwrap_or(
+ models_permissions::share_permission::access_level::AccessLevel::View,
+ )
+ .to_string(),
+ );
+ }
+ UpdateOperation::Remove => {
+ remove_channel_ids.push(perm.channel_id.clone());
+ }
+ }
+ }
+
+ if !remove_channel_ids.is_empty() {
+ sqlx::query!(
+ r#"
+ DELETE FROM "ChannelSharePermission"
+ WHERE "share_permission_id" = $1
+ AND "channel_id" = ANY($2)
+ "#,
+ share_permission_id,
+ &remove_channel_ids,
+ )
+ .execute(transaction.as_mut())
+ .await?;
+ }
+
+ if !upsert_channel_ids.is_empty() {
+ sqlx::query!(
+ r#"
+ INSERT INTO "ChannelSharePermission" ("share_permission_id", "channel_id", "access_level")
+ SELECT $1, channel_id, access_level::"AccessLevel"
+ FROM UNNEST($2::text[], $3::text[]) AS t(channel_id, access_level)
+ ON CONFLICT ("share_permission_id", "channel_id")
+ DO UPDATE SET "access_level" = EXCLUDED."access_level"
+ "#,
+ share_permission_id,
+ &upsert_channel_ids,
+ &upsert_access_levels,
+ )
+ .execute(transaction.as_mut())
+ .await?;
+ }
+
+ Ok(())
+}
diff --git a/rust/cloud-storage/call/src/outbound/pg_call_repo/test.rs b/rust/cloud-storage/call/src/outbound/pg_call_repo/test.rs
index 2d54df38ec..c788c3cd90 100644
--- a/rust/cloud-storage/call/src/outbound/pg_call_repo/test.rs
+++ b/rust/cloud-storage/call/src/outbound/pg_call_repo/test.rs
@@ -1,6 +1,6 @@
use std::{ops::Deref, sync::Arc, sync::LazyLock};
-use crate::domain::models::TranscriptSegmentRequest;
+use crate::domain::models::{EditCallRecordRequest, TranscriptSegmentRequest};
use crate::domain::ports::CallRepository;
use crate::outbound::pg_call_repo::PgCallRepo;
use chrono::Utc;
@@ -8,6 +8,11 @@ use filter_ast::Expr;
use item_filters::ast::{LiteralTree, call::CallLiteral};
use macro_db_migrator::MACRO_DB_MIGRATIONS;
use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};
+use models_permissions::share_permission::UpdateSharePermissionRequestV2;
+use models_permissions::share_permission::access_level::AccessLevel;
+use models_permissions::share_permission::channel_share_permission::{
+ UpdateChannelSharePermission, UpdateOperation,
+};
use sqlx::{Pool, Postgres};
use uuid::Uuid;
@@ -200,13 +205,21 @@ async fn get_participant_count_correct(pool: Pool<Postgres>) -> anyhow::Result<(
migrator = "MACRO_DB_MIGRATIONS"
)]
async fn delete_call_cascades_to_participants(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let repo = repo(pool);
+ let repo = repo(pool.clone());
repo.delete_call(&CALL1).await?;
assert!(repo.get_call_by_channel_id(&CH1).await?.is_none());
// Participants should be cascade-deleted.
assert_eq!(repo.get_participant_count(&CALL1).await?, 0);
+ // entity_access grants for the call must be cleaned up atomically.
+ let remaining_grants: i64 = sqlx::query_scalar!(
+ r#"SELECT COUNT(*) as "count!" FROM entity_access WHERE entity_id = $1 AND entity_type = 'call'"#,
+ CALL1,
+ )
+ .fetch_one(&pool)
+ .await?;
+ assert_eq!(remaining_grants, 0);
Ok(())
}
@@ -309,6 +322,123 @@ async fn archive_call_preserves_soft_deleted_participants(
Ok(())
}
+/// Test helper: give `user_id` a brand new team owned by that user. Inserts
+/// the parent `macro_user` and `User` rows that the `team_user` FK requires.
+async fn give_user_a_team(
+ pool: &Pool<Postgres>,
+ user_id: &str,
+ team_id: &Uuid,
+) -> anyhow::Result<()> {
+ let macro_user_id = Uuid::now_v7();
+
+ sqlx::query(
+ r#"INSERT INTO macro_user (id, username, email, stripe_customer_id) VALUES ($1, $2, $3, '')"#,
+ )
+ .bind(macro_user_id)
+ .bind(user_id)
+ .bind(format!("{user_id}@test.com"))
+ .execute(pool)
+ .await?;
+
+ sqlx::query(r#"INSERT INTO "User" (id, email, macro_user_id) VALUES ($1, $2, $3)"#)
+ .bind(user_id)
+ .bind(format!("{user_id}@test.com"))
+ .bind(macro_user_id)
+ .execute(pool)
+ .await?;
+
+ sqlx::query(r#"INSERT INTO team (id, name, owner_id) VALUES ($1, $2, $3)"#)
+ .bind(team_id)
+ .bind("test team")
+ .bind(user_id)
+ .execute(pool)
+ .await?;
+
+ sqlx::query(r#"INSERT INTO team_user (user_id, team_id, team_role) VALUES ($1, $2, 'owner')"#)
+ .bind(user_id)
+ .bind(team_id)
+ .execute(pool)
+ .await?;
+
+ Ok(())
+}
+
+// -- archive_call grants team view access when share_with_team is true -------
+
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("call_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn archive_call_grants_team_view_access_when_share_with_team_true(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ use sqlx::Row as _;
+
+ let repo = repo(pool.clone());
+ let team_id: Uuid = Uuid::from_u128(0xaaaaaaaa_aaaa_aaaa_aaaa_aaaaaaaaaaaa);
+
+ give_user_a_team(&pool, USER_A.as_ref(), &team_id).await?;
+
+ // share_with_team defaults to TRUE on the fixture call.
+ repo.archive_call(&CALL1).await?;
+
+ let row = sqlx::query(
+ r#"
+ SELECT entity_id, entity_type, source_id, access_level
+ FROM entity_access
+ WHERE entity_id = $1 AND source_type = 'team'
+ "#,
+ )
+ .bind(CALL1)
+ .fetch_one(&pool)
+ .await?;
+
+ assert_eq!(row.get::<Uuid, _>("entity_id"), CALL1);
+ assert_eq!(row.get::<String, _>("entity_type"), "call");
+ assert_eq!(row.get::<String, _>("source_id"), team_id.to_string());
+ assert_eq!(row.get::<AccessLevel, _>("access_level"), AccessLevel::View);
+
+ Ok(())
+}
+
+// -- archive_call skips team grant when share_with_team is false -------------
+
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("call_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn archive_call_skips_team_grant_when_share_with_team_false(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ use sqlx::Row as _;
+
+ let repo = repo(pool.clone());
+ let team_id: Uuid = Uuid::from_u128(0xbbbbbbbb_bbbb_bbbb_bbbb_bbbbbbbbbbbb);
+
+ // USER_A is on a team, but the call opted out of team sharing — so no
+ // team-scoped entity_access row should be created at archive time.
+ give_user_a_team(&pool, USER_A.as_ref(), &team_id).await?;
+
+ sqlx::query(r#"UPDATE calls SET share_with_team = false WHERE id = $1"#)
+ .bind(CALL1)
+ .execute(&pool)
+ .await?;
+
+ repo.archive_call(&CALL1).await?;
+
+ let count: i64 = sqlx::query(
+ r#"SELECT COUNT(*) AS count FROM entity_access WHERE entity_id = $1 AND source_type = 'team'"#,
+ )
+ .bind(CALL1)
+ .map(|r: sqlx::postgres::PgRow| r.get::<i64, _>("count"))
+ .fetch_one(&pool)
+ .await?;
+
+ assert_eq!(count, 0);
+
+ Ok(())
+}
+
// -- archive_call preserves id and share_permission_id ------------------------
#[sqlx::test(
@@ -777,6 +907,14 @@ async fn delete_call_record_cascades(pool: Pool<Postgres>) -> anyhow::Result<()>
.await?;
assert_eq!(remaining_participants, 0);
assert_eq!(remaining_transcripts, 0);
+ // entity_access grants for the archived call must be cleaned up atomically.
+ let remaining_grants: i64 = sqlx::query_scalar!(
+ r#"SELECT COUNT(*) as "count!" FROM entity_access WHERE entity_id = $1 AND entity_type = 'call'"#,
+ CALL_ARCHIVED,
+ )
+ .fetch_one(&pool)
+ .await?;
+ assert_eq!(remaining_grants, 0);
Ok(())
}
@@ -797,3 +935,279 @@ async fn delete_call_record_noop_for_unknown_id(pool: Pool<Postgres>) -> anyhow:
);
Ok(())
}
+
+// -- patch_call_record --------------------------------------------------------
+
+const SP_ARCHIVED: &str = "00000000-0000-0000-0000-00000000sp02";
+
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("call_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn patch_call_record_sets_is_public_true_defaults_view(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ let repo = repo(pool.clone());
+
+ repo.patch_call_record(
+ &CALL_ARCHIVED,
+ &EditCallRecordRequest {
+ share_permission: Some(UpdateSharePermissionRequestV2 {
+ is_public: Some(true),
+ public_access_level: None,
+ channel_share_permissions: None,
+ }),
+ },
+ )
+ .await?;
+
+ let row = sqlx::query!(
+ r#"
+ SELECT "isPublic" as "is_public!", "publicAccessLevel" as "public_access_level?"
+ FROM "SharePermission"
+ WHERE id = $1
+ "#,
+ SP_ARCHIVED,
+ )
+ .fetch_one(&pool)
+ .await?;
+
+ assert!(row.is_public);
+ assert_eq!(row.public_access_level.as_deref(), Some("view"));
+ Ok(())
+}
+
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("call_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn patch_call_record_sets_is_public_false_clears_public_access_level(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ let repo = repo(pool.clone());
+
+ // Seed a non-null public access level so the clear is observable.
+ sqlx::query!(
+ r#"UPDATE "SharePermission" SET "isPublic" = true, "publicAccessLevel" = 'edit' WHERE id = $1"#,
+ SP_ARCHIVED,
+ )
+ .execute(&pool)
+ .await?;
+
+ repo.patch_call_record(
+ &CALL_ARCHIVED,
+ &EditCallRecordRequest {
+ share_permission: Some(UpdateSharePermissionRequestV2 {
+ is_public: Some(false),
+ public_access_level: Some(AccessLevel::Edit),
+ channel_share_permissions: None,
+ }),
+ },
+ )
+ .await?;
+
+ let row = sqlx::query!(
+ r#"
+ SELECT "isPublic" as "is_public!", "publicAccessLevel" as "public_access_level?"
+ FROM "SharePermission"
+ WHERE id = $1
+ "#,
+ SP_ARCHIVED,
+ )
+ .fetch_one(&pool)
+ .await?;
+
+ assert!(!row.is_public);
+ assert!(row.public_access_level.is_none());
+ Ok(())
+}
+
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("call_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn patch_call_record_sets_public_access_level(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let repo = repo(pool.clone());
+
+ repo.patch_call_record(
+ &CALL_ARCHIVED,
+ &EditCallRecordRequest {
+ share_permission: Some(UpdateSharePermissionRequestV2 {
+ is_public: None,
+ public_access_level: Some(AccessLevel::Edit),
+ channel_share_permissions: None,
+ }),
+ },
+ )
+ .await?;
+
+ let row = sqlx::query!(
+ r#"
+ SELECT "publicAccessLevel" as "public_access_level?"
+ FROM "SharePermission"
+ WHERE id = $1
+ "#,
+ SP_ARCHIVED,
+ )
+ .fetch_one(&pool)
+ .await?;
+
+ assert_eq!(row.public_access_level.as_deref(), Some("edit"));
+ Ok(())
+}
+
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("call_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn patch_call_record_adds_channel_share_permission(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ let repo = repo(pool.clone());
+ let channel_id = CH2.to_string();
+
+ repo.patch_call_record(
+ &CALL_ARCHIVED,
+ &EditCallRecordRequest {
+ share_permission: Some(UpdateSharePermissionRequestV2 {
+ is_public: None,
+ public_access_level: None,
+ channel_share_permissions: Some(vec![UpdateChannelSharePermission {
+ operation: UpdateOperation::Add,
+ channel_id: channel_id.clone(),
+ access_level: Some(AccessLevel::View),
+ }]),
+ }),
+ },
+ )
+ .await?;
+
+ let csp_count = sqlx::query_scalar!(
+ r#"
+ SELECT COUNT(*) as "count!"
+ FROM "ChannelSharePermission"
+ WHERE share_permission_id = $1 AND channel_id = $2
+ "#,
+ SP_ARCHIVED,
+ &channel_id,
+ )
+ .fetch_one(&pool)
+ .await?;
+ assert_eq!(csp_count, 1);
+
+ let access_rows = sqlx::query!(
+ r#"
+ SELECT source_id, access_level::text as "access_level", source_type::text as "source_type"
+ FROM entity_access
+ WHERE entity_id = $1
+ AND entity_type = 'call'
+ AND source_id = $2
+ AND source_type = 'channel'
+ "#,
+ CALL_ARCHIVED,
+ &channel_id,
+ )
+ .fetch_all(&pool)
+ .await?;
+
+ assert_eq!(access_rows.len(), 1);
+ assert_eq!(access_rows[0].access_level.as_deref(), Some("view"));
+ Ok(())
+}
+
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("call_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn patch_call_record_removes_channel_share_permission(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ let repo = repo(pool.clone());
+ let channel_id = CH1.to_string();
+
+ // Sanity: the fixture seeded a ChannelSharePermission for CH1.
+ let pre_count = sqlx::query_scalar!(
+ r#"
+ SELECT COUNT(*) as "count!"
+ FROM "ChannelSharePermission"
+ WHERE share_permission_id = $1 AND channel_id = $2
+ "#,
+ SP_ARCHIVED,
+ &channel_id,
+ )
+ .fetch_one(&pool)
+ .await?;
+ assert_eq!(pre_count, 1);
+
+ repo.patch_call_record(
+ &CALL_ARCHIVED,
+ &EditCallRecordRequest {
+ share_permission: Some(UpdateSharePermissionRequestV2 {
+ is_public: None,
+ public_access_level: None,
+ channel_share_permissions: Some(vec![UpdateChannelSharePermission {
+ operation: UpdateOperation::Remove,
+ channel_id: channel_id.clone(),
+ access_level: None,
+ }]),
+ }),
+ },
+ )
+ .await?;
+
+ let post_count = sqlx::query_scalar!(
+ r#"
+ SELECT COUNT(*) as "count!"
+ FROM "ChannelSharePermission"
+ WHERE share_permission_id = $1 AND channel_id = $2
+ "#,
+ SP_ARCHIVED,
+ &channel_id,
+ )
+ .fetch_one(&pool)
+ .await?;
+ assert_eq!(post_count, 0);
+ Ok(())
+}
+
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("call_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn patch_call_record_none_is_noop(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let repo = repo(pool.clone());
+
+ let before = sqlx::query!(
+ r#"
+ SELECT "isPublic" as "is_public!", "publicAccessLevel" as "public_access_level?"
+ FROM "SharePermission"
+ WHERE id = $1
+ "#,
+ SP_ARCHIVED,
+ )
+ .fetch_one(&pool)
+ .await?;
+
+ repo.patch_call_record(
+ &CALL_ARCHIVED,
+ &EditCallRecordRequest {
+ share_permission: None,
+ },
+ )
+ .await?;
+
+ let after = sqlx::query!(
+ r#"
+ SELECT "isPublic" as "is_public!", "publicAccessLevel" as "public_access_level?"
+ FROM "SharePermission"
+ WHERE id = $1
+ "#,
+ SP_ARCHIVED,
+ )
+ .fetch_one(&pool)
+ .await?;
+
+ assert_eq!(before.is_public, after.is_public);
+ assert_eq!(before.public_access_level, after.public_access_level);
+ Ok(())
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-000c1235f8bd55c9dd179d10421e262d6e096bc1a8547f5da22596dbc56e0ddc.json b/rust/cloud-storage/chat/.sqlx/query-000c1235f8bd55c9dd179d10421e262d6e096bc1a8547f5da22596dbc56e0ddc.json
new file mode 100644
index 0000000000..28048605a8
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-000c1235f8bd55c9dd179d10421e262d6e096bc1a8547f5da22596dbc56e0ddc.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n COUNT(DISTINCT cm.id) AS ai_chat_messages,\n COUNT(DISTINCT d.id) AS documents\n FROM \"User\" u\n LEFT JOIN \"Chat\" c ON c.\"userId\" = u.id AND c.\"deletedAt\" IS NULL\n LEFT JOIN \"ChatMessage\" cm ON cm.\"chatId\" = c.id AND cm.role = 'user'\n LEFT JOIN \"Document\" d ON d.\"owner\" = u.id AND d.\"deletedAt\" IS NULL\n WHERE u.id = $1;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "ai_chat_messages",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "documents",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null,
+ null
+ ]
+ },
+ "hash": "000c1235f8bd55c9dd179d10421e262d6e096bc1a8547f5da22596dbc56e0ddc"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-00b50429eacf802503b639b2dc362bbdbf3d29b375b73ca25f7720941929f10b.json b/rust/cloud-storage/chat/.sqlx/query-00b50429eacf802503b639b2dc362bbdbf3d29b375b73ca25f7720941929f10b.json
new file mode 100644
index 0000000000..3cb6780373
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-00b50429eacf802503b639b2dc362bbdbf3d29b375b73ca25f7720941929f10b.json
@@ -0,0 +1,46 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH RECURSIVE project_path AS (\n SELECT\n p.id,\n p.name,\n p.\"userId\",\n p.\"parentId\",\n p.\"updatedAt\",\n ARRAY[p.name] as path\n FROM \"Project\" p\n WHERE p.id = ANY($1)\n\n UNION ALL\n\n SELECT\n pp.id,\n pp.name,\n pp.\"userId\",\n parent.\"parentId\",\n pp.\"updatedAt\",\n ARRAY[parent.name] || pp.path as path\n FROM project_path pp\n JOIN \"Project\" parent ON pp.\"parentId\" = parent.id\n )\n SELECT DISTINCT ON (id)\n id as \"id!\",\n name as \"name!\",\n \"userId\" as \"owner!\",\n path as \"path!\",\n \"updatedAt\"::timestamptz as \"updated_at\"\n FROM project_path\n WHERE \"parentId\" IS NULL\n ORDER BY id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "name!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "path!",
+ "type_info": "TextArray"
+ },
+ {
+ "ordinal": 4,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ null,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "00b50429eacf802503b639b2dc362bbdbf3d29b375b73ca25f7720941929f10b"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-014d3b9b1509bfcd1b11c8c0ef8fe4534c4caa33640876469811d19d64a9b7d0.json b/rust/cloud-storage/chat/.sqlx/query-014d3b9b1509bfcd1b11c8c0ef8fe4534c4caa33640876469811d19d64a9b7d0.json
new file mode 100644
index 0000000000..1e9e030596
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-014d3b9b1509bfcd1b11c8c0ef8fe4534c4caa33640876469811d19d64a9b7d0.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT email\n FROM \"BlockedEmail\"\n WHERE email = ANY($1::text[])\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "email",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "014d3b9b1509bfcd1b11c8c0ef8fe4534c4caa33640876469811d19d64a9b7d0"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-01ee4e5a80a158998dadbbb6b8fe5d27371757cc6e9019589182150af22b5e36.json b/rust/cloud-storage/chat/.sqlx/query-01ee4e5a80a158998dadbbb6b8fe5d27371757cc6e9019589182150af22b5e36.json
new file mode 100644
index 0000000000..7515457926
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-01ee4e5a80a158998dadbbb6b8fe5d27371757cc6e9019589182150af22b5e36.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"Pin\" \n WHERE \"pinnedItemId\" = ANY($1) AND \"pinnedItemType\" = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "01ee4e5a80a158998dadbbb6b8fe5d27371757cc6e9019589182150af22b5e36"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-01fe7f04dbd686c1488b3e98eb9c5ed15ff504b22dce8bc1589c9a557f511dcb.json b/rust/cloud-storage/chat/.sqlx/query-01fe7f04dbd686c1488b3e98eb9c5ed15ff504b22dce8bc1589c9a557f511dcb.json
new file mode 100644
index 0000000000..1c540f1878
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-01fe7f04dbd686c1488b3e98eb9c5ed15ff504b22dce8bc1589c9a557f511dcb.json
@@ -0,0 +1,47 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.\"id\" as \"chat_id\",\n m.id as \"message_id\",\n c.\"userId\" as \"user_id\",\n c.\"createdAt\" as \"created_at\",\n c.\"updatedAt\" as \"updated_at\"\n FROM\n \"ChatMessage\" m\n JOIN\n \"Chat\" c on c.\"id\" = m.\"chatId\"\n WHERE c.\"deletedAt\" IS NULL\n ORDER BY\n m.\"createdAt\" DESC\n LIMIT $1\n OFFSET $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "chat_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "message_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 4,
+ "name": "updated_at",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "01fe7f04dbd686c1488b3e98eb9c5ed15ff504b22dce8bc1589c9a557f511dcb"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-02e665cc90a63f1a040b4e5c8acfc2ec9d8f3ebfdcd4947b1349494bc13618aa.json b/rust/cloud-storage/chat/.sqlx/query-02e665cc90a63f1a040b4e5c8acfc2ec9d8f3ebfdcd4947b1349494bc13618aa.json
new file mode 100644
index 0000000000..f44cdbac14
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-02e665cc90a63f1a040b4e5c8acfc2ec9d8f3ebfdcd4947b1349494bc13618aa.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM\n in_progress_user_link\n WHERE\n created_at < $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Timestamp"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "02e665cc90a63f1a040b4e5c8acfc2ec9d8f3ebfdcd4947b1349494bc13618aa"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-030974957f30c1fc16d1a6bed0ffc3dcd6d71b2c0029f7f7fa3ef3285e12a8f5.json b/rust/cloud-storage/chat/.sqlx/query-030974957f30c1fc16d1a6bed0ffc3dcd6d71b2c0029f7f7fa3ef3285e12a8f5.json
new file mode 100644
index 0000000000..7cbe7bbe84
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-030974957f30c1fc16d1a6bed0ffc3dcd6d71b2c0029f7f7fa3ef3285e12a8f5.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"UserHistory\" WHERE \"itemId\" = ANY($1)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "030974957f30c1fc16d1a6bed0ffc3dcd6d71b2c0029f7f7fa3ef3285e12a8f5"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-033759a1748c41359a8cf5204f457eed63182d21b432b58fd25b7524d1dc0092.json b/rust/cloud-storage/chat/.sqlx/query-033759a1748c41359a8cf5204f457eed63182d21b432b58fd25b7524d1dc0092.json
new file mode 100644
index 0000000000..8e2e7ae90a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-033759a1748c41359a8cf5204f457eed63182d21b432b58fd25b7524d1dc0092.json
@@ -0,0 +1,87 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id as document_id,\n d.owner as owner,\n d.name as document_name,\n COALESCE(db.id, di.id) as \"document_version_id!\",\n d.\"fileType\" as \"file_type?\",\n d.\"createdAt\"::timestamptz as created_at,\n d.\"updatedAt\"::timestamptz as updated_at,\n d.\"projectId\" as \"project_id?\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n CASE \n WHEN dt.sub_type = 'task' \n AND ep_status.values->'value' ? $2\n THEN true \n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL \n END as \"is_completed\"\n FROM\n \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status \n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id \n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $3\n LEFT JOIN LATERAL (\n SELECT\n b.id\n FROM\n \"DocumentBom\" b\n WHERE\n b.\"documentId\" = d.id\n ORDER BY\n b.\"createdAt\" DESC\n LIMIT 1\n ) db ON d.\"fileType\" = 'docx'\n LEFT JOIN LATERAL (\n SELECT\n i.id,\n i.\"documentId\",\n i.\"createdAt\",\n i.\"updatedAt\"\n FROM\n \"DocumentInstance\" i\n WHERE\n i.\"documentId\" = d.id\n ORDER BY\n i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON d.\"fileType\" IS DISTINCT FROM 'docx'\n WHERE d.\"projectId\" = $1 AND d.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "document_version_id!",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 4,
+ "name": "file_type?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "project_id?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 8,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 9,
+ "name": "is_completed",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ null,
+ true,
+ null,
+ null,
+ true,
+ false,
+ null
+ ]
+ },
+ "hash": "033759a1748c41359a8cf5204f457eed63182d21b432b58fd25b7524d1dc0092"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0392a509a0896bd3acc01964a39a4477aeafb381e532657ccb7b11ad05b9038e.json b/rust/cloud-storage/chat/.sqlx/query-0392a509a0896bd3acc01964a39a4477aeafb381e532657ccb7b11ad05b9038e.json
new file mode 100644
index 0000000000..c99a6a2f83
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0392a509a0896bd3acc01964a39a4477aeafb381e532657ccb7b11ad05b9038e.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id\n FROM\n \"Document\" d\n WHERE\n d.id = ANY($1)\n AND d.\"fileType\" = ANY($2)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "0392a509a0896bd3acc01964a39a4477aeafb381e532657ccb7b11ad05b9038e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-050acec4f32b8d9f7e8489a67d626819f39a33f91b635c369e219213afe37668.json b/rust/cloud-storage/chat/.sqlx/query-050acec4f32b8d9f7e8489a67d626819f39a33f91b635c369e219213afe37668.json
new file mode 100644
index 0000000000..4417c165f6
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-050acec4f32b8d9f7e8489a67d626819f39a33f91b635c369e219213afe37668.json
@@ -0,0 +1,45 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT team_id, email, team_role as \"team_role!: models_team::TeamRole\"\n FROM team_invite \n WHERE id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "team_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "email",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "team_role!: models_team::TeamRole",
+ "type_info": {
+ "Custom": {
+ "name": "team_role",
+ "kind": {
+ "Enum": [
+ "member",
+ "admin",
+ "owner"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "050acec4f32b8d9f7e8489a67d626819f39a33f91b635c369e219213afe37668"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-062a45b8e7d65006120b1369981c4e04e513e99855ca9dab076768d43e189a80.json b/rust/cloud-storage/chat/.sqlx/query-062a45b8e7d65006120b1369981c4e04e513e99855ca9dab076768d43e189a80.json
new file mode 100644
index 0000000000..22a0249ea8
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-062a45b8e7d65006120b1369981c4e04e513e99855ca9dab076768d43e189a80.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"ChatMessage\" (\"id\", \"chatId\", \"content\", \"role\", \"model\", \"createdAt\", \"updatedAt\")\n VALUES ($1, $2, $3, $4, $5, $6, $7)\n RETURNING id;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Jsonb",
+ "Text",
+ "Text",
+ "Timestamp",
+ "Timestamp"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "062a45b8e7d65006120b1369981c4e04e513e99855ca9dab076768d43e189a80"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-064772b7d3d47e82f044f6efd03f52f8cc0083e99d30810753539a5df539d94d.json b/rust/cloud-storage/chat/.sqlx/query-064772b7d3d47e82f044f6efd03f52f8cc0083e99d30810753539a5df539d94d.json
new file mode 100644
index 0000000000..0f25e57f4c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-064772b7d3d47e82f044f6efd03f52f8cc0083e99d30810753539a5df539d94d.json
@@ -0,0 +1,26 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"Document\" (owner, name, \"fileType\", \"projectId\", \"createdAt\", \"updatedAt\") \n VALUES ($1, $2, $3, $4, $5, $5)\n RETURNING id;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Text",
+ "Text",
+ "Timestamp"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "064772b7d3d47e82f044f6efd03f52f8cc0083e99d30810753539a5df539d94d"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-06a72bfcfbcc5f5bbed6cd093436309607f9375d2ba7b151e9dc1a8493f88e44.json b/rust/cloud-storage/chat/.sqlx/query-06a72bfcfbcc5f5bbed6cd093436309607f9375d2ba7b151e9dc1a8493f88e44.json
new file mode 100644
index 0000000000..4c5afc274a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-06a72bfcfbcc5f5bbed6cd093436309607f9375d2ba7b151e9dc1a8493f88e44.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM notification_user_device_registration\n WHERE device_endpoint = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "06a72bfcfbcc5f5bbed6cd093436309607f9375d2ba7b151e9dc1a8493f88e44"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-07436aee1f392392f500a116348f388ce48e6b8c596f420af1c837cf9572dcdb.json b/rust/cloud-storage/chat/.sqlx/query-07436aee1f392392f500a116348f388ce48e6b8c596f420af1c837cf9572dcdb.json
new file mode 100644
index 0000000000..80fe803c31
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-07436aee1f392392f500a116348f388ce48e6b8c596f420af1c837cf9572dcdb.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n select name from \"Project\" where id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "name",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "07436aee1f392392f500a116348f388ce48e6b8c596f420af1c837cf9572dcdb"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-077c58347457c72a7f69ff716d27e07c1a4f41d65b619f6f949f18344b78469e.json b/rust/cloud-storage/chat/.sqlx/query-077c58347457c72a7f69ff716d27e07c1a4f41d65b619f6f949f18344b78469e.json
new file mode 100644
index 0000000000..7b6dd846ac
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-077c58347457c72a7f69ff716d27e07c1a4f41d65b619f6f949f18344b78469e.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"DocumentBom\" (\"documentId\")\n VALUES ($1)\n RETURNING id;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "077c58347457c72a7f69ff716d27e07c1a4f41d65b619f6f949f18344b78469e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-07831ac2c19539d4422c940e56add36cfd36e05ad43cfa0cea3654dd0d5ca08a.json b/rust/cloud-storage/chat/.sqlx/query-07831ac2c19539d4422c940e56add36cfd36e05ad43cfa0cea3654dd0d5ca08a.json
new file mode 100644
index 0000000000..46a9e1a12d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-07831ac2c19539d4422c940e56add36cfd36e05ad43cfa0cea3654dd0d5ca08a.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"Chat\"\n WHERE id = $1",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "07831ac2c19539d4422c940e56add36cfd36e05ad43cfa0cea3654dd0d5ca08a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-07c340da8c4771fa651aee608e8b7d15d9f0a638566899c59aae12491ed5b490.json b/rust/cloud-storage/chat/.sqlx/query-07c340da8c4771fa651aee608e8b7d15d9f0a638566899c59aae12491ed5b490.json
new file mode 100644
index 0000000000..4d5b220144
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-07c340da8c4771fa651aee608e8b7d15d9f0a638566899c59aae12491ed5b490.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"Comment\" (\"threadId\", \"owner\", \"sender\", \"text\", \"createdAt\", \"updatedAt\", \"order\")\n VALUES ($1, $2, $3, $4, $5, $6, $7)\n RETURNING id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Text",
+ "Text",
+ "Text",
+ "Timestamp",
+ "Timestamp",
+ "Int4"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "07c340da8c4771fa651aee608e8b7d15d9f0a638566899c59aae12491ed5b490"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0876e7623feb7c8f77b58716cbe3e43456fefad97ac0ba38daf2e5e6880bb51b.json b/rust/cloud-storage/chat/.sqlx/query-0876e7623feb7c8f77b58716cbe3e43456fefad97ac0ba38daf2e5e6880bb51b.json
new file mode 100644
index 0000000000..10cdcda76b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0876e7623feb7c8f77b58716cbe3e43456fefad97ac0ba38daf2e5e6880bb51b.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "UPDATE \"Project\" SET \"parentId\"=$2 WHERE \"id\"=$1",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "0876e7623feb7c8f77b58716cbe3e43456fefad97ac0ba38daf2e5e6880bb51b"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-08896a23d1261be751853b5cf7553cbe0e8500e8f47233914c020d23d5a1b1b6.json b/rust/cloud-storage/chat/.sqlx/query-08896a23d1261be751853b5cf7553cbe0e8500e8f47233914c020d23d5a1b1b6.json
new file mode 100644
index 0000000000..a5f92f9ded
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-08896a23d1261be751853b5cf7553cbe0e8500e8f47233914c020d23d5a1b1b6.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"PdfHighlightAnchor\" (\n \"uuid\", \"documentId\", \"owner\", \"threadId\", \"page\", \"red\", \"green\", \"blue\", \n \"alpha\", \"type\", \"text\", \"pageViewportWidth\", \"pageViewportHeight\"\n ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)\n RETURNING uuid\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "uuid",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text",
+ "Int8",
+ "Int4",
+ "Int4",
+ "Int4",
+ "Int4",
+ "Float8",
+ "Int4",
+ "Text",
+ "Float8",
+ "Float8"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "08896a23d1261be751853b5cf7553cbe0e8500e8f47233914c020d23d5a1b1b6"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0953e38705bd80cf1f053c5287847c2a92639fec6e728a49b1f2a41906adb633.json b/rust/cloud-storage/chat/.sqlx/query-0953e38705bd80cf1f053c5287847c2a92639fec6e728a49b1f2a41906adb633.json
new file mode 100644
index 0000000000..ada738a350
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0953e38705bd80cf1f053c5287847c2a92639fec6e728a49b1f2a41906adb633.json
@@ -0,0 +1,26 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"Thread\" (\"owner\", \"documentId\", \"createdAt\", \"updatedAt\", \"resolved\")\n VALUES ($1, $2, $3, $4, $5)\n RETURNING id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Timestamp",
+ "Timestamp",
+ "Bool"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "0953e38705bd80cf1f053c5287847c2a92639fec6e728a49b1f2a41906adb633"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-09dd0c12a8b30ba045caacad3927e6d7edfba61d784244a01f9d233d9b753dcb.json b/rust/cloud-storage/chat/.sqlx/query-09dd0c12a8b30ba045caacad3927e6d7edfba61d784244a01f9d233d9b753dcb.json
new file mode 100644
index 0000000000..6e8e4fde00
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-09dd0c12a8b30ba045caacad3927e6d7edfba61d784244a01f9d233d9b753dcb.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n rop.\"permissionId\" as permission_id\n FROM \"User\" u\n JOIN \"RolesOnUsers\" ru ON ru.\"userId\" = u.id\n JOIN \"RolesOnPermissions\" rop ON rop.\"roleId\" = ru.\"roleId\"\n WHERE u.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "permission_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "09dd0c12a8b30ba045caacad3927e6d7edfba61d784244a01f9d233d9b753dcb"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-09f6737b4e22a31ee50c69992a0f16140eb27339ca118ef7a6f063e113d78361.json b/rust/cloud-storage/chat/.sqlx/query-09f6737b4e22a31ee50c69992a0f16140eb27339ca118ef7a6f063e113d78361.json
new file mode 100644
index 0000000000..097d5e8c23
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-09f6737b4e22a31ee50c69992a0f16140eb27339ca118ef7a6f063e113d78361.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"RolesOnUsers\" WHERE \"userId\" = $1 AND \"roleId\" = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "09f6737b4e22a31ee50c69992a0f16140eb27339ca118ef7a6f063e113d78361"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0a09ebd68d563695e964576ff60f6a415013c83185c3c325f6b82f44877c8465.json b/rust/cloud-storage/chat/.sqlx/query-0a09ebd68d563695e964576ff60f6a415013c83185c3c325f6b82f44877c8465.json
deleted file mode 100644
index 8d162160b9..0000000000
--- a/rust/cloud-storage/chat/.sqlx/query-0a09ebd68d563695e964576ff60f6a415013c83185c3c325f6b82f44877c8465.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT \"access_level\"::text\n FROM \"UserItemAccess\"\n WHERE \"user_id\" = $1 AND \"item_id\" = $2 AND \"item_type\" = 'chat'\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "access_level",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text"
- ]
- },
- "nullable": [
- null
- ]
- },
- "hash": "0a09ebd68d563695e964576ff60f6a415013c83185c3c325f6b82f44877c8465"
-}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0a1f3835d8dd57e120b0378134d98858f2ba5ed410765ffca1b03abb05c7b098.json b/rust/cloud-storage/chat/.sqlx/query-0a1f3835d8dd57e120b0378134d98858f2ba5ed410765ffca1b03abb05c7b098.json
new file mode 100644
index 0000000000..a13e3d6b24
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0a1f3835d8dd57e120b0378134d98858f2ba5ed410765ffca1b03abb05c7b098.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM\n in_progress_user_link\n WHERE\n id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "0a1f3835d8dd57e120b0378134d98858f2ba5ed410765ffca1b03abb05c7b098"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0a5d8edd85634f5ecdc0a97f86e470a4e91ef06ee2baf734cacc500df5f9cd19.json b/rust/cloud-storage/chat/.sqlx/query-0a5d8edd85634f5ecdc0a97f86e470a4e91ef06ee2baf734cacc500df5f9cd19.json
new file mode 100644
index 0000000000..7959c797e7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0a5d8edd85634f5ecdc0a97f86e470a4e91ef06ee2baf734cacc500df5f9cd19.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "SELECT \"id\" as user_id, \"organizationId\" as \"organization_id?\" FROM \"User\" WHERE \"email\" = $1",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "organization_id?",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ true
+ ]
+ },
+ "hash": "0a5d8edd85634f5ecdc0a97f86e470a4e91ef06ee2baf734cacc500df5f9cd19"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0a98076ae0ee8aa572e7a73b97a4c7fb8a88979a966df92c698b295b8e3e28e0.json b/rust/cloud-storage/chat/.sqlx/query-0a98076ae0ee8aa572e7a73b97a4c7fb8a88979a966df92c698b295b8e3e28e0.json
new file mode 100644
index 0000000000..af279318b7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0a98076ae0ee8aa572e7a73b97a4c7fb8a88979a966df92c698b295b8e3e28e0.json
@@ -0,0 +1,40 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.id as chat_id,\n c.name as chat_name,\n c.\"userId\" as owner,\n c.\"updatedAt\"::timestamptz as \"updated_at\"\n FROM\n \"Chat\" c\n WHERE\n c.\"id\" = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "chat_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "chat_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ null
+ ]
+ },
+ "hash": "0a98076ae0ee8aa572e7a73b97a4c7fb8a88979a966df92c698b295b8e3e28e0"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0af2bfac1a41e4dbd3c7956d306ffab02e9aee53b37e07531426a068007403ec.json b/rust/cloud-storage/chat/.sqlx/query-0af2bfac1a41e4dbd3c7956d306ffab02e9aee53b37e07531426a068007403ec.json
new file mode 100644
index 0000000000..a247c24f9c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0af2bfac1a41e4dbd3c7956d306ffab02e9aee53b37e07531426a068007403ec.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT l.macro_id\n FROM email_threads t\n JOIN email_links l ON t.link_id = l.id\n WHERE t.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "macro_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "0af2bfac1a41e4dbd3c7956d306ffab02e9aee53b37e07531426a068007403ec"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0b3832a8e650ed74622bbe8ceeb7ead8ceb0d4f0d05e22c9e36113b4cba6e5c3.json b/rust/cloud-storage/chat/.sqlx/query-0b3832a8e650ed74622bbe8ceeb7ead8ceb0d4f0d05e22c9e36113b4cba6e5c3.json
new file mode 100644
index 0000000000..5650ce2d29
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0b3832a8e650ed74622bbe8ceeb7ead8ceb0d4f0d05e22c9e36113b4cba6e5c3.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"BlockedEmail\" (email)\n VALUES ($1)\n ON CONFLICT (email) DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "0b3832a8e650ed74622bbe8ceeb7ead8ceb0d4f0d05e22c9e36113b4cba6e5c3"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0bc2a0143c7f09e18223dc04ab8ed7052f7c7587ec002e1716ada1ccd58db8dc.json b/rust/cloud-storage/chat/.sqlx/query-0bc2a0143c7f09e18223dc04ab8ed7052f7c7587ec002e1716ada1ccd58db8dc.json
new file mode 100644
index 0000000000..6e77af4fb4
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0bc2a0143c7f09e18223dc04ab8ed7052f7c7587ec002e1716ada1ccd58db8dc.json
@@ -0,0 +1,71 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id,\n channel_id,\n sender_id,\n content,\n created_at,\n updated_at,\n thread_id,\n edited_at as \"edited_at: chrono::DateTime<chrono::Utc>\",\n deleted_at as \"deleted_at: chrono::DateTime<chrono::Utc>\"\n FROM comms_messages\n WHERE channel_id = (SELECT channel_id FROM comms_messages WHERE id=$1)\n AND\n created_at > (SELECT created_at FROM comms_messages WHERE id=$1)\n ORDER BY created_at ASC\n LIMIT $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "channel_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "sender_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "content",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "thread_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 7,
+ "name": "edited_at: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true,
+ true
+ ]
+ },
+ "hash": "0bc2a0143c7f09e18223dc04ab8ed7052f7c7587ec002e1716ada1ccd58db8dc"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0be9d386d51f355d6c5ab947fe7ed534f7cf96c18081846fcbfbefa0a515f40b.json b/rust/cloud-storage/chat/.sqlx/query-0be9d386d51f355d6c5ab947fe7ed534f7cf96c18081846fcbfbefa0a515f40b.json
new file mode 100644
index 0000000000..e5a541e2c7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0be9d386d51f355d6c5ab947fe7ed534f7cf96c18081846fcbfbefa0a515f40b.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id\n FROM account_merge_request\n WHERE to_merge_macro_user_id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "0be9d386d51f355d6c5ab947fe7ed534f7cf96c18081846fcbfbefa0a515f40b"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0be9fe66d98f68b1d1c3c8f32aef0da52521889a32fce2449d9d7f659835b845.json b/rust/cloud-storage/chat/.sqlx/query-0be9fe66d98f68b1d1c3c8f32aef0da52521889a32fce2449d9d7f659835b845.json
new file mode 100644
index 0000000000..78432bc971
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0be9fe66d98f68b1d1c3c8f32aef0da52521889a32fce2449d9d7f659835b845.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"UserHistory\" \n WHERE \"itemId\" = ANY($1) AND \"itemType\" = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "0be9fe66d98f68b1d1c3c8f32aef0da52521889a32fce2449d9d7f659835b845"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d.json b/rust/cloud-storage/chat/.sqlx/query-0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d.json
new file mode 100644
index 0000000000..99a3b6f452
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id FROM (\n -- Direct user grants\n SELECT source_id as user_id FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'user'\n\n UNION ALL\n\n -- Channel Members\n SELECT cp.user_id FROM comms_channel_participants cp\n WHERE cp.left_at IS NULL AND cp.channel_id IN (\n SELECT source_id::uuid FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'channel'\n )\n\n UNION ALL\n\n -- Team Members\n SELECT tu.user_id FROM team_user tu\n WHERE tu.team_id IN (\n SELECT source_id::uuid FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'team'\n )\n )\n \n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0c129eab69121fd65994c0b50a11f653900045b70bc059b5126905e3cca668fe.json b/rust/cloud-storage/chat/.sqlx/query-0c129eab69121fd65994c0b50a11f653900045b70bc059b5126905e3cca668fe.json
new file mode 100644
index 0000000000..b06c45ada8
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0c129eab69121fd65994c0b50a11f653900045b70bc059b5126905e3cca668fe.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"PdfHighlightAnchor\"\n SET \"threadId\" = NULL\n WHERE uuid = $1 AND \"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "0c129eab69121fd65994c0b50a11f653900045b70bc059b5126905e3cca668fe"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0c36658e4c00abbd672fd1fa7934cb81f5065482c471fffa2bf248f73782a87c.json b/rust/cloud-storage/chat/.sqlx/query-0c36658e4c00abbd672fd1fa7934cb81f5065482c471fffa2bf248f73782a87c.json
new file mode 100644
index 0000000000..75d11599e7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0c36658e4c00abbd672fd1fa7934cb81f5065482c471fffa2bf248f73782a87c.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "SELECT \"userId\" as user_id, \"deletedAt\" as deleted_at FROM \"Chat\" WHERE id=$1",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "deleted_at",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ true
+ ]
+ },
+ "hash": "0c36658e4c00abbd672fd1fa7934cb81f5065482c471fffa2bf248f73782a87c"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0c3bf4ab99e5ef1c2100c82611aeaf4fe7ffe5734a57567dfdfea1a78cfbb3ee.json b/rust/cloud-storage/chat/.sqlx/query-0c3bf4ab99e5ef1c2100c82611aeaf4fe7ffe5734a57567dfdfea1a78cfbb3ee.json
new file mode 100644
index 0000000000..f6f9d3a7c1
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0c3bf4ab99e5ef1c2100c82611aeaf4fe7ffe5734a57567dfdfea1a78cfbb3ee.json
@@ -0,0 +1,65 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n p.\"id\" as \"item_id!\",\n p.\"createdAt\" as \"created_at!\",\n p.\"updatedAt\" as \"updated_at!\",\n p.\"deletedAt\" as \"deleted_at?\",\n p.\"parentId\" as \"parent_project_id?\",\n uh.\"updatedAt\" as \"viewed_at?\",\n p.\"userId\" as \"user_id\",\n p.\"name\"\n FROM\n \"Project\" p\n LEFT JOIN\n \"UserHistory\" uh ON uh.\"itemId\" = p.\"id\"\n AND uh.\"userId\" = $1\n AND uh.\"itemType\" = 'project'\n WHERE\n p.\"id\" = ANY($2)\n ORDER BY\n p.\"updatedAt\" DESC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "created_at!",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 2,
+ "name": "updated_at!",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 3,
+ "name": "deleted_at?",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 4,
+ "name": "parent_project_id?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "viewed_at?",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 6,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 7,
+ "name": "name",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ true,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "0c3bf4ab99e5ef1c2100c82611aeaf4fe7ffe5734a57567dfdfea1a78cfbb3ee"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0c59340d688c2132886f2fb765d3a9843931e9bb4006a4b10588e3eb32ed49c0.json b/rust/cloud-storage/chat/.sqlx/query-0c59340d688c2132886f2fb765d3a9843931e9bb4006a4b10588e3eb32ed49c0.json
new file mode 100644
index 0000000000..e1bbae2e1a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0c59340d688c2132886f2fb765d3a9843931e9bb4006a4b10588e3eb32ed49c0.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE comms_channels\n SET updated_at = $2 \n WHERE id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Timestamptz"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "0c59340d688c2132886f2fb765d3a9843931e9bb4006a4b10588e3eb32ed49c0"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0ca155b0063dd021a80db6b2a9dc2353c6a1dca9e1dc13cc21b3a23d9cd81e92.json b/rust/cloud-storage/chat/.sqlx/query-0ca155b0063dd021a80db6b2a9dc2353c6a1dca9e1dc13cc21b3a23d9cd81e92.json
new file mode 100644
index 0000000000..40abab49c5
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0ca155b0063dd021a80db6b2a9dc2353c6a1dca9e1dc13cc21b3a23d9cd81e92.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "DELETE FROM \"OrganizationInvitation\" WHERE organization_id = $1 AND email = $2",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Int4",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "0ca155b0063dd021a80db6b2a9dc2353c6a1dca9e1dc13cc21b3a23d9cd81e92"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0d38256b23e9ce70797726f76b49889efcf4b3c2fbaec05c395de5e728b0fdbb.json b/rust/cloud-storage/chat/.sqlx/query-0d38256b23e9ce70797726f76b49889efcf4b3c2fbaec05c395de5e728b0fdbb.json
new file mode 100644
index 0000000000..a3ceebc60d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0d38256b23e9ce70797726f76b49889efcf4b3c2fbaec05c395de5e728b0fdbb.json
@@ -0,0 +1,46 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n sp.id as id,\n sp.\"isPublic\" as is_public,\n sp.\"publicAccessLevel\" as \"public_access_level?\",\n c.\"userId\" as owner,\n COALESCE(\n json_agg(json_build_object(\n 'channel_id', csp.\"channel_id\",\n 'access_level', csp.\"access_level\"\n )) FILTER (WHERE csp.\"channel_id\" IS NOT NULL),\n '[]'\n ) as \"channel_share_permissions?\"\n FROM\n \"ChatPermission\" cp\n JOIN \"SharePermission\" sp ON cp.\"sharePermissionId\" = sp.id\n JOIN \"Chat\" c ON cp.\"chatId\" = c.id\n LEFT JOIN \"ChannelSharePermission\" csp ON csp.\"share_permission_id\" = sp.id\n WHERE\n cp.\"chatId\" = $1\n GROUP BY\n sp.id, c.\"userId\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "is_public",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 2,
+ "name": "public_access_level?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "channel_share_permissions?",
+ "type_info": "Json"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ true,
+ false,
+ null
+ ]
+ },
+ "hash": "0d38256b23e9ce70797726f76b49889efcf4b3c2fbaec05c395de5e728b0fdbb"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0da786be8ae29e36cd110a8875d838e3b6b8cf4bd6775d083867c733982545dd.json b/rust/cloud-storage/chat/.sqlx/query-0da786be8ae29e36cd110a8875d838e3b6b8cf4bd6775d083867c733982545dd.json
new file mode 100644
index 0000000000..e635006372
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0da786be8ae29e36cd110a8875d838e3b6b8cf4bd6775d083867c733982545dd.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Document\" SET \"deletedAt\" = $2 WHERE id = ANY($1);\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "Timestamp"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "0da786be8ae29e36cd110a8875d838e3b6b8cf4bd6775d083867c733982545dd"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0db3bbe78101fc309c3358271240926ee07c36bf29ff0031813a2fdbe1fd061d.json b/rust/cloud-storage/chat/.sqlx/query-0db3bbe78101fc309c3358271240926ee07c36bf29ff0031813a2fdbe1fd061d.json
new file mode 100644
index 0000000000..faedc95f8b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0db3bbe78101fc309c3358271240926ee07c36bf29ff0031813a2fdbe1fd061d.json
@@ -0,0 +1,46 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n sp.id as id,\n sp.\"isPublic\" as is_public,\n sp.\"publicAccessLevel\" as \"public_access_level?\",\n d.\"owner\" as owner,\n COALESCE(\n json_agg(json_build_object(\n 'channel_id', csp.\"channel_id\",\n 'access_level', csp.\"access_level\"\n )) FILTER (WHERE csp.\"channel_id\" IS NOT NULL),\n '[]'\n ) as \"channel_share_permissions?\"\n FROM\n \"DocumentPermission\" dp\n JOIN \"SharePermission\" sp ON dp.\"sharePermissionId\" = sp.id\n JOIN \"Document\" d ON dp.\"documentId\" = d.id\n LEFT JOIN \"ChannelSharePermission\" csp ON csp.\"share_permission_id\" = sp.id\n WHERE\n dp.\"documentId\" = $1\n GROUP BY\n sp.id, d.\"owner\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "is_public",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 2,
+ "name": "public_access_level?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "channel_share_permissions?",
+ "type_info": "Json"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ true,
+ false,
+ null
+ ]
+ },
+ "hash": "0db3bbe78101fc309c3358271240926ee07c36bf29ff0031813a2fdbe1fd061d"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0dcbb3a5c0829e285170d8e43e6a6d1246298aa1fc06aba34a9282318841a112.json b/rust/cloud-storage/chat/.sqlx/query-0dcbb3a5c0829e285170d8e43e6a6d1246298aa1fc06aba34a9282318841a112.json
new file mode 100644
index 0000000000..5d46bae2e6
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0dcbb3a5c0829e285170d8e43e6a6d1246298aa1fc06aba34a9282318841a112.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n u.id as user_profile_id, \n mu.id as macro_user_id\n FROM macro_user mu\n JOIN \"User\" u ON mu.id = u.macro_user_id\n WHERE u.id = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_profile_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "macro_user_id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "0dcbb3a5c0829e285170d8e43e6a6d1246298aa1fc06aba34a9282318841a112"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0dd403bdd3475dfb010d5a725be35e76750719785a26e4c56e969fd48c5970b3.json b/rust/cloud-storage/chat/.sqlx/query-0dd403bdd3475dfb010d5a725be35e76750719785a26e4c56e969fd48c5970b3.json
new file mode 100644
index 0000000000..63fcd51931
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0dd403bdd3475dfb010d5a725be35e76750719785a26e4c56e969fd48c5970b3.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH RECURSIVE project_hierarchy AS (\n SELECT\n p.id,\n p.\"userId\" as user_id\n FROM \"Project\" p\n WHERE p.id = $1 AND p.\"deletedAt\" IS NOT NULL\n UNION ALL\n SELECT\n sub_p.id,\n sub_p.\"userId\" as user_id\n FROM \"Project\" sub_p\n INNER JOIN project_hierarchy ph ON sub_p.\"parentId\" = ph.id\n WHERE sub_p.\"deletedAt\" IS NOT NULL\n )\n SELECT\n ph.id as \"id!\",\n ph.user_id as \"user_id!\"\n FROM project_hierarchy ph\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "user_id!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null,
+ null
+ ]
+ },
+ "hash": "0dd403bdd3475dfb010d5a725be35e76750719785a26e4c56e969fd48c5970b3"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0dde9799979e5ae1b4e351a2b8c310950db972cfe6afdf164f822a6b0a6042b8.json b/rust/cloud-storage/chat/.sqlx/query-0dde9799979e5ae1b4e351a2b8c310950db972cfe6afdf164f822a6b0a6042b8.json
new file mode 100644
index 0000000000..ba7d99d7d2
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0dde9799979e5ae1b4e351a2b8c310950db972cfe6afdf164f822a6b0a6042b8.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT a.uuid, a.\"createdAt\" as created_at, a.\"updatedAt\" as updated_at\n FROM \"PdfHighlightAnchor\" a\n WHERE a.\"documentId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "created_at",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 2,
+ "name": "updated_at",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "0dde9799979e5ae1b4e351a2b8c310950db972cfe6afdf164f822a6b0a6042b8"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0eb23959e5def969cff31c097382390a0e9214d8219a3d79f65ea5c66d55121e.json b/rust/cloud-storage/chat/.sqlx/query-0eb23959e5def969cff31c097382390a0e9214d8219a3d79f65ea5c66d55121e.json
new file mode 100644
index 0000000000..478db6e5e9
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0eb23959e5def969cff31c097382390a0e9214d8219a3d79f65ea5c66d55121e.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"DocumentText\" (\"documentId\", \"content\", \"tokenCount\")\n VALUES ($1, $2, $3)\n ON CONFLICT (\"documentId\")\n DO UPDATE SET \"content\" = EXCLUDED.\"content\", \"tokenCount\" = EXCLUDED.\"tokenCount\"\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Int8"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "0eb23959e5def969cff31c097382390a0e9214d8219a3d79f65ea5c66d55121e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0f06d44ac8984b12498f8b41e70d2e692c9a1bec3ec96cd3b2fba1176e075119.json b/rust/cloud-storage/chat/.sqlx/query-0f06d44ac8984b12498f8b41e70d2e692c9a1bec3ec96cd3b2fba1176e075119.json
new file mode 100644
index 0000000000..beba999012
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0f06d44ac8984b12498f8b41e70d2e692c9a1bec3ec96cd3b2fba1176e075119.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"roleId\" as id\n FROM \"RolesOnOrganizations\"\n WHERE \"organizationId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int4"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "0f06d44ac8984b12498f8b41e70d2e692c9a1bec3ec96cd3b2fba1176e075119"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0f180165e0d5d8661d2d9a37550c7372d1de26ee74b39b5e9602534174f1f8c5.json b/rust/cloud-storage/chat/.sqlx/query-0f180165e0d5d8661d2d9a37550c7372d1de26ee74b39b5e9602534174f1f8c5.json
new file mode 100644
index 0000000000..548cc4391e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0f180165e0d5d8661d2d9a37550c7372d1de26ee74b39b5e9602534174f1f8c5.json
@@ -0,0 +1,29 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id as \"chat_id\",\n \"userId\" as \"user_id\"\n FROM\n \"Chat\"\n WHERE\n \"deletedAt\" IS NULL\n ORDER BY\n \"createdAt\" DESC\n LIMIT $1\n OFFSET $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "chat_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "0f180165e0d5d8661d2d9a37550c7372d1de26ee74b39b5e9602534174f1f8c5"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0f48cffd910141d7b0d12f55311f30be2d8bb5808322565b29ce0a8db2bf3c14.json b/rust/cloud-storage/chat/.sqlx/query-0f48cffd910141d7b0d12f55311f30be2d8bb5808322565b29ce0a8db2bf3c14.json
new file mode 100644
index 0000000000..03287f8f3e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0f48cffd910141d7b0d12f55311f30be2d8bb5808322565b29ce0a8db2bf3c14.json
@@ -0,0 +1,20 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT COUNT(*) as \"count\"\n FROM \"Document\" d\n WHERE d.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "count",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": []
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "0f48cffd910141d7b0d12f55311f30be2d8bb5808322565b29ce0a8db2bf3c14"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-0fdbb7ee491e145c23b2e9a5b817eae0345b5e141e5909ee846c68a5cb3e12a1.json b/rust/cloud-storage/chat/.sqlx/query-0fdbb7ee491e145c23b2e9a5b817eae0345b5e141e5909ee846c68a5cb3e12a1.json
new file mode 100644
index 0000000000..9dd7d77d55
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-0fdbb7ee491e145c23b2e9a5b817eae0345b5e141e5909ee846c68a5cb3e12a1.json
@@ -0,0 +1,29 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)\n SELECT $1, $2, u.user_id, 'user', $3\n FROM UNNEST($4::text[]) as u(user_id)\n ON CONFLICT (entity_id, entity_type, source_id, source_type)\n WHERE granted_from_project_id IS NULL\n DO UPDATE SET access_level = EXCLUDED.access_level, updated_at = NOW()\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ {
+ "Custom": {
+ "name": "\"AccessLevel\"",
+ "kind": {
+ "Enum": [
+ "view",
+ "comment",
+ "edit",
+ "owner"
+ ]
+ }
+ }
+ },
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "0fdbb7ee491e145c23b2e9a5b817eae0345b5e141e5909ee846c68a5cb3e12a1"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-100d56e0bac5061aa9f43b50e065f04b372963a63e81918d061a0c0ffab89060.json b/rust/cloud-storage/chat/.sqlx/query-100d56e0bac5061aa9f43b50e065f04b372963a63e81918d061a0c0ffab89060.json
new file mode 100644
index 0000000000..53d34de890
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-100d56e0bac5061aa9f43b50e065f04b372963a63e81918d061a0c0ffab89060.json
@@ -0,0 +1,64 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n t.id as thread_id, \n t.resolved, \n t.\"documentId\" as document_id, \n t.\"createdAt\"::timestamptz as created_at, \n t.\"updatedAt\"::timestamptz as updated_at, \n t.\"deletedAt\"::timestamptz as deleted_at, \n t.metadata, \n t.owner\n FROM \"Thread\" t\n WHERE t.\"id\" = $1\n AND t.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "resolved",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 4,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "metadata",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 7,
+ "name": "owner",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ true,
+ false
+ ]
+ },
+ "hash": "100d56e0bac5061aa9f43b50e065f04b372963a63e81918d061a0c0ffab89060"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-11a723b710519837eb7643af73af6526dfa6bf93465f9c6708dc95e8237c1f51.json b/rust/cloud-storage/chat/.sqlx/query-11a723b710519837eb7643af73af6526dfa6bf93465f9c6708dc95e8237c1f51.json
new file mode 100644
index 0000000000..ce42810756
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-11a723b710519837eb7643af73af6526dfa6bf93465f9c6708dc95e8237c1f51.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"id\" FROM \"Document\" WHERE \"projectId\" = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "11a723b710519837eb7643af73af6526dfa6bf93465f9c6708dc95e8237c1f51"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-11ddfba613626f54d684c1399279df5c3364e8d3dfc0484cda469086991a64fd.json b/rust/cloud-storage/chat/.sqlx/query-11ddfba613626f54d684c1399279df5c3364e8d3dfc0484cda469086991a64fd.json
new file mode 100644
index 0000000000..f8c1b33c14
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-11ddfba613626f54d684c1399279df5c3364e8d3dfc0484cda469086991a64fd.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id as \"chat_id\"\n FROM\n \"Chat\"\n WHERE\n \"deletedAt\" IS NULL\n ORDER BY\n \"createdAt\" ASC\n LIMIT $1\n OFFSET $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "chat_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "11ddfba613626f54d684c1399279df5c3364e8d3dfc0484cda469086991a64fd"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1220fdf68c54c2bbb630bc32b642bccc39501f39821f5a5fac209930e6afd338.json b/rust/cloud-storage/chat/.sqlx/query-1220fdf68c54c2bbb630bc32b642bccc39501f39821f5a5fac209930e6afd338.json
new file mode 100644
index 0000000000..4c8372a82b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1220fdf68c54c2bbb630bc32b642bccc39501f39821f5a5fac209930e6afd338.json
@@ -0,0 +1,70 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Document\" SET \"updatedAt\" = NOW()\n WHERE id = $1\n RETURNING id as \"document_id\", owner, \"fileType\" as file_type, name as document_name,\n \"branchedFromId\" as branched_from_id, \"branchedFromVersionId\" as branched_from_version_id,\n \"documentFamilyId\" as document_family_id,\n \"projectId\" as project_id,\n \"deletedAt\"::timestamptz as \"deleted_at\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "document_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "branched_from_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "branched_from_version_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 6,
+ "name": "document_family_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 7,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ true,
+ false,
+ true,
+ true,
+ true,
+ true,
+ null
+ ]
+ },
+ "hash": "1220fdf68c54c2bbb630bc32b642bccc39501f39821f5a5fac209930e6afd338"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-12332b2ea487399f281dbdc5f7c0bddccfdff4da1d53fe8e16c26e825dbc1b14.json b/rust/cloud-storage/chat/.sqlx/query-12332b2ea487399f281dbdc5f7c0bddccfdff4da1d53fe8e16c26e825dbc1b14.json
new file mode 100644
index 0000000000..6720c10665
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-12332b2ea487399f281dbdc5f7c0bddccfdff4da1d53fe8e16c26e825dbc1b14.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"EmailThreadPermission\" (\"threadId\", \"sharePermissionId\", \"userId\")\n VALUES ($1, $2, $3)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "12332b2ea487399f281dbdc5f7c0bddccfdff4da1d53fe8e16c26e825dbc1b14"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-126bf3c6fc9b29a885703ecfab9a69bc36b7eeee011d09a63b4b44b81f7663df.json b/rust/cloud-storage/chat/.sqlx/query-126bf3c6fc9b29a885703ecfab9a69bc36b7eeee011d09a63b4b44b81f7663df.json
new file mode 100644
index 0000000000..23389bd286
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-126bf3c6fc9b29a885703ecfab9a69bc36b7eeee011d09a63b4b44b81f7663df.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM\n in_progress_email_link\n WHERE\n id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "126bf3c6fc9b29a885703ecfab9a69bc36b7eeee011d09a63b4b44b81f7663df"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-127b4b2d2391121a41b63f3ad116bea2be0329fccb27362d4e3a5a37601e0ba0.json b/rust/cloud-storage/chat/.sqlx/query-127b4b2d2391121a41b63f3ad116bea2be0329fccb27362d4e3a5a37601e0ba0.json
new file mode 100644
index 0000000000..14b2e4c2c3
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-127b4b2d2391121a41b63f3ad116bea2be0329fccb27362d4e3a5a37601e0ba0.json
@@ -0,0 +1,40 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT a.owner, a.\"threadId\" as thread_id, d.owner as document_owner, d.id as document_id\n FROM \"PdfHighlightAnchor\" a\n JOIN \"Document\" d ON a.\"documentId\" = d.id\n WHERE a.uuid = $1 AND a.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "document_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ true,
+ false,
+ false
+ ]
+ },
+ "hash": "127b4b2d2391121a41b63f3ad116bea2be0329fccb27362d4e3a5a37601e0ba0"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-13739c28aac5015e3bb881dbf24f0a657d995d9292dd6cffc385e2f92ec07276.json b/rust/cloud-storage/chat/.sqlx/query-13739c28aac5015e3bb881dbf24f0a657d995d9292dd6cffc385e2f92ec07276.json
new file mode 100644
index 0000000000..b1c2763d8b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-13739c28aac5015e3bb881dbf24f0a657d995d9292dd6cffc385e2f92ec07276.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH message_channel AS (\n SELECT channel_id FROM comms_messages WHERE id = $1\n ),\n mentions_to_insert AS (\n SELECT t.entity_type, t.entity_id\n FROM UNNEST($2::text[], $3::text[]) AS t(entity_type, entity_id)\n ),\n inserted_mentions AS (\n INSERT INTO comms_entity_mentions (id, source_entity_type, source_entity_id, entity_type, entity_id, user_id)\n SELECT gen_random_uuid(), 'message', $1::text, m.entity_type, m.entity_id, NULL\n FROM mentions_to_insert m\n WHERE NOT EXISTS (\n SELECT 1 FROM comms_entity_mentions em \n WHERE em.source_entity_type = 'message' \n AND em.source_entity_id = $1::text\n AND em.entity_type = m.entity_type \n AND em.entity_id = m.entity_id\n )\n )\n SELECT DISTINCT cp.user_id\n FROM mentions_to_insert m\n CROSS JOIN message_channel mc\n JOIN comms_channel_participants cp ON m.entity_id = cp.user_id\n WHERE m.entity_type = 'user'\n AND cp.channel_id = mc.channel_id\n AND cp.left_at IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "13739c28aac5015e3bb881dbf24f0a657d995d9292dd6cffc385e2f92ec07276"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1400e6024ad92e90369be284cd0ca35a4b9b6c1d70fb86dde1ec83a2314350d2.json b/rust/cloud-storage/chat/.sqlx/query-1400e6024ad92e90369be284cd0ca35a4b9b6c1d70fb86dde1ec83a2314350d2.json
new file mode 100644
index 0000000000..31173c10d4
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1400e6024ad92e90369be284cd0ca35a4b9b6c1d70fb86dde1ec83a2314350d2.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"macro_user_id\" as \"macro_user_id!\"\n FROM \"User\"\n WHERE \"email\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "macro_user_id!",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "1400e6024ad92e90369be284cd0ca35a4b9b6c1d70fb86dde1ec83a2314350d2"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-146fdea46a07193ea84051c9d3300b516be3f85d42ddeaf9cd9d0563e1303201.json b/rust/cloud-storage/chat/.sqlx/query-146fdea46a07193ea84051c9d3300b516be3f85d42ddeaf9cd9d0563e1303201.json
new file mode 100644
index 0000000000..660fdb55e4
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-146fdea46a07193ea84051c9d3300b516be3f85d42ddeaf9cd9d0563e1303201.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n t.id,\n t.name,\n t.owner_id\n FROM team t\n JOIN team_user tu ON t.id = tu.team_id\n WHERE tu.user_id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "146fdea46a07193ea84051c9d3300b516be3f85d42ddeaf9cd9d0563e1303201"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-14acfc516e4790908d6e9378281d30f55a71271945c03e98665acc3cc9d4ea4b.json b/rust/cloud-storage/chat/.sqlx/query-14acfc516e4790908d6e9378281d30f55a71271945c03e98665acc3cc9d4ea4b.json
new file mode 100644
index 0000000000..42b8e34c98
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-14acfc516e4790908d6e9378281d30f55a71271945c03e98665acc3cc9d4ea4b.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "SELECT \"organizationId\" as organization_id FROM \"User\" WHERE id = $1",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "organization_id",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "14acfc516e4790908d6e9378281d30f55a71271945c03e98665acc3cc9d4ea4b"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-14cb6f59ddb400c9539d83f42f665da8af863d2fd1ebf848a1a6e64db75a9ef2.json b/rust/cloud-storage/chat/.sqlx/query-14cb6f59ddb400c9539d83f42f665da8af863d2fd1ebf848a1a6e64db75a9ef2.json
new file mode 100644
index 0000000000..a952d834cc
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-14cb6f59ddb400c9539d83f42f665da8af863d2fd1ebf848a1a6e64db75a9ef2.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"stripeCustomerId\" as \"stripe_customer_id?\"\n FROM \"User\"\n WHERE \"id\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "stripe_customer_id?",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "14cb6f59ddb400c9539d83f42f665da8af863d2fd1ebf848a1a6e64db75a9ef2"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-152c4be0db7c3ecd7cf7ca77049231154b7f03ae0ebb073103df8b0554d416af.json b/rust/cloud-storage/chat/.sqlx/query-152c4be0db7c3ecd7cf7ca77049231154b7f03ae0ebb073103df8b0554d416af.json
new file mode 100644
index 0000000000..62daab76de
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-152c4be0db7c3ecd7cf7ca77049231154b7f03ae0ebb073103df8b0554d416af.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"User\"\n SET \"tutorialComplete\" = $1\n WHERE id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Bool",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "152c4be0db7c3ecd7cf7ca77049231154b7f03ae0ebb073103df8b0554d416af"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-166a1874072c2882aaca16d26b22a66944f723c32d9066d1d8b671b177986aa4.json b/rust/cloud-storage/chat/.sqlx/query-166a1874072c2882aaca16d26b22a66944f723c32d9066d1d8b671b177986aa4.json
new file mode 100644
index 0000000000..746d602d16
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-166a1874072c2882aaca16d26b22a66944f723c32d9066d1d8b671b177986aa4.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"organizationId\" as organization_id\n FROM \"OrganizationEmailMatches\"\n WHERE email = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "organization_id",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "166a1874072c2882aaca16d26b22a66944f723c32d9066d1d8b671b177986aa4"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-169914b00c5e4ced19940e170f8135d288553a7fdc41589e2211da4c32cead9a.json b/rust/cloud-storage/chat/.sqlx/query-169914b00c5e4ced19940e170f8135d288553a7fdc41589e2211da4c32cead9a.json
new file mode 100644
index 0000000000..0ff57465ef
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-169914b00c5e4ced19940e170f8135d288553a7fdc41589e2211da4c32cead9a.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH RECURSIVE project_hierarchy AS (\n SELECT\n p.id\n FROM \"Project\" p\n WHERE p.id = ANY($1) AND p.\"deletedAt\" IS NULL\n UNION ALL\n SELECT\n sub_p.id\n FROM \"Project\" sub_p\n INNER JOIN project_hierarchy ph ON sub_p.\"parentId\" = ph.id\n WHERE sub_p.\"deletedAt\" IS NULL\n )\n SELECT\n ph.id as \"id!\"\n FROM project_hierarchy ph\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "169914b00c5e4ced19940e170f8135d288553a7fdc41589e2211da4c32cead9a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-16da7cf038f35f49f83fc3a869f56da725bccb87d92dc3a2c4195a7b4c436a29.json b/rust/cloud-storage/chat/.sqlx/query-16da7cf038f35f49f83fc3a869f56da725bccb87d92dc3a2c4195a7b4c436a29.json
new file mode 100644
index 0000000000..45ffc5a866
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-16da7cf038f35f49f83fc3a869f56da725bccb87d92dc3a2c4195a7b4c436a29.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"documentId\" as \"document_id\"\n FROM \"InstructionsDocuments\" id\n JOIN \"Document\" d ON d.\"id\" = id.\"documentId\"\n WHERE \"userId\" = $1 AND d.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "16da7cf038f35f49f83fc3a869f56da725bccb87d92dc3a2c4195a7b4c436a29"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1720e22537ea916ca9c3ed5987b6ad4b8560ff21943acef9383cb92c46195d8e.json b/rust/cloud-storage/chat/.sqlx/query-1720e22537ea916ca9c3ed5987b6ad4b8560ff21943acef9383cb92c46195d8e.json
new file mode 100644
index 0000000000..54063b0e84
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1720e22537ea916ca9c3ed5987b6ad4b8560ff21943acef9383cb92c46195d8e.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT COUNT(*) as \"count\"\n FROM \"Document\"\n WHERE owner = $1 AND \"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "count",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "1720e22537ea916ca9c3ed5987b6ad4b8560ff21943acef9383cb92c46195d8e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1780a52d3024ae99105fd28c74121b9a3611ea3ae3bf5edccebda195b52bead2.json b/rust/cloud-storage/chat/.sqlx/query-1780a52d3024ae99105fd28c74121b9a3611ea3ae3bf5edccebda195b52bead2.json
new file mode 100644
index 0000000000..59dfc222e7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1780a52d3024ae99105fd28c74121b9a3611ea3ae3bf5edccebda195b52bead2.json
@@ -0,0 +1,40 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT e.id, e.active, e.\"started_at\"::timestamptz as started_at, e.\"ended_at\"::timestamptz as ended_at\n FROM \"Experiment\" e\n JOIN \"ExperimentLog\" el ON e.id = el.experiment_id\n WHERE el.user_id = $1 AND e.active = true\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "active",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 2,
+ "name": "started_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 3,
+ "name": "ended_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ null,
+ null
+ ]
+ },
+ "hash": "1780a52d3024ae99105fd28c74121b9a3611ea3ae3bf5edccebda195b52bead2"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-178aa765b997de754dd7405fc233aa7b24dd0a456f3cd4863725b3089f7bbe27.json b/rust/cloud-storage/chat/.sqlx/query-178aa765b997de754dd7405fc233aa7b24dd0a456f3cd4863725b3089f7bbe27.json
new file mode 100644
index 0000000000..98595cec9c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-178aa765b997de754dd7405fc233aa7b24dd0a456f3cd4863725b3089f7bbe27.json
@@ -0,0 +1,52 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n id, \n owner, \n text as content, \n \"createdAt\" as created_at, \n \"updatedAt\" as updated_at,\n \"order\"\n FROM \"Comment\" \n WHERE \"threadId\" = $1\n ORDER BY \"order\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "content",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 4,
+ "name": "updated_at",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 5,
+ "name": "order",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "178aa765b997de754dd7405fc233aa7b24dd0a456f3cd4863725b3089f7bbe27"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-18134bc97487fbf6b88e8afdb94dc601bf0d997ad5b6974ef5866dd6262b8618.json b/rust/cloud-storage/chat/.sqlx/query-18134bc97487fbf6b88e8afdb94dc601bf0d997ad5b6974ef5866dd6262b8618.json
new file mode 100644
index 0000000000..cbb754459e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-18134bc97487fbf6b88e8afdb94dc601bf0d997ad5b6974ef5866dd6262b8618.json
@@ -0,0 +1,31 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n -- Get all entities the user has access to via entity_access, filtered to requested items\n AllAccessGrants AS (\n -- Documents the user has access to\n SELECT ea.entity_id::text as item_id, ea.entity_type as item_type\n FROM entity_access ea\n LEFT JOIN \"Document\" d ON ea.entity_type = 'document' AND ea.entity_id::text = d.id\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n AND ea.entity_type = 'document'\n AND ea.entity_id::text = ANY($2)\n AND d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Chats the user has access to\n SELECT ea.entity_id::text as item_id, ea.entity_type as item_type\n FROM entity_access ea\n LEFT JOIN \"Chat\" c ON ea.entity_type = 'chat' AND ea.entity_id::text = c.id\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n AND ea.entity_type = 'chat'\n AND ea.entity_id::text = ANY($3)\n AND c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Projects the user has access to\n SELECT ea.entity_id::text as item_id, ea.entity_type as item_type\n FROM entity_access ea\n LEFT JOIN \"Project\" p ON ea.entity_type = 'project' AND ea.entity_id::text = p.id\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n AND ea.entity_type = 'project'\n AND ea.entity_id::text = ANY($4)\n AND p.\"deletedAt\" IS NULL\n ),\n UserAccessibleItems AS (\n SELECT\n item_id,\n item_type\n FROM AllAccessGrants\n GROUP BY item_id, item_type\n )\n SELECT item_id as \"item_id!\", item_type as \"item_type!\" FROM UserAccessibleItems\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "item_type!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray",
+ "TextArray",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ null,
+ null
+ ]
+ },
+ "hash": "18134bc97487fbf6b88e8afdb94dc601bf0d997ad5b6974ef5866dd6262b8618"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-18aac439d006f5d15299582df56f00790bde81c4e7a515e6cadbf341466b9fa8.json b/rust/cloud-storage/chat/.sqlx/query-18aac439d006f5d15299582df56f00790bde81c4e7a515e6cadbf341466b9fa8.json
new file mode 100644
index 0000000000..f542fc63f8
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-18aac439d006f5d15299582df56f00790bde81c4e7a515e6cadbf341466b9fa8.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n bp.sha\n FROM \"BomPart\" bp\n JOIN \"DocumentBom\" db ON bp.\"documentBomId\" = db.id\n WHERE db.\"documentId\" = $1\n AND db.id = (\n SELECT db_inner.id\n FROM \"DocumentBom\" db_inner\n WHERE db_inner.\"documentId\" = $1\n ORDER BY db_inner.\"updatedAt\" DESC\n LIMIT 1\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "sha",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "18aac439d006f5d15299582df56f00790bde81c4e7a515e6cadbf341466b9fa8"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-18d2885f4c7a6ffd835a5d661ec5e81dd143cd4a51873e92050a0beedbbb86cb.json b/rust/cloud-storage/chat/.sqlx/query-18d2885f4c7a6ffd835a5d661ec5e81dd143cd4a51873e92050a0beedbbb86cb.json
new file mode 100644
index 0000000000..6c17e2c89d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-18d2885f4c7a6ffd835a5d661ec5e81dd143cd4a51873e92050a0beedbbb86cb.json
@@ -0,0 +1,46 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n channel_id,\n share_permission_id,\n access_level as \"access_level: AccessLevel\"\n FROM\n \"ChannelSharePermission\"\n WHERE\n channel_id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "channel_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "share_permission_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "access_level: AccessLevel",
+ "type_info": {
+ "Custom": {
+ "name": "\"AccessLevel\"",
+ "kind": {
+ "Enum": [
+ "view",
+ "comment",
+ "edit",
+ "owner"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "18d2885f4c7a6ffd835a5d661ec5e81dd143cd4a51873e92050a0beedbbb86cb"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-18fc1de07e3dc64355b0baf69f67bd8c5254c63292c67e87ac3c3f45c20b7284.json b/rust/cloud-storage/chat/.sqlx/query-18fc1de07e3dc64355b0baf69f67bd8c5254c63292c67e87ac3c3f45c20b7284.json
new file mode 100644
index 0000000000..ff6c450bbb
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-18fc1de07e3dc64355b0baf69f67bd8c5254c63292c67e87ac3c3f45c20b7284.json
@@ -0,0 +1,127 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"PdfPlaceableCommentAnchor\" (\n \"uuid\", \"owner\", \"threadId\", \"page\", \"originalPage\", \"originalIndex\", \n \"xPct\", \"yPct\", \"widthPct\", \"heightPct\", \"allowableEdits\", \n \"wasEdited\", \"wasDeleted\", \"shouldLockOnSave\", \"documentId\", \"rotation\"\n ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)\n RETURNING \n uuid, \n \"documentId\" as document_id,\n owner, \n \"threadId\" as thread_id, \n page, \n \"originalPage\" as original_page, \n \"originalIndex\" as original_index, \n \"xPct\" as x_pct, \n \"yPct\" as y_pct, \n \"widthPct\" as width_pct, \n \"heightPct\" as height_pct, \n rotation,\n \"allowableEdits\" as allowable_edits, \n \"wasEdited\" as was_edited, \n \"wasDeleted\" as was_deleted, \n \"shouldLockOnSave\" as should_lock_on_save\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 4,
+ "name": "page",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 5,
+ "name": "original_page",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 6,
+ "name": "original_index",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 7,
+ "name": "x_pct",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 8,
+ "name": "y_pct",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 9,
+ "name": "width_pct",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 10,
+ "name": "height_pct",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 11,
+ "name": "rotation",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 12,
+ "name": "allowable_edits",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 13,
+ "name": "was_edited",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 14,
+ "name": "was_deleted",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 15,
+ "name": "should_lock_on_save",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Int8",
+ "Int4",
+ "Int4",
+ "Int4",
+ "Float8",
+ "Float8",
+ "Float8",
+ "Float8",
+ "Jsonb",
+ "Bool",
+ "Bool",
+ "Bool",
+ "Text",
+ "Float8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "18fc1de07e3dc64355b0baf69f67bd8c5254c63292c67e87ac3c3f45c20b7284"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-190452da4bb37a289c415dfbb4ec725bbda911931e97ccb22a5868b5a7655709.json b/rust/cloud-storage/chat/.sqlx/query-190452da4bb37a289c415dfbb4ec725bbda911931e97ccb22a5868b5a7655709.json
new file mode 100644
index 0000000000..1a46bafb16
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-190452da4bb37a289c415dfbb4ec725bbda911931e97ccb22a5868b5a7655709.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n u.\"id\" as id\n FROM \"Chat\" c\n INNER JOIN \"UserHistory\" uh ON uh.\"itemId\" = c.\"id\" AND uh.\"itemType\" = 'chat'\n INNER JOIN \"User\" u ON u.id = uh.\"userId\"\n WHERE c.id = $1 AND u.id != c.\"userId\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "190452da4bb37a289c415dfbb4ec725bbda911931e97ccb22a5868b5a7655709"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-19ad643d2447743fb58441e39654369eb50ac8efbea1fd554bdca3d7545d61e0.json b/rust/cloud-storage/chat/.sqlx/query-19ad643d2447743fb58441e39654369eb50ac8efbea1fd554bdca3d7545d61e0.json
new file mode 100644
index 0000000000..69c93d3037
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-19ad643d2447743fb58441e39654369eb50ac8efbea1fd554bdca3d7545d61e0.json
@@ -0,0 +1,25 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"Document\" (owner, name, \"fileType\", \"projectId\")\n VALUES ($1, $2, $3, $4)\n RETURNING id;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "19ad643d2447743fb58441e39654369eb50ac8efbea1fd554bdca3d7545d61e0"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1a5d33c55a52c7076f78b54e915e57fe675a43d9dd2d6198d1039565131d52f1.json b/rust/cloud-storage/chat/.sqlx/query-1a5d33c55a52c7076f78b54e915e57fe675a43d9dd2d6198d1039565131d52f1.json
new file mode 100644
index 0000000000..a67426e009
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1a5d33c55a52c7076f78b54e915e57fe675a43d9dd2d6198d1039565131d52f1.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT COUNT(*)\n FROM \"DocumentView\" dv\n WHERE dv.\"document_id\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "count",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "1a5d33c55a52c7076f78b54e915e57fe675a43d9dd2d6198d1039565131d52f1"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1b40eda58263b088d61f65897fdfe490653e4c1065cd55e9c39722b988c54a02.json b/rust/cloud-storage/chat/.sqlx/query-1b40eda58263b088d61f65897fdfe490653e4c1065cd55e9c39722b988c54a02.json
new file mode 100644
index 0000000000..bf7f89fe5e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1b40eda58263b088d61f65897fdfe490653e4c1065cd55e9c39722b988c54a02.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "DELETE FROM \"DocumentBom\" WHERE id = $2 and \"documentId\" = $1",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Int8"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "1b40eda58263b088d61f65897fdfe490653e4c1065cd55e9c39722b988c54a02"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1b50363c934ae7e01406a2cbb674b84fa6af6f7caa8353d52ed22e48b3899327.json b/rust/cloud-storage/chat/.sqlx/query-1b50363c934ae7e01406a2cbb674b84fa6af6f7caa8353d52ed22e48b3899327.json
new file mode 100644
index 0000000000..6a64b12e48
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1b50363c934ae7e01406a2cbb674b84fa6af6f7caa8353d52ed22e48b3899327.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"Pin\" WHERE \"pinnedItemId\" = ANY($1) AND \"pinnedItemType\" = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "1b50363c934ae7e01406a2cbb674b84fa6af6f7caa8353d52ed22e48b3899327"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6.json b/rust/cloud-storage/chat/.sqlx/query-1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6.json
new file mode 100644
index 0000000000..f97907a55c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" = $1\n )\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1b8266e388b4e120d27c47d891f5f447e26ff2b83fc6c6e6a0e2726aba761a51.json b/rust/cloud-storage/chat/.sqlx/query-1b8266e388b4e120d27c47d891f5f447e26ff2b83fc6c6e6a0e2726aba761a51.json
new file mode 100644
index 0000000000..e8dcefae26
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1b8266e388b4e120d27c47d891f5f447e26ff2b83fc6c6e6a0e2726aba761a51.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT DISTINCT m.\"chatId\" as chat_id\n FROM \"ChatMessage\" m\n WHERE m.\"id\" = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "chat_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "1b8266e388b4e120d27c47d891f5f447e26ff2b83fc6c6e6a0e2726aba761a51"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1b9256d39a08d605aba08de1c5bddd8eb29bedd31dd21719114646449ab1333f.json b/rust/cloud-storage/chat/.sqlx/query-1b9256d39a08d605aba08de1c5bddd8eb29bedd31dd21719114646449ab1333f.json
new file mode 100644
index 0000000000..d75fdd9537
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1b9256d39a08d605aba08de1c5bddd8eb29bedd31dd21719114646449ab1333f.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH RECURSIVE project_hierarchy AS (\n SELECT\n p.id\n FROM \"Project\" p\n WHERE p.id = $1 AND p.\"deletedAt\" IS NULL\n UNION ALL\n SELECT\n sub_p.id\n FROM \"Project\" sub_p\n INNER JOIN project_hierarchy ph ON sub_p.\"parentId\" = ph.id\n WHERE sub_p.\"deletedAt\" IS NULL\n )\n SELECT\n ph.id as \"id!\"\n FROM project_hierarchy ph\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "1b9256d39a08d605aba08de1c5bddd8eb29bedd31dd21719114646449ab1333f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1b9cfa3d4094394511f73413672e79e2ec7426b562ad9dbf8d6adfb3b33045e8.json b/rust/cloud-storage/chat/.sqlx/query-1b9cfa3d4094394511f73413672e79e2ec7426b562ad9dbf8d6adfb3b33045e8.json
new file mode 100644
index 0000000000..68b44d7f91
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1b9cfa3d4094394511f73413672e79e2ec7426b562ad9dbf8d6adfb3b33045e8.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n name\n FROM comms_channels\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "name",
+ "type_info": "Varchar"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "1b9cfa3d4094394511f73413672e79e2ec7426b562ad9dbf8d6adfb3b33045e8"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1c5f9c90a5ee11ffedc5c98b589c821898f04952a5a597c9796e152fa4c65bb1.json b/rust/cloud-storage/chat/.sqlx/query-1c5f9c90a5ee11ffedc5c98b589c821898f04952a5a597c9796e152fa4c65bb1.json
new file mode 100644
index 0000000000..dee1621260
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1c5f9c90a5ee11ffedc5c98b589c821898f04952a5a597c9796e152fa4c65bb1.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n e.subject,\n l.macro_id\n FROM\n \"email_messages\" e\n JOIN email_links l ON l.id = e.link_id\n WHERE\n e.thread_id = $1\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "subject",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "macro_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ true,
+ false
+ ]
+ },
+ "hash": "1c5f9c90a5ee11ffedc5c98b589c821898f04952a5a597c9796e152fa4c65bb1"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1d0181be77c26e2242abd2aa0a3c9bf77b8247494b2f5937e3dc977dcfc8f90b.json b/rust/cloud-storage/chat/.sqlx/query-1d0181be77c26e2242abd2aa0a3c9bf77b8247494b2f5937e3dc977dcfc8f90b.json
new file mode 100644
index 0000000000..dbdcc4795c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1d0181be77c26e2242abd2aa0a3c9bf77b8247494b2f5937e3dc977dcfc8f90b.json
@@ -0,0 +1,17 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"ChatAttachment\" (\"attachmentType\", \"attachmentId\", \"chatId\", \"messageId\")\n SELECT * FROM UNNEST($1::TEXT[], $2::TEXT[], $3::TEXT[], $4::TEXT[])\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "TextArray",
+ "TextArray",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "1d0181be77c26e2242abd2aa0a3c9bf77b8247494b2f5937e3dc977dcfc8f90b"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1dba8f7824a404cbe6b276df601bbf45b0bbe751d89e8b841068d86b855f44ae.json b/rust/cloud-storage/chat/.sqlx/query-1dba8f7824a404cbe6b276df601bbf45b0bbe751d89e8b841068d86b855f44ae.json
new file mode 100644
index 0000000000..4c0a3e375a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1dba8f7824a404cbe6b276df601bbf45b0bbe751d89e8b841068d86b855f44ae.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id FROM \"Document\" WHERE \"owner\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "1dba8f7824a404cbe6b276df601bbf45b0bbe751d89e8b841068d86b855f44ae"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1e14d3e8348556865af942ec6e3d883668d0b8073143094ed67d34285f9cc92b.json b/rust/cloud-storage/chat/.sqlx/query-1e14d3e8348556865af942ec6e3d883668d0b8073143094ed67d34285f9cc92b.json
new file mode 100644
index 0000000000..e5287b48b3
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1e14d3e8348556865af942ec6e3d883668d0b8073143094ed67d34285f9cc92b.json
@@ -0,0 +1,17 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"UserHistory\" (\"userId\", \"itemId\", \"itemType\", \"createdAt\", \"updatedAt\")\n VALUES ($1, $2, $3, $4, $4)\n ON CONFLICT (\"userId\", \"itemId\", \"itemType\") DO UPDATE\n SET \"updatedAt\" = $4;\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Text",
+ "Timestamp"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "1e14d3e8348556865af942ec6e3d883668d0b8073143094ed67d34285f9cc92b"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1e96a9f033805dc354b5b3f06575ce22f1e4fbd6770c390a252cd6c790ee2d6e.json b/rust/cloud-storage/chat/.sqlx/query-1e96a9f033805dc354b5b3f06575ce22f1e4fbd6770c390a252cd6c790ee2d6e.json
new file mode 100644
index 0000000000..023a7e4749
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1e96a9f033805dc354b5b3f06575ce22f1e4fbd6770c390a252cd6c790ee2d6e.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Chat\" SET \"projectId\" = NULL\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "1e96a9f033805dc354b5b3f06575ce22f1e4fbd6770c390a252cd6c790ee2d6e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1ea0c7996fa301f1b842d74bc2c42c4c399bae6774014cf03704024bd4293821.json b/rust/cloud-storage/chat/.sqlx/query-1ea0c7996fa301f1b842d74bc2c42c4c399bae6774014cf03704024bd4293821.json
new file mode 100644
index 0000000000..ec2174302b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1ea0c7996fa301f1b842d74bc2c42c4c399bae6774014cf03704024bd4293821.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n macro_user_id,\n id\n FROM\n in_progress_email_link\n WHERE\n in_progress_email_link.email = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "macro_user_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "1ea0c7996fa301f1b842d74bc2c42c4c399bae6774014cf03704024bd4293821"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1ee4ffd924167f7e5cda2be1ac66506c341547cd49c76e365129d91650474605.json b/rust/cloud-storage/chat/.sqlx/query-1ee4ffd924167f7e5cda2be1ac66506c341547cd49c76e365129d91650474605.json
new file mode 100644
index 0000000000..cafa6efc60
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1ee4ffd924167f7e5cda2be1ac66506c341547cd49c76e365129d91650474605.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"UserHistory\" (\"userId\", \"itemId\", \"itemType\", \"createdAt\", \"updatedAt\")\n SELECT u.user_id, u.item_id, 'document', NOW(), NOW()\n FROM UNNEST($1::text[], $2::text[]) AS u(item_id, user_id)\n ON CONFLICT (\"userId\", \"itemId\", \"itemType\") DO UPDATE\n SET \"updatedAt\" = NOW();\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "1ee4ffd924167f7e5cda2be1ac66506c341547cd49c76e365129d91650474605"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1f0770cc758a37117b875b129eeb2e3e3e1143e8ab3dae3a85e9e756cdf9bdc0.json b/rust/cloud-storage/chat/.sqlx/query-1f0770cc758a37117b875b129eeb2e3e3e1143e8ab3dae3a85e9e756cdf9bdc0.json
new file mode 100644
index 0000000000..ad81720097
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1f0770cc758a37117b875b129eeb2e3e3e1143e8ab3dae3a85e9e756cdf9bdc0.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"organizationId\" as id\n FROM \"OrganizationBilling\"\n WHERE \"email\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "1f0770cc758a37117b875b129eeb2e3e3e1143e8ab3dae3a85e9e756cdf9bdc0"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-1fc848546237b4ee2447fc0484f1bff04cb3809b95257519006428cfb07e9d93.json b/rust/cloud-storage/chat/.sqlx/query-1fc848546237b4ee2447fc0484f1bff04cb3809b95257519006428cfb07e9d93.json
new file mode 100644
index 0000000000..30cef276b0
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-1fc848546237b4ee2447fc0484f1bff04cb3809b95257519006428cfb07e9d93.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_id = $3 AND source_type = 'user'\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "1fc848546237b4ee2447fc0484f1bff04cb3809b95257519006428cfb07e9d93"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-2032b8706e7c7928243b8185349df6fde6d25c6187e9b03a75640a771aa8899a.json b/rust/cloud-storage/chat/.sqlx/query-2032b8706e7c7928243b8185349df6fde6d25c6187e9b03a75640a771aa8899a.json
new file mode 100644
index 0000000000..0890ed3cf7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-2032b8706e7c7928243b8185349df6fde6d25c6187e9b03a75640a771aa8899a.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n u.id,\n u.\"stripeCustomerId\" as \"stripe_customer_id\"\n FROM \"User\" u\n WHERE u.\"macro_user_id\" IS NULL\n ORDER BY u.id ASC\n LIMIT $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "stripe_customer_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ true
+ ]
+ },
+ "hash": "2032b8706e7c7928243b8185349df6fde6d25c6187e9b03a75640a771aa8899a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-21cce4388c4839d33ceac5f09a2f3f7a506003afe498d487699c0cb4b78c7899.json b/rust/cloud-storage/chat/.sqlx/query-21cce4388c4839d33ceac5f09a2f3f7a506003afe498d487699c0cb4b78c7899.json
new file mode 100644
index 0000000000..4cfd33f2d4
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-21cce4388c4839d33ceac5f09a2f3f7a506003afe498d487699c0cb4b78c7899.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n u.id\n FROM\n \"User\" u\n WHERE\n u.email = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "21cce4388c4839d33ceac5f09a2f3f7a506003afe498d487699c0cb4b78c7899"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-22b6d77bfd1c45120ccf35569e79ddb46a99a61528c59231a0dd5f263df499e6.json b/rust/cloud-storage/chat/.sqlx/query-22b6d77bfd1c45120ccf35569e79ddb46a99a61528c59231a0dd5f263df499e6.json
new file mode 100644
index 0000000000..efdf0025ad
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-22b6d77bfd1c45120ccf35569e79ddb46a99a61528c59231a0dd5f263df499e6.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM comms_reactions\n WHERE message_id = $1 AND emoji = $2 AND user_id = $3\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "22b6d77bfd1c45120ccf35569e79ddb46a99a61528c59231a0dd5f263df499e6"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-22c535eec28118577d247aed68b7064a5a22071296f2603d6f86a7bc1816dd0f.json b/rust/cloud-storage/chat/.sqlx/query-22c535eec28118577d247aed68b7064a5a22071296f2603d6f86a7bc1816dd0f.json
new file mode 100644
index 0000000000..80831ac218
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-22c535eec28118577d247aed68b7064a5a22071296f2603d6f86a7bc1816dd0f.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"Pin\" WHERE \"userId\" = $1 AND \"pinnedItemId\" = $2 AND \"pinnedItemType\" = $3\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "22c535eec28118577d247aed68b7064a5a22071296f2603d6f86a7bc1816dd0f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-22cfead49cd3d400a1752f2c232b9ccc7072aac9d5dd7c17a15c6be812fb3d4f.json b/rust/cloud-storage/chat/.sqlx/query-22cfead49cd3d400a1752f2c232b9ccc7072aac9d5dd7c17a15c6be812fb3d4f.json
new file mode 100644
index 0000000000..6bff4d79af
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-22cfead49cd3d400a1752f2c232b9ccc7072aac9d5dd7c17a15c6be812fb3d4f.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"User\"\n SET macro_user_id = $1\n WHERE id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "22cfead49cd3d400a1752f2c232b9ccc7072aac9d5dd7c17a15c6be812fb3d4f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-233648d4502d3b4c6190603e4692c9224a44d046cecb5cce585afbb2e8aeaf49.json b/rust/cloud-storage/chat/.sqlx/query-233648d4502d3b4c6190603e4692c9224a44d046cecb5cce585afbb2e8aeaf49.json
new file mode 100644
index 0000000000..ff086d1c89
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-233648d4502d3b4c6190603e4692c9224a44d046cecb5cce585afbb2e8aeaf49.json
@@ -0,0 +1,46 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id,\n d.name,\n d.\"owner\",\n d.\"fileType\" as \"file_type!\",\n di.id as \"document_version_id?\"\n FROM\n \"Document\" d\n LEFT JOIN LATERAL (\n SELECT\n i.id\n FROM\n \"DocumentInstance\" i\n WHERE\n i.\"documentId\" = d.id\n ORDER BY\n i.\"createdAt\" ASC\n LIMIT 1\n ) di ON true\n WHERE\n d.\"deletedAt\" IS NULL AND\n d.id = $1 AND\n d.\"fileType\" IS NOT NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "file_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "document_version_id?",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ false
+ ]
+ },
+ "hash": "233648d4502d3b4c6190603e4692c9224a44d046cecb5cce585afbb2e8aeaf49"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-2448b50af4a227c3a7d638e1377145f8a813091547e4f47a9f1fed4b8959e4bf.json b/rust/cloud-storage/chat/.sqlx/query-2448b50af4a227c3a7d638e1377145f8a813091547e4f47a9f1fed4b8959e4bf.json
new file mode 100644
index 0000000000..7ec90a9c87
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-2448b50af4a227c3a7d638e1377145f8a813091547e4f47a9f1fed4b8959e4bf.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n id,\n email,\n \"organizationId\" as \"organization_id?\"\n FROM \"User\"\n WHERE \"id\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "email",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "organization_id?",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "2448b50af4a227c3a7d638e1377145f8a813091547e4f47a9f1fed4b8959e4bf"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-2500e65cc47f0cfb5cf99c7b4aa87ca672780591c4b7b2ff5429121d5b4594bf.json b/rust/cloud-storage/chat/.sqlx/query-2500e65cc47f0cfb5cf99c7b4aa87ca672780591c4b7b2ff5429121d5b4594bf.json
new file mode 100644
index 0000000000..e6831d38ae
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-2500e65cc47f0cfb5cf99c7b4aa87ca672780591c4b7b2ff5429121d5b4594bf.json
@@ -0,0 +1,70 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id as \"document_id\",\n COALESCE(db.id, di.id) as \"document_version_id!\",\n d.name as \"document_name\",\n d.\"fileType\" as \"file_type\",\n d.\"branchedFromId\" as branched_from_id,\n d.\"branchedFromVersionId\" as branched_from_version_id,\n d.\"documentFamilyId\" as document_family_id,\n d.\"createdAt\"::timestamptz as created_at,\n d.\"updatedAt\"::timestamptz as updated_at\n FROM\n \"Document\" d\n LEFT JOIN LATERAL (\n SELECT\n i.id\n FROM\n \"DocumentInstance\" i\n WHERE\n i.\"documentId\" = d.id\n ORDER BY\n i.\"createdAt\" DESC\n LIMIT 1\n ) di ON d.\"fileType\" IS DISTINCT FROM 'docx'\n LEFT JOIN LATERAL (\n SELECT\n b.id\n FROM\n \"DocumentBom\" b\n WHERE\n b.\"documentId\" = d.id\n ORDER BY\n b.\"createdAt\" DESC\n LIMIT 1\n ) db ON d.\"fileType\" = 'docx'\n WHERE\n d.owner = $1 AND d.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "document_version_id!",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "branched_from_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "branched_from_version_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 6,
+ "name": "document_family_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 7,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ null,
+ false,
+ true,
+ true,
+ true,
+ true,
+ null,
+ null
+ ]
+ },
+ "hash": "2500e65cc47f0cfb5cf99c7b4aa87ca672780591c4b7b2ff5429121d5b4594bf"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-2611958405cf94c91ef85a09da00b0a8701621b42e4c57e74d2da40062d577d4.json b/rust/cloud-storage/chat/.sqlx/query-2611958405cf94c91ef85a09da00b0a8701621b42e4c57e74d2da40062d577d4.json
new file mode 100644
index 0000000000..afc95c996f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-2611958405cf94c91ef85a09da00b0a8701621b42e4c57e74d2da40062d577d4.json
@@ -0,0 +1,129 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH PinnedItems AS (\n SELECT\n p.\"pinnedItemId\" as pin_item_id,\n p.\"pinnedItemType\" as pin_item_type,\n p.\"pinIndex\" as pin_index\n FROM \"Pin\" p\n WHERE p.\"userId\" = $1\n ), Combined AS (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at\",\n d.\"updatedAt\"::timestamptz as \"updated_at\",\n d.\"projectId\" as \"project_id\",\n di.sha as \"sha\",\n NULL as \"is_persistent\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n pi.pin_index as \"pin_index\",\n CASE \n WHEN dt.sub_type = 'task' \n AND ep_status.values->'value' ? $2\n THEN true \n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL \n END as \"is_completed\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status \n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id \n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $3\n INNER JOIN PinnedItems pi ON pi.pin_item_id = d.id AND pi.pin_item_type = 'document'\n LEFT JOIN LATERAL (\n SELECT\n b.id\n FROM\n \"DocumentBom\" b\n WHERE\n b.\"documentId\" = d.id\n ORDER BY\n b.\"createdAt\" DESC\n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT\n i.id,\n i.\"documentId\",\n i.\"sha\",\n i.\"createdAt\",\n i.\"updatedAt\"\n FROM\n \"DocumentInstance\" i\n WHERE\n i.\"documentId\" = d.id\n ORDER BY\n i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON true\n UNION ALL\n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at\",\n c.\"updatedAt\"::timestamptz as \"updated_at\",\n c.\"projectId\" as \"project_id\",\n NULL as \"sha\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as sub_type,\n pi.pin_index as \"pin_index\",\n NULL as \"is_completed\"\n FROM \"Chat\" c\n INNER JOIN PinnedItems pi ON pi.pin_item_id = c.id AND pi.pin_item_type = 'chat'\n UNION ALL\n SELECT\n 'project' as \"item_type!\",\n p.id as \"id!\",\n NULL as \"document_version_id\",\n p.\"userId\" as \"user_id!\",\n p.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n p.\"createdAt\"::timestamptz as \"created_at\",\n p.\"updatedAt\"::timestamptz as \"updated_at\",\n p.\"parentId\" as \"project_id\",\n NULL as \"sha\",\n NULL as \"is_persistent\",\n NULL as sub_type,\n pi.pin_index as \"pin_index\",\n NULL as \"is_completed\"\n FROM \"Project\" p\n INNER JOIN PinnedItems pi ON pi.pin_item_id = p.id AND pi.pin_item_type = 'project'\n )\n SELECT * FROM Combined\n ORDER BY pin_index ASC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_version_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "user_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "name!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "branched_from_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "branched_from_version_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 7,
+ "name": "document_family_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 8,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 9,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 11,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 12,
+ "name": "sha",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 13,
+ "name": "is_persistent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 14,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 15,
+ "name": "pin_index",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 16,
+ "name": "is_completed",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "2611958405cf94c91ef85a09da00b0a8701621b42e4c57e74d2da40062d577d4"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-2683ed5de04d186f9d997d088e4d371be0b22106450171fbc1cef5ce96fb00b6.json b/rust/cloud-storage/chat/.sqlx/query-2683ed5de04d186f9d997d088e4d371be0b22106450171fbc1cef5ce96fb00b6.json
new file mode 100644
index 0000000000..99c433ede6
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-2683ed5de04d186f9d997d088e4d371be0b22106450171fbc1cef5ce96fb00b6.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT name\n FROM team\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "name",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "2683ed5de04d186f9d997d088e4d371be0b22106450171fbc1cef5ce96fb00b6"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-26b3b2da3cc2f75ee37842ebe33e1bda1e5b15a490bd8aa3a2a3c27afa728348.json b/rust/cloud-storage/chat/.sqlx/query-26b3b2da3cc2f75ee37842ebe33e1bda1e5b15a490bd8aa3a2a3c27afa728348.json
new file mode 100644
index 0000000000..d5b85b3456
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-26b3b2da3cc2f75ee37842ebe33e1bda1e5b15a490bd8aa3a2a3c27afa728348.json
@@ -0,0 +1,48 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.\"id\" as \"chat_id\",\n m.id as \"message_id\",\n c.\"userId\" as \"user_id\",\n c.\"createdAt\" as \"created_at\",\n c.\"updatedAt\" as \"updated_at\"\n FROM\n \"ChatMessage\" m\n JOIN\n \"Chat\" c on c.\"id\" = m.\"chatId\"\n WHERE\n m.\"chatId\" = ANY($1) AND c.\"deletedAt\" IS NULL\n ORDER BY\n m.\"createdAt\" DESC\n LIMIT $2\n OFFSET $3\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "chat_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "message_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 4,
+ "name": "updated_at",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "26b3b2da3cc2f75ee37842ebe33e1bda1e5b15a490bd8aa3a2a3c27afa728348"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-26c357f323179bc7c5c64492521aa202a0a8119036d4be0975aaac1ce6d96cd2.json b/rust/cloud-storage/chat/.sqlx/query-26c357f323179bc7c5c64492521aa202a0a8119036d4be0975aaac1ce6d96cd2.json
new file mode 100644
index 0000000000..77a2fec9fa
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-26c357f323179bc7c5c64492521aa202a0a8119036d4be0975aaac1ce6d96cd2.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n u.email\n FROM \"UserHistory\" uh\n JOIN \"User\" u ON uh.\"userId\" = u.id\n WHERE uh.\"itemId\" = $1 AND uh.\"itemType\" = 'document'\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "email",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "26c357f323179bc7c5c64492521aa202a0a8119036d4be0975aaac1ce6d96cd2"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-270cd8ae6b47508cb7e4e920bd76cb0f6177d685bddedb06f1892d0014af6f01.json b/rust/cloud-storage/chat/.sqlx/query-270cd8ae6b47508cb7e4e920bd76cb0f6177d685bddedb06f1892d0014af6f01.json
new file mode 100644
index 0000000000..01cece9642
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-270cd8ae6b47508cb7e4e920bd76cb0f6177d685bddedb06f1892d0014af6f01.json
@@ -0,0 +1,33 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM notification_user_device_registration\n WHERE device_token = $1 AND device_type = $2\n RETURNING device_endpoint\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "device_endpoint",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ {
+ "Custom": {
+ "name": "notification_device_type_option",
+ "kind": {
+ "Enum": [
+ "ios",
+ "android"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "270cd8ae6b47508cb7e4e920bd76cb0f6177d685bddedb06f1892d0014af6f01"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-05c8ccc939bbfd3b3d43f11d66fb683d71c34dac4fcf202142d90564086e36e8.json b/rust/cloud-storage/chat/.sqlx/query-270e056bb1d522c9f46b8f8f0fde1d3307bf0627fe420be6bc0509072bae1565.json
similarity index 53%
rename from rust/cloud-storage/macro_db_client/.sqlx/query-05c8ccc939bbfd3b3d43f11d66fb683d71c34dac4fcf202142d90564086e36e8.json
rename to rust/cloud-storage/chat/.sqlx/query-270e056bb1d522c9f46b8f8f0fde1d3307bf0627fe420be6bc0509072bae1565.json
index 9319b07deb..df429bfdc5 100644
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-05c8ccc939bbfd3b3d43f11d66fb683d71c34dac4fcf202142d90564086e36e8.json
+++ b/rust/cloud-storage/chat/.sqlx/query-270e056bb1d522c9f46b8f8f0fde1d3307bf0627fe420be6bc0509072bae1565.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT\n cp.\"sharePermissionId\" as share_permission_id\n FROM \"ChatPermission\" cp\n WHERE cp.\"chatId\" = $1\n ",
+ "query": "\n SELECT \"sharePermissionId\" as share_permission_id\n FROM \"ProjectPermission\"\n WHERE \"projectId\"=$1",
"describe": {
"columns": [
{
@@ -18,5 +18,5 @@
false
]
},
- "hash": "05c8ccc939bbfd3b3d43f11d66fb683d71c34dac4fcf202142d90564086e36e8"
+ "hash": "270e056bb1d522c9f46b8f8f0fde1d3307bf0627fe420be6bc0509072bae1565"
}
diff --git a/rust/cloud-storage/chat/.sqlx/query-278876b19e66f90a52e4a982f6dc6376849461c5df6a9cb1037d1eee6e30cfab.json b/rust/cloud-storage/chat/.sqlx/query-278876b19e66f90a52e4a982f6dc6376849461c5df6a9cb1037d1eee6e30cfab.json
new file mode 100644
index 0000000000..090c1515dc
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-278876b19e66f90a52e4a982f6dc6376849461c5df6a9cb1037d1eee6e30cfab.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n COALESCE(db.id, di.id) as \"id!\",\n d.uploaded\n FROM\n \"Document\" d\n LEFT JOIN LATERAL (\n SELECT\n i.id\n FROM\n \"DocumentInstance\" i\n WHERE\n i.\"documentId\" = d.id\n ORDER BY\n i.\"createdAt\" ASC\n LIMIT 1\n ) di ON d.\"fileType\" IS DISTINCT FROM 'docx'\n LEFT JOIN LATERAL (\n SELECT\n b.id\n FROM\n \"DocumentBom\" b\n WHERE\n b.\"documentId\" = d.id\n ORDER BY\n b.\"createdAt\" ASC\n LIMIT 1\n ) db ON d.\"fileType\" = 'docx'\n WHERE\n d.id = $1\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "uploaded",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null,
+ false
+ ]
+ },
+ "hash": "278876b19e66f90a52e4a982f6dc6376849461c5df6a9cb1037d1eee6e30cfab"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-27a48907486b15f7c32fe0e84865904a6f2389ae59275c8b14ceb52035c473c0.json b/rust/cloud-storage/chat/.sqlx/query-27a48907486b15f7c32fe0e84865904a6f2389ae59275c8b14ceb52035c473c0.json
new file mode 100644
index 0000000000..e927a616e0
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-27a48907486b15f7c32fe0e84865904a6f2389ae59275c8b14ceb52035c473c0.json
@@ -0,0 +1,70 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id as \"document_id\",\n d.owner,\n d.name as \"document_name\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"projectId\" as \"project_id\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM\n \"Document\" d\n WHERE\n d.id = $1\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "branched_from_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "branched_from_version_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 5,
+ "name": "document_family_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 6,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 7,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ true,
+ true,
+ true,
+ true,
+ null
+ ]
+ },
+ "hash": "27a48907486b15f7c32fe0e84865904a6f2389ae59275c8b14ceb52035c473c0"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-27af0e4ef3bfa65509108039027a7a0891ce7e5f9d3ff36e6598d5f51650416c.json b/rust/cloud-storage/chat/.sqlx/query-27af0e4ef3bfa65509108039027a7a0891ce7e5f9d3ff36e6598d5f51650416c.json
new file mode 100644
index 0000000000..0a50742ac6
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-27af0e4ef3bfa65509108039027a7a0891ce7e5f9d3ff36e6598d5f51650416c.json
@@ -0,0 +1,60 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"Project\" (\"name\", \"userId\", \"parentId\", \"createdAt\", \"updatedAt\")\n VALUES ($1, $2, $3, NOW(), NOW())\n RETURNING id, name, \"userId\"::text as user_id, \"createdAt\"::timestamptz as created_at, \"deletedAt\"::timestamptz as deleted_at,\n \"updatedAt\"::timestamptz as updated_at, \"parentId\" as parent_id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 4,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "parent_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ true
+ ]
+ },
+ "hash": "27af0e4ef3bfa65509108039027a7a0891ce7e5f9d3ff36e6598d5f51650416c"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-28aca4b1b6794f9509b0cc56ea46bb4addfdd91ebf78cd2bef8026c2f6e86c77.json b/rust/cloud-storage/chat/.sqlx/query-28aca4b1b6794f9509b0cc56ea46bb4addfdd91ebf78cd2bef8026c2f6e86c77.json
new file mode 100644
index 0000000000..0f3a4895c5
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-28aca4b1b6794f9509b0cc56ea46bb4addfdd91ebf78cd2bef8026c2f6e86c77.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access with source_ids (user, teams, channels)\n SELECT access_level::text FROM entity_access\n WHERE source_id = ANY(ARRAY(\n SELECT cp.channel_id::text FROM comms_channel_participants cp\n WHERE cp.user_id = $3 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $3\n UNION ALL\n SELECT $3\n ))\n AND entity_id = $1\n AND entity_type = 'document'\n UNION ALL\n -- Source 2: Select the publicAccessLevel (which is already text).\n SELECT \"publicAccessLevel\" as access_level\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true AND \"publicAccessLevel\" IS NOT NULL AND id IN (\n SELECT \"sharePermissionId\" FROM \"DocumentPermission\" WHERE \"documentId\" = $2\n )\n ) as all_levels\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "28aca4b1b6794f9509b0cc56ea46bb4addfdd91ebf78cd2bef8026c2f6e86c77"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-28c518d844cd4d843c097af1551f6f384a4763514d278b5444341390f58a8281.json b/rust/cloud-storage/chat/.sqlx/query-28c518d844cd4d843c097af1551f6f384a4763514d278b5444341390f58a8281.json
new file mode 100644
index 0000000000..98ceb2aeec
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-28c518d844cd4d843c097af1551f6f384a4763514d278b5444341390f58a8281.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "UPDATE \"Project\" SET \"updatedAt\" = NOW() WHERE id = $1",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "28c518d844cd4d843c097af1551f6f384a4763514d278b5444341390f58a8281"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-29a11db8b490eb1c5d38e3675c052d9b254b34f31fd8ec476909d3ded6efe340.json b/rust/cloud-storage/chat/.sqlx/query-29a11db8b490eb1c5d38e3675c052d9b254b34f31fd8ec476909d3ded6efe340.json
new file mode 100644
index 0000000000..5f203b58b1
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-29a11db8b490eb1c5d38e3675c052d9b254b34f31fd8ec476909d3ded6efe340.json
@@ -0,0 +1,58 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id, source_entity_type, source_entity_id, entity_type, entity_id, user_id, created_at\n FROM comms_entity_mentions\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "source_entity_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 2,
+ "name": "source_entity_id",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 3,
+ "name": "entity_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 4,
+ "name": "entity_id",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 5,
+ "name": "user_id",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ false
+ ]
+ },
+ "hash": "29a11db8b490eb1c5d38e3675c052d9b254b34f31fd8ec476909d3ded6efe340"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-29f40fc78b59a74c6b0df0c8cb0abe9d4e5f57b4b08a18673276967b456d8bb5.json b/rust/cloud-storage/chat/.sqlx/query-29f40fc78b59a74c6b0df0c8cb0abe9d4e5f57b4b08a18673276967b456d8bb5.json
new file mode 100644
index 0000000000..fa71ec2445
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-29f40fc78b59a74c6b0df0c8cb0abe9d4e5f57b4b08a18673276967b456d8bb5.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"UserHistory\" WHERE \"itemId\" = $1 AND \"itemType\" = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "29f40fc78b59a74c6b0df0c8cb0abe9d4e5f57b4b08a18673276967b456d8bb5"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-2a0a599cfa9f11e74e868ab0e9fd58931b4c1a38570a2c575ec544a73aaf7394.json b/rust/cloud-storage/chat/.sqlx/query-2a0a599cfa9f11e74e868ab0e9fd58931b4c1a38570a2c575ec544a73aaf7394.json
similarity index 100%
rename from rust/cloud-storage/macro_db_client/.sqlx/query-2a0a599cfa9f11e74e868ab0e9fd58931b4c1a38570a2c575ec544a73aaf7394.json
rename to rust/cloud-storage/chat/.sqlx/query-2a0a599cfa9f11e74e868ab0e9fd58931b4c1a38570a2c575ec544a73aaf7394.json
diff --git a/rust/cloud-storage/chat/.sqlx/query-2c2e1fbbc52b300640cab8add807f581aba22df15410900b9f598daf699b60de.json b/rust/cloud-storage/chat/.sqlx/query-2c2e1fbbc52b300640cab8add807f581aba22df15410900b9f598daf699b60de.json
new file mode 100644
index 0000000000..81c377d3c2
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-2c2e1fbbc52b300640cab8add807f581aba22df15410900b9f598daf699b60de.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n u.id\n FROM \"User\" u\n WHERE u.\"id\" = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "2c2e1fbbc52b300640cab8add807f581aba22df15410900b9f598daf699b60de"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-2c8623569ad039d0ee10321ab06c2563d7f90f17e00e6c4e18d25bc0a7b1355b.json b/rust/cloud-storage/chat/.sqlx/query-2c8623569ad039d0ee10321ab06c2563d7f90f17e00e6c4e18d25bc0a7b1355b.json
new file mode 100644
index 0000000000..b60c8f01fa
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-2c8623569ad039d0ee10321ab06c2563d7f90f17e00e6c4e18d25bc0a7b1355b.json
@@ -0,0 +1,106 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n t.id as thread_id, \n t.resolved as is_resolved,\n a.uuid as anchor_uuid, \n a.page, \n a.\"originalPage\" as original_page,\n a.\"originalIndex\" as original_index,\n a.\"shouldLockOnSave\" as should_lock_on_save,\n a.\"wasEdited\" as was_edited,\n a.\"wasDeleted\" as was_deleted,\n a.\"allowableEdits\" as allowable_edits,\n a.\"xPct\" as x_pct,\n a.\"yPct\" as y_pct,\n a.\"widthPct\" as width_pct,\n a.\"heightPct\" as height_pct,\n a.rotation\n FROM \"Thread\" t\n JOIN \"PdfPlaceableCommentAnchor\" a ON t.\"id\" = a.\"threadId\"\n WHERE t.\"documentId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "is_resolved",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 2,
+ "name": "anchor_uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 3,
+ "name": "page",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 4,
+ "name": "original_page",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 5,
+ "name": "original_index",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 6,
+ "name": "should_lock_on_save",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 7,
+ "name": "was_edited",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 8,
+ "name": "was_deleted",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 9,
+ "name": "allowable_edits",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 10,
+ "name": "x_pct",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 11,
+ "name": "y_pct",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 12,
+ "name": "width_pct",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 13,
+ "name": "height_pct",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 14,
+ "name": "rotation",
+ "type_info": "Float8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ false,
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "2c8623569ad039d0ee10321ab06c2563d7f90f17e00e6c4e18d25bc0a7b1355b"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-2d1112d21440f0dfdf8fcbec264389f7abdcc74544558d60d817f56ff0c14524.json b/rust/cloud-storage/chat/.sqlx/query-2d1112d21440f0dfdf8fcbec264389f7abdcc74544558d60d817f56ff0c14524.json
new file mode 100644
index 0000000000..61b064aaf0
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-2d1112d21440f0dfdf8fcbec264389f7abdcc74544558d60d817f56ff0c14524.json
@@ -0,0 +1,55 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id as \"document_id\",\n d.owner,\n d.name as \"document_name\",\n d.\"fileType\" as \"file_type\",\n dst.sub_type as \"sub_type?: DocumentSubType\"\n FROM\n \"Document\" d\n LEFT JOIN document_sub_type dst ON dst.document_id = d.id\n WHERE d.id = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ true
+ ]
+ },
+ "hash": "2d1112d21440f0dfdf8fcbec264389f7abdcc74544558d60d817f56ff0c14524"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-2d17144ac0fad7ccde292b6da4197cee6ec3a0e3eefc8711308ef3c6b3f7f30c.json b/rust/cloud-storage/chat/.sqlx/query-2d17144ac0fad7ccde292b6da4197cee6ec3a0e3eefc8711308ef3c6b3f7f30c.json
new file mode 100644
index 0000000000..b615b341e1
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-2d17144ac0fad7ccde292b6da4197cee6ec3a0e3eefc8711308ef3c6b3f7f30c.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Chat\" SET \"tokenCount\" = $1\n WHERE id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "2d17144ac0fad7ccde292b6da4197cee6ec3a0e3eefc8711308ef3c6b3f7f30c"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-2ddddebfec3d3bded1e74b0e34abf9daee5e67d46eb8d977a6942669d5c8bdf5.json b/rust/cloud-storage/chat/.sqlx/query-2ddddebfec3d3bded1e74b0e34abf9daee5e67d46eb8d977a6942669d5c8bdf5.json
new file mode 100644
index 0000000000..eb06e65e1f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-2ddddebfec3d3bded1e74b0e34abf9daee5e67d46eb8d977a6942669d5c8bdf5.json
@@ -0,0 +1,77 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH SingleAttachmentChats AS (\n SELECT\n \"chatId\",\n COUNT(*) as attachment_count\n FROM \"ChatAttachment\"\n GROUP BY \"chatId\"\n HAVING COUNT(*) = 1\n )\n SELECT\n c.id,\n c.name,\n c.\"userId\" as \"user_id\",\n c.\"createdAt\"::timestamptz as \"created_at\",\n c.\"updatedAt\"::timestamptz as \"updated_at\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\",\n c.model,\n c.\"tokenCount\" as \"token_count\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\"\n FROM \"Chat\" c\n INNER JOIN \"ChatAttachment\" ca ON c.id = ca.\"chatId\"\n INNER JOIN SingleAttachmentChats sac ON c.id = sac.\"chatId\"\n WHERE\n ca.\"attachmentId\" = $1 AND c.\"userId\" = $2\n AND\n c.\"deletedAt\" IS NULL\n\n ORDER BY c.\"updatedAt\" DESC\n LIMIT 1;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 4,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "model",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 7,
+ "name": "token_count",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 8,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 9,
+ "name": "is_persistent",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ false,
+ true,
+ true,
+ false
+ ]
+ },
+ "hash": "2ddddebfec3d3bded1e74b0e34abf9daee5e67d46eb8d977a6942669d5c8bdf5"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-2e318ed8eff90b0e145afae548e3f895f7b7c4f8458df987c7bed9054fbc3450.json b/rust/cloud-storage/chat/.sqlx/query-2e318ed8eff90b0e145afae548e3f895f7b7c4f8458df987c7bed9054fbc3450.json
new file mode 100644
index 0000000000..7dc8bf69a0
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-2e318ed8eff90b0e145afae548e3f895f7b7c4f8458df987c7bed9054fbc3450.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n name\n FROM\n \"Organization\"\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "name",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int4"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "2e318ed8eff90b0e145afae548e3f895f7b7c4f8458df987c7bed9054fbc3450"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-2e344d477bc3f8cfc2d031455a958b25d1a27c42d3420a624c0ec71de1d85ba9.json b/rust/cloud-storage/chat/.sqlx/query-2e344d477bc3f8cfc2d031455a958b25d1a27c42d3420a624c0ec71de1d85ba9.json
new file mode 100644
index 0000000000..f0e4926786
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-2e344d477bc3f8cfc2d031455a958b25d1a27c42d3420a624c0ec71de1d85ba9.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access with source_ids (user, teams, channels)\n SELECT access_level::text FROM entity_access\n WHERE source_id = ANY(ARRAY(\n SELECT cp.channel_id::text FROM comms_channel_participants cp\n WHERE cp.user_id = $3 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $3\n UNION ALL\n SELECT $3\n ))\n AND entity_id = $1\n AND entity_type = 'email_thread'\n UNION ALL\n -- Source 2: Select the publicAccessLevel (which is already text).\n SELECT \"publicAccessLevel\" as access_level\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true AND \"publicAccessLevel\" IS NOT NULL AND id IN (\n SELECT \"sharePermissionId\" FROM \"EmailThreadPermission\" WHERE \"threadId\" = $2\n )\n ) as all_levels\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "2e344d477bc3f8cfc2d031455a958b25d1a27c42d3420a624c0ec71de1d85ba9"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-2e86cba5f8e5a4358520e11e33cea6c51ce2ca2d05b985a30debdb97f9d7d78a.json b/rust/cloud-storage/chat/.sqlx/query-2e86cba5f8e5a4358520e11e33cea6c51ce2ca2d05b985a30debdb97f9d7d78a.json
new file mode 100644
index 0000000000..38ea8a45d4
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-2e86cba5f8e5a4358520e11e33cea6c51ce2ca2d05b985a30debdb97f9d7d78a.json
@@ -0,0 +1,124 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"PdfPlaceableCommentAnchor\" SET\n \"page\" = COALESCE($1, \"page\"),\n \"originalPage\" = COALESCE($2, \"originalPage\"),\n \"originalIndex\" = COALESCE($3, \"originalIndex\"),\n \"xPct\" = COALESCE($4, \"xPct\"),\n \"yPct\" = COALESCE($5, \"yPct\"),\n \"widthPct\" = COALESCE($6, \"widthPct\"),\n \"heightPct\" = COALESCE($7, \"heightPct\"),\n \"rotation\" = COALESCE($8, \"rotation\"),\n \"allowableEdits\" = COALESCE($9, \"allowableEdits\"),\n \"wasEdited\" = COALESCE($10, \"wasEdited\"),\n \"wasDeleted\" = COALESCE($11, \"wasDeleted\"),\n \"shouldLockOnSave\" = COALESCE($12, \"shouldLockOnSave\")\n WHERE uuid = $13\n RETURNING \n uuid, \n \"documentId\" as document_id,\n owner, \n \"threadId\" as thread_id, \n page, \n \"originalPage\" as original_page, \n \"originalIndex\" as original_index, \n \"xPct\" as x_pct, \n \"yPct\" as y_pct, \n \"widthPct\" as width_pct, \n \"heightPct\" as height_pct, \n rotation,\n \"allowableEdits\" as allowable_edits, \n \"wasEdited\" as was_edited, \n \"wasDeleted\" as was_deleted, \n \"shouldLockOnSave\" as should_lock_on_save\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 4,
+ "name": "page",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 5,
+ "name": "original_page",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 6,
+ "name": "original_index",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 7,
+ "name": "x_pct",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 8,
+ "name": "y_pct",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 9,
+ "name": "width_pct",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 10,
+ "name": "height_pct",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 11,
+ "name": "rotation",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 12,
+ "name": "allowable_edits",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 13,
+ "name": "was_edited",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 14,
+ "name": "was_deleted",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 15,
+ "name": "should_lock_on_save",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int4",
+ "Int4",
+ "Int4",
+ "Float8",
+ "Float8",
+ "Float8",
+ "Float8",
+ "Float8",
+ "Jsonb",
+ "Bool",
+ "Bool",
+ "Bool",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "2e86cba5f8e5a4358520e11e33cea6c51ce2ca2d05b985a30debdb97f9d7d78a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-2f1f54eaf23c0c277b0685c35ae75eea5921057be13e25a9609410d6ac5b17ba.json b/rust/cloud-storage/chat/.sqlx/query-2f1f54eaf23c0c277b0685c35ae75eea5921057be13e25a9609410d6ac5b17ba.json
new file mode 100644
index 0000000000..1428af8b0e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-2f1f54eaf23c0c277b0685c35ae75eea5921057be13e25a9609410d6ac5b17ba.json
@@ -0,0 +1,26 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"User\" (\"id\", \"email\", \"stripeCustomerId\", \"organizationId\", \"macro_user_id\")\n VALUES ($1, $2, $3, $4, $5)\n RETURNING id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Text",
+ "Int4",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "2f1f54eaf23c0c277b0685c35ae75eea5921057be13e25a9609410d6ac5b17ba"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-2f3f099717f4ffb3f73532fab42a02a6467e73fbd05c4d265903fd4bec995a89.json b/rust/cloud-storage/chat/.sqlx/query-2f3f099717f4ffb3f73532fab42a02a6467e73fbd05c4d265903fd4bec995a89.json
new file mode 100644
index 0000000000..7afa5d1c7f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-2f3f099717f4ffb3f73532fab42a02a6467e73fbd05c4d265903fd4bec995a89.json
@@ -0,0 +1,58 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n em.id,\n em.source_entity_type,\n em.source_entity_id,\n em.entity_type,\n em.entity_id,\n em.user_id,\n em.created_at\n FROM comms_entity_mentions AS em\n JOIN comms_messages AS m ON em.source_entity_id = m.id::text\n WHERE em.source_entity_type = 'message'\n AND (m.id = $1 OR m.thread_id = $1)\n ORDER BY em.created_at ASC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "source_entity_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 2,
+ "name": "source_entity_id",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 3,
+ "name": "entity_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 4,
+ "name": "entity_id",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 5,
+ "name": "user_id",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ false
+ ]
+ },
+ "hash": "2f3f099717f4ffb3f73532fab42a02a6467e73fbd05c4d265903fd4bec995a89"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-2f57ef816b974c70f46ed469ff98a316ee83b8e0b87a504a40ab4eb6f91c9bf6.json b/rust/cloud-storage/chat/.sqlx/query-2f57ef816b974c70f46ed469ff98a316ee83b8e0b87a504a40ab4eb6f91c9bf6.json
new file mode 100644
index 0000000000..8dab22de3e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-2f57ef816b974c70f46ed469ff98a316ee83b8e0b87a504a40ab4eb6f91c9bf6.json
@@ -0,0 +1,18 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"PdfHighlightRect\" (\"pdfHighlightAnchorId\", \"top\", \"left\", \"width\", \"height\")\n SELECT *\n FROM UNNEST(\n $1::uuid[], \n $2::double precision[], \n $3::double precision[], \n $4::double precision[], \n $5::double precision[]\n )\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "UuidArray",
+ "Float8Array",
+ "Float8Array",
+ "Float8Array",
+ "Float8Array"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "2f57ef816b974c70f46ed469ff98a316ee83b8e0b87a504a40ab4eb6f91c9bf6"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-30cb91911aecb757da05dab343255e9c81997db622339c1f414e36e873cb476e.json b/rust/cloud-storage/chat/.sqlx/query-30cb91911aecb757da05dab343255e9c81997db622339c1f414e36e873cb476e.json
new file mode 100644
index 0000000000..d1649a41c1
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-30cb91911aecb757da05dab343255e9c81997db622339c1f414e36e873cb476e.json
@@ -0,0 +1,32 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n u.id AS user_id,\n u.email,\n COUNT(d.id) AS document_count\n FROM\n \"User\" u\n LEFT JOIN\n \"Document\" d ON u.id = d.owner AND d.\"fileType\" IS DISTINCT FROM 'docx'\n WHERE\n u.id NOT LIKE 'macro|%'\n GROUP BY\n u.id, u.email\n ORDER BY\n document_count DESC;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "email",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_count",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": []
+ },
+ "nullable": [
+ false,
+ false,
+ null
+ ]
+ },
+ "hash": "30cb91911aecb757da05dab343255e9c81997db622339c1f414e36e873cb476e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-317f05707fdc73269f3017a3bb96d55b7327338bf5e52dfaad106b4b492cbb8e.json b/rust/cloud-storage/chat/.sqlx/query-317f05707fdc73269f3017a3bb96d55b7327338bf5e52dfaad106b4b492cbb8e.json
new file mode 100644
index 0000000000..b17b203167
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-317f05707fdc73269f3017a3bb96d55b7327338bf5e52dfaad106b4b492cbb8e.json
@@ -0,0 +1,98 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n un.user_id as owner_id,\n un.notification_id,\n n.event_item_id,\n n.event_item_type,\n un.sent,\n un.done,\n un.created_at::timestamptz as \"created_at!\",\n un.seen_at::timestamptz as viewed_at,\n un.created_at::timestamptz as \"updated_at!\",\n un.deleted_at::timestamptz,\n n.metadata as \"notification_metadata: serde_json::Value\",\n n.notification_event_type as notification_event_type,\n n.sender_id as sender_id\n FROM user_notification un\n JOIN notification n ON n.id = un.notification_id\n WHERE un.user_id = $1\n AND n.event_item_id = ANY($2)\n AND un.deleted_at IS NULL\n AND un.done = false\n AND (($4::timestamptz IS NULL)\n OR (un.created_at, un.notification_id) < ($4, $5))\n ORDER BY un.created_at DESC, un.notification_id DESC\n LIMIT $3\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "owner_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "event_item_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "event_item_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "sent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 5,
+ "name": "done",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "notification_metadata: serde_json::Value",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 11,
+ "name": "notification_event_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 12,
+ "name": "sender_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray",
+ "Int8",
+ "Timestamptz",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ null,
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "317f05707fdc73269f3017a3bb96d55b7327338bf5e52dfaad106b4b492cbb8e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-31e8eb8fb8d4562d654245be9afd54beff087b85e84ebd5b93c12eb9d7ebc877.json b/rust/cloud-storage/chat/.sqlx/query-31e8eb8fb8d4562d654245be9afd54beff087b85e84ebd5b93c12eb9d7ebc877.json
new file mode 100644
index 0000000000..e4f32c45b5
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-31e8eb8fb8d4562d654245be9afd54beff087b85e84ebd5b93c12eb9d7ebc877.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE team_invite\n SET last_sent_at = NOW()\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "31e8eb8fb8d4562d654245be9afd54beff087b85e84ebd5b93c12eb9d7ebc877"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-3293eab63193f1b3822a59e9a6a9621520f26e6ec8248abed103985281ef7ff1.json b/rust/cloud-storage/chat/.sqlx/query-3293eab63193f1b3822a59e9a6a9621520f26e6ec8248abed103985281ef7ff1.json
new file mode 100644
index 0000000000..e4a18ac5f0
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-3293eab63193f1b3822a59e9a6a9621520f26e6ec8248abed103985281ef7ff1.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET done = $3\n WHERE user_id = $1 AND notification_id = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray",
+ "Bool"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "3293eab63193f1b3822a59e9a6a9621520f26e6ec8248abed103985281ef7ff1"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-32d4e521979a071490ce529b37db5210b6068fa4a23b88e2b2d922f04e7129d8.json b/rust/cloud-storage/chat/.sqlx/query-32d4e521979a071490ce529b37db5210b6068fa4a23b88e2b2d922f04e7129d8.json
new file mode 100644
index 0000000000..95e3693fce
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-32d4e521979a071490ce529b37db5210b6068fa4a23b88e2b2d922f04e7129d8.json
@@ -0,0 +1,76 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n c.id as comment_id, \n c.\"threadId\" as thread_id, \n c.owner, \n c.sender, \n c.text, \n c.metadata, \n c.\"createdAt\"::timestamptz as created_at, \n c.\"updatedAt\"::timestamptz as updated_at, \n c.\"deletedAt\"::timestamptz as deleted_at, \n c.order\n FROM \"Comment\" c\n JOIN \"Thread\" t ON c.\"threadId\" = t.id\n WHERE t.\"documentId\" = $1 AND t.\"deletedAt\" IS NULL AND c.\"deletedAt\" IS NULL\n ORDER BY c.\"createdAt\" ASC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "comment_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "sender",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "text",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "metadata",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "order",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ false,
+ true,
+ null,
+ null,
+ null,
+ true
+ ]
+ },
+ "hash": "32d4e521979a071490ce529b37db5210b6068fa4a23b88e2b2d922f04e7129d8"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-32d69c4b151395989d7d00d594b1bd7161f5cc97b63616e9062feef7a335321c.json b/rust/cloud-storage/chat/.sqlx/query-32d69c4b151395989d7d00d594b1bd7161f5cc97b63616e9062feef7a335321c.json
new file mode 100644
index 0000000000..06db0f26c9
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-32d69c4b151395989d7d00d594b1bd7161f5cc97b63616e9062feef7a335321c.json
@@ -0,0 +1,60 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO comms_activity (\n id,\n user_id,\n channel_id,\n viewed_at\n )\n VALUES (\n $1, $2, $3, NOW()\n )\n ON CONFLICT (user_id, channel_id) DO UPDATE \n SET \n viewed_at = NOW(),\n updated_at = NOW()\n RETURNING \n id as \"id!: Uuid\",\n user_id as \"user_id!: String\",\n channel_id as \"channel_id!: Uuid\",\n created_at as \"created_at!: DateTime<Utc>\",\n updated_at as \"updated_at!: DateTime<Utc>\",\n viewed_at as \"viewed_at?: DateTime<Utc>\",\n interacted_at as \"interacted_at?: DateTime<Utc>\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!: Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "user_id!: String",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "channel_id!: Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at!: DateTime<Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 4,
+ "name": "updated_at!: DateTime<Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 5,
+ "name": "viewed_at?: DateTime<Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 6,
+ "name": "interacted_at?: DateTime<Utc>",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true
+ ]
+ },
+ "hash": "32d69c4b151395989d7d00d594b1bd7161f5cc97b63616e9062feef7a335321c"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-3357165799ff1f7bf1de3891174668e0ab16c64bd9dfc905213681e6021474fa.json b/rust/cloud-storage/chat/.sqlx/query-3357165799ff1f7bf1de3891174668e0ab16c64bd9dfc905213681e6021474fa.json
new file mode 100644
index 0000000000..6696253445
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-3357165799ff1f7bf1de3891174668e0ab16c64bd9dfc905213681e6021474fa.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT EXISTS(\n SELECT 1 FROM notification_message_receipt\n WHERE user_id = $1\n AND notification_id = $2\n AND failed = false\n ) as \"exists!\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "exists!",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "3357165799ff1f7bf1de3891174668e0ab16c64bd9dfc905213681e6021474fa"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-33e0a69e797d9274f49771113b4abc47b8a9fe63263b050379d73cc14ce38fd7.json b/rust/cloud-storage/chat/.sqlx/query-33e0a69e797d9274f49771113b4abc47b8a9fe63263b050379d73cc14ce38fd7.json
new file mode 100644
index 0000000000..ae0c6b9b23
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-33e0a69e797d9274f49771113b4abc47b8a9fe63263b050379d73cc14ce38fd7.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id\n FROM\n \"Document\" d\n WHERE\n d.\"projectId\" = ANY($1::text[])\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "33e0a69e797d9274f49771113b4abc47b8a9fe63263b050379d73cc14ce38fd7"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-3463e587c615fd82082c41897c917aef97239bcdd408c928caffed0d69c21613.json b/rust/cloud-storage/chat/.sqlx/query-3463e587c615fd82082c41897c917aef97239bcdd408c928caffed0d69c21613.json
similarity index 100%
rename from rust/cloud-storage/macro_db_client/.sqlx/query-3463e587c615fd82082c41897c917aef97239bcdd408c928caffed0d69c21613.json
rename to rust/cloud-storage/chat/.sqlx/query-3463e587c615fd82082c41897c917aef97239bcdd408c928caffed0d69c21613.json
diff --git a/rust/cloud-storage/chat/.sqlx/query-348f6c573e2e3eb6b568da52ec2e32692287496e4c8b17fd0a75187ce02f4ac9.json b/rust/cloud-storage/chat/.sqlx/query-348f6c573e2e3eb6b568da52ec2e32692287496e4c8b17fd0a75187ce02f4ac9.json
new file mode 100644
index 0000000000..f75802231d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-348f6c573e2e3eb6b568da52ec2e32692287496e4c8b17fd0a75187ce02f4ac9.json
@@ -0,0 +1,65 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $2 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $2\n UNION ALL\n SELECT $2\n )\n SELECT\n entity_id::text as \"entity_id!\",\n entity_type as \"entity_type!\",\n source_id as \"source_id!\",\n access_level as \"access_level!: AccessLevel\",\n created_at as \"created_at!: DateTime<Utc>\",\n updated_at as \"updated_at!: DateTime<Utc>\"\n FROM entity_access\n WHERE source_id = ANY(SELECT source_id FROM user_source_ids)\n AND entity_id = $1\n AND entity_type = 'email_thread'\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "entity_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "entity_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "source_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "access_level!: AccessLevel",
+ "type_info": {
+ "Custom": {
+ "name": "\"AccessLevel\"",
+ "kind": {
+ "Enum": [
+ "view",
+ "comment",
+ "edit",
+ "owner"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at!: DateTime<Utc>",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at!: DateTime<Utc>",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null,
+ false,
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "348f6c573e2e3eb6b568da52ec2e32692287496e4c8b17fd0a75187ce02f4ac9"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-350800132ce9026847f44354b415156432c57f20036d3e05eb8a72f09d88e10f.json b/rust/cloud-storage/chat/.sqlx/query-350800132ce9026847f44354b415156432c57f20036d3e05eb8a72f09d88e10f.json
new file mode 100644
index 0000000000..573f3269e8
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-350800132ce9026847f44354b415156432c57f20036d3e05eb8a72f09d88e10f.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"UserHistory\" (\"userId\", \"itemId\", \"itemType\", \"createdAt\", \"updatedAt\")\n SELECT u.user_id, u.item_id, 'project', NOW(), NOW()\n FROM UNNEST($1::text[], $2::text[]) AS u(item_id, user_id)\n ON CONFLICT (\"userId\", \"itemId\", \"itemType\") DO UPDATE\n SET \"updatedAt\" = NOW();\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "350800132ce9026847f44354b415156432c57f20036d3e05eb8a72f09d88e10f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-35dd883b5e9798f3946761308fccae6247ea21ab4446b1cd699aafb7290c30e6.json b/rust/cloud-storage/chat/.sqlx/query-35dd883b5e9798f3946761308fccae6247ea21ab4446b1cd699aafb7290c30e6.json
new file mode 100644
index 0000000000..4160d3b1f5
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-35dd883b5e9798f3946761308fccae6247ea21ab4446b1cd699aafb7290c30e6.json
@@ -0,0 +1,84 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO team_invite (id, team_id, email, team_role, invited_by, created_at, last_sent_at)\n VALUES ($1, $2, $3, $4, $5, NOW(), NOW())\n RETURNING id, email, team_id, team_role as \"team_role!: models_team::TeamRole\", invited_by, created_at as \"created_at!: chrono::DateTime<chrono::Utc>\", last_sent_at as \"last_sent_at!: chrono::DateTime<chrono::Utc>\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "email",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "team_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 3,
+ "name": "team_role!: models_team::TeamRole",
+ "type_info": {
+ "Custom": {
+ "name": "team_role",
+ "kind": {
+ "Enum": [
+ "member",
+ "admin",
+ "owner"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 4,
+ "name": "invited_by",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "created_at!: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 6,
+ "name": "last_sent_at!: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Uuid",
+ "Text",
+ {
+ "Custom": {
+ "name": "team_role",
+ "kind": {
+ "Enum": [
+ "member",
+ "admin",
+ "owner"
+ ]
+ }
+ }
+ },
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "35dd883b5e9798f3946761308fccae6247ea21ab4446b1cd699aafb7290c30e6"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-36dfcf982834f117d97d1ba332be6784c946f05120c7c228ff258389ceba97a1.json b/rust/cloud-storage/chat/.sqlx/query-36dfcf982834f117d97d1ba332be6784c946f05120c7c228ff258389ceba97a1.json
new file mode 100644
index 0000000000..c07ec0acbe
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-36dfcf982834f117d97d1ba332be6784c946f05120c7c228ff258389ceba97a1.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO user_notification_type_preference (user_id, notification_event_type)\n VALUES ($1, $2)\n ON CONFLICT (user_id, notification_event_type) DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Varchar"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "36dfcf982834f117d97d1ba332be6784c946f05120c7c228ff258389ceba97a1"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-376d485681b329e1febf28f35020eadfdbec930e33a0666707593e20ae4f67f5.json b/rust/cloud-storage/chat/.sqlx/query-376d485681b329e1febf28f35020eadfdbec930e33a0666707593e20ae4f67f5.json
new file mode 100644
index 0000000000..8b67204019
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-376d485681b329e1febf28f35020eadfdbec930e33a0666707593e20ae4f67f5.json
@@ -0,0 +1,118 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n ph.uuid, \n ph.\"documentId\" as document_id,\n ph.owner, \n ph.\"threadId\" as thread_id, \n ph.page, \n ph.red,\n ph.green, \n ph.blue, \n ph.alpha, \n ph.type as highlight_type, \n ph.text, \n ph.\"pageViewportWidth\" as page_viewport_width, \n ph.\"pageViewportHeight\" as page_viewport_height, \n ph.\"createdAt\"::timestamptz as created_at, \n ph.\"updatedAt\"::timestamptz as updated_at, \n ph.\"deletedAt\"::timestamptz as deleted_at, \n array_agg((phr.id, phr.top, phr.left, phr.width, phr.height)) as \"highlight_rects!: Vec<PdfHighlightRect>\"\n FROM \"PdfHighlightAnchor\" ph\n JOIN \"PdfHighlightRect\" phr ON ph.uuid = phr.\"pdfHighlightAnchorId\"\n LEFT JOIN \"Thread\" t ON ph.\"threadId\" = t.id\n WHERE ph.\"documentId\" = $1\n AND ph.\"deletedAt\" IS NULL\n AND t.\"deletedAt\" IS NULL\n GROUP BY ph.uuid, ph.owner, ph.\"threadId\", ph.page, ph.red, ph.green, ph.blue, ph.alpha, ph.type, ph.text, ph.\"pageViewportWidth\", ph.\"pageViewportHeight\", ph.\"createdAt\", ph.\"updatedAt\", ph.\"deletedAt\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 4,
+ "name": "page",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 5,
+ "name": "red",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 6,
+ "name": "green",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 7,
+ "name": "blue",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 8,
+ "name": "alpha",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 9,
+ "name": "highlight_type",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 10,
+ "name": "text",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 11,
+ "name": "page_viewport_width",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 12,
+ "name": "page_viewport_height",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 13,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 14,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 15,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 16,
+ "name": "highlight_rects!: Vec<PdfHighlightRect>",
+ "type_info": "RecordArray"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "376d485681b329e1febf28f35020eadfdbec930e33a0666707593e20ae4f67f5"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08.json b/rust/cloud-storage/chat/.sqlx/query-377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08.json
new file mode 100644
index 0000000000..9348d25315
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"DocumentPermission\" WHERE \"documentId\" = $1\n )\n \n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60.json b/rust/cloud-storage/chat/.sqlx/query-37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60.json
new file mode 100644
index 0000000000..44d3a67e72
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT EXISTS (\n SELECT 1\n FROM public.email_threads t\n JOIN public.email_links l ON l.id = t.link_id\n WHERE t.id = $1::uuid\n AND l.macro_id = $2\n ) AS \"exists!\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "exists!",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-38100c858a13cb36daa9ab6dce62d5d8755152a4d61877318d709aeee6d7a7cc.json b/rust/cloud-storage/chat/.sqlx/query-38100c858a13cb36daa9ab6dce62d5d8755152a4d61877318d709aeee6d7a7cc.json
deleted file mode 100644
index c3966b8c2d..0000000000
--- a/rust/cloud-storage/chat/.sqlx/query-38100c858a13cb36daa9ab6dce62d5d8755152a4d61877318d709aeee6d7a7cc.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "DELETE FROM \"UserItemAccess\" WHERE \"item_id\" = $1 AND \"item_type\" = 'chat'",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": []
- },
- "hash": "38100c858a13cb36daa9ab6dce62d5d8755152a4d61877318d709aeee6d7a7cc"
-}
diff --git a/rust/cloud-storage/chat/.sqlx/query-3819e79d674b6629df95c52d2e865328a519ed67ec84b882261f44489823523e.json b/rust/cloud-storage/chat/.sqlx/query-3819e79d674b6629df95c52d2e865328a519ed67ec84b882261f44489823523e.json
new file mode 100644
index 0000000000..666c462838
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-3819e79d674b6629df95c52d2e865328a519ed67ec84b882261f44489823523e.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT DISTINCT m.channel_id\n FROM comms_entity_mentions em\n JOIN comms_messages m ON m.id::text = em.source_entity_id AND em.source_entity_type = 'message'\n JOIN comms_channels c ON c.id = m.channel_id\n WHERE em.entity_id = $1 AND em.entity_type = $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "channel_id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "3819e79d674b6629df95c52d2e865328a519ed67ec84b882261f44489823523e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-39257a88a1d0bda4726e269ce262291e713cf20f121e10997bcf944f3363efb8.json b/rust/cloud-storage/chat/.sqlx/query-39257a88a1d0bda4726e269ce262291e713cf20f121e10997bcf944f3363efb8.json
new file mode 100644
index 0000000000..edc2b98e8c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-39257a88a1d0bda4726e269ce262291e713cf20f121e10997bcf944f3363efb8.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n bp.sha as sha,\n bp.path as path,\n bp.id as id\n FROM \"BomPart\" bp\n JOIN \"DocumentBom\" db ON bp.\"documentBomId\" = db.id\n WHERE db.\"documentId\" = $1;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "sha",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "path",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "39257a88a1d0bda4726e269ce262291e713cf20f121e10997bcf944f3363efb8"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-399d9c2a1c07919059e7d5a7c58c97f9eff09db1237092b37fc80ece52ff410f.json b/rust/cloud-storage/chat/.sqlx/query-399d9c2a1c07919059e7d5a7c58c97f9eff09db1237092b37fc80ece52ff410f.json
new file mode 100644
index 0000000000..6773f99e9e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-399d9c2a1c07919059e7d5a7c58c97f9eff09db1237092b37fc80ece52ff410f.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"User\" SET \"macro_user_id\" = $1 WHERE \"macro_user_id\" = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "399d9c2a1c07919059e7d5a7c58c97f9eff09db1237092b37fc80ece52ff410f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-3a4acf38ce09e3278ff2020de09c48267215a33e4c8d135319959aed14edbe63.json b/rust/cloud-storage/chat/.sqlx/query-3a4acf38ce09e3278ff2020de09c48267215a33e4c8d135319959aed14edbe63.json
new file mode 100644
index 0000000000..d507796bee
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-3a4acf38ce09e3278ff2020de09c48267215a33e4c8d135319959aed14edbe63.json
@@ -0,0 +1,42 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"ExperimentLog\" (experiment_id, user_id, \"group\")\n VALUES ($1, $2, $3)\n RETURNING experiment_id, user_id, \"group\" as experiment_group, completed\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "experiment_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "experiment_group",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 3,
+ "name": "completed",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Varchar"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "3a4acf38ce09e3278ff2020de09c48267215a33e4c8d135319959aed14edbe63"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-3c082e8dc2056f62233bb2d68147a491c8ccb46f90738f8ebbf25afea699876a.json b/rust/cloud-storage/chat/.sqlx/query-3c082e8dc2056f62233bb2d68147a491c8ccb46f90738f8ebbf25afea699876a.json
new file mode 100644
index 0000000000..1f389c60ba
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-3c082e8dc2056f62233bb2d68147a491c8ccb46f90738f8ebbf25afea699876a.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n u.id as user_id\n FROM \"User\" u\n WHERE u.\"organizationId\" = $1\n LIMIT $2\n OFFSET $3\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int4",
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "3c082e8dc2056f62233bb2d68147a491c8ccb46f90738f8ebbf25afea699876a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-3c53847bf278b4452c56d695306bb384f3a9354e7e078bfc73ffd0b95f46dd03.json b/rust/cloud-storage/chat/.sqlx/query-3c53847bf278b4452c56d695306bb384f3a9354e7e078bfc73ffd0b95f46dd03.json
new file mode 100644
index 0000000000..0d46873a60
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-3c53847bf278b4452c56d695306bb384f3a9354e7e078bfc73ffd0b95f46dd03.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_channels AS (\n SELECT DISTINCT c.*\n FROM comms_channels c\n INNER JOIN comms_channel_participants cp ON cp.channel_id = c.id\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n \n UNION\n \n SELECT c.*\n FROM comms_channels c\n WHERE c.channel_type = 'organization'::comms_channel_type\n AND c.org_id = $2::bigint\n )\n SELECT \n id as \"id!\"\n FROM user_channels\n ORDER BY created_at DESC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "3c53847bf278b4452c56d695306bb384f3a9354e7e078bfc73ffd0b95f46dd03"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-3d0cc500bd9cee7fe4179b9ebc8176e5b20c478d2e5c4cba230e5fa3f57d38d6.json b/rust/cloud-storage/chat/.sqlx/query-3d0cc500bd9cee7fe4179b9ebc8176e5b20c478d2e5c4cba230e5fa3f57d38d6.json
new file mode 100644
index 0000000000..90d7d9ea68
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-3d0cc500bd9cee7fe4179b9ebc8176e5b20c478d2e5c4cba230e5fa3f57d38d6.json
@@ -0,0 +1,58 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n p.id as id,\n p.name,\n p.\"userId\" as user_id,\n p.\"parentId\" as \"parent_id?\",\n p.\"createdAt\"::timestamptz as created_at,\n p.\"updatedAt\"::timestamptz as updated_at,\n p.\"deletedAt\"::timestamptz as deleted_at\n FROM\n \"Project\" p\n WHERE p.\"parentId\" = $1 AND p.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "parent_id?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "3d0cc500bd9cee7fe4179b9ebc8176e5b20c478d2e5c4cba230e5fa3f57d38d6"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-3ddef23b2904342f1b84795fd71b50de4413626a5dd460c83ad9e997fb8e09ae.json b/rust/cloud-storage/chat/.sqlx/query-3ddef23b2904342f1b84795fd71b50de4413626a5dd460c83ad9e997fb8e09ae.json
new file mode 100644
index 0000000000..53ba1ca60d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-3ddef23b2904342f1b84795fd71b50de4413626a5dd460c83ad9e997fb8e09ae.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Chat\" SET \"deletedAt\" = NOW() WHERE id = $1",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "3ddef23b2904342f1b84795fd71b50de4413626a5dd460c83ad9e997fb8e09ae"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-3de786ce00b9b7a2cf935b39ed0bed0d042a4133b63124b1894da135d0a9449b.json b/rust/cloud-storage/chat/.sqlx/query-3de786ce00b9b7a2cf935b39ed0bed0d042a4133b63124b1894da135d0a9449b.json
new file mode 100644
index 0000000000..036b2d51d9
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-3de786ce00b9b7a2cf935b39ed0bed0d042a4133b63124b1894da135d0a9449b.json
@@ -0,0 +1,20 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.\"documentId\" as \"document_id\"\n FROM\n \"DocumentText\" d\n WHERE\n d.\"tokenCount\" = 0\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": []
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "3de786ce00b9b7a2cf935b39ed0bed0d042a4133b63124b1894da135d0a9449b"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-3e161b7906ba15490634a5375e300d649e4aa06841adb1645d4f17507cf15694.json b/rust/cloud-storage/chat/.sqlx/query-3e161b7906ba15490634a5375e300d649e4aa06841adb1645d4f17507cf15694.json
new file mode 100644
index 0000000000..8a601b1311
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-3e161b7906ba15490634a5375e300d649e4aa06841adb1645d4f17507cf15694.json
@@ -0,0 +1,25 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"User\" (\"id\", \"email\", \"organizationId\", \"macro_user_id\")\n VALUES ($1, $2, $3, $4)\n RETURNING id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Int4",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "3e161b7906ba15490634a5375e300d649e4aa06841adb1645d4f17507cf15694"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-3e3b2b04a9eb28ea82f8f97a2b725b205e0b6f330e4f3eb9690375e992ce2194.json b/rust/cloud-storage/chat/.sqlx/query-3e3b2b04a9eb28ea82f8f97a2b725b205e0b6f330e4f3eb9690375e992ce2194.json
new file mode 100644
index 0000000000..dad50de6d8
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-3e3b2b04a9eb28ea82f8f97a2b725b205e0b6f330e4f3eb9690375e992ce2194.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"id\" FROM \"Chat\" WHERE \"projectId\" = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "3e3b2b04a9eb28ea82f8f97a2b725b205e0b6f330e4f3eb9690375e992ce2194"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-3e5924421ddbfb3eef5e5d949677a72f6dddf521d5df201bb11207e89be08747.json b/rust/cloud-storage/chat/.sqlx/query-3e5924421ddbfb3eef5e5d949677a72f6dddf521d5df201bb11207e89be08747.json
new file mode 100644
index 0000000000..c97deb4e61
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-3e5924421ddbfb3eef5e5d949677a72f6dddf521d5df201bb11207e89be08747.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id,\n macro_user_id,\n email\n FROM\n in_progress_email_link\n WHERE\n id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "macro_user_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "email",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "3e5924421ddbfb3eef5e5d949677a72f6dddf521d5df201bb11207e89be08747"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-3e8b0491c7a948d3f6d821b9b7d7516558a0c38da48816d8a8f3ac8420fb4fa7.json b/rust/cloud-storage/chat/.sqlx/query-3e8b0491c7a948d3f6d821b9b7d7516558a0c38da48816d8a8f3ac8420fb4fa7.json
new file mode 100644
index 0000000000..73aeb3e457
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-3e8b0491c7a948d3f6d821b9b7d7516558a0c38da48816d8a8f3ac8420fb4fa7.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT EXISTS (\n SELECT 1 FROM comms_channel_participants\n WHERE channel_id = $1\n AND user_id = $2\n AND role IN ('admin'::comms_participant_role, 'owner'::comms_participant_role)\n ) as \"is_authorized!\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "is_authorized!",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "3e8b0491c7a948d3f6d821b9b7d7516558a0c38da48816d8a8f3ac8420fb4fa7"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-3e8c8b376d3e0ae4e7245e3b07a3e64b8847f80831d648ae9b5216560d5e27eb.json b/rust/cloud-storage/chat/.sqlx/query-3e8c8b376d3e0ae4e7245e3b07a3e64b8847f80831d648ae9b5216560d5e27eb.json
new file mode 100644
index 0000000000..98172db9c0
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-3e8c8b376d3e0ae4e7245e3b07a3e64b8847f80831d648ae9b5216560d5e27eb.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "UPDATE \"Document\" SET \"uploaded\" = true WHERE id = $1",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "3e8c8b376d3e0ae4e7245e3b07a3e64b8847f80831d648ae9b5216560d5e27eb"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-3e8d3378b4651a45d6e1cfee02d1d991bb8fa6a687207164d713487c524d87a6.json b/rust/cloud-storage/chat/.sqlx/query-3e8d3378b4651a45d6e1cfee02d1d991bb8fa6a687207164d713487c524d87a6.json
new file mode 100644
index 0000000000..6496703c4d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-3e8d3378b4651a45d6e1cfee02d1d991bb8fa6a687207164d713487c524d87a6.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Chat\" SET \"deletedAt\" = NULL WHERE id = ANY($1);\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "3e8d3378b4651a45d6e1cfee02d1d991bb8fa6a687207164d713487c524d87a6"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-3eebc9f54cadfffef67a78b403320f8f305d08873a4c857c118f166d6c16b6af.json b/rust/cloud-storage/chat/.sqlx/query-3eebc9f54cadfffef67a78b403320f8f305d08873a4c857c118f166d6c16b6af.json
new file mode 100644
index 0000000000..b4e060a62c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-3eebc9f54cadfffef67a78b403320f8f305d08873a4c857c118f166d6c16b6af.json
@@ -0,0 +1,60 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO comms_activity (\n id,\n user_id,\n channel_id,\n created_at,\n updated_at\n )\n VALUES (\n $1, $2, $3, NOW(), NOW()\n )\n RETURNING \n id as \"id!: Uuid\",\n user_id as \"user_id!: String\",\n channel_id as \"channel_id!: Uuid\",\n created_at as \"created_at!: DateTime<Utc>\",\n updated_at as \"updated_at!: DateTime<Utc>\",\n viewed_at as \"viewed_at?: DateTime<Utc>\",\n interacted_at as \"interacted_at?: DateTime<Utc>\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!: Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "user_id!: String",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "channel_id!: Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at!: DateTime<Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 4,
+ "name": "updated_at!: DateTime<Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 5,
+ "name": "viewed_at?: DateTime<Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 6,
+ "name": "interacted_at?: DateTime<Utc>",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true
+ ]
+ },
+ "hash": "3eebc9f54cadfffef67a78b403320f8f305d08873a4c857c118f166d6c16b6af"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-3ff726c2ff64c69e2af5dca67815300efe7b0bcbd74ae96f3d65aeb8edd064f7.json b/rust/cloud-storage/chat/.sqlx/query-3ff726c2ff64c69e2af5dca67815300efe7b0bcbd74ae96f3d65aeb8edd064f7.json
new file mode 100644
index 0000000000..9cd2b5c5ae
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-3ff726c2ff64c69e2af5dca67815300efe7b0bcbd74ae96f3d65aeb8edd064f7.json
@@ -0,0 +1,58 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n p.id,\n p.name,\n p.\"userId\" as user_id,\n p.\"parentId\" as parent_id,\n p.\"createdAt\"::timestamptz as created_at,\n p.\"updatedAt\"::timestamptz as updated_at,\n p.\"deletedAt\"::timestamptz as deleted_at\n FROM \"Project\" p\n WHERE id = $1 AND p.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "parent_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "3ff726c2ff64c69e2af5dca67815300efe7b0bcbd74ae96f3d65aeb8edd064f7"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-42546a42d5b23be78e06b0bdf3188821246cd0b2d459d8dc667be1e6c8de1c98.json b/rust/cloud-storage/chat/.sqlx/query-42546a42d5b23be78e06b0bdf3188821246cd0b2d459d8dc667be1e6c8de1c98.json
new file mode 100644
index 0000000000..001698c6b2
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-42546a42d5b23be78e06b0bdf3188821246cd0b2d459d8dc667be1e6c8de1c98.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n u.\"id\" as id\n FROM \"Document\" d\n INNER JOIN \"UserHistory\" uh ON uh.\"itemId\" = d.\"id\" AND uh.\"itemType\" = 'document'\n INNER JOIN \"User\" u ON u.id = uh.\"userId\"\n WHERE d.id = $1 AND u.id != d.\"owner\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "42546a42d5b23be78e06b0bdf3188821246cd0b2d459d8dc667be1e6c8de1c98"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-428083ae29c00ef5dfae2fadc0d3ebe3c3191c212f37631feda29343104f9548.json b/rust/cloud-storage/chat/.sqlx/query-428083ae29c00ef5dfae2fadc0d3ebe3c3191c212f37631feda29343104f9548.json
new file mode 100644
index 0000000000..dff060816a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-428083ae29c00ef5dfae2fadc0d3ebe3c3191c212f37631feda29343104f9548.json
@@ -0,0 +1,18 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"User\"\n SET \"firstName\" = $1,\n \"lastName\" = $2,\n \"title\" = $3,\n \"industry\" = $4\n WHERE id = $5\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Varchar",
+ "Varchar",
+ "Varchar",
+ "Varchar",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "428083ae29c00ef5dfae2fadc0d3ebe3c3191c212f37631feda29343104f9548"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-42f09cdfac72096bac4124c84318142bbc2bc0256ff84a6ba9ab2f98fd9fb0c1.json b/rust/cloud-storage/chat/.sqlx/query-42f09cdfac72096bac4124c84318142bbc2bc0256ff84a6ba9ab2f98fd9fb0c1.json
new file mode 100644
index 0000000000..a7dfaf200c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-42f09cdfac72096bac4124c84318142bbc2bc0256ff84a6ba9ab2f98fd9fb0c1.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "DELETE FROM \"OrganizationEmailMatches\" WHERE \"organizationId\" = $1 AND email = $2",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Int4",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "42f09cdfac72096bac4124c84318142bbc2bc0256ff84a6ba9ab2f98fd9fb0c1"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-4465cdde5f953cd550e7190572d8e5e4c70fce8558763d56a3f57e99474a9aeb.json b/rust/cloud-storage/chat/.sqlx/query-4465cdde5f953cd550e7190572d8e5e4c70fce8558763d56a3f57e99474a9aeb.json
new file mode 100644
index 0000000000..8f303de688
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-4465cdde5f953cd550e7190572d8e5e4c70fce8558763d56a3f57e99474a9aeb.json
@@ -0,0 +1,39 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO comms_channels (id, name, owner_id, org_id, channel_type)\n VALUES ($1, $2, $3, $4, $5)\n RETURNING id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Varchar",
+ "Text",
+ "Int8",
+ {
+ "Custom": {
+ "name": "comms_channel_type",
+ "kind": {
+ "Enum": [
+ "public",
+ "organization",
+ "private",
+ "direct_message",
+ "team"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "4465cdde5f953cd550e7190572d8e5e4c70fce8558763d56a3f57e99474a9aeb"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-9ca2064c1f9ecd29c3c30ffbb4729af9a0ff0aa059a326a1c119d1a0ac597419.json b/rust/cloud-storage/chat/.sqlx/query-44a05989da2597deae3eaded94e7270307a3e4f36625e76d489d4bc39b66e759.json
similarity index 52%
rename from rust/cloud-storage/macro_db_client/.sqlx/query-9ca2064c1f9ecd29c3c30ffbb4729af9a0ff0aa059a326a1c119d1a0ac597419.json
rename to rust/cloud-storage/chat/.sqlx/query-44a05989da2597deae3eaded94e7270307a3e4f36625e76d489d4bc39b66e759.json
index 7a8fe22644..fad533832f 100644
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-9ca2064c1f9ecd29c3c30ffbb4729af9a0ff0aa059a326a1c119d1a0ac597419.json
+++ b/rust/cloud-storage/chat/.sqlx/query-44a05989da2597deae3eaded94e7270307a3e4f36625e76d489d4bc39b66e759.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT\n dp.\"sharePermissionId\" as share_permission_id\n FROM \"DocumentPermission\" dp\n WHERE dp.\"documentId\" = $1\n ",
+ "query": "\n SELECT\n pp.\"sharePermissionId\" as share_permission_id\n FROM \"ProjectPermission\" pp\n WHERE pp.\"projectId\" = $1\n ",
"describe": {
"columns": [
{
@@ -18,5 +18,5 @@
false
]
},
- "hash": "9ca2064c1f9ecd29c3c30ffbb4729af9a0ff0aa059a326a1c119d1a0ac597419"
+ "hash": "44a05989da2597deae3eaded94e7270307a3e4f36625e76d489d4bc39b66e759"
}
diff --git a/rust/cloud-storage/chat/.sqlx/query-44aa0fedb485db7f86d0dd21c5ac83ffd5ac9b4ce85a5d08d0fc5095efa73505.json b/rust/cloud-storage/chat/.sqlx/query-44aa0fedb485db7f86d0dd21c5ac83ffd5ac9b4ce85a5d08d0fc5095efa73505.json
new file mode 100644
index 0000000000..3d662e3a32
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-44aa0fedb485db7f86d0dd21c5ac83ffd5ac9b4ce85a5d08d0fc5095efa73505.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT oem.email\n FROM \"OrganizationEmailMatches\" oem\n JOIN \"Organization\" o ON o.\"id\" = oem.\"organizationId\"\n WHERE oem.\"organizationId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "email",
+ "type_info": "Varchar"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int4"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "44aa0fedb485db7f86d0dd21c5ac83ffd5ac9b4ce85a5d08d0fc5095efa73505"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-454e1202630627f0f8c9f876f1917d6cfbed8fc192939cc0e5e43b86905a4ca2.json b/rust/cloud-storage/chat/.sqlx/query-454e1202630627f0f8c9f876f1917d6cfbed8fc192939cc0e5e43b86905a4ca2.json
new file mode 100644
index 0000000000..0e8a2423f4
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-454e1202630627f0f8c9f876f1917d6cfbed8fc192939cc0e5e43b86905a4ca2.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"OrganizationInvitation\"\n WHERE email = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "454e1202630627f0f8c9f876f1917d6cfbed8fc192939cc0e5e43b86905a4ca2"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-467fc7bd79aaa296588af3527f1d1fa944740f01ce65798b18269b099a65a283.json b/rust/cloud-storage/chat/.sqlx/query-467fc7bd79aaa296588af3527f1d1fa944740f01ce65798b18269b099a65a283.json
new file mode 100644
index 0000000000..f7c0d8d0b0
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-467fc7bd79aaa296588af3527f1d1fa944740f01ce65798b18269b099a65a283.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"sharePermissionId\" as id FROM \"ProjectPermission\" WHERE \"projectId\" = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "467fc7bd79aaa296588af3527f1d1fa944740f01ce65798b18269b099a65a283"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-47527ceedb84aa81cf48fd3529718a5303e9f456e3db0ac35840627b086d3995.json b/rust/cloud-storage/chat/.sqlx/query-47527ceedb84aa81cf48fd3529718a5303e9f456e3db0ac35840627b086d3995.json
new file mode 100644
index 0000000000..76fa7f167e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-47527ceedb84aa81cf48fd3529718a5303e9f456e3db0ac35840627b086d3995.json
@@ -0,0 +1,74 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n UserAccessibleDocuments AS (\n SELECT DISTINCT ON (entity_id) entity_id, access_level\n FROM entity_access\n WHERE source_id = ANY(SELECT source_id FROM user_source_ids)\n AND entity_type = 'document'\n ORDER BY entity_id,\n CASE access_level::text\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3\n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END DESC\n )\n SELECT\n d.id as \"document_id!\",\n d.name as \"document_name!\",\n d.owner as \"owner!\",\n d.\"fileType\" as \"file_type\",\n d.\"projectId\" as \"project_id\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\",\n uad.access_level::text as \"access_level!\"\n FROM \"Document\" d\n INNER JOIN UserAccessibleDocuments uad ON uad.entity_id = d.id::uuid\n WHERE d.\"deletedAt\" IS NULL\n AND ($2::text[] IS NULL OR d.\"fileType\" = ANY($2))\n AND (\n CASE uad.access_level::text\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3\n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END >=\n CASE $3\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3\n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END\n )\n ORDER BY d.\"updatedAt\" DESC\n LIMIT $4 OFFSET $5\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "document_name!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray",
+ "Text",
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ true,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "47527ceedb84aa81cf48fd3529718a5303e9f456e3db0ac35840627b086d3995"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-47f0213791a57c90d28af2015b1de283865e6bbf5776a9f482a5d21568c14d3e.json b/rust/cloud-storage/chat/.sqlx/query-47f0213791a57c90d28af2015b1de283865e6bbf5776a9f482a5d21568c14d3e.json
new file mode 100644
index 0000000000..1d742c4cac
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-47f0213791a57c90d28af2015b1de283865e6bbf5776a9f482a5d21568c14d3e.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"User\"\n SET \"aiDataConsent\" = $1\n WHERE id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Bool",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "47f0213791a57c90d28af2015b1de283865e6bbf5776a9f482a5d21568c14d3e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-47fb0faaa3568c45ff7abcc6b1b1229d7042950891759db010a27c5a18ed2909.json b/rust/cloud-storage/chat/.sqlx/query-47fb0faaa3568c45ff7abcc6b1b1229d7042950891759db010a27c5a18ed2909.json
new file mode 100644
index 0000000000..7013b71318
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-47fb0faaa3568c45ff7abcc6b1b1229d7042950891759db010a27c5a18ed2909.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT d.id\n FROM \"Document\" d\n WHERE d.\"deletedAt\" IS NOT NULL AND d.\"deletedAt\" <= $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Timestamp"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "47fb0faaa3568c45ff7abcc6b1b1229d7042950891759db010a27c5a18ed2909"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-4825133a0ea4f2d839f5976681269e6ad7a517fd29a3d2a7634cc655bf7f2bfb.json b/rust/cloud-storage/chat/.sqlx/query-4825133a0ea4f2d839f5976681269e6ad7a517fd29a3d2a7634cc655bf7f2bfb.json
new file mode 100644
index 0000000000..e9ccf34748
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-4825133a0ea4f2d839f5976681269e6ad7a517fd29a3d2a7634cc655bf7f2bfb.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"entity_access\"\n WHERE entity_id = ANY($1) AND entity_type = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "UuidArray",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "4825133a0ea4f2d839f5976681269e6ad7a517fd29a3d2a7634cc655bf7f2bfb"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-48293aa40f783e58d4f49e2d0495255d70d2b790baa1bfb5397913d2a4b1dd8f.json b/rust/cloud-storage/chat/.sqlx/query-48293aa40f783e58d4f49e2d0495255d70d2b790baa1bfb5397913d2a4b1dd8f.json
new file mode 100644
index 0000000000..d5d5bbf1a9
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-48293aa40f783e58d4f49e2d0495255d70d2b790baa1bfb5397913d2a4b1dd8f.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"OrganizationRetentionPolicy\" \n SET \"retention_days\" = $2\n WHERE \"organization_id\" = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Int4",
+ "Int4"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "48293aa40f783e58d4f49e2d0495255d70d2b790baa1bfb5397913d2a4b1dd8f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-483f8f8ef068fb6394d5af8d06068d4463413d22894b6c6b72965f90d8ef0436.json b/rust/cloud-storage/chat/.sqlx/query-483f8f8ef068fb6394d5af8d06068d4463413d22894b6c6b72965f90d8ef0436.json
new file mode 100644
index 0000000000..338983b3a7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-483f8f8ef068fb6394d5af8d06068d4463413d22894b6c6b72965f90d8ef0436.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "DELETE FROM \"UserHistory\" WHERE \"userId\" = $1 AND \"itemId\" = $2 AND \"itemType\" = $3",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "483f8f8ef068fb6394d5af8d06068d4463413d22894b6c6b72965f90d8ef0436"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-48697f17a7121986cc770d6698fbca7bf107ae20dbadbf64a7799ab162b2feb4.json b/rust/cloud-storage/chat/.sqlx/query-48697f17a7121986cc770d6698fbca7bf107ae20dbadbf64a7799ab162b2feb4.json
new file mode 100644
index 0000000000..3fdea7e232
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-48697f17a7121986cc770d6698fbca7bf107ae20dbadbf64a7799ab162b2feb4.json
@@ -0,0 +1,95 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n un.user_id as owner_id,\n un.notification_id,\n n.event_item_id,\n n.event_item_type,\n un.sent,\n un.done,\n un.created_at::timestamptz as \"created_at!\",\n un.seen_at::timestamptz as viewed_at,\n un.created_at::timestamptz as \"updated_at!\",\n un.deleted_at::timestamptz,\n n.metadata as \"notification_metadata: serde_json::Value\",\n n.notification_event_type as notification_event_type,\n n.sender_id as sender_id\n FROM user_notification un\n JOIN notification n ON n.id = un.notification_id\n WHERE un.user_id = $1\n AND un.notification_id = $2\n AND un.deleted_at IS NULL\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "owner_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "event_item_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "event_item_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "sent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 5,
+ "name": "done",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "notification_metadata: serde_json::Value",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 11,
+ "name": "notification_event_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 12,
+ "name": "sender_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ null,
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "48697f17a7121986cc770d6698fbca7bf107ae20dbadbf64a7799ab162b2feb4"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-48b369655e2258f40d38ab1352825be135e66c8215c051a56c7aa032b2abbd02.json b/rust/cloud-storage/chat/.sqlx/query-48b369655e2258f40d38ab1352825be135e66c8215c051a56c7aa032b2abbd02.json
new file mode 100644
index 0000000000..8c77e4ca15
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-48b369655e2258f40d38ab1352825be135e66c8215c051a56c7aa032b2abbd02.json
@@ -0,0 +1,26 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"ThreadAnchor\" (\"threadId\", \"anchorId\", \"anchorTableName\")\n VALUES ($1, $2, $3::\"anchor_table_name\")\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Uuid",
+ {
+ "Custom": {
+ "name": "anchor_table_name",
+ "kind": {
+ "Enum": [
+ "PdfPlaceableCommentAnchor",
+ "PdfHighlightAnchor"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "48b369655e2258f40d38ab1352825be135e66c8215c051a56c7aa032b2abbd02"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-4a02aab26f16872fc4f19617011e4dc054b233dea57f9c78a4f2ba5b19284f62.json b/rust/cloud-storage/chat/.sqlx/query-4a02aab26f16872fc4f19617011e4dc054b233dea57f9c78a4f2ba5b19284f62.json
new file mode 100644
index 0000000000..9b18331876
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-4a02aab26f16872fc4f19617011e4dc054b233dea57f9c78a4f2ba5b19284f62.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n oi.email\n FROM \"OrganizationInvitation\" oi\n WHERE oi.organization_id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "email",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int4"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "4a02aab26f16872fc4f19617011e4dc054b233dea57f9c78a4f2ba5b19284f62"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-4b483617cc20e22761392cb54e682762a83c3dbeec3eacfeaadae1ca8aff376c.json b/rust/cloud-storage/chat/.sqlx/query-4b483617cc20e22761392cb54e682762a83c3dbeec3eacfeaadae1ca8aff376c.json
new file mode 100644
index 0000000000..70a5865537
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-4b483617cc20e22761392cb54e682762a83c3dbeec3eacfeaadae1ca8aff376c.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id, username, stripe_customer_id\n FROM macro_user\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "username",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "stripe_customer_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "4b483617cc20e22761392cb54e682762a83c3dbeec3eacfeaadae1ca8aff376c"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-4bce30abb40ab058dd6e4681f28e4e0761b29a596122af48beb1a062bd157844.json b/rust/cloud-storage/chat/.sqlx/query-4bce30abb40ab058dd6e4681f28e4e0761b29a596122af48beb1a062bd157844.json
new file mode 100644
index 0000000000..4a8318f952
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-4bce30abb40ab058dd6e4681f28e4e0761b29a596122af48beb1a062bd157844.json
@@ -0,0 +1,29 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n a.user_id as \"user_id!: String\",\n a.updated_at\n FROM comms_activity a\n WHERE channel_id = $1 AND user_id = ANY($2)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id!: String",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "updated_at",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "4bce30abb40ab058dd6e4681f28e4e0761b29a596122af48beb1a062bd157844"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-4be607458d6cc823fa5a692842b502b405bd0e971be8425d4573846beadb6bf3.json b/rust/cloud-storage/chat/.sqlx/query-4be607458d6cc823fa5a692842b502b405bd0e971be8425d4573846beadb6bf3.json
new file mode 100644
index 0000000000..b502f33690
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-4be607458d6cc823fa5a692842b502b405bd0e971be8425d4573846beadb6bf3.json
@@ -0,0 +1,61 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"Project\" (\"name\", \"userId\", \"parentId\", \"createdAt\", \"updatedAt\", \"uploadPending\", \"uploadRequestId\")\n VALUES ($1, $2, $3, NOW(), NOW(), TRUE, $4)\n RETURNING id, name, \"userId\"::text as user_id, \"createdAt\"::timestamptz as created_at, \"deletedAt\"::timestamptz as deleted_at,\n \"updatedAt\"::timestamptz as updated_at, \"parentId\" as parent_id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 4,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "parent_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ true
+ ]
+ },
+ "hash": "4be607458d6cc823fa5a692842b502b405bd0e971be8425d4573846beadb6bf3"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-4beff28bd0fc4ab7fbe74078b14f100a55cf2bb037ec171c3bcc8650edd73548.json b/rust/cloud-storage/chat/.sqlx/query-4beff28bd0fc4ab7fbe74078b14f100a55cf2bb037ec171c3bcc8650edd73548.json
new file mode 100644
index 0000000000..966f64c84d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-4beff28bd0fc4ab7fbe74078b14f100a55cf2bb037ec171c3bcc8650edd73548.json
@@ -0,0 +1,25 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"account_merge_request\" (id, macro_user_id, to_merge_macro_user_id, code, created_at)\n VALUES ($1, $2, $3, $4, NOW())\n RETURNING \"code\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "code",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Uuid",
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "4beff28bd0fc4ab7fbe74078b14f100a55cf2bb037ec171c3bcc8650edd73548"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-4c11c2c42479bad0cd549ab31c1dcb90b605b55480a604c4e047c450b5ab433f.json b/rust/cloud-storage/chat/.sqlx/query-4c11c2c42479bad0cd549ab31c1dcb90b605b55480a604c4e047c450b5ab433f.json
new file mode 100644
index 0000000000..c5070fa577
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-4c11c2c42479bad0cd549ab31c1dcb90b605b55480a604c4e047c450b5ab433f.json
@@ -0,0 +1,20 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT COUNT(*) as \"count\"\n FROM \"Document\" d\n LEFT JOIN \"DocumentText\" dt ON d.id = dt.\"documentId\"\n WHERE d.\"deletedAt\" IS NULL\n AND dt.\"documentId\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "count",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": []
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "4c11c2c42479bad0cd549ab31c1dcb90b605b55480a604c4e047c450b5ab433f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-4ca8409d9a2c8bf1634c3b1543e02daa92a5a01f2ad46d8124e0568ce8b17073.json b/rust/cloud-storage/chat/.sqlx/query-4ca8409d9a2c8bf1634c3b1543e02daa92a5a01f2ad46d8124e0568ce8b17073.json
new file mode 100644
index 0000000000..e71deba787
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-4ca8409d9a2c8bf1634c3b1543e02daa92a5a01f2ad46d8124e0568ce8b17073.json
@@ -0,0 +1,20 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT COUNT(*) as \"count\"\n FROM \"Document\" d\n WHERE d.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "count",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": []
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "4ca8409d9a2c8bf1634c3b1543e02daa92a5a01f2ad46d8124e0568ce8b17073"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-4d0f38e351a6a9b4a559ae4df808653289e7abb1719b58fd0a4d7e8f6cedb423.json b/rust/cloud-storage/chat/.sqlx/query-4d0f38e351a6a9b4a559ae4df808653289e7abb1719b58fd0a4d7e8f6cedb423.json
new file mode 100644
index 0000000000..c04f432a08
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-4d0f38e351a6a9b4a559ae4df808653289e7abb1719b58fd0a4d7e8f6cedb423.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"ChatMessage\"\n WHERE id = $1\n RETURNING id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "4d0f38e351a6a9b4a559ae4df808653289e7abb1719b58fd0a4d7e8f6cedb423"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-4e096eb7d3c507e3647685073fba7b3f36ef0e70c887db31f5cc5a8eb8ee1844.json b/rust/cloud-storage/chat/.sqlx/query-4e096eb7d3c507e3647685073fba7b3f36ef0e70c887db31f5cc5a8eb8ee1844.json
new file mode 100644
index 0000000000..55fcda1121
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-4e096eb7d3c507e3647685073fba7b3f36ef0e70c887db31f5cc5a8eb8ee1844.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM user_notification\n WHERE user_id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "4e096eb7d3c507e3647685073fba7b3f36ef0e70c887db31f5cc5a8eb8ee1844"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-4e6737a5a777280784037e88ccdda4e6e89dae702e5b50269db6e17265d14643.json b/rust/cloud-storage/chat/.sqlx/query-4e6737a5a777280784037e88ccdda4e6e89dae702e5b50269db6e17265d14643.json
new file mode 100644
index 0000000000..df6dc3c263
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-4e6737a5a777280784037e88ccdda4e6e89dae702e5b50269db6e17265d14643.json
@@ -0,0 +1,66 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n m.channel_id AS \"channel_id: uuid::Uuid\",\n c.name AS \"channel_name?\", -- Option<String>\n m.id AS \"message_id: uuid::Uuid\",\n m.thread_id AS \"thread_id?: uuid::Uuid\",\n m.sender_id AS \"sender_id!\", -- String\n m.content AS \"message_content!\", -- String\n m.created_at AS \"message_created_at!: chrono::DateTime<chrono::Utc>\",\n em.created_at AS \"attachment_created_at!: chrono::DateTime<chrono::Utc>\"\n FROM comms_entity_mentions em\n JOIN comms_messages m ON (em.source_entity_id = m.id::text AND em.source_entity_type = 'message')\n JOIN comms_channels c ON m.channel_id = c.id\n JOIN comms_channel_participants cp ON cp.channel_id = c.id\n WHERE em.entity_type = $1\n AND em.entity_id = $2\n AND cp.user_id = $3\n AND cp.left_at IS NULL\n AND m.deleted_at IS NULL\n ORDER BY em.created_at DESC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "channel_id: uuid::Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "channel_name?",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 2,
+ "name": "message_id: uuid::Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 3,
+ "name": "thread_id?: uuid::Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 4,
+ "name": "sender_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "message_content!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "message_created_at!: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "attachment_created_at!: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ true,
+ false,
+ true,
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "4e6737a5a777280784037e88ccdda4e6e89dae702e5b50269db6e17265d14643"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-4eb050dbd9d68aa914696bdf5c03315c56e84c969498cb55c34bd93d937dd924.json b/rust/cloud-storage/chat/.sqlx/query-4eb050dbd9d68aa914696bdf5c03315c56e84c969498cb55c34bd93d937dd924.json
new file mode 100644
index 0000000000..8629eccbfd
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-4eb050dbd9d68aa914696bdf5c03315c56e84c969498cb55c34bd93d937dd924.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"macro_user\" WHERE \"id\" = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "4eb050dbd9d68aa914696bdf5c03315c56e84c969498cb55c34bd93d937dd924"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-4eece2777920eb0f5c4d2746221fb5b8070dbb37abe0dda364ed27e46eae230e.json b/rust/cloud-storage/chat/.sqlx/query-4eece2777920eb0f5c4d2746221fb5b8070dbb37abe0dda364ed27e46eae230e.json
similarity index 100%
rename from rust/cloud-storage/macro_db_client/.sqlx/query-4eece2777920eb0f5c4d2746221fb5b8070dbb37abe0dda364ed27e46eae230e.json
rename to rust/cloud-storage/chat/.sqlx/query-4eece2777920eb0f5c4d2746221fb5b8070dbb37abe0dda364ed27e46eae230e.json
diff --git a/rust/cloud-storage/chat/.sqlx/query-4febc8d1902ceb02cc22d1bf9d9f1ebd8a471c3b0e6e4016de97a8fbfd1288b7.json b/rust/cloud-storage/chat/.sqlx/query-4febc8d1902ceb02cc22d1bf9d9f1ebd8a471c3b0e6e4016de97a8fbfd1288b7.json
new file mode 100644
index 0000000000..ab86a1c245
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-4febc8d1902ceb02cc22d1bf9d9f1ebd8a471c3b0e6e4016de97a8fbfd1288b7.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"DocumentView\" (\"document_id\", \"user_id\", \"created_at\")\n VALUES ($1, $2, NOW())\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "4febc8d1902ceb02cc22d1bf9d9f1ebd8a471c3b0e6e4016de97a8fbfd1288b7"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-4ffa9cfbefb9f75c3964db40d92d40085e0093d476d8b3d8aab8e81e575e1897.json b/rust/cloud-storage/chat/.sqlx/query-4ffa9cfbefb9f75c3964db40d92d40085e0093d476d8b3d8aab8e81e575e1897.json
new file mode 100644
index 0000000000..1e340576fa
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-4ffa9cfbefb9f75c3964db40d92d40085e0093d476d8b3d8aab8e81e575e1897.json
@@ -0,0 +1,46 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT c.owner, t.\"documentId\" as document_id, d.name as document_name, d.\"fileType\" as file_type, d.owner as document_owner\n FROM \"Comment\" c\n JOIN \"Thread\" t ON c.\"threadId\" = t.id\n JOIN \"Document\" d ON t.\"documentId\" = d.id\n WHERE c.id = $1 and c.\"deletedAt\" IS NULL AND t.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "document_owner",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ false
+ ]
+ },
+ "hash": "4ffa9cfbefb9f75c3964db40d92d40085e0093d476d8b3d8aab8e81e575e1897"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-506f7fbc61e5c2b0caedcc8ca1af001b1da7b88bcd175929f42b88146d4707f8.json b/rust/cloud-storage/chat/.sqlx/query-506f7fbc61e5c2b0caedcc8ca1af001b1da7b88bcd175929f42b88146d4707f8.json
new file mode 100644
index 0000000000..b0dbe81774
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-506f7fbc61e5c2b0caedcc8ca1af001b1da7b88bcd175929f42b88146d4707f8.json
@@ -0,0 +1,66 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n a.channel_id AS \"channel_id: uuid::Uuid\",\n c.name AS \"channel_name?\", -- Option<String>\n a.message_id AS \"message_id: uuid::Uuid\",\n m.thread_id AS \"thread_id?: uuid::Uuid\",\n m.sender_id AS \"sender_id!\", -- String\n m.content AS \"message_content!\", -- String\n m.created_at AS \"message_created_at!: chrono::DateTime<chrono::Utc>\",\n a.created_at AS \"attachment_created_at!: chrono::DateTime<chrono::Utc>\"\n FROM comms_attachments a\n JOIN comms_messages m ON a.message_id = m.id\n JOIN comms_channels c ON a.channel_id = c.id\n JOIN comms_channel_participants cp ON cp.channel_id = c.id\n WHERE a.entity_type = $1\n AND a.entity_id = $2\n AND cp.user_id = $3\n AND cp.left_at IS NULL\n AND m.deleted_at IS NULL\n ORDER BY a.created_at DESC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "channel_id: uuid::Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "channel_name?",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 2,
+ "name": "message_id: uuid::Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 3,
+ "name": "thread_id?: uuid::Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 4,
+ "name": "sender_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "message_content!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "message_created_at!: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "attachment_created_at!: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ true,
+ false,
+ true,
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "506f7fbc61e5c2b0caedcc8ca1af001b1da7b88bcd175929f42b88146d4707f8"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-514af45f8facfb915211cc9b0a92991b831dc11f9ab91d92b368340fa0aa8f8f.json b/rust/cloud-storage/chat/.sqlx/query-514af45f8facfb915211cc9b0a92991b831dc11f9ab91d92b368340fa0aa8f8f.json
new file mode 100644
index 0000000000..877c7bc78a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-514af45f8facfb915211cc9b0a92991b831dc11f9ab91d92b368340fa0aa8f8f.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"DocumentPermission\"\n WHERE \"sharePermissionId\" = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "514af45f8facfb915211cc9b0a92991b831dc11f9ab91d92b368340fa0aa8f8f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-5183d95583de1d3aa5cb183c528a2ea768622c3b189ffa6664c15669f7d78b90.json b/rust/cloud-storage/chat/.sqlx/query-5183d95583de1d3aa5cb183c528a2ea768622c3b189ffa6664c15669f7d78b90.json
new file mode 100644
index 0000000000..3c5f804ed2
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-5183d95583de1d3aa5cb183c528a2ea768622c3b189ffa6664c15669f7d78b90.json
@@ -0,0 +1,77 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id as document_id,\n d.owner as owner,\n d.name as document_name,\n db.id as \"document_version_id!\",\n d.\"fileType\" as \"file_type?\",\n d.\"createdAt\"::timestamptz as created_at,\n d.\"updatedAt\"::timestamptz as updated_at,\n db.bom_parts as \"document_bom?\",\n d.\"projectId\" as \"project_id?\",\n p.name as \"project_name?\"\n FROM\n \"Document\" d\n LEFT JOIN LATERAL (\n SELECT\n b.id,\n (\n SELECT\n json_agg(\n json_build_object(\n 'id', bp.id,\n 'sha', bp.sha,\n 'path', bp.path\n )\n )\n FROM\n \"BomPart\" bp\n WHERE\n bp.\"documentBomId\" = b.id\n ) as bom_parts\n FROM\n \"DocumentBom\" b\n WHERE\n b.\"documentId\" = d.id\n ORDER BY\n b.\"createdAt\" DESC\n LIMIT 1\n\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT\n p.name\n FROM \"Project\" p\n WHERE p.id = d.\"projectId\"\n ) p ON d.\"projectId\" IS NOT NULL\n WHERE d.\"fileType\" = 'docx' AND d.\"deletedAt\" IS NULL AND d.uploaded = true\n ORDER BY d.\"updatedAt\" DESC\n LIMIT $1 OFFSET $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "document_version_id!",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 4,
+ "name": "file_type?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "document_bom?",
+ "type_info": "Json"
+ },
+ {
+ "ordinal": 8,
+ "name": "project_id?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 9,
+ "name": "project_name?",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ true,
+ null,
+ null,
+ null,
+ true,
+ false
+ ]
+ },
+ "hash": "5183d95583de1d3aa5cb183c528a2ea768622c3b189ffa6664c15669f7d78b90"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-51873bdb08381231f01403f4e58bb5f5d73338d8cb9ec96c67fd8d6ea4746970.json b/rust/cloud-storage/chat/.sqlx/query-51873bdb08381231f01403f4e58bb5f5d73338d8cb9ec96c67fd8d6ea4746970.json
new file mode 100644
index 0000000000..7d015cf85e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-51873bdb08381231f01403f4e58bb5f5d73338d8cb9ec96c67fd8d6ea4746970.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "DELETE FROM \"User\" WHERE id = $1 RETURNING id, email, \"organizationId\" as organization_id",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "email",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "organization_id",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "51873bdb08381231f01403f4e58bb5f5d73338d8cb9ec96c67fd8d6ea4746970"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-52274fa0bcbaf995cd7ccf4025dcae43516d969d93066adf3bea59f64fcce246.json b/rust/cloud-storage/chat/.sqlx/query-52274fa0bcbaf995cd7ccf4025dcae43516d969d93066adf3bea59f64fcce246.json
new file mode 100644
index 0000000000..2d58ede92f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-52274fa0bcbaf995cd7ccf4025dcae43516d969d93066adf3bea59f64fcce246.json
@@ -0,0 +1,29 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"id\" as \"merge_request_id!\",\n \"to_merge_macro_user_id\" as \"to_merge_macro_user_id!\"\n FROM \"account_merge_request\"\n WHERE \"code\" = $1 AND \"macro_user_id\" = $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "merge_request_id!",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "to_merge_macro_user_id!",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "52274fa0bcbaf995cd7ccf4025dcae43516d969d93066adf3bea59f64fcce246"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-525b9b86055a3dc112adcb8973efb21edf79cf3409c9d1fbcb71c4564b6b453d.json b/rust/cloud-storage/chat/.sqlx/query-525b9b86055a3dc112adcb8973efb21edf79cf3409c9d1fbcb71c4564b6b453d.json
new file mode 100644
index 0000000000..57bef9cf37
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-525b9b86055a3dc112adcb8973efb21edf79cf3409c9d1fbcb71c4564b6b453d.json
@@ -0,0 +1,76 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.id,\n c.name,\n c.model,\n c.\"userId\" as \"user_id\",\n c.\"createdAt\"::timestamptz as \"created_at\",\n c.\"updatedAt\"::timestamptz as \"updated_at\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\",\n c.\"projectId\" as \"project_id\",\n c.\"tokenCount\" as \"token_count\",\n c.\"isPersistent\" as \"is_persistent\"\n FROM \"Chat\" c WHERE c.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "model",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 8,
+ "name": "token_count",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 9,
+ "name": "is_persistent",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ true,
+ true,
+ false
+ ]
+ },
+ "hash": "525b9b86055a3dc112adcb8973efb21edf79cf3409c9d1fbcb71c4564b6b453d"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-52bd1907e946a5c7b45c1954491c0d10a911eecd17e12d2c3937dae20ae71bef.json b/rust/cloud-storage/chat/.sqlx/query-52bd1907e946a5c7b45c1954491c0d10a911eecd17e12d2c3937dae20ae71bef.json
new file mode 100644
index 0000000000..03329c31cb
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-52bd1907e946a5c7b45c1954491c0d10a911eecd17e12d2c3937dae20ae71bef.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT COUNT(*) as \"count\"\n FROM \"Chat\" c\n WHERE c.\"userId\" = $1 and c.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "count",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "52bd1907e946a5c7b45c1954491c0d10a911eecd17e12d2c3937dae20ae71bef"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-52cc02c4d43669d3a1c8f350e3af7c261071298ef899917c3380d56d4873e0d2.json b/rust/cloud-storage/chat/.sqlx/query-52cc02c4d43669d3a1c8f350e3af7c261071298ef899917c3380d56d4873e0d2.json
new file mode 100644
index 0000000000..08b2dd3e86
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-52cc02c4d43669d3a1c8f350e3af7c261071298ef899917c3380d56d4873e0d2.json
@@ -0,0 +1,64 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id,\n message_id as \"message_id: Uuid\",\n channel_id as \"channel_id: Uuid\",\n entity_type,\n entity_id,\n width,\n height,\n created_at\n FROM comms_attachments\n WHERE message_id = $1",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "message_id: Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "channel_id: Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 3,
+ "name": "entity_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 4,
+ "name": "entity_id",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 5,
+ "name": "width",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 6,
+ "name": "height",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 7,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true,
+ false
+ ]
+ },
+ "hash": "52cc02c4d43669d3a1c8f350e3af7c261071298ef899917c3380d56d4873e0d2"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-532bde51c937e59bf4b6bd5ad735cd58ff2db92684a0c685bad7e8f133521563.json b/rust/cloud-storage/chat/.sqlx/query-532bde51c937e59bf4b6bd5ad735cd58ff2db92684a0c685bad7e8f133521563.json
new file mode 100644
index 0000000000..a6d05ec2f1
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-532bde51c937e59bf4b6bd5ad735cd58ff2db92684a0c685bad7e8f133521563.json
@@ -0,0 +1,38 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT e.id, e.active, e.\"started_at\"::timestamptz as started_at, e.\"ended_at\"::timestamptz as ended_at\n FROM \"Experiment\" e\n WHERE e.active = true\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "active",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 2,
+ "name": "started_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 3,
+ "name": "ended_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": []
+ },
+ "nullable": [
+ false,
+ false,
+ null,
+ null
+ ]
+ },
+ "hash": "532bde51c937e59bf4b6bd5ad735cd58ff2db92684a0c685bad7e8f133521563"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-53803816cc7149ffc49cd92a665229df9ec397fa2035c305d00133abeea39358.json b/rust/cloud-storage/chat/.sqlx/query-53803816cc7149ffc49cd92a665229df9ec397fa2035c305d00133abeea39358.json
new file mode 100644
index 0000000000..e2c0dec188
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-53803816cc7149ffc49cd92a665229df9ec397fa2035c305d00133abeea39358.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT a.owner, d.owner as document_owner\n FROM \"PdfPlaceableCommentAnchor\" a\n JOIN \"Thread\" t ON a.\"threadId\" = t.id\n JOIN \"Document\" d ON a.\"documentId\" = d.id\n WHERE a.uuid = $1 AND t.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "document_owner",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "53803816cc7149ffc49cd92a665229df9ec397fa2035c305d00133abeea39358"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-5429a0ff80ba0e9394eb205bddbb2dc247030b9e6eb3a750e30cdd770bf92fa9.json b/rust/cloud-storage/chat/.sqlx/query-5429a0ff80ba0e9394eb205bddbb2dc247030b9e6eb3a750e30cdd770bf92fa9.json
new file mode 100644
index 0000000000..c6eb93ad48
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-5429a0ff80ba0e9394eb205bddbb2dc247030b9e6eb3a750e30cdd770bf92fa9.json
@@ -0,0 +1,40 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO comms_channels (id, name, owner_id, org_id, team_id, channel_type)\n VALUES ($1, $2, $3, $4, $5, $6)\n RETURNING id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Varchar",
+ "Text",
+ "Int8",
+ "Uuid",
+ {
+ "Custom": {
+ "name": "comms_channel_type",
+ "kind": {
+ "Enum": [
+ "public",
+ "organization",
+ "private",
+ "direct_message",
+ "team"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "5429a0ff80ba0e9394eb205bddbb2dc247030b9e6eb3a750e30cdd770bf92fa9"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-54eb040ca9944d83dd7a79c3a6bb5d7c6f8264109d57c825e903233bb7ea22ff.json b/rust/cloud-storage/chat/.sqlx/query-54eb040ca9944d83dd7a79c3a6bb5d7c6f8264109d57c825e903233bb7ea22ff.json
new file mode 100644
index 0000000000..cd2311d8f0
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-54eb040ca9944d83dd7a79c3a6bb5d7c6f8264109d57c825e903233bb7ea22ff.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"User\"\n SET id = $1\n WHERE id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "54eb040ca9944d83dd7a79c3a6bb5d7c6f8264109d57c825e903233bb7ea22ff"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-5553458fc15f58a3a981b54210e10ebf8de2788f357c3af3932a6516c235271e.json b/rust/cloud-storage/chat/.sqlx/query-5553458fc15f58a3a981b54210e10ebf8de2788f357c3af3932a6516c235271e.json
new file mode 100644
index 0000000000..da513430f1
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-5553458fc15f58a3a981b54210e10ebf8de2788f357c3af3932a6516c235271e.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Experiment\" SET active = false AND ended_at = NOW() WHERE id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "5553458fc15f58a3a981b54210e10ebf8de2788f357c3af3932a6516c235271e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-569440328317c8738d56baf89e528c093cc117a1ff6a8628f3bea4ea860c2dfd.json b/rust/cloud-storage/chat/.sqlx/query-569440328317c8738d56baf89e528c093cc117a1ff6a8628f3bea4ea860c2dfd.json
new file mode 100644
index 0000000000..e3d5edd8c0
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-569440328317c8738d56baf89e528c093cc117a1ff6a8628f3bea4ea860c2dfd.json
@@ -0,0 +1,94 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n a.uuid, \n a.\"threadId\" as thread_id,\n a.page, \n a.red, \n a.green, \n a.blue, \n a.alpha,\n a.type as highlight_type, \n a.text,\n a.\"pageViewportWidth\" as page_viewport_width, \n a.\"pageViewportHeight\" as page_viewport_height, \n a.\"createdAt\"::timestamptz as created_at, \n a.\"updatedAt\"::timestamptz as updated_at\n FROM \"PdfHighlightAnchor\" a\n WHERE a.\"documentId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 2,
+ "name": "page",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 3,
+ "name": "red",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 4,
+ "name": "green",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 5,
+ "name": "blue",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 6,
+ "name": "alpha",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 7,
+ "name": "highlight_type",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 8,
+ "name": "text",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 9,
+ "name": "page_viewport_width",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 10,
+ "name": "page_viewport_height",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 11,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 12,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ true,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ null,
+ null
+ ]
+ },
+ "hash": "569440328317c8738d56baf89e528c093cc117a1ff6a8628f3bea4ea860c2dfd"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-56bc98d55555a5605ffe1fb098c61a56fe28b866c4e6684d4208f97a21a7c5d8.json b/rust/cloud-storage/chat/.sqlx/query-56bc98d55555a5605ffe1fb098c61a56fe28b866c4e6684d4208f97a21a7c5d8.json
new file mode 100644
index 0000000000..c75072ce00
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-56bc98d55555a5605ffe1fb098c61a56fe28b866c4e6684d4208f97a21a7c5d8.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"UserHistory\" (\"userId\", \"itemId\", \"itemType\", \"createdAt\", \"updatedAt\")\n SELECT u.user_id, u.item_id, 'chat', NOW(), NOW()\n FROM UNNEST($1::text[], $2::text[]) AS u(item_id, user_id)\n ON CONFLICT (\"userId\", \"itemId\", \"itemType\") DO UPDATE\n SET \"updatedAt\" = NOW();\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "56bc98d55555a5605ffe1fb098c61a56fe28b866c4e6684d4208f97a21a7c5d8"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-56bd1e06751e63ed197d0d29b48585d16912c6fd506196d2058ee41c09e71433.json b/rust/cloud-storage/chat/.sqlx/query-56bd1e06751e63ed197d0d29b48585d16912c6fd506196d2058ee41c09e71433.json
new file mode 100644
index 0000000000..ccf176175d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-56bd1e06751e63ed197d0d29b48585d16912c6fd506196d2058ee41c09e71433.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO\n in_progress_email_link (id, macro_user_id, email, created_at)\n VALUES\n ($1, $2, $3, NOW())\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "56bd1e06751e63ed197d0d29b48585d16912c6fd506196d2058ee41c09e71433"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-575a01f5f6907c1586c226426b338c649fa27b433650b735c685e60ad9435a4b.json b/rust/cloud-storage/chat/.sqlx/query-575a01f5f6907c1586c226426b338c649fa27b433650b735c685e60ad9435a4b.json
new file mode 100644
index 0000000000..389dd19f0b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-575a01f5f6907c1586c226426b338c649fa27b433650b735c685e60ad9435a4b.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id\n FROM\n \"Document\" d\n WHERE\n d.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "575a01f5f6907c1586c226426b338c649fa27b433650b735c685e60ad9435a4b"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-5766ebb8dbd1ad5d06624c7e715e3d2e68f8539e835552e8c8ca0d562adbbefe.json b/rust/cloud-storage/chat/.sqlx/query-5766ebb8dbd1ad5d06624c7e715e3d2e68f8539e835552e8c8ca0d562adbbefe.json
new file mode 100644
index 0000000000..15af8c6d02
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-5766ebb8dbd1ad5d06624c7e715e3d2e68f8539e835552e8c8ca0d562adbbefe.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT bp.sha\n FROM \"BomPart\" bp\n JOIN \"DocumentBom\" db ON bp.\"documentBomId\" = db.id\n WHERE db.\"documentId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "sha",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "5766ebb8dbd1ad5d06624c7e715e3d2e68f8539e835552e8c8ca0d562adbbefe"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-584a3f488f9149430d13e21a9bf1bef7da249de88d145a2925832425785250f8.json b/rust/cloud-storage/chat/.sqlx/query-584a3f488f9149430d13e21a9bf1bef7da249de88d145a2925832425785250f8.json
new file mode 100644
index 0000000000..b6ea64eede
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-584a3f488f9149430d13e21a9bf1bef7da249de88d145a2925832425785250f8.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n LENGTH(REGEXP_REPLACE(d.\"content\", '\\s', '', 'g')) AS content_length\n FROM\n \"DocumentText\" d\n WHERE\n d.\"documentId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "content_length",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "584a3f488f9149430d13e21a9bf1bef7da249de88d145a2925832425785250f8"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-58bcc36d5e748a63f9f35516f0c0ace37f77dd6806bf7f26211b3faa0fa84422.json b/rust/cloud-storage/chat/.sqlx/query-58bcc36d5e748a63f9f35516f0c0ace37f77dd6806bf7f26211b3faa0fa84422.json
new file mode 100644
index 0000000000..34a8fe34a1
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-58bcc36d5e748a63f9f35516f0c0ace37f77dd6806bf7f26211b3faa0fa84422.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id\n FROM macro_user\n WHERE username = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "58bcc36d5e748a63f9f35516f0c0ace37f77dd6806bf7f26211b3faa0fa84422"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-5904887b6e8f4db0d2bd73b6e2921530de25c237c7e369b43a60ed7c28958fb8.json b/rust/cloud-storage/chat/.sqlx/query-5904887b6e8f4db0d2bd73b6e2921530de25c237c7e369b43a60ed7c28958fb8.json
new file mode 100644
index 0000000000..db2b1c4b96
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-5904887b6e8f4db0d2bd73b6e2921530de25c237c7e369b43a60ed7c28958fb8.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n sp.id as id\n FROM\n \"EmailThreadPermission\" tp\n JOIN \"SharePermission\" sp ON tp.\"sharePermissionId\" = sp.id\n WHERE\n tp.\"threadId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "5904887b6e8f4db0d2bd73b6e2921530de25c237c7e369b43a60ed7c28958fb8"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf.json b/rust/cloud-storage/chat/.sqlx/query-5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf.json
new file mode 100644
index 0000000000..514e8d9770
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ChatPermission\" WHERE \"chatId\" = $1\n )\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-5959ff0d2410e3f2599a53bc1bf0de19c2d6e90cb030f64dccf965a0515b467e.json b/rust/cloud-storage/chat/.sqlx/query-5959ff0d2410e3f2599a53bc1bf0de19c2d6e90cb030f64dccf965a0515b467e.json
new file mode 100644
index 0000000000..334a1ac1ac
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-5959ff0d2410e3f2599a53bc1bf0de19c2d6e90cb030f64dccf965a0515b467e.json
@@ -0,0 +1,105 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at\",\n d.\"updatedAt\"::timestamptz as \"updated_at\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n CASE \n WHEN dt.sub_type = 'task' \n AND ep_status.values->'value' ? $2\n THEN true \n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL \n END as \"is_completed\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status \n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id \n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $3\n LEFT JOIN LATERAL (\n SELECT\n b.id\n FROM\n \"DocumentBom\" b\n WHERE\n b.\"documentId\" = d.id\n ORDER BY\n b.\"createdAt\" DESC\n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT\n i.id\n FROM\n \"DocumentInstance\" i\n WHERE\n i.\"documentId\" = d.id\n ORDER BY\n i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON true\n WHERE d.owner = $1 AND d.\"deletedAt\" IS NOT NULL\n UNION ALL\n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at\",\n c.\"updatedAt\"::timestamptz as \"updated_at\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as \"sub_type\",\n NULL as \"is_completed\"\n FROM \"Chat\" c\n WHERE c.\"userId\" = $1 AND c.\"deletedAt\" IS NOT NULL\n UNION ALL\n SELECT\n 'project' as \"item_type!\",\n p.id as \"id!\",\n NULL as \"document_version_id\",\n p.\"userId\" as \"user_id!\",\n p.name as \"name!\",\n NULL as \"file_type\",\n p.\"createdAt\"::timestamptz as \"created_at\",\n p.\"updatedAt\"::timestamptz as \"updated_at\",\n p.\"deletedAt\"::timestamptz as \"deleted_at\",\n p.\"parentId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL as \"sub_type\",\n NULL as \"is_completed\"\n FROM \"Project\" p\n WHERE p.\"userId\" = $1 AND p.\"deletedAt\" IS NOT NULL\n ORDER BY deleted_at DESC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_version_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "user_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "name!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 10,
+ "name": "is_persistent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 11,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 12,
+ "name": "is_completed",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "5959ff0d2410e3f2599a53bc1bf0de19c2d6e90cb030f64dccf965a0515b467e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-5a1016dee1c30860cc21fed65aa3a7f7f3c37e866d38c2ab99cfeb2fe940b2c8.json b/rust/cloud-storage/chat/.sqlx/query-5a1016dee1c30860cc21fed65aa3a7f7f3c37e866d38c2ab99cfeb2fe940b2c8.json
new file mode 100644
index 0000000000..4a5f27b20e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-5a1016dee1c30860cc21fed65aa3a7f7f3c37e866d38c2ab99cfeb2fe940b2c8.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n p.id\n FROM\n \"Project\" p\n WHERE\n p.id = ANY($1)\n AND p.\"userId\" = ANY($2)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "5a1016dee1c30860cc21fed65aa3a7f7f3c37e866d38c2ab99cfeb2fe940b2c8"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-5abca30105f179742a58a602030a033a255c6eb5c9ba657c4038072f974aaeaa.json b/rust/cloud-storage/chat/.sqlx/query-5abca30105f179742a58a602030a033a255c6eb5c9ba657c4038072f974aaeaa.json
similarity index 100%
rename from rust/cloud-storage/macro_db_client/.sqlx/query-5abca30105f179742a58a602030a033a255c6eb5c9ba657c4038072f974aaeaa.json
rename to rust/cloud-storage/chat/.sqlx/query-5abca30105f179742a58a602030a033a255c6eb5c9ba657c4038072f974aaeaa.json
diff --git a/rust/cloud-storage/chat/.sqlx/query-5b80d3808a67dec493adf6f88ed7d642451d84970962ddb75a13d017b4837fbb.json b/rust/cloud-storage/chat/.sqlx/query-5b80d3808a67dec493adf6f88ed7d642451d84970962ddb75a13d017b4837fbb.json
new file mode 100644
index 0000000000..33f5fcf029
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-5b80d3808a67dec493adf6f88ed7d642451d84970962ddb75a13d017b4837fbb.json
@@ -0,0 +1,77 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH MultiAttachmentChats AS (\n SELECT\n \"chatId\",\n COUNT(*) as attachment_count\n FROM \"ChatAttachment\"\n GROUP BY \"chatId\"\n )\n SELECT\n c.id,\n c.name,\n c.\"userId\" as \"user_id\",\n c.\"createdAt\"::timestamptz as \"created_at\",\n c.\"updatedAt\"::timestamptz as \"updated_at\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\",\n c.model,\n c.\"tokenCount\" as \"token_count\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\"\n FROM \"Chat\" c\n INNER JOIN \"ChatAttachment\" ca ON c.id = ca.\"chatId\"\n INNER JOIN MultiAttachmentChats mac ON c.id = mac.\"chatId\"\n WHERE\n ca.\"attachmentId\" = $1 AND c.\"userId\" = $2\n AND\n c.\"deletedAt\" IS NULL\n ORDER BY c.\"updatedAt\" DESC;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 4,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "model",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 7,
+ "name": "token_count",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 8,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 9,
+ "name": "is_persistent",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ false,
+ true,
+ true,
+ false
+ ]
+ },
+ "hash": "5b80d3808a67dec493adf6f88ed7d642451d84970962ddb75a13d017b4837fbb"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-5c110b698a00004a548556064f3ec7f96170613378e2fc37f78f2585a26f91f0.json b/rust/cloud-storage/chat/.sqlx/query-5c110b698a00004a548556064f3ec7f96170613378e2fc37f78f2585a26f91f0.json
new file mode 100644
index 0000000000..ab05ec9386
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-5c110b698a00004a548556064f3ec7f96170613378e2fc37f78f2585a26f91f0.json
@@ -0,0 +1,30 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n -- Get all entities the user has access to via entity_access\n UserAccessibleEntities AS (\n SELECT DISTINCT\n ea.entity_id,\n ea.entity_type\n FROM entity_access ea\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n AND ($2::text IS NULL OR ea.entity_type = $2)\n ),\n -- Filter out deleted items and optionally exclude owned\n FilteredItems AS (\n SELECT uae.entity_id::text as item_id, uae.entity_type as item_type\n FROM UserAccessibleEntities uae\n LEFT JOIN \"Document\" d ON uae.entity_type = 'document' AND uae.entity_id::text = d.id\n LEFT JOIN \"Chat\" c ON uae.entity_type = 'chat' AND uae.entity_id::text = c.id\n LEFT JOIN \"Project\" p ON uae.entity_type = 'project' AND uae.entity_id::text = p.id\n WHERE\n (uae.entity_type = 'document' AND d.\"deletedAt\" IS NULL\n AND ($3 = false OR d.owner != $1)) OR\n (uae.entity_type = 'chat' AND c.\"deletedAt\" IS NULL\n AND ($3 = false OR c.\"userId\" != $1)) OR\n (uae.entity_type = 'project' AND p.\"deletedAt\" IS NULL\n AND ($3 = false OR p.\"userId\" != $1))\n )\n SELECT item_id as \"item_id!\", item_type as \"item_type!\" FROM FilteredItems\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "item_type!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Bool"
+ ]
+ },
+ "nullable": [
+ null,
+ false
+ ]
+ },
+ "hash": "5c110b698a00004a548556064f3ec7f96170613378e2fc37f78f2585a26f91f0"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-5c138b3279b9ec08049316d52887064c46d9799c3d1282237646ec295890b2f7.json b/rust/cloud-storage/chat/.sqlx/query-5c138b3279b9ec08049316d52887064c46d9799c3d1282237646ec295890b2f7.json
new file mode 100644
index 0000000000..47d617747d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-5c138b3279b9ec08049316d52887064c46d9799c3d1282237646ec295890b2f7.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"UploadJob\" SET \"documentId\" = $1 WHERE \"jobId\" = $2;\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "5c138b3279b9ec08049316d52887064c46d9799c3d1282237646ec295890b2f7"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-5ca006bf302d626774ecb05adde9c5bd7f594804d634f2d805ef47f997b270df.json b/rust/cloud-storage/chat/.sqlx/query-5ca006bf302d626774ecb05adde9c5bd7f594804d634f2d805ef47f997b270df.json
new file mode 100644
index 0000000000..daa8c66b98
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-5ca006bf302d626774ecb05adde9c5bd7f594804d634f2d805ef47f997b270df.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"Project\"\n WHERE id = ANY($1)",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "5ca006bf302d626774ecb05adde9c5bd7f594804d634f2d805ef47f997b270df"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-5cf744cd176688700ea98da0351a8c39369e808fdcb9ae39bb8e31ef99bbf3e8.json b/rust/cloud-storage/chat/.sqlx/query-5cf744cd176688700ea98da0351a8c39369e808fdcb9ae39bb8e31ef99bbf3e8.json
new file mode 100644
index 0000000000..28507e9701
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-5cf744cd176688700ea98da0351a8c39369e808fdcb9ae39bb8e31ef99bbf3e8.json
@@ -0,0 +1,66 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Thread\" t\n SET \"updatedAt\" = NOW(), \"metadata\" = $3\n WHERE t.\"documentId\" = $1 AND t.\"deletedAt\" IS NULL AND t.id = $2\n RETURNING\n t.id as thread_id, \n t.resolved, \n t.\"documentId\" as document_id, \n t.\"createdAt\"::timestamptz as created_at, \n t.\"updatedAt\"::timestamptz as updated_at, \n t.\"deletedAt\"::timestamptz as deleted_at, \n t.metadata, \n t.owner\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "resolved",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 4,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "metadata",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 7,
+ "name": "owner",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Int8",
+ "Jsonb"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ true,
+ false
+ ]
+ },
+ "hash": "5cf744cd176688700ea98da0351a8c39369e808fdcb9ae39bb8e31ef99bbf3e8"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-5d922b5d0478e241a8b0bb3062a61448366cff0f2db4b3bade0294bf0e4a9bf0.json b/rust/cloud-storage/chat/.sqlx/query-5d922b5d0478e241a8b0bb3062a61448366cff0f2db4b3bade0294bf0e4a9bf0.json
new file mode 100644
index 0000000000..8627106f3b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-5d922b5d0478e241a8b0bb3062a61448366cff0f2db4b3bade0294bf0e4a9bf0.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT name\n FROM \"Chat\"\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "name",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "5d922b5d0478e241a8b0bb3062a61448366cff0f2db4b3bade0294bf0e4a9bf0"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-5f05ad6ca76854ac7e9257b63a5ce27e9f8c6a5ba43888d9e357b10d95e0f6f2.json b/rust/cloud-storage/chat/.sqlx/query-5f05ad6ca76854ac7e9257b63a5ce27e9f8c6a5ba43888d9e357b10d95e0f6f2.json
new file mode 100644
index 0000000000..964ba5a296
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-5f05ad6ca76854ac7e9257b63a5ce27e9f8c6a5ba43888d9e357b10d95e0f6f2.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n di.sha\n FROM\n \"DocumentInstance\" di\n WHERE di.\"documentId\" = $1 AND di.id = $2\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "sha",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "5f05ad6ca76854ac7e9257b63a5ce27e9f8c6a5ba43888d9e357b10d95e0f6f2"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-5f8f702012590c04c79b43fdb82d0252976b275c608a3eb96e3043a1a02d452f.json b/rust/cloud-storage/chat/.sqlx/query-5f8f702012590c04c79b43fdb82d0252976b275c608a3eb96e3043a1a02d452f.json
new file mode 100644
index 0000000000..f34fbaf789
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-5f8f702012590c04c79b43fdb82d0252976b275c608a3eb96e3043a1a02d452f.json
@@ -0,0 +1,47 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id,\n d.name,\n d.owner,\n d.\"fileType\" as \"file_type!\",\n di.id as \"document_version_id?\"\n FROM\n \"Document\" d\n LEFT JOIN \"DocumentText\" dt ON d.id = dt.\"documentId\"\n LEFT JOIN LATERAL (\n SELECT\n i.id\n FROM\n \"DocumentInstance\" i\n WHERE\n i.\"documentId\" = d.id\n ORDER BY\n i.\"createdAt\" ASC\n LIMIT 1\n ) di ON true\n WHERE\n d.\"deletedAt\" IS NULL\n AND dt.\"documentId\" IS NULL\n AND d.\"fileType\" IS NOT NULL\n ORDER BY d.\"createdAt\" DESC\n LIMIT $1 OFFSET $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "file_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "document_version_id?",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ false
+ ]
+ },
+ "hash": "5f8f702012590c04c79b43fdb82d0252976b275c608a3eb96e3043a1a02d452f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6038d459d2d8e60479180f5b8a756380bda195f4769b6420e601ed147a9439f9.json b/rust/cloud-storage/chat/.sqlx/query-6038d459d2d8e60479180f5b8a756380bda195f4769b6420e601ed147a9439f9.json
new file mode 100644
index 0000000000..a8e38250f7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6038d459d2d8e60479180f5b8a756380bda195f4769b6420e601ed147a9439f9.json
@@ -0,0 +1,72 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.\"id\" as \"item_id!\",\n c.created_at as \"created_at!\",\n c.updated_at as \"updated_at!\",\n uh.viewed_at as \"viewed_at?\",\n uh.interacted_at as \"interacted_at?\",\n c.owner_id as \"user_id\",\n c.channel_type AS \"channel_type: ChannelType\"\n FROM\n comms_channels c\n LEFT JOIN\n comms_activity uh ON uh.channel_id = c.id\n AND uh.user_id = $1\n WHERE\n c.id = ANY($2)\n ORDER BY\n c.updated_at DESC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_id!",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 2,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 3,
+ "name": "viewed_at?",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 4,
+ "name": "interacted_at?",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 5,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "channel_type: ChannelType",
+ "type_info": {
+ "Custom": {
+ "name": "comms_channel_type",
+ "kind": {
+ "Enum": [
+ "public",
+ "organization",
+ "private",
+ "direct_message",
+ "team"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ true,
+ false,
+ false
+ ]
+ },
+ "hash": "6038d459d2d8e60479180f5b8a756380bda195f4769b6420e601ed147a9439f9"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6107da3c9e3018aed3dce2c0a29baa584754659223dc45b3adbf30959b7f739e.json b/rust/cloud-storage/chat/.sqlx/query-6107da3c9e3018aed3dce2c0a29baa584754659223dc45b3adbf30959b7f739e.json
new file mode 100644
index 0000000000..70975b0a69
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6107da3c9e3018aed3dce2c0a29baa584754659223dc45b3adbf30959b7f739e.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"SharePermission\"\n WHERE id IN (\n SELECT \"sharePermissionId\"\n FROM \"ChatPermission\"\n WHERE \"chatId\" = ANY($1)\n )\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "6107da3c9e3018aed3dce2c0a29baa584754659223dc45b3adbf30959b7f739e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-61246005cb69889a67ac46d2032f4fe9c1da7b19594f1b7dc59f2ed0a613dec1.json b/rust/cloud-storage/chat/.sqlx/query-61246005cb69889a67ac46d2032f4fe9c1da7b19594f1b7dc59f2ed0a613dec1.json
new file mode 100644
index 0000000000..ccd0aadea5
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-61246005cb69889a67ac46d2032f4fe9c1da7b19594f1b7dc59f2ed0a613dec1.json
@@ -0,0 +1,74 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO comms_messages (id, channel_id, sender_id, content, thread_id)\n VALUES ($1, $2, $3, $4, $5)\n RETURNING\n id,\n channel_id,\n sender_id,\n content,\n created_at,\n updated_at,\n thread_id,\n edited_at as \"edited_at: chrono::DateTime<chrono::Utc>\",\n deleted_at as \"deleted_at: chrono::DateTime<chrono::Utc>\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "channel_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "sender_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "content",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "thread_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 7,
+ "name": "edited_at: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Uuid",
+ "Text",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true,
+ true
+ ]
+ },
+ "hash": "61246005cb69889a67ac46d2032f4fe9c1da7b19594f1b7dc59f2ed0a613dec1"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6206a64301c4a62de624c6cb0db3c1053c050c7529496a73e3cf74d728f5b6ff.json b/rust/cloud-storage/chat/.sqlx/query-6206a64301c4a62de624c6cb0db3c1053c050c7529496a73e3cf74d728f5b6ff.json
new file mode 100644
index 0000000000..0dc7579362
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6206a64301c4a62de624c6cb0db3c1053c050c7529496a73e3cf74d728f5b6ff.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"RolesOnUsers\" (\"userId\", \"roleId\")\n VALUES ($1, $2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "6206a64301c4a62de624c6cb0db3c1053c050c7529496a73e3cf74d728f5b6ff"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-621186dcec072b603a5f3d7b9e987a1638589d539c60d9dc5c2ab0865ff062d6.json b/rust/cloud-storage/chat/.sqlx/query-621186dcec072b603a5f3d7b9e987a1638589d539c60d9dc5c2ab0865ff062d6.json
new file mode 100644
index 0000000000..d0a749ebd2
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-621186dcec072b603a5f3d7b9e987a1638589d539c60d9dc5c2ab0865ff062d6.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id FROM user_mute_notification\n WHERE user_id = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "621186dcec072b603a5f3d7b9e987a1638589d539c60d9dc5c2ab0865ff062d6"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6257cdadf393b1b0664a63334ecc38865b3af1ea328024194f3b790da13c8df3.json b/rust/cloud-storage/chat/.sqlx/query-6257cdadf393b1b0664a63334ecc38865b3af1ea328024194f3b790da13c8df3.json
new file mode 100644
index 0000000000..cc27e0141e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6257cdadf393b1b0664a63334ecc38865b3af1ea328024194f3b790da13c8df3.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access with source_ids (user, teams, channels)\n SELECT access_level::text FROM entity_access\n WHERE source_id = ANY(ARRAY(\n SELECT cp.channel_id::text FROM comms_channel_participants cp\n WHERE cp.user_id = $3 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $3\n UNION ALL\n SELECT $3\n ))\n AND entity_id = $1\n AND entity_type = 'project'\n UNION ALL\n -- Source 2: Select the publicAccessLevel (which is already text).\n SELECT \"publicAccessLevel\" as access_level\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true AND \"publicAccessLevel\" IS NOT NULL AND id IN (\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\"\n WHERE \"projectId\" = $2\n )\n ) as all_levels\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "6257cdadf393b1b0664a63334ecc38865b3af1ea328024194f3b790da13c8df3"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-625ee33d48768e369ee1fe3abe27811ad04313b1aa31f4b51abe5fd3bf569674.json b/rust/cloud-storage/chat/.sqlx/query-625ee33d48768e369ee1fe3abe27811ad04313b1aa31f4b51abe5fd3bf569674.json
new file mode 100644
index 0000000000..d374c2f79f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-625ee33d48768e369ee1fe3abe27811ad04313b1aa31f4b51abe5fd3bf569674.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM user_notification_type_preference\n WHERE user_id = $1 AND notification_event_type = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "625ee33d48768e369ee1fe3abe27811ad04313b1aa31f4b51abe5fd3bf569674"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-638409c05db350cedd85b28991817b43793526453437ac01d9d20df52ff87ced.json b/rust/cloud-storage/chat/.sqlx/query-638409c05db350cedd85b28991817b43793526453437ac01d9d20df52ff87ced.json
new file mode 100644
index 0000000000..b36019aa97
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-638409c05db350cedd85b28991817b43793526453437ac01d9d20df52ff87ced.json
@@ -0,0 +1,29 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id,\n \"userId\" as user_id\n FROM\n \"Project\"\n WHERE\n \"deletedAt\" IS NULL\n ORDER BY\n \"createdAt\" DESC\n LIMIT $1 OFFSET $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "638409c05db350cedd85b28991817b43793526453437ac01d9d20df52ff87ced"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-63a478f0ae0ec6d9e9cb4c3de55a880b859bc61f745087e067f6b05e6878cc04.json b/rust/cloud-storage/chat/.sqlx/query-63a478f0ae0ec6d9e9cb4c3de55a880b859bc61f745087e067f6b05e6878cc04.json
new file mode 100644
index 0000000000..31007ad5b4
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-63a478f0ae0ec6d9e9cb4c3de55a880b859bc61f745087e067f6b05e6878cc04.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"organizationId\" as id\n FROM \"OrganizationIT\"\n WHERE \"email\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "63a478f0ae0ec6d9e9cb4c3de55a880b859bc61f745087e067f6b05e6878cc04"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json b/rust/cloud-storage/chat/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json
new file mode 100644
index 0000000000..a110bb67c6
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT DISTINCT cp.user_id\n FROM comms_channel_participants cp\n WHERE cp.channel_id = $1 AND cp.left_at IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6405181c054f5b865e4dafb1a665d33e0f3cdd3a3bab22f0fd1eb5e71c46a935.json b/rust/cloud-storage/chat/.sqlx/query-6405181c054f5b865e4dafb1a665d33e0f3cdd3a3bab22f0fd1eb5e71c46a935.json
new file mode 100644
index 0000000000..03bae7e074
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6405181c054f5b865e4dafb1a665d33e0f3cdd3a3bab22f0fd1eb5e71c46a935.json
@@ -0,0 +1,20 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO macro_user_info (macro_user_id, industry, title, first_name, last_name, profile_picture, profile_picture_hash)\n VALUES ($1, $2, $3, $4, $5, $6, $7)\n ON CONFLICT (macro_user_id) DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text",
+ "Text",
+ "Text",
+ "Text",
+ "Varchar"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "6405181c054f5b865e4dafb1a665d33e0f3cdd3a3bab22f0fd1eb5e71c46a935"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-64407ed474bb1ea2930c431fad30657cfa6d5e400247cbf304a3d28cde13c39d.json b/rust/cloud-storage/chat/.sqlx/query-64407ed474bb1ea2930c431fad30657cfa6d5e400247cbf304a3d28cde13c39d.json
new file mode 100644
index 0000000000..388d284af5
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-64407ed474bb1ea2930c431fad30657cfa6d5e400247cbf304a3d28cde13c39d.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n u.email\n FROM\n \"User\" u\n LIMIT $1 OFFSET $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "email",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "64407ed474bb1ea2930c431fad30657cfa6d5e400247cbf304a3d28cde13c39d"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-64d3a59468f973251be473a78180d6178a8fbdfe21983501c6baf4ce30cbe5d2.json b/rust/cloud-storage/chat/.sqlx/query-64d3a59468f973251be473a78180d6178a8fbdfe21983501c6baf4ce30cbe5d2.json
new file mode 100644
index 0000000000..1336af405e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-64d3a59468f973251be473a78180d6178a8fbdfe21983501c6baf4ce30cbe5d2.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"SharePermission\"\n WHERE \"id\" = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "64d3a59468f973251be473a78180d6178a8fbdfe21983501c6baf4ce30cbe5d2"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-64f2c1aab2341caa0d39b79208f2da0aa73a08b9317c8d7932b81590dc73169d.json b/rust/cloud-storage/chat/.sqlx/query-64f2c1aab2341caa0d39b79208f2da0aa73a08b9317c8d7932b81590dc73169d.json
similarity index 100%
rename from rust/cloud-storage/macro_db_client/.sqlx/query-64f2c1aab2341caa0d39b79208f2da0aa73a08b9317c8d7932b81590dc73169d.json
rename to rust/cloud-storage/chat/.sqlx/query-64f2c1aab2341caa0d39b79208f2da0aa73a08b9317c8d7932b81590dc73169d.json
diff --git a/rust/cloud-storage/chat/.sqlx/query-65312be3e9b6d4bb6debf39d7fe4f0abbb105b8fb03e44c12f7241fc52b022d4.json b/rust/cloud-storage/chat/.sqlx/query-65312be3e9b6d4bb6debf39d7fe4f0abbb105b8fb03e44c12f7241fc52b022d4.json
new file mode 100644
index 0000000000..b03cf39b93
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-65312be3e9b6d4bb6debf39d7fe4f0abbb105b8fb03e44c12f7241fc52b022d4.json
@@ -0,0 +1,46 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.id as \"id\",\n c.name as \"name\",\n c.\"projectId\" as \"project_id\",\n c.\"userId\" as \"user_id\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM\n \"Chat\" c\n WHERE\n c.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ true,
+ false,
+ null
+ ]
+ },
+ "hash": "65312be3e9b6d4bb6debf39d7fe4f0abbb105b8fb03e44c12f7241fc52b022d4"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-65818d5e257f9e76534f4ac3414f98f24d1991cacd53b806e81746c16144cc83.json b/rust/cloud-storage/chat/.sqlx/query-65818d5e257f9e76534f4ac3414f98f24d1991cacd53b806e81746c16144cc83.json
new file mode 100644
index 0000000000..05a8dc4343
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-65818d5e257f9e76534f4ac3414f98f24d1991cacd53b806e81746c16144cc83.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"Pin\" WHERE \"pinnedItemId\" = $1 AND \"pinnedItemType\" = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "65818d5e257f9e76534f4ac3414f98f24d1991cacd53b806e81746c16144cc83"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-65af936c2ba7200bb57024fb52cd27fbb4ac3a6b655e5dc2c11ea4c802587214.json b/rust/cloud-storage/chat/.sqlx/query-65af936c2ba7200bb57024fb52cd27fbb4ac3a6b655e5dc2c11ea4c802587214.json
new file mode 100644
index 0000000000..9e5261243d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-65af936c2ba7200bb57024fb52cd27fbb4ac3a6b655e5dc2c11ea4c802587214.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id as \"document_id\"\n FROM\n \"Document\"\n WHERE\n \"deletedAt\" IS NULL\n ORDER BY\n \"createdAt\" ASC\n LIMIT $1\n OFFSET $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "65af936c2ba7200bb57024fb52cd27fbb4ac3a6b655e5dc2c11ea4c802587214"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-66106766fa34cf3660615011a75f7640171d9adbb9f95962db83d979d02cc2d5.json b/rust/cloud-storage/chat/.sqlx/query-66106766fa34cf3660615011a75f7640171d9adbb9f95962db83d979d02cc2d5.json
new file mode 100644
index 0000000000..ad286ad459
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-66106766fa34cf3660615011a75f7640171d9adbb9f95962db83d979d02cc2d5.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"DocumentBom\" (\"documentId\")\n VALUES ($1)\n RETURNING id, \"createdAt\"::timestamptz as created_at, \"updatedAt\"::timestamptz as updated_at;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 2,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ null,
+ null
+ ]
+ },
+ "hash": "66106766fa34cf3660615011a75f7640171d9adbb9f95962db83d979d02cc2d5"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-666ad2a732546aa9a48262eeaeba037263a6ef8f1daf5eb8ee95ee50ad97f3c0.json b/rust/cloud-storage/chat/.sqlx/query-666ad2a732546aa9a48262eeaeba037263a6ef8f1daf5eb8ee95ee50ad97f3c0.json
new file mode 100644
index 0000000000..6614498635
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-666ad2a732546aa9a48262eeaeba037263a6ef8f1daf5eb8ee95ee50ad97f3c0.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Chat\" SET \"projectId\" = $1\n WHERE id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "666ad2a732546aa9a48262eeaeba037263a6ef8f1daf5eb8ee95ee50ad97f3c0"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-66db94821f8946fd3494e1ae5df52425ff06f3bdc9bf008414db8301161d1f4f.json b/rust/cloud-storage/chat/.sqlx/query-66db94821f8946fd3494e1ae5df52425ff06f3bdc9bf008414db8301161d1f4f.json
new file mode 100644
index 0000000000..4e6df68b0f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-66db94821f8946fd3494e1ae5df52425ff06f3bdc9bf008414db8301161d1f4f.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.name,\n d.\"fileType\" as \"file_type!\"\n FROM\n \"Document\" d\n WHERE\n d.id = $1 AND d.\"fileType\" IS NOT NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "file_type!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ true
+ ]
+ },
+ "hash": "66db94821f8946fd3494e1ae5df52425ff06f3bdc9bf008414db8301161d1f4f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-679af359cf0fccd5b687fe58ece3b1052fe8c636b986fb6f59f67fcfd08fce38.json b/rust/cloud-storage/chat/.sqlx/query-679af359cf0fccd5b687fe58ece3b1052fe8c636b986fb6f59f67fcfd08fce38.json
new file mode 100644
index 0000000000..02e4d8a7ad
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-679af359cf0fccd5b687fe58ece3b1052fe8c636b986fb6f59f67fcfd08fce38.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "UPDATE \"Chat\" SET \"projectId\"=$2 WHERE \"id\"=$1",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "679af359cf0fccd5b687fe58ece3b1052fe8c636b986fb6f59f67fcfd08fce38"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-67d6061e983a68f7c75c0272885bb866cacda011d43947e9dd29e0ec60f42d2b.json b/rust/cloud-storage/chat/.sqlx/query-67d6061e983a68f7c75c0272885bb866cacda011d43947e9dd29e0ec60f42d2b.json
new file mode 100644
index 0000000000..d83f78a498
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-67d6061e983a68f7c75c0272885bb866cacda011d43947e9dd29e0ec60f42d2b.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"id\", \"stripeCustomerId\" as \"stripe_customer_id?\"\n FROM \"User\"\n WHERE \"email\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "stripe_customer_id?",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ true
+ ]
+ },
+ "hash": "67d6061e983a68f7c75c0272885bb866cacda011d43947e9dd29e0ec60f42d2b"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-68ab26135b27913a38d7670c8c1a304b0d9676ba2fb8cd7ac3e9c9906e5726d7.json b/rust/cloud-storage/chat/.sqlx/query-68ab26135b27913a38d7670c8c1a304b0d9676ba2fb8cd7ac3e9c9906e5726d7.json
new file mode 100644
index 0000000000..60b912d427
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-68ab26135b27913a38d7670c8c1a304b0d9676ba2fb8cd7ac3e9c9906e5726d7.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "DELETE FROM \"Document\" WHERE id = $1",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "68ab26135b27913a38d7670c8c1a304b0d9676ba2fb8cd7ac3e9c9906e5726d7"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-68ce38278462b5328c5444aadd3f309c9fbe4f4a2883ee55e7247c65a911ee80.json b/rust/cloud-storage/chat/.sqlx/query-68ce38278462b5328c5444aadd3f309c9fbe4f4a2883ee55e7247c65a911ee80.json
new file mode 100644
index 0000000000..d682fd6e7c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-68ce38278462b5328c5444aadd3f309c9fbe4f4a2883ee55e7247c65a911ee80.json
@@ -0,0 +1,60 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO comms_activity (\n id,\n user_id,\n channel_id,\n interacted_at\n )\n VALUES (\n $1, $2, $3, NOW()\n )\n ON CONFLICT (user_id, channel_id) DO UPDATE \n SET \n interacted_at = NOW(),\n updated_at = NOW()\n RETURNING \n id as \"id!: Uuid\",\n user_id as \"user_id!: String\",\n channel_id as \"channel_id!: Uuid\",\n created_at as \"created_at!: DateTime<Utc>\",\n updated_at as \"updated_at!: DateTime<Utc>\",\n viewed_at as \"viewed_at?: DateTime<Utc>\",\n interacted_at as \"interacted_at?: DateTime<Utc>\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!: Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "user_id!: String",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "channel_id!: Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at!: DateTime<Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 4,
+ "name": "updated_at!: DateTime<Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 5,
+ "name": "viewed_at?: DateTime<Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 6,
+ "name": "interacted_at?: DateTime<Utc>",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true
+ ]
+ },
+ "hash": "68ce38278462b5328c5444aadd3f309c9fbe4f4a2883ee55e7247c65a911ee80"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6925ae890683c9b94bc1f89f1d8fbe0b72aafdd053092bbbd4b1f918d3e194e2.json b/rust/cloud-storage/chat/.sqlx/query-6925ae890683c9b94bc1f89f1d8fbe0b72aafdd053092bbbd4b1f918d3e194e2.json
new file mode 100644
index 0000000000..21c0c2a5d1
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6925ae890683c9b94bc1f89f1d8fbe0b72aafdd053092bbbd4b1f918d3e194e2.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"RolesOnUsers\" (\"userId\", \"roleId\")\n VALUES ($1, $2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "6925ae890683c9b94bc1f89f1d8fbe0b72aafdd053092bbbd4b1f918d3e194e2"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-69af04267546961d49bdd35751b2f89a5c06f05102a6b68a8fc36429f48eced1.json b/rust/cloud-storage/chat/.sqlx/query-69af04267546961d49bdd35751b2f89a5c06f05102a6b68a8fc36429f48eced1.json
new file mode 100644
index 0000000000..5a96fb6793
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-69af04267546961d49bdd35751b2f89a5c06f05102a6b68a8fc36429f48eced1.json
@@ -0,0 +1,46 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n ca.id,\n ca.\"attachmentType\" as \"attachment_type: AttachmentType\",\n ca.\"attachmentId\" as \"attachment_id\",\n ca.\"chatId\" as \"chat_id\",\n ca.\"messageId\" as \"message_id\"\n FROM\n \"ChatAttachment\" ca\n WHERE\n ca.\"messageId\" = $1\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "attachment_type: AttachmentType",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "attachment_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "chat_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "message_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ true
+ ]
+ },
+ "hash": "69af04267546961d49bdd35751b2f89a5c06f05102a6b68a8fc36429f48eced1"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6a959012e52fd6acf519e2ff3b2d48c962d566f65758eb3084d384fca676efde.json b/rust/cloud-storage/chat/.sqlx/query-6a959012e52fd6acf519e2ff3b2d48c962d566f65758eb3084d384fca676efde.json
new file mode 100644
index 0000000000..38961c137b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6a959012e52fd6acf519e2ff3b2d48c962d566f65758eb3084d384fca676efde.json
@@ -0,0 +1,71 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE comms_messages\n SET content = $1, updated_at = NOW(), deleted_at = NOW()\n WHERE id = $2\n RETURNING \n id, \n channel_id,\n sender_id,\n content, \n created_at,\n updated_at,\n thread_id,\n edited_at as \"edited_at: chrono::DateTime<chrono::Utc>\",\n deleted_at as \"deleted_at: chrono::DateTime<chrono::Utc>\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "channel_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "sender_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "content",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "thread_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 7,
+ "name": "edited_at: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true,
+ true
+ ]
+ },
+ "hash": "6a959012e52fd6acf519e2ff3b2d48c962d566f65758eb3084d384fca676efde"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6ac0f229f06980ddbc62f5f5056b7996d92d842e88d386cb0b65fb11468cdc57.json b/rust/cloud-storage/chat/.sqlx/query-6ac0f229f06980ddbc62f5f5056b7996d92d842e88d386cb0b65fb11468cdc57.json
new file mode 100644
index 0000000000..c1dc3cfe3e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6ac0f229f06980ddbc62f5f5056b7996d92d842e88d386cb0b65fb11468cdc57.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"PdfHighlightAnchor\"\n SET \"deletedAt\" = NOW()\n WHERE uuid = $1 AND \"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "6ac0f229f06980ddbc62f5f5056b7996d92d842e88d386cb0b65fb11468cdc57"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6b5d1c6cd2318d630632681a46fc22d2c1075924eb4c5089bd81b1f3b72e0455.json b/rust/cloud-storage/chat/.sqlx/query-6b5d1c6cd2318d630632681a46fc22d2c1075924eb4c5089bd81b1f3b72e0455.json
new file mode 100644
index 0000000000..639f950925
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6b5d1c6cd2318d630632681a46fc22d2c1075924eb4c5089bd81b1f3b72e0455.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO in_progress_user_link (id, macro_user_id)\n VALUES ($1, $2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "6b5d1c6cd2318d630632681a46fc22d2c1075924eb4c5089bd81b1f3b72e0455"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6b7094e2eaf150972507f937e120984ee4911e974d0bcc78248c022d44fa20f1.json b/rust/cloud-storage/chat/.sqlx/query-6b7094e2eaf150972507f937e120984ee4911e974d0bcc78248c022d44fa20f1.json
new file mode 100644
index 0000000000..396f195c48
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6b7094e2eaf150972507f937e120984ee4911e974d0bcc78248c022d44fa20f1.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"sharePermissionId\" as id FROM \"ChatPermission\" WHERE \"chatId\" = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "6b7094e2eaf150972507f937e120984ee4911e974d0bcc78248c022d44fa20f1"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6be5aa69eb2f953dcefeebec85994f26d25cc170a7ae1eaca2e73ef0581605e4.json b/rust/cloud-storage/chat/.sqlx/query-6be5aa69eb2f953dcefeebec85994f26d25cc170a7ae1eaca2e73ef0581605e4.json
new file mode 100644
index 0000000000..aa097e55a5
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6be5aa69eb2f953dcefeebec85994f26d25cc170a7ae1eaca2e73ef0581605e4.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT COUNT(id) as count FROM comms_messages\n WHERE channel_id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "count",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "6be5aa69eb2f953dcefeebec85994f26d25cc170a7ae1eaca2e73ef0581605e4"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6c8ac695bf54550d865d143ee7a01a65dc6bad54ef3c3462f7bf5727f9ab3a42.json b/rust/cloud-storage/chat/.sqlx/query-6c8ac695bf54550d865d143ee7a01a65dc6bad54ef3c3462f7bf5727f9ab3a42.json
new file mode 100644
index 0000000000..b3228c70bf
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6c8ac695bf54550d865d143ee7a01a65dc6bad54ef3c3462f7bf5727f9ab3a42.json
@@ -0,0 +1,47 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id,\n d.\"owner\",\n d.name,\n d.\"fileType\" as \"file_type!\",\n di.id as \"document_version_id?\"\n FROM\n \"Document\" d\n LEFT JOIN LATERAL (\n SELECT\n i.id\n FROM\n \"DocumentInstance\" i\n WHERE\n i.\"documentId\" = d.id\n ORDER BY\n i.\"createdAt\" ASC\n LIMIT 1\n ) di ON true\n WHERE\n d.\"deletedAt\" IS NULL\n AND d.\"fileType\" IS NOT NULL\n ORDER BY d.\"createdAt\" DESC\n LIMIT $1 OFFSET $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "file_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "document_version_id?",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ false
+ ]
+ },
+ "hash": "6c8ac695bf54550d865d143ee7a01a65dc6bad54ef3c3462f7bf5727f9ab3a42"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6ca4be786e151f81e8e7d6b13ada596369e6a42d1371b871c7739e2dc0ff0b11.json b/rust/cloud-storage/chat/.sqlx/query-6ca4be786e151f81e8e7d6b13ada596369e6a42d1371b871c7739e2dc0ff0b11.json
new file mode 100644
index 0000000000..1a27c4b4be
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6ca4be786e151f81e8e7d6b13ada596369e6a42d1371b871c7739e2dc0ff0b11.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Chat\" SET \"name\" = $1\n WHERE id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "6ca4be786e151f81e8e7d6b13ada596369e6a42d1371b871c7739e2dc0ff0b11"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6cb6733cf58165e7c9ca63656c4c14b7bf0fc875462a0d335caf25969f272308.json b/rust/cloud-storage/chat/.sqlx/query-6cb6733cf58165e7c9ca63656c4c14b7bf0fc875462a0d335caf25969f272308.json
new file mode 100644
index 0000000000..6c36a67607
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6cb6733cf58165e7c9ca63656c4c14b7bf0fc875462a0d335caf25969f272308.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM entity_access\n WHERE source_id = $1 AND source_type = 'channel'\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "6cb6733cf58165e7c9ca63656c4c14b7bf0fc875462a0d335caf25969f272308"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6ce3b9755eb7d0e6eff85dfb08d9ca5ab3dffaa6794fe78612b94389ee90e3b4.json b/rust/cloud-storage/chat/.sqlx/query-6ce3b9755eb7d0e6eff85dfb08d9ca5ab3dffaa6794fe78612b94389ee90e3b4.json
new file mode 100644
index 0000000000..15267a7827
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6ce3b9755eb7d0e6eff85dfb08d9ca5ab3dffaa6794fe78612b94389ee90e3b4.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id as document_id\n FROM\n \"Document\" d\n WHERE\n d.owner = $1 AND d.\"deletedAt\" IS NULL AND d.\"fileType\" = ANY($2)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "6ce3b9755eb7d0e6eff85dfb08d9ca5ab3dffaa6794fe78612b94389ee90e3b4"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6d7020b1f916fc36d8da4a2bc277de97b6045e3908a0b3cee7ceabb3dccf0e7b.json b/rust/cloud-storage/chat/.sqlx/query-6d7020b1f916fc36d8da4a2bc277de97b6045e3908a0b3cee7ceabb3dccf0e7b.json
new file mode 100644
index 0000000000..9f13f899ff
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6d7020b1f916fc36d8da4a2bc277de97b6045e3908a0b3cee7ceabb3dccf0e7b.json
@@ -0,0 +1,40 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "SELECT * FROM comms_reactions WHERE message_id = $1",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "message_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "emoji",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 2,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "6d7020b1f916fc36d8da4a2bc277de97b6045e3908a0b3cee7ceabb3dccf0e7b"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6dbeb827ecd69ff3c396cdd1ad2fe22f3298692ad5c45b2ff87b1e396a492108.json b/rust/cloud-storage/chat/.sqlx/query-6dbeb827ecd69ff3c396cdd1ad2fe22f3298692ad5c45b2ff87b1e396a492108.json
new file mode 100644
index 0000000000..dd32fa44a6
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6dbeb827ecd69ff3c396cdd1ad2fe22f3298692ad5c45b2ff87b1e396a492108.json
@@ -0,0 +1,47 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n channel_type AS \"channel_type: ChannelType\",\n name,\n org_id\n FROM comms_channels\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "channel_type: ChannelType",
+ "type_info": {
+ "Custom": {
+ "name": "comms_channel_type",
+ "kind": {
+ "Enum": [
+ "public",
+ "organization",
+ "private",
+ "direct_message",
+ "team"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 2,
+ "name": "org_id",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ true,
+ true
+ ]
+ },
+ "hash": "6dbeb827ecd69ff3c396cdd1ad2fe22f3298692ad5c45b2ff87b1e396a492108"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6ddfc76d4a95ab81c18c930d8c08c51813d41f72f734271c538bd3e5377e2a4c.json b/rust/cloud-storage/chat/.sqlx/query-6ddfc76d4a95ab81c18c930d8c08c51813d41f72f734271c538bd3e5377e2a4c.json
new file mode 100644
index 0000000000..6cf849fd5c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6ddfc76d4a95ab81c18c930d8c08c51813d41f72f734271c538bd3e5377e2a4c.json
@@ -0,0 +1,53 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n em.source_entity_type,\n em.source_entity_id,\n em.entity_type,\n em.entity_id,\n em.user_id,\n em.created_at\n FROM comms_entity_mentions em\n WHERE em.entity_type = $1\n AND em.entity_id = $2\n AND em.source_entity_type != 'message'\n ORDER BY em.created_at DESC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "source_entity_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 1,
+ "name": "source_entity_id",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 2,
+ "name": "entity_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 3,
+ "name": "entity_id",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 4,
+ "name": "user_id",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 5,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ true,
+ false
+ ]
+ },
+ "hash": "6ddfc76d4a95ab81c18c930d8c08c51813d41f72f734271c538bd3e5377e2a4c"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6df8edb2ab31514a1ad2e48eecc81d52bf70ec8e34a2741be8f7a7b521d5074a.json b/rust/cloud-storage/chat/.sqlx/query-6df8edb2ab31514a1ad2e48eecc81d52bf70ec8e34a2741be8f7a7b521d5074a.json
new file mode 100644
index 0000000000..ac1ba33a99
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6df8edb2ab31514a1ad2e48eecc81d52bf70ec8e34a2741be8f7a7b521d5074a.json
@@ -0,0 +1,46 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH attachment_info AS (\n SELECT\n ca.id,\n ca.\"attachmentType\",\n ca.\"attachmentId\",\n ca.\"messageId\",\n CASE\n WHEN ca.\"attachmentType\" = 'document' THEN d.name\n WHEN ca.\"attachmentType\" = 'chat' THEN c.name\n WHEN ca.\"attachmentType\" = 'project' THEN p.name\n WHEN ca.\"attachmentType\" = 'image' THEN d.name\n ELSE NULL\n END AS document_name,\n CASE\n WHEN ca.\"attachmentType\" = 'document' THEN d.\"fileType\"\n WHEN ca.\"attachmentType\" = 'image' THEN d.\"fileType\"\n ELSE NULL\n END as document_type\n FROM\n \"ChatAttachment\" ca\n LEFT JOIN\n \"Document\" d ON (\n (ca.\"attachmentType\" = 'document' AND ca.\"attachmentId\" = d.id)\n OR\n (ca.\"attachmentType\" = 'image' AND ca.\"attachmentId\" = d.id)\n )\n LEFT JOIN\n \"Chat\" c ON ca.\"attachmentType\" = 'chat' AND ca.\"attachmentId\" = c.id\n LEFT JOIN\n \"Project\" p ON ca.\"attachmentType\" = 'project' AND ca.\"attachmentId\" = p.id\n )\n SELECT\n cm.id AS \"id!\",\n cm.content,\n cm.role,\n cm.model,\n COALESCE(\n (\n SELECT json_agg(\n json_build_object(\n 'id', attachment_info.\"attachmentId\",\n 'attachmentType', attachment_info.\"attachmentType\",\n 'attachmentId', attachment_info.\"attachmentId\",\n 'documentName', attachment_info.document_name,\n 'documentType', attachment_info.document_type\n )\n )\n FROM attachment_info\n WHERE attachment_info.\"messageId\" = cm.id\n ),\n '[]'::json\n ) AS attachments\n FROM\n \"ChatMessage\" cm\n WHERE\n cm.\"chatId\" = $1\n ORDER BY\n cm.\"createdAt\" ASC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "content",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 2,
+ "name": "role",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "model",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "attachments",
+ "type_info": "Json"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ null
+ ]
+ },
+ "hash": "6df8edb2ab31514a1ad2e48eecc81d52bf70ec8e34a2741be8f7a7b521d5074a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6e0240fcbc3f8f086e2529a680a1eee5f2495c0db613c33984e5755936513654.json b/rust/cloud-storage/chat/.sqlx/query-6e0240fcbc3f8f086e2529a680a1eee5f2495c0db613c33984e5755936513654.json
new file mode 100644
index 0000000000..c6c06891e2
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6e0240fcbc3f8f086e2529a680a1eee5f2495c0db613c33984e5755936513654.json
@@ -0,0 +1,45 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n user_id,\n team_id,\n team_role as \"team_role!: TeamRole\"\n FROM team_user\n WHERE team_id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "team_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "team_role!: TeamRole",
+ "type_info": {
+ "Custom": {
+ "name": "team_role",
+ "kind": {
+ "Enum": [
+ "member",
+ "admin",
+ "owner"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "6e0240fcbc3f8f086e2529a680a1eee5f2495c0db613c33984e5755936513654"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6e755ab9205277781336779cc7c41346b3432771aa29162272624e4bed3e54e5.json b/rust/cloud-storage/chat/.sqlx/query-6e755ab9205277781336779cc7c41346b3432771aa29162272624e4bed3e54e5.json
new file mode 100644
index 0000000000..4e92123853
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6e755ab9205277781336779cc7c41346b3432771aa29162272624e4bed3e54e5.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT d.\"documentId\" as \"document_id\"\n FROM \"DocumentText\" as d\n WHERE d.\"documentId\" = ANY($1)\n AND d.\"tokenCount\" > 0\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "6e755ab9205277781336779cc7c41346b3432771aa29162272624e4bed3e54e5"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-6ea5fe0c08693b233361460d1a1b46168b4bf9848d252242a06569301144a4f6.json b/rust/cloud-storage/chat/.sqlx/query-6ea5fe0c08693b233361460d1a1b46168b4bf9848d252242a06569301144a4f6.json
new file mode 100644
index 0000000000..5d785a97ee
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6ea5fe0c08693b233361460d1a1b46168b4bf9848d252242a06569301144a4f6.json
@@ -0,0 +1,55 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id as \"document_id\",\n d.owner,\n d.name as \"document_name\",\n d.\"fileType\" as \"file_type\",\n dst.sub_type as \"sub_type?: DocumentSubType\"\n FROM\n \"Document\" d\n LEFT JOIN document_sub_type dst ON dst.document_id = d.id\n WHERE d.id = $1\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ false
+ ]
+ },
+ "hash": "6ea5fe0c08693b233361460d1a1b46168b4bf9848d252242a06569301144a4f6"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-6ff8a4185b9a2a3ac8026b23d1d2c3014192dacd3588b1a33e23f59f22718822.json b/rust/cloud-storage/chat/.sqlx/query-6ff8a4185b9a2a3ac8026b23d1d2c3014192dacd3588b1a33e23f59f22718822.json
similarity index 100%
rename from rust/cloud-storage/macro_db_client/.sqlx/query-6ff8a4185b9a2a3ac8026b23d1d2c3014192dacd3588b1a33e23f59f22718822.json
rename to rust/cloud-storage/chat/.sqlx/query-6ff8a4185b9a2a3ac8026b23d1d2c3014192dacd3588b1a33e23f59f22718822.json
diff --git a/rust/cloud-storage/chat/.sqlx/query-6ff8a6b2288105fc7239b69206424f13f0542b0fa1d4499f8fe34cbf0c5a2fbc.json b/rust/cloud-storage/chat/.sqlx/query-6ff8a6b2288105fc7239b69206424f13f0542b0fa1d4499f8fe34cbf0c5a2fbc.json
new file mode 100644
index 0000000000..73dcf683dd
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-6ff8a6b2288105fc7239b69206424f13f0542b0fa1d4499f8fe34cbf0c5a2fbc.json
@@ -0,0 +1,70 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id,\n channel_id,\n sender_id,\n content,\n created_at,\n updated_at,\n thread_id,\n edited_at as \"edited_at: chrono::DateTime<chrono::Utc>\",\n deleted_at as \"deleted_at: chrono::DateTime<chrono::Utc>\"\n FROM comms_messages\n WHERE id = $1;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "channel_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "sender_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "content",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "thread_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 7,
+ "name": "edited_at: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true,
+ true
+ ]
+ },
+ "hash": "6ff8a6b2288105fc7239b69206424f13f0542b0fa1d4499f8fe34cbf0c5a2fbc"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-706da2cb5edbf06f5304e87bed3866c7a6ba7f2a405b174a238623f5e496886c.json b/rust/cloud-storage/chat/.sqlx/query-706da2cb5edbf06f5304e87bed3866c7a6ba7f2a405b174a238623f5e496886c.json
new file mode 100644
index 0000000000..c729246c07
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-706da2cb5edbf06f5304e87bed3866c7a6ba7f2a405b174a238623f5e496886c.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM comms_entity_mentions\n WHERE source_entity_id = ANY($1)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "706da2cb5edbf06f5304e87bed3866c7a6ba7f2a405b174a238623f5e496886c"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-70f12c0591fd0f66402ffc3720a5f5f7c6116cd761471bd5e03f528bf32effa5.json b/rust/cloud-storage/chat/.sqlx/query-70f12c0591fd0f66402ffc3720a5f5f7c6116cd761471bd5e03f528bf32effa5.json
new file mode 100644
index 0000000000..020d3dd88c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-70f12c0591fd0f66402ffc3720a5f5f7c6116cd761471bd5e03f528bf32effa5.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"sharePermissionId\" as id FROM \"DocumentPermission\" WHERE \"documentId\" = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "70f12c0591fd0f66402ffc3720a5f5f7c6116cd761471bd5e03f528bf32effa5"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-71b68b23ef028192231dd2129f4f8671f0af53a90629efe34f6f4e13ba227e91.json b/rust/cloud-storage/chat/.sqlx/query-71b68b23ef028192231dd2129f4f8671f0af53a90629efe34f6f4e13ba227e91.json
new file mode 100644
index 0000000000..51ac02ab79
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-71b68b23ef028192231dd2129f4f8671f0af53a90629efe34f6f4e13ba227e91.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n bp.sha as sha,\n bp.path as path,\n bp.id as id\n FROM \"BomPart\" bp\n JOIN \"DocumentBom\" db ON bp.\"documentBomId\" = db.id\n WHERE db.\"documentId\" = ANY($1);\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "sha",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "path",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "71b68b23ef028192231dd2129f4f8671f0af53a90629efe34f6f4e13ba227e91"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-71b975abc8c63ea8116cd8944e99d46e5747660807a30564921bc371ddd1338d.json b/rust/cloud-storage/chat/.sqlx/query-71b975abc8c63ea8116cd8944e99d46e5747660807a30564921bc371ddd1338d.json
new file mode 100644
index 0000000000..2dc1809409
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-71b975abc8c63ea8116cd8944e99d46e5747660807a30564921bc371ddd1338d.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"ItemLastAccessed\" (\"item_id\", \"item_type\", \"last_accessed\")\n VALUES ($1, $2, $3)\n ON CONFLICT (\"item_id\", \"item_type\") DO UPDATE\n SET \"last_accessed\" = $3;\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Timestamp"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "71b975abc8c63ea8116cd8944e99d46e5747660807a30564921bc371ddd1338d"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-725db444624bc6b4df387c7f45d750328437c7732e147e15818a269bb63be183.json b/rust/cloud-storage/chat/.sqlx/query-725db444624bc6b4df387c7f45d750328437c7732e147e15818a269bb63be183.json
new file mode 100644
index 0000000000..743945260d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-725db444624bc6b4df387c7f45d750328437c7732e147e15818a269bb63be183.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"OrganizationRetentionPolicy\"\n WHERE \"organization_id\" = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Int4"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "725db444624bc6b4df387c7f45d750328437c7732e147e15818a269bb63be183"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-7335b4f26cdbd5ad240545c4231cc1d34d10eda3212c0dcbd92db0ed61e86ec4.json b/rust/cloud-storage/chat/.sqlx/query-7335b4f26cdbd5ad240545c4231cc1d34d10eda3212c0dcbd92db0ed61e86ec4.json
new file mode 100644
index 0000000000..06337d4c3e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-7335b4f26cdbd5ad240545c4231cc1d34d10eda3212c0dcbd92db0ed61e86ec4.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Document\" SET \"documentFamilyId\" = $1 WHERE id = $2;\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "7335b4f26cdbd5ad240545c4231cc1d34d10eda3212c0dcbd92db0ed61e86ec4"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-7346e8f6a04f0e2d0b0c3b711afc10673c7756fda2cce9fe8619d68d92219a88.json b/rust/cloud-storage/chat/.sqlx/query-7346e8f6a04f0e2d0b0c3b711afc10673c7756fda2cce9fe8619d68d92219a88.json
new file mode 100644
index 0000000000..c52083e7eb
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-7346e8f6a04f0e2d0b0c3b711afc10673c7756fda2cce9fe8619d68d92219a88.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n sp.id as id\n FROM\n \"ProjectPermission\" pp\n JOIN \"SharePermission\" sp ON pp.\"sharePermissionId\" = sp.id\n WHERE\n pp.\"projectId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "7346e8f6a04f0e2d0b0c3b711afc10673c7756fda2cce9fe8619d68d92219a88"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-7385a803bf786406cafdce24628f9cca114fa5fe46b7bb0de469135f54dcd710.json b/rust/cloud-storage/chat/.sqlx/query-7385a803bf786406cafdce24628f9cca114fa5fe46b7bb0de469135f54dcd710.json
new file mode 100644
index 0000000000..9cce76e686
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-7385a803bf786406cafdce24628f9cca114fa5fe46b7bb0de469135f54dcd710.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id\n FROM\n \"Document\" d\n WHERE\n d.id = ANY($1)\n AND d.\"projectId\" = ANY($2)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "7385a803bf786406cafdce24628f9cca114fa5fe46b7bb0de469135f54dcd710"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-73c67fbf678e1479d528adcc5bea7da3261d0a04e24cc16f96ec9f2dea3b2e98.json b/rust/cloud-storage/chat/.sqlx/query-73c67fbf678e1479d528adcc5bea7da3261d0a04e24cc16f96ec9f2dea3b2e98.json
new file mode 100644
index 0000000000..65459bcefd
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-73c67fbf678e1479d528adcc5bea7da3261d0a04e24cc16f96ec9f2dea3b2e98.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id\n FROM \"User\"\n WHERE email = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "73c67fbf678e1479d528adcc5bea7da3261d0a04e24cc16f96ec9f2dea3b2e98"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-74d33764e454fb9ab4f2775974462d6fdb092bffc720d929de5e7b50ecef5139.json b/rust/cloud-storage/chat/.sqlx/query-74d33764e454fb9ab4f2775974462d6fdb092bffc720d929de5e7b50ecef5139.json
new file mode 100644
index 0000000000..34382e8725
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-74d33764e454fb9ab4f2775974462d6fdb092bffc720d929de5e7b50ecef5139.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id, apns_collapse_key as \"apns_collapse_key!: String\"\n FROM notification\n WHERE id = ANY($1) AND apns_collapse_key IS NOT NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "apns_collapse_key!: String",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "UuidArray"
+ ]
+ },
+ "nullable": [
+ false,
+ true
+ ]
+ },
+ "hash": "74d33764e454fb9ab4f2775974462d6fdb092bffc720d929de5e7b50ecef5139"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-75f7c645bd7640d085b759c4246f683ccf76c634d71337d35d1a8b7004f31c35.json b/rust/cloud-storage/chat/.sqlx/query-75f7c645bd7640d085b759c4246f683ccf76c634d71337d35d1a8b7004f31c35.json
new file mode 100644
index 0000000000..721336c9fe
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-75f7c645bd7640d085b759c4246f683ccf76c634d71337d35d1a8b7004f31c35.json
@@ -0,0 +1,41 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"DocumentInstance\" (\"documentId\", \"sha\")\n VALUES ($1, $2)\n RETURNING id, sha, \"createdAt\"::timestamptz as created_at, \"updatedAt\"::timestamptz as updated_at;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "sha",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 3,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ null,
+ null
+ ]
+ },
+ "hash": "75f7c645bd7640d085b759c4246f683ccf76c634d71337d35d1a8b7004f31c35"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-76096541f7696b2035acdb51754b4f783e345db19b32a815bbf68652121da947.json b/rust/cloud-storage/chat/.sqlx/query-76096541f7696b2035acdb51754b4f783e345db19b32a815bbf68652121da947.json
new file mode 100644
index 0000000000..a489813ed4
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-76096541f7696b2035acdb51754b4f783e345db19b32a815bbf68652121da947.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "DELETE FROM \"User\" WHERE id = $1",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "76096541f7696b2035acdb51754b4f783e345db19b32a815bbf68652121da947"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a.json b/rust/cloud-storage/chat/.sqlx/query-7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a.json
new file mode 100644
index 0000000000..655495fb29
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT c.id\n FROM comms_channels c\n INNER JOIN comms_channel_participants cp ON cp.channel_id = c.id\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n AND c.id = ANY($2::uuid[])\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-765650cab2b1a1d1abe6ca406438bf48968cebebc7316b87b192d649e096cd67.json b/rust/cloud-storage/chat/.sqlx/query-765650cab2b1a1d1abe6ca406438bf48968cebebc7316b87b192d649e096cd67.json
new file mode 100644
index 0000000000..a8e7326c35
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-765650cab2b1a1d1abe6ca406438bf48968cebebc7316b87b192d649e096cd67.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id FROM user_notification_item_unsubscribe\n WHERE item_id = $1 AND user_id = ANY($2)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "765650cab2b1a1d1abe6ca406438bf48968cebebc7316b87b192d649e096cd67"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-7671b43028d90ea50536fbcd10ee0c1625c2e66de29cdf080f66832e62e07e76.json b/rust/cloud-storage/chat/.sqlx/query-7671b43028d90ea50536fbcd10ee0c1625c2e66de29cdf080f66832e62e07e76.json
new file mode 100644
index 0000000000..33c4519459
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-7671b43028d90ea50536fbcd10ee0c1625c2e66de29cdf080f66832e62e07e76.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Chat\" SET \"deletedAt\" = $2 WHERE id = ANY($1);\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "Timestamp"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "7671b43028d90ea50536fbcd10ee0c1625c2e66de29cdf080f66832e62e07e76"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-769d1b9f8e1e88c30aabe8698b9d64bfc2b69def0b66bbd9d4010f81617b4ce3.json b/rust/cloud-storage/chat/.sqlx/query-769d1b9f8e1e88c30aabe8698b9d64bfc2b69def0b66bbd9d4010f81617b4ce3.json
new file mode 100644
index 0000000000..df6dfbd303
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-769d1b9f8e1e88c30aabe8698b9d64bfc2b69def0b66bbd9d4010f81617b4ce3.json
@@ -0,0 +1,71 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n id as \"id!\",\n name as \"name!\",\n channel_type as \"channel_type!: ChannelType\",\n org_id, -- This can be NULL\n created_at as \"created_at!\",\n updated_at as \"updated_at!\",\n owner_id as \"owner_id!\"\n FROM comms_channels\n WHERE channel_type = 'organization'::comms_channel_type\n AND org_id = $1::bigint\n ORDER BY created_at DESC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "name!",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 2,
+ "name": "channel_type!: ChannelType",
+ "type_info": {
+ "Custom": {
+ "name": "comms_channel_type",
+ "kind": {
+ "Enum": [
+ "public",
+ "organization",
+ "private",
+ "direct_message",
+ "team"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 3,
+ "name": "org_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "owner_id!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ true,
+ false,
+ true,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "769d1b9f8e1e88c30aabe8698b9d64bfc2b69def0b66bbd9d4010f81617b4ce3"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-76caf706a1f0846ad3a7075878e941a9293a5eeeb1de3900c3c39386d5dc57c0.json b/rust/cloud-storage/chat/.sqlx/query-76caf706a1f0846ad3a7075878e941a9293a5eeeb1de3900c3c39386d5dc57c0.json
new file mode 100644
index 0000000000..8f83e9a7d1
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-76caf706a1f0846ad3a7075878e941a9293a5eeeb1de3900c3c39386d5dc57c0.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT macro_user_id, first_name, last_name FROM macro_user_info WHERE macro_user_id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "macro_user_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "first_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "last_name",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ true,
+ true
+ ]
+ },
+ "hash": "76caf706a1f0846ad3a7075878e941a9293a5eeeb1de3900c3c39386d5dc57c0"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-76ebe39d39b36dc8c0d0f4d7741856a320bd22a3962cf1ccec2c930a56ed6a26.json b/rust/cloud-storage/chat/.sqlx/query-76ebe39d39b36dc8c0d0f4d7741856a320bd22a3962cf1ccec2c930a56ed6a26.json
new file mode 100644
index 0000000000..45fd98094d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-76ebe39d39b36dc8c0d0f4d7741856a320bd22a3962cf1ccec2c930a56ed6a26.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT resolved as is_resolved\n FROM \"Thread\"\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "is_resolved",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "76ebe39d39b36dc8c0d0f4d7741856a320bd22a3962cf1ccec2c930a56ed6a26"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-7704391a443f1375ebd231197c4c21c7843eea381e396a3c688b390ced89620a.json b/rust/cloud-storage/chat/.sqlx/query-7704391a443f1375ebd231197c4c21c7843eea381e396a3c688b390ced89620a.json
new file mode 100644
index 0000000000..e973ff399b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-7704391a443f1375ebd231197c4c21c7843eea381e396a3c688b390ced89620a.json
@@ -0,0 +1,76 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.id as id,\n c.name as name,\n c.\"userId\" as user_id,\n c.model as \"model?\",\n c.\"projectId\" as \"project_id?\",\n c.\"tokenCount\" as token_count,\n c.\"createdAt\"::timestamptz as created_at,\n c.\"updatedAt\"::timestamptz as updated_at,\n c.\"deletedAt\"::timestamptz as deleted_at,\n c.\"isPersistent\" as is_persistent\n FROM\n \"Chat\" c\n WHERE c.\"projectId\" = $1 AND c.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "model?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "project_id?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "token_count",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "is_persistent",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ true,
+ true,
+ null,
+ null,
+ null,
+ false
+ ]
+ },
+ "hash": "7704391a443f1375ebd231197c4c21c7843eea381e396a3c688b390ced89620a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-77ff9385b1d74c036dde9f03404de53c3002b45bbe4e800fd2edf3c09f7625cc.json b/rust/cloud-storage/chat/.sqlx/query-77ff9385b1d74c036dde9f03404de53c3002b45bbe4e800fd2edf3c09f7625cc.json
new file mode 100644
index 0000000000..e2694fd100
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-77ff9385b1d74c036dde9f03404de53c3002b45bbe4e800fd2edf3c09f7625cc.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "SELECT COUNT(*) as \"count\" FROM \"User\" WHERE \"organizationId\" = $1",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "count",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int4"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "77ff9385b1d74c036dde9f03404de53c3002b45bbe4e800fd2edf3c09f7625cc"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-7843258fc5ef444237a72be82c1be7ebbd77c6e056cde81c14b5526eef9045c2.json b/rust/cloud-storage/chat/.sqlx/query-7843258fc5ef444237a72be82c1be7ebbd77c6e056cde81c14b5526eef9045c2.json
new file mode 100644
index 0000000000..0f10c737ca
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-7843258fc5ef444237a72be82c1be7ebbd77c6e056cde81c14b5526eef9045c2.json
@@ -0,0 +1,69 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id,\n email,\n team_id,\n team_role as \"team_role!: TeamRole\",\n invited_by,\n created_at as \"created_at!: chrono::DateTime<chrono::Utc>\",\n last_sent_at as \"last_sent_at!: chrono::DateTime<chrono::Utc>\"\n FROM team_invite\n WHERE team_id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "email",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "team_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 3,
+ "name": "team_role!: TeamRole",
+ "type_info": {
+ "Custom": {
+ "name": "team_role",
+ "kind": {
+ "Enum": [
+ "member",
+ "admin",
+ "owner"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 4,
+ "name": "invited_by",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "created_at!: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 6,
+ "name": "last_sent_at!: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "7843258fc5ef444237a72be82c1be7ebbd77c6e056cde81c14b5526eef9045c2"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-78f1cf9da464937604c1a2d5115c014cab9de72bd88605ff47a316baa2c7acc2.json b/rust/cloud-storage/chat/.sqlx/query-78f1cf9da464937604c1a2d5115c014cab9de72bd88605ff47a316baa2c7acc2.json
new file mode 100644
index 0000000000..9e6f7f8877
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-78f1cf9da464937604c1a2d5115c014cab9de72bd88605ff47a316baa2c7acc2.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT d.device_endpoint\n FROM notification_user_device_registration d\n WHERE d.device_token = $1\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "device_endpoint",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "78f1cf9da464937604c1a2d5115c014cab9de72bd88605ff47a316baa2c7acc2"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-79c6974496c155f372a458d21240a09730630660ae75e8f6e5cfd8f5ba0ceb4e.json b/rust/cloud-storage/chat/.sqlx/query-79c6974496c155f372a458d21240a09730630660ae75e8f6e5cfd8f5ba0ceb4e.json
new file mode 100644
index 0000000000..06f69bc198
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-79c6974496c155f372a458d21240a09730630660ae75e8f6e5cfd8f5ba0ceb4e.json
@@ -0,0 +1,35 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"SharePermission\" (\"isPublic\", \"publicAccessLevel\", \"createdAt\", \"updatedAt\")\n VALUES ($1, $2, NOW(), NOW())\n RETURNING id, \"isPublic\" as is_public, \"publicAccessLevel\" as public_access_level;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "is_public",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 2,
+ "name": "public_access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Bool",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "79c6974496c155f372a458d21240a09730630660ae75e8f6e5cfd8f5ba0ceb4e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-7a648c2b6fb238695165051b64883dbc7d0e3fe4ecf4e65943e6c3c897261799.json b/rust/cloud-storage/chat/.sqlx/query-7a648c2b6fb238695165051b64883dbc7d0e3fe4ecf4e65943e6c3c897261799.json
new file mode 100644
index 0000000000..b7303fb33f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-7a648c2b6fb238695165051b64883dbc7d0e3fe4ecf4e65943e6c3c897261799.json
@@ -0,0 +1,29 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n channel_id,\n id\n FROM comms_messages\n ORDER BY created_at ASC\n LIMIT $1\n OFFSET $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "channel_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "7a648c2b6fb238695165051b64883dbc7d0e3fe4ecf4e65943e6c3c897261799"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-7ab64e5cba66fcea21b94760cf7c840a90db5fa8c9cba8247d07b0ef6fa3b004.json b/rust/cloud-storage/chat/.sqlx/query-7ab64e5cba66fcea21b94760cf7c840a90db5fa8c9cba8247d07b0ef6fa3b004.json
new file mode 100644
index 0000000000..db6ad1869a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-7ab64e5cba66fcea21b94760cf7c840a90db5fa8c9cba8247d07b0ef6fa3b004.json
@@ -0,0 +1,36 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO team (id, name, owner_id)\n VALUES ($1, $2, $3)\n RETURNING id, name, owner_id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "7ab64e5cba66fcea21b94760cf7c840a90db5fa8c9cba8247d07b0ef6fa3b004"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-7aee0251787584d5ae4c7b01fc06562ccabe8d554bb4013b3970ddd3f10fc364.json b/rust/cloud-storage/chat/.sqlx/query-7aee0251787584d5ae4c7b01fc06562ccabe8d554bb4013b3970ddd3f10fc364.json
new file mode 100644
index 0000000000..dcc7e4820a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-7aee0251787584d5ae4c7b01fc06562ccabe8d554bb4013b3970ddd3f10fc364.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT 'document' as \"item_type!\", \"documentId\" as \"item_id!\", \"sharePermissionId\" as \"share_permission_id!\"\n FROM \"DocumentPermission\"\n WHERE \"sharePermissionId\" = ANY($1)\n UNION ALL\n SELECT 'chat' as \"item_type!\", \"chatId\" as \"item_id!\", \"sharePermissionId\" as \"share_permission_id!\"\n FROM \"ChatPermission\"\n WHERE \"sharePermissionId\" = ANY($1)\n UNION ALL\n SELECT 'project' as \"item_type!\", \"projectId\" as \"item_id!\", \"sharePermissionId\" as \"share_permission_id!\"\n FROM \"ProjectPermission\"\n WHERE \"sharePermissionId\" = ANY($1)\n UNION ALL\n SELECT 'thread' as \"item_type!\", \"threadId\" as \"item_id!\", \"sharePermissionId\" as \"share_permission_id!\"\n FROM \"EmailThreadPermission\"\n WHERE \"sharePermissionId\" = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "item_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "share_permission_id!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "7aee0251787584d5ae4c7b01fc06562ccabe8d554bb4013b3970ddd3f10fc364"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-7b57355357a891761f608fc4d7ad472b901c087890909de9a068d6bc1ba0eb7a.json b/rust/cloud-storage/chat/.sqlx/query-7b57355357a891761f608fc4d7ad472b901c087890909de9a068d6bc1ba0eb7a.json
new file mode 100644
index 0000000000..fa801927c7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-7b57355357a891761f608fc4d7ad472b901c087890909de9a068d6bc1ba0eb7a.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n u.email\n FROM\n \"User\" u\n WHERE\n u.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "email",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "7b57355357a891761f608fc4d7ad472b901c087890909de9a068d6bc1ba0eb7a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-7b747964b75e86cda7393af6cd483d86a7214baaa710e8a527e1dd77ab8274b6.json b/rust/cloud-storage/chat/.sqlx/query-7b747964b75e86cda7393af6cd483d86a7214baaa710e8a527e1dd77ab8274b6.json
new file mode 100644
index 0000000000..e2226076d5
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-7b747964b75e86cda7393af6cd483d86a7214baaa710e8a527e1dd77ab8274b6.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Chat\" SET \"updatedAt\" = NOW()\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "7b747964b75e86cda7393af6cd483d86a7214baaa710e8a527e1dd77ab8274b6"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-7bb408bf30aecce0065dcfcf07da69efaab69905bb6b97d5d57ad591ff8c2006.json b/rust/cloud-storage/chat/.sqlx/query-7bb408bf30aecce0065dcfcf07da69efaab69905bb6b97d5d57ad591ff8c2006.json
new file mode 100644
index 0000000000..59735d180a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-7bb408bf30aecce0065dcfcf07da69efaab69905bb6b97d5d57ad591ff8c2006.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"account_merge_request\"\n WHERE \"id\" = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "7bb408bf30aecce0065dcfcf07da69efaab69905bb6b97d5d57ad591ff8c2006"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-7c0b9d645a85e30577377e4d8c8a8f976e86c6251e12517a2b1e14d525e09198.json b/rust/cloud-storage/chat/.sqlx/query-7c0b9d645a85e30577377e4d8c8a8f976e86c6251e12517a2b1e14d525e09198.json
new file mode 100644
index 0000000000..721b0038f2
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-7c0b9d645a85e30577377e4d8c8a8f976e86c6251e12517a2b1e14d525e09198.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id, notification_event_type\n FROM user_notification_type_preference\n WHERE user_id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_event_type",
+ "type_info": "Varchar"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "7c0b9d645a85e30577377e4d8c8a8f976e86c6251e12517a2b1e14d525e09198"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-7c4cd009982b182b18927dc5671aad059a55440c2de73c818ef28d6cf08acf80.json b/rust/cloud-storage/chat/.sqlx/query-7c4cd009982b182b18927dc5671aad059a55440c2de73c818ef28d6cf08acf80.json
new file mode 100644
index 0000000000..d51bf18635
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-7c4cd009982b182b18927dc5671aad059a55440c2de73c818ef28d6cf08acf80.json
@@ -0,0 +1,19 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"Document\" (id, owner, name, \"fileType\", \"projectId\", \"createdAt\", \"updatedAt\")\n VALUES ($1, $2, $3, $4, $5, $6, $6)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Text",
+ "Text",
+ "Text",
+ "Timestamp"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "7c4cd009982b182b18927dc5671aad059a55440c2de73c818ef28d6cf08acf80"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc.json b/rust/cloud-storage/chat/.sqlx/query-7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc.json
new file mode 100644
index 0000000000..a166680895
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc.json
@@ -0,0 +1,21 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO notification (id, notification_event_type, event_item_id, event_item_type, service_sender, metadata, sender_id, apns_collapse_key)\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8)\n ON CONFLICT (id) DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Varchar",
+ "Text",
+ "Text",
+ "Text",
+ "Jsonb",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-7d2487e2e00482505b104e5386377e939dd85a9090b3d89d71bb495b2ba7cca9.json b/rust/cloud-storage/chat/.sqlx/query-7d2487e2e00482505b104e5386377e939dd85a9090b3d89d71bb495b2ba7cca9.json
new file mode 100644
index 0000000000..88476d02eb
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-7d2487e2e00482505b104e5386377e939dd85a9090b3d89d71bb495b2ba7cca9.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Document\" SET \"deletedAt\" = NULL WHERE id = ANY($1);\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "7d2487e2e00482505b104e5386377e939dd85a9090b3d89d71bb495b2ba7cca9"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-7f5d80a93c34a98c84c86f6dd678139fbab4c5bf559090a45d79384bcef71a43.json b/rust/cloud-storage/chat/.sqlx/query-7f5d80a93c34a98c84c86f6dd678139fbab4c5bf559090a45d79384bcef71a43.json
new file mode 100644
index 0000000000..699c743a02
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-7f5d80a93c34a98c84c86f6dd678139fbab4c5bf559090a45d79384bcef71a43.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"Project\"\n WHERE id = $1",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "7f5d80a93c34a98c84c86f6dd678139fbab4c5bf559090a45d79384bcef71a43"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-8038c7f88cea547f6ed9e7d8d8e3b547ad7f8880f4e695bc037ccc7ca8493f82.json b/rust/cloud-storage/chat/.sqlx/query-8038c7f88cea547f6ed9e7d8d8e3b547ad7f8880f4e695bc037ccc7ca8493f82.json
new file mode 100644
index 0000000000..e8811731fa
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-8038c7f88cea547f6ed9e7d8d8e3b547ad7f8880f4e695bc037ccc7ca8493f82.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"content\"\n FROM \"DocumentProcessResult\"\n WHERE \"documentId\" = $1 AND \"jobType\" = $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "content",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "8038c7f88cea547f6ed9e7d8d8e3b547ad7f8880f4e695bc037ccc7ca8493f82"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-80d20d5b664dbbb320a52bf47f134534f93906716e415c54b6e3b30834973bc7.json b/rust/cloud-storage/chat/.sqlx/query-80d20d5b664dbbb320a52bf47f134534f93906716e415c54b6e3b30834973bc7.json
new file mode 100644
index 0000000000..8d3011486c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-80d20d5b664dbbb320a52bf47f134534f93906716e415c54b6e3b30834973bc7.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "SELECT owner, \"deletedAt\" as deleted_at FROM \"Document\" WHERE id=$1",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "deleted_at",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ true
+ ]
+ },
+ "hash": "80d20d5b664dbbb320a52bf47f134534f93906716e415c54b6e3b30834973bc7"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-8147aab2de8747d607d38b11d39c62991540fc188b1c70f3c40a8a12f4908071.json b/rust/cloud-storage/chat/.sqlx/query-8147aab2de8747d607d38b11d39c62991540fc188b1c70f3c40a8a12f4908071.json
new file mode 100644
index 0000000000..e294b94dc9
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-8147aab2de8747d607d38b11d39c62991540fc188b1c70f3c40a8a12f4908071.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT name FROM \"Project\" WHERE id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "name",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "8147aab2de8747d607d38b11d39c62991540fc188b1c70f3c40a8a12f4908071"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-82329af5032380193f6774277bf662f7a68651a2375e36b9923a6bf7fec71426.json b/rust/cloud-storage/chat/.sqlx/query-82329af5032380193f6774277bf662f7a68651a2375e36b9923a6bf7fec71426.json
new file mode 100644
index 0000000000..ff952f5055
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-82329af5032380193f6774277bf662f7a68651a2375e36b9923a6bf7fec71426.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n u.\"organizationId\" as organization_id\n FROM\n \"User\" u\n WHERE\n u.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "organization_id",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "82329af5032380193f6774277bf662f7a68651a2375e36b9923a6bf7fec71426"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-8238816f3d6e5b374b83023a799251d28c15592d8b50959c331bbc2ba45ceaea.json b/rust/cloud-storage/chat/.sqlx/query-8238816f3d6e5b374b83023a799251d28c15592d8b50959c331bbc2ba45ceaea.json
new file mode 100644
index 0000000000..80302fe8d7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-8238816f3d6e5b374b83023a799251d28c15592d8b50959c331bbc2ba45ceaea.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id as document_id\n FROM\n \"Document\" d\n WHERE\n d.owner = $1 AND d.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "8238816f3d6e5b374b83023a799251d28c15592d8b50959c331bbc2ba45ceaea"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-8334abc3fffa33d4b93704f039d5cd78bb02fa8505c3ba8111d1c9e17ffd93d8.json b/rust/cloud-storage/chat/.sqlx/query-8334abc3fffa33d4b93704f039d5cd78bb02fa8505c3ba8111d1c9e17ffd93d8.json
new file mode 100644
index 0000000000..5446721266
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-8334abc3fffa33d4b93704f039d5cd78bb02fa8505c3ba8111d1c9e17ffd93d8.json
@@ -0,0 +1,76 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n c.id as comment_id, \n c.\"threadId\" as thread_id, \n c.owner, \n c.sender, \n c.text, \n c.metadata, \n c.\"createdAt\"::timestamptz as created_at, \n c.\"updatedAt\"::timestamptz as updated_at, \n c.\"deletedAt\"::timestamptz as deleted_at, \n c.order\n FROM \"Comment\" c\n JOIN \"Thread\" t ON c.\"threadId\" = t.id\n WHERE c.\"threadId\" = $1\n AND c.\"deletedAt\" IS NULL\n AND t.\"deletedAt\" IS NULL\n ORDER BY c.\"createdAt\" ASC \n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "comment_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "sender",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "text",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "metadata",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "order",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ false,
+ true,
+ null,
+ null,
+ null,
+ true
+ ]
+ },
+ "hash": "8334abc3fffa33d4b93704f039d5cd78bb02fa8505c3ba8111d1c9e17ffd93d8"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-833f7916c7445825f248eac09769afd4b4971b517b12e578ec2f534038609572.json b/rust/cloud-storage/chat/.sqlx/query-833f7916c7445825f248eac09769afd4b4971b517b12e578ec2f534038609572.json
new file mode 100644
index 0000000000..8b6519505d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-833f7916c7445825f248eac09769afd4b4971b517b12e578ec2f534038609572.json
@@ -0,0 +1,29 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $2 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $2\n UNION ALL\n SELECT $2\n )\n SELECT\n chat_id,\n access_level\n FROM (\n -- Source 1: entity_access for chats\n SELECT\n ea.entity_id::text as chat_id,\n ea.access_level::text as access_level\n FROM entity_access ea\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n AND ea.entity_id = ANY(SELECT id::uuid FROM \"Chat\" WHERE id = ANY($1) AND \"deletedAt\" IS NULL)\n AND ea.entity_type = 'chat'\n UNION ALL\n -- Source 2: Direct chat public permissions\n SELECT\n c.id as chat_id,\n sp.\"publicAccessLevel\" as access_level\n FROM \"Chat\" c\n JOIN \"ChatPermission\" cp ON cp.\"chatId\" = c.id\n JOIN \"SharePermission\" sp ON sp.id = cp.\"sharePermissionId\"\n AND sp.\"isPublic\" = true\n AND sp.\"publicAccessLevel\" IS NOT NULL\n WHERE c.id = ANY($1) AND c.\"deletedAt\" IS NULL\n ) as all_levels\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "chat_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null,
+ null
+ ]
+ },
+ "hash": "833f7916c7445825f248eac09769afd4b4971b517b12e578ec2f534038609572"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-84bcc8595057c11bf854c4ecefc2abb2b0d392b7f098fdedac066a67d4dfd7d9.json b/rust/cloud-storage/chat/.sqlx/query-84bcc8595057c11bf854c4ecefc2abb2b0d392b7f098fdedac066a67d4dfd7d9.json
new file mode 100644
index 0000000000..cebd9aa412
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-84bcc8595057c11bf854c4ecefc2abb2b0d392b7f098fdedac066a67d4dfd7d9.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.\"id\" as \"chat_id\"\n FROM\n \"Chat\" c\n WHERE\n c.\"userId\" = $1 AND c.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "chat_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "84bcc8595057c11bf854c4ecefc2abb2b0d392b7f098fdedac066a67d4dfd7d9"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-84e1db53f1407e16ed5e2fccf64ecb7a7493b1a1df0b372b460170154a49a509.json b/rust/cloud-storage/chat/.sqlx/query-84e1db53f1407e16ed5e2fccf64ecb7a7493b1a1df0b372b460170154a49a509.json
new file mode 100644
index 0000000000..aeffc58687
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-84e1db53f1407e16ed5e2fccf64ecb7a7493b1a1df0b372b460170154a49a509.json
@@ -0,0 +1,66 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"Thread\" AS t \n (\"owner\", \"documentId\", \"createdAt\", \"updatedAt\", \"metadata\")\n VALUES ($1, $2, NOW(), NOW(), $3)\n RETURNING\n t.id as thread_id, \n t.resolved, \n t.\"documentId\" as document_id, \n t.\"createdAt\"::timestamptz as created_at, \n t.\"updatedAt\"::timestamptz as updated_at, \n t.\"deletedAt\"::timestamptz as deleted_at, \n t.metadata, \n t.owner\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "resolved",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 4,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "metadata",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 7,
+ "name": "owner",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Jsonb"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ true,
+ false
+ ]
+ },
+ "hash": "84e1db53f1407e16ed5e2fccf64ecb7a7493b1a1df0b372b460170154a49a509"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-850ac15de719742dcee861fed5d0199ded6efb032bc7e2daaca06013bb130e9b.json b/rust/cloud-storage/chat/.sqlx/query-850ac15de719742dcee861fed5d0199ded6efb032bc7e2daaca06013bb130e9b.json
new file mode 100644
index 0000000000..1b2535f9bf
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-850ac15de719742dcee861fed5d0199ded6efb032bc7e2daaca06013bb130e9b.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n bp.id as id,\n bp.sha as sha,\n bp.path as path\n FROM\n \"BomPart\" bp\n WHERE\n bp.\"documentBomId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "sha",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "path",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "850ac15de719742dcee861fed5d0199ded6efb032bc7e2daaca06013bb130e9b"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-857660d2872b58e76b92cd38e6100f7963d9d2e566acaa8849c5adc537cfc2f1.json b/rust/cloud-storage/chat/.sqlx/query-857660d2872b58e76b92cd38e6100f7963d9d2e566acaa8849c5adc537cfc2f1.json
new file mode 100644
index 0000000000..0dbcf950ad
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-857660d2872b58e76b92cd38e6100f7963d9d2e566acaa8849c5adc537cfc2f1.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM comms_entity_mentions\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "857660d2872b58e76b92cd38e6100f7963d9d2e566acaa8849c5adc537cfc2f1"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-869cd93b000ff26b2c872e5822ab4adb80d18fdc595352afa30159ac3eb864bc.json b/rust/cloud-storage/chat/.sqlx/query-869cd93b000ff26b2c872e5822ab4adb80d18fdc595352afa30159ac3eb864bc.json
new file mode 100644
index 0000000000..7d754d3f07
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-869cd93b000ff26b2c872e5822ab4adb80d18fdc595352afa30159ac3eb864bc.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Chat\" SET \"model\" = $1\n WHERE id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "869cd93b000ff26b2c872e5822ab4adb80d18fdc595352afa30159ac3eb864bc"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-86c882f1999ad9c5b87e684ae17a1c1307846848b1b1bd40ee02438ada43052f.json b/rust/cloud-storage/chat/.sqlx/query-86c882f1999ad9c5b87e684ae17a1c1307846848b1b1bd40ee02438ada43052f.json
new file mode 100644
index 0000000000..6d3290429d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-86c882f1999ad9c5b87e684ae17a1c1307846848b1b1bd40ee02438ada43052f.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO macro_user_info (macro_user_id, profile_picture, profile_picture_hash)\n VALUES ($1, $2, $3)\n ON CONFLICT (macro_user_id)\n DO UPDATE SET \n profile_picture = EXCLUDED.profile_picture,\n profile_picture_hash = EXCLUDED.profile_picture_hash\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Varchar"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "86c882f1999ad9c5b87e684ae17a1c1307846848b1b1bd40ee02438ada43052f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-86d18e7e4b32bfa5e0ca2c8048f2e544756b6c60a5745705c726b3269f743c3c.json b/rust/cloud-storage/chat/.sqlx/query-86d18e7e4b32bfa5e0ca2c8048f2e544756b6c60a5745705c726b3269f743c3c.json
new file mode 100644
index 0000000000..41e01db088
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-86d18e7e4b32bfa5e0ca2c8048f2e544756b6c60a5745705c726b3269f743c3c.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO team_user (team_id, user_id, team_role)\n VALUES ($1, $2, 'owner')\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "86d18e7e4b32bfa5e0ca2c8048f2e544756b6c60a5745705c726b3269f743c3c"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-86eee52e30e4168f4a7f319d1dcaa59144a5b3269120df892f161c74b5fe7436.json b/rust/cloud-storage/chat/.sqlx/query-86eee52e30e4168f4a7f319d1dcaa59144a5b3269120df892f161c74b5fe7436.json
new file mode 100644
index 0000000000..eab49b91f7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-86eee52e30e4168f4a7f319d1dcaa59144a5b3269120df892f161c74b5fe7436.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET sent = true\n WHERE notification_id = $1 AND user_id = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "86eee52e30e4168f4a7f319d1dcaa59144a5b3269120df892f161c74b5fe7436"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-8733fe389d5f98dd34fe87d42e680e664655853aab4646cc5e889f48c5511aa1.json b/rust/cloud-storage/chat/.sqlx/query-8733fe389d5f98dd34fe87d42e680e664655853aab4646cc5e889f48c5511aa1.json
new file mode 100644
index 0000000000..687224c45b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-8733fe389d5f98dd34fe87d42e680e664655853aab4646cc5e889f48c5511aa1.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"macro_user_email_verification\" (\"macro_user_id\", \"email\", \"is_verified\")\n VALUES ($1, $2, $3)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Bool"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "8733fe389d5f98dd34fe87d42e680e664655853aab4646cc5e889f48c5511aa1"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-874a0c4d1f171a6b97f75dd0e0c2df35b86bb10ef4bb518fb4594fe81d282606.json b/rust/cloud-storage/chat/.sqlx/query-874a0c4d1f171a6b97f75dd0e0c2df35b86bb10ef4bb518fb4594fe81d282606.json
new file mode 100644
index 0000000000..a40a259e15
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-874a0c4d1f171a6b97f75dd0e0c2df35b86bb10ef4bb518fb4594fe81d282606.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n db.id\n FROM \"DocumentBom\" db\n JOIN \"Document\" d ON db.\"documentId\" = d.id\n WHERE db.\"documentId\" = $1\n ORDER BY db.\"createdAt\" DESC\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "874a0c4d1f171a6b97f75dd0e0c2df35b86bb10ef4bb518fb4594fe81d282606"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-87877cda339e72a128639a459295ce165cd096206e1f17f3fa5e98c27508095f.json b/rust/cloud-storage/chat/.sqlx/query-87877cda339e72a128639a459295ce165cd096206e1f17f3fa5e98c27508095f.json
similarity index 100%
rename from rust/cloud-storage/macro_db_client/.sqlx/query-87877cda339e72a128639a459295ce165cd096206e1f17f3fa5e98c27508095f.json
rename to rust/cloud-storage/chat/.sqlx/query-87877cda339e72a128639a459295ce165cd096206e1f17f3fa5e98c27508095f.json
diff --git a/rust/cloud-storage/chat/.sqlx/query-87eec4033f46191de7f443e2f1ab2bf5e342b790423e98d6c62ba29a1a434d85.json b/rust/cloud-storage/chat/.sqlx/query-87eec4033f46191de7f443e2f1ab2bf5e342b790423e98d6c62ba29a1a434d85.json
new file mode 100644
index 0000000000..e1050f8af8
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-87eec4033f46191de7f443e2f1ab2bf5e342b790423e98d6c62ba29a1a434d85.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id FROM \"Chat\" WHERE \"userId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "87eec4033f46191de7f443e2f1ab2bf5e342b790423e98d6c62ba29a1a434d85"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-88caded3c9250cb4835eb952d9e6ae02c0e492ab45c9ba26cc77c4fe1befec0a.json b/rust/cloud-storage/chat/.sqlx/query-88caded3c9250cb4835eb952d9e6ae02c0e492ab45c9ba26cc77c4fe1befec0a.json
new file mode 100644
index 0000000000..e1edff567e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-88caded3c9250cb4835eb952d9e6ae02c0e492ab45c9ba26cc77c4fe1befec0a.json
@@ -0,0 +1,65 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $2 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $2\n UNION ALL\n SELECT $2\n )\n SELECT\n entity_id::text as \"entity_id!\",\n entity_type as \"entity_type!\",\n source_id as \"source_id!\",\n access_level as \"access_level!: AccessLevel\",\n created_at as \"created_at!: DateTime<Utc>\",\n updated_at as \"updated_at!: DateTime<Utc>\"\n FROM entity_access\n WHERE source_id = ANY(SELECT source_id FROM user_source_ids)\n AND entity_id = $1\n AND entity_type = 'project'\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "entity_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "entity_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "source_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "access_level!: AccessLevel",
+ "type_info": {
+ "Custom": {
+ "name": "\"AccessLevel\"",
+ "kind": {
+ "Enum": [
+ "view",
+ "comment",
+ "edit",
+ "owner"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at!: DateTime<Utc>",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at!: DateTime<Utc>",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null,
+ false,
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "88caded3c9250cb4835eb952d9e6ae02c0e492ab45c9ba26cc77c4fe1befec0a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-88ef62575a41128850e0943150af07a886168487ebe62c651b4cd33e26cf5ea7.json b/rust/cloud-storage/chat/.sqlx/query-88ef62575a41128850e0943150af07a886168487ebe62c651b4cd33e26cf5ea7.json
new file mode 100644
index 0000000000..92d4d68f99
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-88ef62575a41128850e0943150af07a886168487ebe62c651b4cd33e26cf5ea7.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE team\n SET name = $1\n WHERE id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "88ef62575a41128850e0943150af07a886168487ebe62c651b4cd33e26cf5ea7"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-893ba4ca56a651ac3f29465976b0809413930f77ea2b5be2af1e97759582f310.json b/rust/cloud-storage/chat/.sqlx/query-893ba4ca56a651ac3f29465976b0809413930f77ea2b5be2af1e97759582f310.json
new file mode 100644
index 0000000000..5532acf1d7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-893ba4ca56a651ac3f29465976b0809413930f77ea2b5be2af1e97759582f310.json
@@ -0,0 +1,17 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)\n SELECT\n u.entity_id,\n u.entity_type,\n u.source_id,\n 'user',\n u.access_level::\"AccessLevel\"\n FROM UNNEST(\n $1::uuid[],\n $2::text[],\n $3::text[],\n $4::text[]\n ) as u(\n entity_id,\n entity_type,\n source_id,\n access_level\n )\n ON CONFLICT (entity_id, entity_type, source_id, source_type)\n WHERE granted_from_project_id IS NULL\n DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "UuidArray",
+ "TextArray",
+ "TextArray",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "893ba4ca56a651ac3f29465976b0809413930f77ea2b5be2af1e97759582f310"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-894b2bdfc3046722023572c4b37870258288ab2b3125c4f31dec62d916f0b64a.json b/rust/cloud-storage/chat/.sqlx/query-894b2bdfc3046722023572c4b37870258288ab2b3125c4f31dec62d916f0b64a.json
new file mode 100644
index 0000000000..d6e3ef0406
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-894b2bdfc3046722023572c4b37870258288ab2b3125c4f31dec62d916f0b64a.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n rp.\"roleId\" AS role_id,\n rp.\"permissionId\" AS permission_id\n FROM\n \"User\" u\n INNER JOIN\n \"RolesOnUsers\" ru ON u.id = ru.\"userId\"\n INNER JOIN\n \"RolesOnPermissions\" rp ON ru.\"roleId\" = rp.\"roleId\"\n WHERE\n u.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "role_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "permission_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "894b2bdfc3046722023572c4b37870258288ab2b3125c4f31dec62d916f0b64a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-89b618eb18b7ae1ab21e40391daea7da6a544800e931142ac88d413aaed73653.json b/rust/cloud-storage/chat/.sqlx/query-89b618eb18b7ae1ab21e40391daea7da6a544800e931142ac88d413aaed73653.json
new file mode 100644
index 0000000000..0a50dad356
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-89b618eb18b7ae1ab21e40391daea7da6a544800e931142ac88d413aaed73653.json
@@ -0,0 +1,20 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT COUNT(*) as \"count\"\n FROM \"Document\" d\n WHERE d.\"fileType\" = 'docx' AND d.\"deletedAt\" IS NULL AND d.uploaded = true\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "count",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": []
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "89b618eb18b7ae1ab21e40391daea7da6a544800e931142ac88d413aaed73653"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-89d146cd834b7c70073f612c7460da8c2421c820f980f067e875a8e4fffe6515.json b/rust/cloud-storage/chat/.sqlx/query-89d146cd834b7c70073f612c7460da8c2421c820f980f067e875a8e4fffe6515.json
new file mode 100644
index 0000000000..13512d24bd
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-89d146cd834b7c70073f612c7460da8c2421c820f980f067e875a8e4fffe6515.json
@@ -0,0 +1,65 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $2 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $2\n UNION ALL\n SELECT $2\n )\n SELECT\n entity_id::text as \"entity_id!\",\n entity_type as \"entity_type!\",\n source_id as \"source_id!\",\n access_level as \"access_level!: AccessLevel\",\n created_at as \"created_at!: DateTime<Utc>\",\n updated_at as \"updated_at!: DateTime<Utc>\"\n FROM entity_access\n WHERE source_id = ANY(SELECT source_id FROM user_source_ids)\n AND entity_id = $1\n AND entity_type = 'chat'\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "entity_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "entity_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "source_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "access_level!: AccessLevel",
+ "type_info": {
+ "Custom": {
+ "name": "\"AccessLevel\"",
+ "kind": {
+ "Enum": [
+ "view",
+ "comment",
+ "edit",
+ "owner"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at!: DateTime<Utc>",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at!: DateTime<Utc>",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null,
+ false,
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "89d146cd834b7c70073f612c7460da8c2421c820f980f067e875a8e4fffe6515"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-8a09a252705dac4a5d37461d81354c02f0776d151ed57da06713a6a0d7185392.json b/rust/cloud-storage/chat/.sqlx/query-8a09a252705dac4a5d37461d81354c02f0776d151ed57da06713a6a0d7185392.json
new file mode 100644
index 0000000000..184bdca121
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-8a09a252705dac4a5d37461d81354c02f0776d151ed57da06713a6a0d7185392.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"SharePermission\" sp\n USING \"DocumentPermission\" dp \n WHERE dp.\"sharePermissionId\" = sp.id\n AND dp.\"documentId\" = ANY($1)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "8a09a252705dac4a5d37461d81354c02f0776d151ed57da06713a6a0d7185392"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-8a4688fb6685c28f7fc9f48487b2fe1ce97205a1574fcedd7e87596c63d6dab0.json b/rust/cloud-storage/chat/.sqlx/query-8a4688fb6685c28f7fc9f48487b2fe1ce97205a1574fcedd7e87596c63d6dab0.json
new file mode 100644
index 0000000000..a41d940fca
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-8a4688fb6685c28f7fc9f48487b2fe1ce97205a1574fcedd7e87596c63d6dab0.json
@@ -0,0 +1,62 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT c.owner, t.id as thread_id, d.owner as document_owner, d.id as document_id, ta.\"anchorId\" as \"anchor_id?\", ta.\"anchorTableName\" as \"anchor_table_name?: AnchorTableName\"\n FROM \"Comment\" c\n JOIN \"Thread\" t ON c.\"threadId\" = t.id\n JOIN \"Document\" d ON t.\"documentId\" = d.id\n LEFT JOIN \"ThreadAnchor\" ta ON ta.\"threadId\" = t.id\n WHERE c.id = $1 AND c.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "anchor_id?",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 5,
+ "name": "anchor_table_name?: AnchorTableName",
+ "type_info": {
+ "Custom": {
+ "name": "anchor_table_name",
+ "kind": {
+ "Enum": [
+ "PdfPlaceableCommentAnchor",
+ "PdfHighlightAnchor"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "8a4688fb6685c28f7fc9f48487b2fe1ce97205a1574fcedd7e87596c63d6dab0"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-8b640c24a0a71ba83db60c1bd7a273aae232cbb8fab78cf029c66ec1e8576b61.json b/rust/cloud-storage/chat/.sqlx/query-8b640c24a0a71ba83db60c1bd7a273aae232cbb8fab78cf029c66ec1e8576b61.json
new file mode 100644
index 0000000000..238e214685
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-8b640c24a0a71ba83db60c1bd7a273aae232cbb8fab78cf029c66ec1e8576b61.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.id\n FROM\n comms_channels c\n WHERE\n c.id = ANY($1)\n AND c.channel_type = 'organization'\n AND c.org_id = $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "UuidArray",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "8b640c24a0a71ba83db60c1bd7a273aae232cbb8fab78cf029c66ec1e8576b61"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-8b7993e0c49a8c1b1fb9449770a500362b483bcea23aec896bfaf9e67fd6dc95.json b/rust/cloud-storage/chat/.sqlx/query-8b7993e0c49a8c1b1fb9449770a500362b483bcea23aec896bfaf9e67fd6dc95.json
new file mode 100644
index 0000000000..646f2cc8b7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-8b7993e0c49a8c1b1fb9449770a500362b483bcea23aec896bfaf9e67fd6dc95.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n p.id\n FROM\n \"Project\" p\n WHERE\n p.\"parentId\" = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "8b7993e0c49a8c1b1fb9449770a500362b483bcea23aec896bfaf9e67fd6dc95"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-8b7e81c3b4f31c86100de517e1978a1879039b7230aa83df18f583106c97a18f.json b/rust/cloud-storage/chat/.sqlx/query-8b7e81c3b4f31c86100de517e1978a1879039b7230aa83df18f583106c97a18f.json
new file mode 100644
index 0000000000..06dcafa73e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-8b7e81c3b4f31c86100de517e1978a1879039b7230aa83df18f583106c97a18f.json
@@ -0,0 +1,129 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH UserHistories AS (\n SELECT\n h.\"itemId\" as item_id,\n h.\"itemType\" as item_type\n FROM \"UserHistory\" h\n WHERE h.\"userId\" = $1\n ), Combined AS (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at\",\n d.\"updatedAt\"::timestamptz as \"updated_at\",\n d.\"projectId\" as \"project_id\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\",\n NULL as \"is_persistent\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n CASE \n WHEN dt.sub_type = 'task' \n AND ep_status.values->'value' ? $2\n THEN true \n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL \n END as \"is_completed\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status \n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id \n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $3\n INNER JOIN UserHistories uh ON uh.item_id = d.id AND uh.item_type = 'document'\n LEFT JOIN LATERAL (\n SELECT\n b.id\n FROM\n \"DocumentBom\" b\n WHERE\n b.\"documentId\" = d.id\n ORDER BY\n b.\"createdAt\" DESC\n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT\n i.id,\n i.\"documentId\",\n i.\"sha\",\n i.\"createdAt\",\n i.\"updatedAt\"\n FROM\n \"DocumentInstance\" i\n WHERE\n i.\"documentId\" = d.id\n ORDER BY\n i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON true\n UNION ALL\n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at\",\n c.\"updatedAt\"::timestamptz as \"updated_at\",\n c.\"projectId\" as \"project_id\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n NULL as \"is_completed\"\n FROM \"Chat\" c\n INNER JOIN UserHistories uh ON uh.item_id = c.id AND uh.item_type = 'chat'\n UNION ALL\n SELECT\n 'project' as \"item_type!\",\n p.id as \"id!\",\n NULL as \"document_version_id\",\n p.\"userId\" as \"user_id!\",\n p.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n p.\"createdAt\"::timestamptz as \"created_at\",\n p.\"updatedAt\"::timestamptz as \"updated_at\",\n p.\"parentId\" as \"project_id\",\n p.\"deletedAt\"::timestamptz as \"deleted_at\",\n NULL as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n NULL as \"is_completed\"\n FROM \"Project\" p\n INNER JOIN UserHistories uh ON uh.item_id = p.id AND uh.item_type = 'project'\n )\n SELECT * FROM Combined\n ORDER BY updated_at DESC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_version_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "user_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "name!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "branched_from_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "branched_from_version_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 7,
+ "name": "document_family_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 8,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 9,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 11,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 12,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 13,
+ "name": "is_persistent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 14,
+ "name": "sha",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 15,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 16,
+ "name": "is_completed",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "8b7e81c3b4f31c86100de517e1978a1879039b7230aa83df18f583106c97a18f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-8bbec277addaa63540e2e5f0e8bf028a0d4bd3693357894d25d879dcd9b72563.json b/rust/cloud-storage/chat/.sqlx/query-8bbec277addaa63540e2e5f0e8bf028a0d4bd3693357894d25d879dcd9b72563.json
new file mode 100644
index 0000000000..ca5613aa3c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-8bbec277addaa63540e2e5f0e8bf028a0d4bd3693357894d25d879dcd9b72563.json
@@ -0,0 +1,71 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE comms_messages\n SET \n updated_at = NOW(),\n edited_at = NOW(),\n deleted_at = CASE \n WHEN $2 = false AND (content IS NULL OR content ~ '^[\\s]*$') THEN NOW()\n ELSE deleted_at\n END\n WHERE id = $1\n RETURNING\n id,\n channel_id,\n sender_id,\n content,\n created_at,\n updated_at,\n thread_id,\n edited_at as \"edited_at: chrono::DateTime<chrono::Utc>\",\n deleted_at as \"deleted_at: chrono::DateTime<chrono::Utc>\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "channel_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "sender_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "content",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "thread_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 7,
+ "name": "edited_at: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Bool"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true,
+ true
+ ]
+ },
+ "hash": "8bbec277addaa63540e2e5f0e8bf028a0d4bd3693357894d25d879dcd9b72563"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-8bca1bc084d24daf8db19d8fc04301467f257fbc1bde2a018fe9efb1e6728cd3.json b/rust/cloud-storage/chat/.sqlx/query-8bca1bc084d24daf8db19d8fc04301467f257fbc1bde2a018fe9efb1e6728cd3.json
new file mode 100644
index 0000000000..20d8eb1130
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-8bca1bc084d24daf8db19d8fc04301467f257fbc1bde2a018fe9efb1e6728cd3.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"UserDocumentViewLocation\" (user_id, document_id, location)\n VALUES ($1, $2, $3)\n ON CONFLICT (user_id, document_id) \n DO UPDATE SET location = EXCLUDED.location, updated_at = NOW()\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "8bca1bc084d24daf8db19d8fc04301467f257fbc1bde2a018fe9efb1e6728cd3"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-8cab0f54798d95a0549e022187648a7e8ad714623a8a2fe32c785ddb27937eae.json b/rust/cloud-storage/chat/.sqlx/query-8cab0f54798d95a0549e022187648a7e8ad714623a8a2fe32c785ddb27937eae.json
new file mode 100644
index 0000000000..d742c4ba27
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-8cab0f54798d95a0549e022187648a7e8ad714623a8a2fe32c785ddb27937eae.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"sharePermissionId\" as share_permission_id\n FROM \"ChatPermission\"\n WHERE \"chatId\"=$1",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "share_permission_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "8cab0f54798d95a0549e022187648a7e8ad714623a8a2fe32c785ddb27937eae"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-86844f724bc063be712fbf68d1a21e252b27aba90790bc14e979f07bf6dedf92.json b/rust/cloud-storage/chat/.sqlx/query-8cc1aa2163c9650b121037b241370b154ad229bcf9280c54e5975914d1c6fc78.json
similarity index 56%
rename from rust/cloud-storage/documents/.sqlx/query-86844f724bc063be712fbf68d1a21e252b27aba90790bc14e979f07bf6dedf92.json
rename to rust/cloud-storage/chat/.sqlx/query-8cc1aa2163c9650b121037b241370b154ad229bcf9280c54e5975914d1c6fc78.json
index 3023106dc8..ed15384636 100644
--- a/rust/cloud-storage/documents/.sqlx/query-86844f724bc063be712fbf68d1a21e252b27aba90790bc14e979f07bf6dedf92.json
+++ b/rust/cloud-storage/chat/.sqlx/query-8cc1aa2163c9650b121037b241370b154ad229bcf9280c54e5975914d1c6fc78.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT user_id\n FROM team_user\n WHERE team_id = $1\n ",
+ "query": "\n SELECT\n user_id\n FROM comms_channel_participants\n WHERE channel_id = $1\n ",
"describe": {
"columns": [
{
@@ -18,5 +18,5 @@
false
]
},
- "hash": "86844f724bc063be712fbf68d1a21e252b27aba90790bc14e979f07bf6dedf92"
+ "hash": "8cc1aa2163c9650b121037b241370b154ad229bcf9280c54e5975914d1c6fc78"
}
diff --git a/rust/cloud-storage/chat/.sqlx/query-8d25b1711e2c00fe92b1921e1c2ee17e311301f88b1550dbff4eb41b6e12db13.json b/rust/cloud-storage/chat/.sqlx/query-8d25b1711e2c00fe92b1921e1c2ee17e311301f88b1550dbff4eb41b6e12db13.json
new file mode 100644
index 0000000000..9623da14ab
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-8d25b1711e2c00fe92b1921e1c2ee17e311301f88b1550dbff4eb41b6e12db13.json
@@ -0,0 +1,76 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n u.\"id\" as \"user_id\",\n u.\"email\" as \"email\",\n u.\"stripeCustomerId\" as \"stripe_customer_id?\",\n u.\"name\" as name,\n u.\"tutorialComplete\" as tutorial_complete,\n u.\"group\" as \"group?\",\n u.\"hasChromeExt\" as has_chrome_ext,\n u.\"aiDataConsent\" as ai_data_consent,\n mu.has_trialed as has_trialed,\n u.macro_user_id as \"macro_user_id\"\n FROM \"User\" u\n JOIN \"macro_user\" mu ON u.macro_user_id = mu.id\n WHERE u.\"id\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "email",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "stripe_customer_id?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "tutorial_complete",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 5,
+ "name": "group?",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 6,
+ "name": "has_chrome_ext",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 7,
+ "name": "ai_data_consent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 8,
+ "name": "has_trialed",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 9,
+ "name": "macro_user_id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ true,
+ true,
+ false,
+ true,
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "8d25b1711e2c00fe92b1921e1c2ee17e311301f88b1550dbff4eb41b6e12db13"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-8da326cb4addb18bca0e08c8728c86a1aa898bcf344fe913db7ee5c47dfde47c.json b/rust/cloud-storage/chat/.sqlx/query-8da326cb4addb18bca0e08c8728c86a1aa898bcf344fe913db7ee5c47dfde47c.json
new file mode 100644
index 0000000000..bda502d199
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-8da326cb4addb18bca0e08c8728c86a1aa898bcf344fe913db7ee5c47dfde47c.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT c.id\n FROM \"Chat\" c\n WHERE c.\"deletedAt\" IS NOT NULL AND c.\"deletedAt\" <= $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Timestamp"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "8da326cb4addb18bca0e08c8728c86a1aa898bcf344fe913db7ee5c47dfde47c"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-8e916c1355943f5a5d48d153bdf82e453c82b6a4c279973b2f7c0c631ffeff12.json b/rust/cloud-storage/chat/.sqlx/query-8e916c1355943f5a5d48d153bdf82e453c82b6a4c279973b2f7c0c631ffeff12.json
new file mode 100644
index 0000000000..829fc1e846
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-8e916c1355943f5a5d48d153bdf82e453c82b6a4c279973b2f7c0c631ffeff12.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n o.name as name,\n orp.retention_days as \"retention_days?\"\n FROM \"Organization\" o\n LEFT JOIN \"OrganizationRetentionPolicy\" orp ON o.id = orp.organization_id\n WHERE o.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "retention_days?",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int4"
+ ]
+ },
+ "nullable": [
+ false,
+ true
+ ]
+ },
+ "hash": "8e916c1355943f5a5d48d153bdf82e453c82b6a4c279973b2f7c0c631ffeff12"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-8ea09698a4333b2b2d97f16423008a172b5a030ede2b8528a103397a6dc4a42e.json b/rust/cloud-storage/chat/.sqlx/query-8ea09698a4333b2b2d97f16423008a172b5a030ede2b8528a103397a6dc4a42e.json
new file mode 100644
index 0000000000..e33956234c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-8ea09698a4333b2b2d97f16423008a172b5a030ede2b8528a103397a6dc4a42e.json
@@ -0,0 +1,35 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"DocumentBom\" (\"documentId\", \"createdAt\", \"updatedAt\")\n VALUES ($1, $2, $2)\n RETURNING id, \"createdAt\"::timestamptz as created_at, \"updatedAt\"::timestamptz as updated_at;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 2,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Timestamp"
+ ]
+ },
+ "nullable": [
+ false,
+ null,
+ null
+ ]
+ },
+ "hash": "8ea09698a4333b2b2d97f16423008a172b5a030ede2b8528a103397a6dc4a42e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-8fc112d6aeef9c2a223351d2b80947769f26aafbebb3a1b0c759f5246fcca507.json b/rust/cloud-storage/chat/.sqlx/query-8fc112d6aeef9c2a223351d2b80947769f26aafbebb3a1b0c759f5246fcca507.json
new file mode 100644
index 0000000000..55b8ca5614
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-8fc112d6aeef9c2a223351d2b80947769f26aafbebb3a1b0c759f5246fcca507.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level::text\n FROM entity_access\n WHERE source_id = ANY(ARRAY(\n SELECT cp.channel_id::text FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ))\n AND entity_id = $2\n AND entity_type = 'chat'\n ORDER BY\n CASE access_level::text\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3\n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END DESC\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "8fc112d6aeef9c2a223351d2b80947769f26aafbebb3a1b0c759f5246fcca507"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-908627bdd27f344ce26c501bb7431b621173c04bfda9678021360817c3f25103.json b/rust/cloud-storage/chat/.sqlx/query-908627bdd27f344ce26c501bb7431b621173c04bfda9678021360817c3f25103.json
new file mode 100644
index 0000000000..d509d3fe6f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-908627bdd27f344ce26c501bb7431b621173c04bfda9678021360817c3f25103.json
@@ -0,0 +1,96 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.id as \"channel_id\",\n c.name as \"name\",\n c.channel_type AS \"channel_type: ChannelType\",\n c.org_id as \"org_id\",\n m.id as \"message_id\",\n m.thread_id as \"thread_id\",\n m.sender_id as \"sender_id\",\n m.content as \"content\",\n m.created_at as \"created_at\",\n m.updated_at as \"updated_at\",\n m.deleted_at::timestamptz as \"deleted_at\"\n FROM\n comms_messages m\n JOIN\n comms_channels c on c.\"id\" = m.\"channel_id\"\n WHERE\n m.id = $1\n AND c.id = $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "channel_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 2,
+ "name": "channel_type: ChannelType",
+ "type_info": {
+ "Custom": {
+ "name": "comms_channel_type",
+ "kind": {
+ "Enum": [
+ "public",
+ "organization",
+ "private",
+ "direct_message",
+ "team"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 3,
+ "name": "org_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 4,
+ "name": "message_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 5,
+ "name": "thread_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 6,
+ "name": "sender_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 7,
+ "name": "content",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 8,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ true,
+ false,
+ true,
+ false,
+ true,
+ false,
+ false,
+ false,
+ false,
+ null
+ ]
+ },
+ "hash": "908627bdd27f344ce26c501bb7431b621173c04bfda9678021360817c3f25103"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-90d75cee091fe17362db20b9d855e6c8e8d204599eb1ee4d576b9a913aca0b41.json b/rust/cloud-storage/chat/.sqlx/query-90d75cee091fe17362db20b9d855e6c8e8d204599eb1ee4d576b9a913aca0b41.json
new file mode 100644
index 0000000000..ebd0d84d18
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-90d75cee091fe17362db20b9d855e6c8e8d204599eb1ee4d576b9a913aca0b41.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Comment\"\n SET \"deletedAt\" = NOW()\n WHERE \"threadId\" = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Int8"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "90d75cee091fe17362db20b9d855e6c8e8d204599eb1ee4d576b9a913aca0b41"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-915c50350c5513c6e1ba12eae31520046ac0e7e882d9c5ec76a3578ae4bc7d50.json b/rust/cloud-storage/chat/.sqlx/query-915c50350c5513c6e1ba12eae31520046ac0e7e882d9c5ec76a3578ae4bc7d50.json
new file mode 100644
index 0000000000..0a2c18aa63
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-915c50350c5513c6e1ba12eae31520046ac0e7e882d9c5ec76a3578ae4bc7d50.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "SELECT \"userId\" as user_id, \"deletedAt\" as deleted_at FROM \"Project\" WHERE id=$1",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "deleted_at",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ true
+ ]
+ },
+ "hash": "915c50350c5513c6e1ba12eae31520046ac0e7e882d9c5ec76a3578ae4bc7d50"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-9173d68221d7b73f7a1e3ec0632ab9ae6a9269c950b45897a5e64c14cd00e117.json b/rust/cloud-storage/chat/.sqlx/query-9173d68221d7b73f7a1e3ec0632ab9ae6a9269c950b45897a5e64c14cd00e117.json
new file mode 100644
index 0000000000..81a258d19e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-9173d68221d7b73f7a1e3ec0632ab9ae6a9269c950b45897a5e64c14cd00e117.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id\n FROM \"OrganizationRetentionPolicy\"\n WHERE organization_id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int4"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "9173d68221d7b73f7a1e3ec0632ab9ae6a9269c950b45897a5e64c14cd00e117"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-91badd3aa8d3cc89c16ae8013b20eb521625862f180e9bc75096de5573436928.json b/rust/cloud-storage/chat/.sqlx/query-91badd3aa8d3cc89c16ae8013b20eb521625862f180e9bc75096de5573436928.json
new file mode 100644
index 0000000000..da286915f0
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-91badd3aa8d3cc89c16ae8013b20eb521625862f180e9bc75096de5573436928.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"DocumentFamily\" (\"rootDocumentId\")\n VALUES ($1)\n RETURNING id;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "91badd3aa8d3cc89c16ae8013b20eb521625862f180e9bc75096de5573436928"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-91e974129e2c983925d29dabf73c8ae86c6f090cbfd28f22cd952756950a94db.json b/rust/cloud-storage/chat/.sqlx/query-91e974129e2c983925d29dabf73c8ae86c6f090cbfd28f22cd952756950a94db.json
new file mode 100644
index 0000000000..806760a2c8
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-91e974129e2c983925d29dabf73c8ae86c6f090cbfd28f22cd952756950a94db.json
@@ -0,0 +1,74 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO comms_messages (id, channel_id, sender_id, content, thread_id)\n VALUES ($1, $2, $3, $4, $5)\n RETURNING\n id,\n channel_id,\n sender_id,\n content,\n created_at,\n updated_at,\n thread_id,\n edited_at as \"edited_at: chrono::DateTime<chrono::Utc>\",\n deleted_at as \"deleted_at: chrono::DateTime<chrono::Utc>\" \n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "channel_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "sender_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "content",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "thread_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 7,
+ "name": "edited_at: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Uuid",
+ "Text",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true,
+ true
+ ]
+ },
+ "hash": "91e974129e2c983925d29dabf73c8ae86c6f090cbfd28f22cd952756950a94db"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-929e8e21a0b181340c4d74adbb26e14ec0c63b5f7da47d260f84eb0cfb15c575.json b/rust/cloud-storage/chat/.sqlx/query-929e8e21a0b181340c4d74adbb26e14ec0c63b5f7da47d260f84eb0cfb15c575.json
new file mode 100644
index 0000000000..352ba12ced
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-929e8e21a0b181340c4d74adbb26e14ec0c63b5f7da47d260f84eb0cfb15c575.json
@@ -0,0 +1,51 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id as document_id,\n d.owner as owner,\n d.\"fileType\" as \"file_type!\",\n COALESCE(db.id, di.id, dipdf.id) as \"document_version_id!\",\n d.\"createdAt\"::timestamptz as \"created_at\"\n FROM\n \"Document\" d\n LEFT JOIN document_sub_type dst ON dst.document_id = d.id\n LEFT JOIN LATERAL (\n SELECT\n b.id\n FROM\n \"DocumentBom\" b\n WHERE\n b.\"documentId\" = d.id\n ORDER BY\n b.\"createdAt\" DESC\n LIMIT 1\n ) db ON d.\"fileType\" = 'docx'\n LEFT JOIN LATERAL (\n SELECT\n i.id\n FROM\n \"DocumentInstance\" i\n WHERE\n i.\"documentId\" = d.id\n ORDER BY\n i.\"updatedAt\" ASC\n LIMIT 1\n ) dipdf ON d.\"fileType\" = 'pdf'\n LEFT JOIN LATERAL (\n SELECT\n i.id\n FROM\n \"DocumentInstance\" i\n WHERE\n i.\"documentId\" = d.id\n ORDER BY\n i.\"createdAt\" DESC\n LIMIT 1\n ) di ON d.\"fileType\" IS DISTINCT FROM 'docx' AND d.\"fileType\" IS DISTINCT FROM 'pdf'\n WHERE\n d.\"deletedAt\" IS NULL\n AND d.\"fileType\" IS NOT NULL\n AND ($3::text[] IS NULL OR d.\"fileType\" = ANY($3))\n AND ($4::text IS NULL OR dst.sub_type::text = $4)\n AND ($5::timestamptz IS NULL OR d.\"createdAt\" >= $5)\n AND ($6::timestamptz IS NULL OR d.\"createdAt\" < $6)\n ORDER BY d.\"createdAt\" ASC, d.id ASC\n LIMIT $1 OFFSET $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "file_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "document_version_id!",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Int8",
+ "TextArray",
+ "Text",
+ "Timestamptz",
+ "Timestamptz"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ true,
+ null,
+ null
+ ]
+ },
+ "hash": "929e8e21a0b181340c4d74adbb26e14ec0c63b5f7da47d260f84eb0cfb15c575"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-92edc80110af7b96f7f908989461a4abb11652671a95454969369a0484ed9239.json b/rust/cloud-storage/chat/.sqlx/query-92edc80110af7b96f7f908989461a4abb11652671a95454969369a0484ed9239.json
new file mode 100644
index 0000000000..a8520fdfd0
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-92edc80110af7b96f7f908989461a4abb11652671a95454969369a0484ed9239.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO notification_message_receipt (message_id, user_id, notification_id)\n VALUES ($1, $2, $3)\n ON CONFLICT (message_id) DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "92edc80110af7b96f7f908989461a4abb11652671a95454969369a0484ed9239"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-935031443597f0e3057ef41537c2baa9efd886c9ed75aabbf05e9cc43636d319.json b/rust/cloud-storage/chat/.sqlx/query-935031443597f0e3057ef41537c2baa9efd886c9ed75aabbf05e9cc43636d319.json
new file mode 100644
index 0000000000..10a2e0a032
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-935031443597f0e3057ef41537c2baa9efd886c9ed75aabbf05e9cc43636d319.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"SharePermission\" sp\n USING \"ChatPermission\" cp \n WHERE cp.\"sharePermissionId\" = sp.id\n AND cp.\"chatId\" = ANY($1)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "935031443597f0e3057ef41537c2baa9efd886c9ed75aabbf05e9cc43636d319"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-93edad49b012cc8119b969091ba78ee6d16600fb11697445001c661e49bf48f4.json b/rust/cloud-storage/chat/.sqlx/query-93edad49b012cc8119b969091ba78ee6d16600fb11697445001c661e49bf48f4.json
new file mode 100644
index 0000000000..949ae7ef8b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-93edad49b012cc8119b969091ba78ee6d16600fb11697445001c661e49bf48f4.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"ProjectPermission\" (\"projectId\", \"sharePermissionId\")\n VALUES ($1, $2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "93edad49b012cc8119b969091ba78ee6d16600fb11697445001c661e49bf48f4"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-94c019227741f6c4fe8411454cb7c0a3a97e5594c29f11fa893238656e161ff1.json b/rust/cloud-storage/chat/.sqlx/query-94c019227741f6c4fe8411454cb7c0a3a97e5594c29f11fa893238656e161ff1.json
new file mode 100644
index 0000000000..4035617965
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-94c019227741f6c4fe8411454cb7c0a3a97e5594c29f11fa893238656e161ff1.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET deleted_at = NOW()\n WHERE user_id = $1 AND notification_id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "94c019227741f6c4fe8411454cb7c0a3a97e5594c29f11fa893238656e161ff1"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-95a8a0117d0bbc25adf4dc08cf0cec40eaa0faddb4490ad14ae9cc6c4d922256.json b/rust/cloud-storage/chat/.sqlx/query-95a8a0117d0bbc25adf4dc08cf0cec40eaa0faddb4490ad14ae9cc6c4d922256.json
new file mode 100644
index 0000000000..8db9a4bf0c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-95a8a0117d0bbc25adf4dc08cf0cec40eaa0faddb4490ad14ae9cc6c4d922256.json
@@ -0,0 +1,40 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"Experiment\" (id)\n VALUES ($1)\n RETURNING id, active, \"started_at\"::timestamptz as started_at, \"ended_at\"::timestamptz as ended_at\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "active",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 2,
+ "name": "started_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 3,
+ "name": "ended_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ null,
+ null
+ ]
+ },
+ "hash": "95a8a0117d0bbc25adf4dc08cf0cec40eaa0faddb4490ad14ae9cc6c4d922256"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-95dda7d94d399b451c4ba4a78ed6809895c255a103ca296451cbfe6c99833e8f.json b/rust/cloud-storage/chat/.sqlx/query-95dda7d94d399b451c4ba4a78ed6809895c255a103ca296451cbfe6c99833e8f.json
new file mode 100644
index 0000000000..e4c1284d23
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-95dda7d94d399b451c4ba4a78ed6809895c255a103ca296451cbfe6c99833e8f.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"document_email\" (document_id, email_attachment_id)\n VALUES ($1, $2) \n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "95dda7d94d399b451c4ba4a78ed6809895c255a103ca296451cbfe6c99833e8f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-95de69ef467e5821f5d4f5b632a04a344fa87a00986709ff1b6e04a222ce0795.json b/rust/cloud-storage/chat/.sqlx/query-95de69ef467e5821f5d4f5b632a04a344fa87a00986709ff1b6e04a222ce0795.json
new file mode 100644
index 0000000000..061871fdc7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-95de69ef467e5821f5d4f5b632a04a344fa87a00986709ff1b6e04a222ce0795.json
@@ -0,0 +1,69 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id,\n email,\n team_id,\n team_role as \"team_role!: TeamRole\",\n invited_by,\n created_at as \"created_at!: chrono::DateTime<chrono::Utc>\",\n last_sent_at as \"last_sent_at!: chrono::DateTime<chrono::Utc>\"\n FROM team_invite\n WHERE email = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "email",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "team_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 3,
+ "name": "team_role!: TeamRole",
+ "type_info": {
+ "Custom": {
+ "name": "team_role",
+ "kind": {
+ "Enum": [
+ "member",
+ "admin",
+ "owner"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 4,
+ "name": "invited_by",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "created_at!: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 6,
+ "name": "last_sent_at!: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "95de69ef467e5821f5d4f5b632a04a344fa87a00986709ff1b6e04a222ce0795"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-9676374e780121fbb6724ac51d9c742deb835c1e2c5a23390501ef95bc0f12cd.json b/rust/cloud-storage/chat/.sqlx/query-9676374e780121fbb6724ac51d9c742deb835c1e2c5a23390501ef95bc0f12cd.json
new file mode 100644
index 0000000000..678dc0399c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-9676374e780121fbb6724ac51d9c742deb835c1e2c5a23390501ef95bc0f12cd.json
@@ -0,0 +1,118 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n ph.uuid, \n ph.\"documentId\" as document_id,\n ph.owner, \n ph.\"threadId\" as thread_id, \n ph.page, \n ph.red,\n ph.green, \n ph.blue, \n ph.alpha, \n ph.type as highlight_type, \n ph.text, \n ph.\"pageViewportWidth\" as page_viewport_width, \n ph.\"pageViewportHeight\" as page_viewport_height, \n ph.\"createdAt\"::timestamptz as created_at, \n ph.\"updatedAt\"::timestamptz as updated_at, \n ph.\"deletedAt\"::timestamptz as deleted_at, \n array_agg((phr.id, phr.top, phr.left, phr.width, phr.height)) as \"highlight_rects!: Vec<PdfHighlightRect>\"\n FROM \"PdfHighlightAnchor\" ph\n JOIN \"PdfHighlightRect\" phr ON ph.uuid = phr.\"pdfHighlightAnchorId\"\n WHERE ph.uuid = $1\n GROUP BY ph.uuid, ph.owner, ph.\"threadId\", ph.page, ph.red, ph.green, ph.blue, ph.alpha, ph.type, ph.text, ph.\"pageViewportWidth\", ph.\"pageViewportHeight\", ph.\"createdAt\", ph.\"updatedAt\", ph.\"deletedAt\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 4,
+ "name": "page",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 5,
+ "name": "red",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 6,
+ "name": "green",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 7,
+ "name": "blue",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 8,
+ "name": "alpha",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 9,
+ "name": "highlight_type",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 10,
+ "name": "text",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 11,
+ "name": "page_viewport_width",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 12,
+ "name": "page_viewport_height",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 13,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 14,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 15,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 16,
+ "name": "highlight_rects!: Vec<PdfHighlightRect>",
+ "type_info": "RecordArray"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "9676374e780121fbb6724ac51d9c742deb835c1e2c5a23390501ef95bc0f12cd"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-96813c302ddd0c88c30ca845c668dcc47089bf02ae5dbf0f15eb0be64395d09f.json b/rust/cloud-storage/chat/.sqlx/query-96813c302ddd0c88c30ca845c668dcc47089bf02ae5dbf0f15eb0be64395d09f.json
new file mode 100644
index 0000000000..10a698064c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-96813c302ddd0c88c30ca845c668dcc47089bf02ae5dbf0f15eb0be64395d09f.json
@@ -0,0 +1,36 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"PdfHighlightAnchor\" (\n \"uuid\", \"documentId\", \"owner\", \"page\", \"red\", \"green\", \"blue\", \"alpha\", \n \"type\", \"text\", \"pageViewportWidth\", \"pageViewportHeight\", \n \"threadId\", \"createdAt\", \"updatedAt\"\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)\n RETURNING uuid\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "uuid",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text",
+ "Int4",
+ "Int4",
+ "Int4",
+ "Int4",
+ "Float8",
+ "Int4",
+ "Text",
+ "Float8",
+ "Float8",
+ "Int8",
+ "Timestamp",
+ "Timestamp"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "96813c302ddd0c88c30ca845c668dcc47089bf02ae5dbf0f15eb0be64395d09f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-96b75da06aef543dc7d626c98501bd176b609bdab2f96a13e2d035510a72eebb.json b/rust/cloud-storage/chat/.sqlx/query-96b75da06aef543dc7d626c98501bd176b609bdab2f96a13e2d035510a72eebb.json
new file mode 100644
index 0000000000..c170856c4b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-96b75da06aef543dc7d626c98501bd176b609bdab2f96a13e2d035510a72eebb.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"Comment\" (\"threadId\", \"owner\", \"sender\", \"text\", \"createdAt\", \"updatedAt\", \"order\")\n VALUES ($1, $2, $3, $4, $5, $6, $7)\n RETURNING id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Text",
+ "Text",
+ "Text",
+ "Timestamp",
+ "Timestamp",
+ "Int4"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "96b75da06aef543dc7d626c98501bd176b609bdab2f96a13e2d035510a72eebb"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-980f95d4b95f6a981b86bdbdda30b4b5ee7ee34505f206d0a6861cec41ef589a.json b/rust/cloud-storage/chat/.sqlx/query-980f95d4b95f6a981b86bdbdda30b4b5ee7ee34505f206d0a6861cec41ef589a.json
new file mode 100644
index 0000000000..4145c5fb82
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-980f95d4b95f6a981b86bdbdda30b4b5ee7ee34505f206d0a6861cec41ef589a.json
@@ -0,0 +1,58 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n p.id,\n p.name,\n p.\"userId\" as user_id,\n p.\"parentId\" as parent_id,\n p.\"createdAt\"::timestamptz as created_at,\n p.\"updatedAt\"::timestamptz as updated_at,\n p.\"uploadRequestId\" as upload_request_id\n FROM \"Project\" p\n WHERE p.\"userId\" = $1 AND p.\"deletedAt\" IS NULL AND p.\"uploadPending\" = true AND p.\"parentId\" IS NULL\n ORDER BY p.\"updatedAt\" DESC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "parent_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "upload_request_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ null,
+ null,
+ true
+ ]
+ },
+ "hash": "980f95d4b95f6a981b86bdbdda30b4b5ee7ee34505f206d0a6861cec41ef589a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-989e8adb9e267d1400ad5cb3e0e4b3d4a434de5c66f3cbcadedc4c6f20769ade.json b/rust/cloud-storage/chat/.sqlx/query-989e8adb9e267d1400ad5cb3e0e4b3d4a434de5c66f3cbcadedc4c6f20769ade.json
new file mode 100644
index 0000000000..bad2cb0d0e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-989e8adb9e267d1400ad5cb3e0e4b3d4a434de5c66f3cbcadedc4c6f20769ade.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"SharePermission\" WHERE id = $1",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "989e8adb9e267d1400ad5cb3e0e4b3d4a434de5c66f3cbcadedc4c6f20769ade"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-98b0bd8f950443e4240f137adebdf2219b052d3bcbd4a3e79a5f80e81a61522e.json b/rust/cloud-storage/chat/.sqlx/query-98b0bd8f950443e4240f137adebdf2219b052d3bcbd4a3e79a5f80e81a61522e.json
new file mode 100644
index 0000000000..94d5f34dbe
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-98b0bd8f950443e4240f137adebdf2219b052d3bcbd4a3e79a5f80e81a61522e.json
@@ -0,0 +1,71 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE comms_messages\n SET content = $1, updated_at = NOW(), edited_at = NOW()\n WHERE id = $2\n RETURNING\n id,\n channel_id,\n sender_id,\n content,\n created_at,\n updated_at,\n thread_id,\n edited_at as \"edited_at: chrono::DateTime<chrono::Utc>\",\n deleted_at as \"deleted_at: chrono::DateTime<chrono::Utc>\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "channel_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "sender_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "content",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "thread_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 7,
+ "name": "edited_at: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true,
+ true
+ ]
+ },
+ "hash": "98b0bd8f950443e4240f137adebdf2219b052d3bcbd4a3e79a5f80e81a61522e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-9947668e4041d1e3297dce4942ca41a916397efdb2620e338a211f97751c0d89.json b/rust/cloud-storage/chat/.sqlx/query-9947668e4041d1e3297dce4942ca41a916397efdb2620e338a211f97751c0d89.json
new file mode 100644
index 0000000000..a215c3bde7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-9947668e4041d1e3297dce4942ca41a916397efdb2620e338a211f97751c0d89.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id\n FROM \"User\"\n WHERE \"macro_user_id\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "9947668e4041d1e3297dce4942ca41a916397efdb2620e338a211f97751c0d89"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-99c26d3fcc7cc1494cd3f8387e4f9fd70cd817602df9ad6d355b26e13b47553a.json b/rust/cloud-storage/chat/.sqlx/query-99c26d3fcc7cc1494cd3f8387e4f9fd70cd817602df9ad6d355b26e13b47553a.json
new file mode 100644
index 0000000000..2b17a5a941
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-99c26d3fcc7cc1494cd3f8387e4f9fd70cd817602df9ad6d355b26e13b47553a.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"User\"\n SET \"group\" = $1\n WHERE id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Varchar",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "99c26d3fcc7cc1494cd3f8387e4f9fd70cd817602df9ad6d355b26e13b47553a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-99f5d2da898d5e7f29f1966c51370af1692f03a0df09f0ee78a589158e8f51ee.json b/rust/cloud-storage/chat/.sqlx/query-99f5d2da898d5e7f29f1966c51370af1692f03a0df09f0ee78a589158e8f51ee.json
new file mode 100644
index 0000000000..6ce1b7af93
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-99f5d2da898d5e7f29f1966c51370af1692f03a0df09f0ee78a589158e8f51ee.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "DELETE FROM \"InstructionsDocuments\" WHERE \"userId\" = $1",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "99f5d2da898d5e7f29f1966c51370af1692f03a0df09f0ee78a589158e8f51ee"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-9a85a116815c36f9cbde5a097e39e0547ed654489c726b44faf23524f148ec86.json b/rust/cloud-storage/chat/.sqlx/query-9a85a116815c36f9cbde5a097e39e0547ed654489c726b44faf23524f148ec86.json
new file mode 100644
index 0000000000..85472bb383
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-9a85a116815c36f9cbde5a097e39e0547ed654489c726b44faf23524f148ec86.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT reference, \"documentId\"\n FROM \"DocumentTextParts\"\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "reference",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "documentId",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "9a85a116815c36f9cbde5a097e39e0547ed654489c726b44faf23524f148ec86"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-9b83758d2e1a6855b03ceee2f0bebf87a5152702bb5b9ffb2b817ad93c0635ea.json b/rust/cloud-storage/chat/.sqlx/query-9b83758d2e1a6855b03ceee2f0bebf87a5152702bb5b9ffb2b817ad93c0635ea.json
new file mode 100644
index 0000000000..afc75443c3
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-9b83758d2e1a6855b03ceee2f0bebf87a5152702bb5b9ffb2b817ad93c0635ea.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"DocumentInstanceModificationData\" (\"documentInstanceId\", \"modificationData\")\n VALUES ($1, $2);\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Jsonb"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "9b83758d2e1a6855b03ceee2f0bebf87a5152702bb5b9ffb2b817ad93c0635ea"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-9bb89d78cff9b84ca91fa891dd3e61c04906fa841a9d21c29127d03797e98186.json b/rust/cloud-storage/chat/.sqlx/query-9bb89d78cff9b84ca91fa891dd3e61c04906fa841a9d21c29127d03797e98186.json
new file mode 100644
index 0000000000..50d679e8f6
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-9bb89d78cff9b84ca91fa891dd3e61c04906fa841a9d21c29127d03797e98186.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "UPDATE \"Document\" SET \"projectId\"=$2 WHERE \"id\"=$1",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "9bb89d78cff9b84ca91fa891dd3e61c04906fa841a9d21c29127d03797e98186"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-9c81b4664d019cc6242259ff81d5abe2ad4c2f28d0f4cea773ef7b4267eb0e81.json b/rust/cloud-storage/chat/.sqlx/query-9c81b4664d019cc6242259ff81d5abe2ad4c2f28d0f4cea773ef7b4267eb0e81.json
new file mode 100644
index 0000000000..4519ec280c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-9c81b4664d019cc6242259ff81d5abe2ad4c2f28d0f4cea773ef7b4267eb0e81.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE macro_user\n SET has_trialed = $2\n WHERE email = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Bool"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "9c81b4664d019cc6242259ff81d5abe2ad4c2f28d0f4cea773ef7b4267eb0e81"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-9cbb599d24ea1f22756926601cb3dc157a2a327ce9aea06a1a772c1741abcf9a.json b/rust/cloud-storage/chat/.sqlx/query-9cbb599d24ea1f22756926601cb3dc157a2a327ce9aea06a1a772c1741abcf9a.json
new file mode 100644
index 0000000000..2fd40ad53a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-9cbb599d24ea1f22756926601cb3dc157a2a327ce9aea06a1a772c1741abcf9a.json
@@ -0,0 +1,36 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n u.id as user_id,\n u.email as user_email,\n array_agg(DISTINCT rop.\"permissionId\") AS permissions\n FROM \"User\" u\n LEFT JOIN \"RolesOnUsers\" rou ON rou.\"userId\" = u.id\n LEFT JOIN \"Role\" r ON r.id = rou.\"roleId\"\n LEFT JOIN \"RolesOnPermissions\" rop ON rop.\"roleId\" = r.id\n WHERE u.\"organizationId\" = $1\n GROUP BY u.id\n LIMIT $2\n OFFSET $3\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "user_email",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "permissions",
+ "type_info": "TextArray"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int4",
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ null
+ ]
+ },
+ "hash": "9cbb599d24ea1f22756926601cb3dc157a2a327ce9aea06a1a772c1741abcf9a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-9d8ebf3f5901badeacb46837f0a2222f49274e9e72dbd25cf9c197b4f97654a5.json b/rust/cloud-storage/chat/.sqlx/query-9d8ebf3f5901badeacb46837f0a2222f49274e9e72dbd25cf9c197b4f97654a5.json
new file mode 100644
index 0000000000..05f7b62da7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-9d8ebf3f5901badeacb46837f0a2222f49274e9e72dbd25cf9c197b4f97654a5.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id, owner FROM \"Document\" WHERE \"projectId\" = ANY($1) AND \"deletedAt\" IS NOT NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "9d8ebf3f5901badeacb46837f0a2222f49274e9e72dbd25cf9c197b4f97654a5"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-9e0a5d81fc7d5897a95ede42af6d3495c14fbf4095333a1f5632f836b365065f.json b/rust/cloud-storage/chat/.sqlx/query-9e0a5d81fc7d5897a95ede42af6d3495c14fbf4095333a1f5632f836b365065f.json
new file mode 100644
index 0000000000..0ddd9840fc
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-9e0a5d81fc7d5897a95ede42af6d3495c14fbf4095333a1f5632f836b365065f.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.id\n FROM\n \"Chat\" c\n WHERE\n c.id = ANY($1)\n AND c.\"userId\" = ANY($2)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "9e0a5d81fc7d5897a95ede42af6d3495c14fbf4095333a1f5632f836b365065f"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-9e506dc5e6ce5381990d8258bfda1102377246f0a58ab49801b7fa12ab400560.json b/rust/cloud-storage/chat/.sqlx/query-9e506dc5e6ce5381990d8258bfda1102377246f0a58ab49801b7fa12ab400560.json
similarity index 100%
rename from rust/cloud-storage/macro_db_client/.sqlx/query-9e506dc5e6ce5381990d8258bfda1102377246f0a58ab49801b7fa12ab400560.json
rename to rust/cloud-storage/chat/.sqlx/query-9e506dc5e6ce5381990d8258bfda1102377246f0a58ab49801b7fa12ab400560.json
diff --git a/rust/cloud-storage/chat/.sqlx/query-9f595d4ae9aa9111c316efa5d4be2b8e4a6cc69374b90600457a32b14a91ae61.json b/rust/cloud-storage/chat/.sqlx/query-9f595d4ae9aa9111c316efa5d4be2b8e4a6cc69374b90600457a32b14a91ae61.json
new file mode 100644
index 0000000000..2620ca0739
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-9f595d4ae9aa9111c316efa5d4be2b8e4a6cc69374b90600457a32b14a91ae61.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT p.id\n FROM \"Project\" p\n WHERE p.\"deletedAt\" IS NOT NULL AND p.\"deletedAt\" <= $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Timestamp"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "9f595d4ae9aa9111c316efa5d4be2b8e4a6cc69374b90600457a32b14a91ae61"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a0046a263c572915a8e14a8ac70479f1ba89549f1930f571bf278fcfe259cfd1.json b/rust/cloud-storage/chat/.sqlx/query-a0046a263c572915a8e14a8ac70479f1ba89549f1930f571bf278fcfe259cfd1.json
new file mode 100644
index 0000000000..ad14cfedba
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a0046a263c572915a8e14a8ac70479f1ba89549f1930f571bf278fcfe259cfd1.json
@@ -0,0 +1,44 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id, device_endpoint, device_type as \"device_type: DbDeviceType\"\n FROM notification_user_device_registration\n WHERE user_id = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "device_endpoint",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "device_type: DbDeviceType",
+ "type_info": {
+ "Custom": {
+ "name": "notification_device_type_option",
+ "kind": {
+ "Enum": [
+ "ios",
+ "android"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "a0046a263c572915a8e14a8ac70479f1ba89549f1930f571bf278fcfe259cfd1"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-a050d4452afd8a03be00d98fb2d74d089cc1f02baf1933477ce87b69558082d4.json b/rust/cloud-storage/chat/.sqlx/query-a050d4452afd8a03be00d98fb2d74d089cc1f02baf1933477ce87b69558082d4.json
similarity index 100%
rename from rust/cloud-storage/macro_db_client/.sqlx/query-a050d4452afd8a03be00d98fb2d74d089cc1f02baf1933477ce87b69558082d4.json
rename to rust/cloud-storage/chat/.sqlx/query-a050d4452afd8a03be00d98fb2d74d089cc1f02baf1933477ce87b69558082d4.json
diff --git a/rust/cloud-storage/chat/.sqlx/query-a0e0e46ab257c9dd4285a6494f7b9fcc32c2a19dd97678335c04dab4739024d4.json b/rust/cloud-storage/chat/.sqlx/query-a0e0e46ab257c9dd4285a6494f7b9fcc32c2a19dd97678335c04dab4739024d4.json
new file mode 100644
index 0000000000..bdff179616
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a0e0e46ab257c9dd4285a6494f7b9fcc32c2a19dd97678335c04dab4739024d4.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Document\" SET \"projectId\" = NULL WHERE \"id\" = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "a0e0e46ab257c9dd4285a6494f7b9fcc32c2a19dd97678335c04dab4739024d4"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a13fae598b8b785a7f516d7d4fdf91510017a27cd442f5693c5777ddc64d1c9b.json b/rust/cloud-storage/chat/.sqlx/query-a13fae598b8b785a7f516d7d4fdf91510017a27cd442f5693c5777ddc64d1c9b.json
new file mode 100644
index 0000000000..11964cca0f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a13fae598b8b785a7f516d7d4fdf91510017a27cd442f5693c5777ddc64d1c9b.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT DISTINCT\n d.\"documentId\",\n LENGTH(REGEXP_REPLACE(d.\"content\", '\\s', '', 'g')) AS content_length\n FROM\n \"DocumentText\" d\n WHERE\n d.\"documentId\" = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "documentId",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "content_length",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ null
+ ]
+ },
+ "hash": "a13fae598b8b785a7f516d7d4fdf91510017a27cd442f5693c5777ddc64d1c9b"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a1bf47e0cd99428ebbd99069e9ed4fdcdb3aaeb946ea3e5ca94dc58050ca7d97.json b/rust/cloud-storage/chat/.sqlx/query-a1bf47e0cd99428ebbd99069e9ed4fdcdb3aaeb946ea3e5ca94dc58050ca7d97.json
new file mode 100644
index 0000000000..a20997623f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a1bf47e0cd99428ebbd99069e9ed4fdcdb3aaeb946ea3e5ca94dc58050ca7d97.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Project\" SET \"deletedAt\" = $2 WHERE id = ANY($1);\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "Timestamp"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "a1bf47e0cd99428ebbd99069e9ed4fdcdb3aaeb946ea3e5ca94dc58050ca7d97"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a2079ac110ef2d83a92a7c759540c373e29c8ff79ed52417fdeeb4de8fe00782.json b/rust/cloud-storage/chat/.sqlx/query-a2079ac110ef2d83a92a7c759540c373e29c8ff79ed52417fdeeb4de8fe00782.json
new file mode 100644
index 0000000000..1699281ff6
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a2079ac110ef2d83a92a7c759540c373e29c8ff79ed52417fdeeb4de8fe00782.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"ChannelSharePermission\" (\"share_permission_id\", \"channel_id\", \"access_level\")\n SELECT $1, channel_id, access_level::\"AccessLevel\"\n FROM UNNEST($2::text[], $3::text[]) AS t(channel_id, access_level)\n ON CONFLICT (\"share_permission_id\", \"channel_id\") \n DO UPDATE SET \"access_level\" = EXCLUDED.\"access_level\"\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "a2079ac110ef2d83a92a7c759540c373e29c8ff79ed52417fdeeb4de8fe00782"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a277974b231f69f2a2912fb1634affdf67114b90d5d398d16dec2f801aabdda8.json b/rust/cloud-storage/chat/.sqlx/query-a277974b231f69f2a2912fb1634affdf67114b90d5d398d16dec2f801aabdda8.json
new file mode 100644
index 0000000000..b504b24713
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a277974b231f69f2a2912fb1634affdf67114b90d5d398d16dec2f801aabdda8.json
@@ -0,0 +1,59 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n a.id as \"id!: Uuid\",\n a.user_id as \"user_id!: String\",\n a.channel_id as \"channel_id!: Uuid\",\n a.viewed_at as \"viewed_at?: DateTime<Utc>\",\n a.interacted_at as \"interacted_at?: DateTime<Utc>\",\n a.created_at as \"created_at!: DateTime<Utc>\",\n a.updated_at as \"updated_at!: DateTime<Utc>\"\n FROM comms_activity a\n WHERE channel_id = $1 AND user_id = $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!: Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "user_id!: String",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "channel_id!: Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 3,
+ "name": "viewed_at?: DateTime<Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 4,
+ "name": "interacted_at?: DateTime<Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 5,
+ "name": "created_at!: DateTime<Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 6,
+ "name": "updated_at!: DateTime<Utc>",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ true,
+ false,
+ false
+ ]
+ },
+ "hash": "a277974b231f69f2a2912fb1634affdf67114b90d5d398d16dec2f801aabdda8"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a27ad96e62764cad74a23addabe461a1b8aa81a865bf1af5434d5469efa44f76.json b/rust/cloud-storage/chat/.sqlx/query-a27ad96e62764cad74a23addabe461a1b8aa81a865bf1af5434d5469efa44f76.json
new file mode 100644
index 0000000000..d46f0a6f31
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a27ad96e62764cad74a23addabe461a1b8aa81a865bf1af5434d5469efa44f76.json
@@ -0,0 +1,37 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"PdfPlaceableCommentAnchor\" (\"uuid\", \"documentId\", \"owner\", \"page\", \"originalPage\", \"originalIndex\", \"shouldLockOnSave\", \"xPct\", \"yPct\", \"widthPct\", \"heightPct\", \"rotation\", \"threadId\", \"wasEdited\", \"wasDeleted\", \"allowableEdits\")\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)\n RETURNING uuid\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "uuid",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text",
+ "Int4",
+ "Int4",
+ "Int4",
+ "Bool",
+ "Float8",
+ "Float8",
+ "Float8",
+ "Float8",
+ "Float8",
+ "Int8",
+ "Bool",
+ "Bool",
+ "Jsonb"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "a27ad96e62764cad74a23addabe461a1b8aa81a865bf1af5434d5469efa44f76"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a299a66e2c0a88c6d2d9a131611789a544d3b7e5710bbc19254fdff129624b87.json b/rust/cloud-storage/chat/.sqlx/query-a299a66e2c0a88c6d2d9a131611789a544d3b7e5710bbc19254fdff129624b87.json
new file mode 100644
index 0000000000..fe2c31babd
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a299a66e2c0a88c6d2d9a131611789a544d3b7e5710bbc19254fdff129624b87.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id,\n macro_user_id\n FROM\n in_progress_user_link\n WHERE\n id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "macro_user_id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "a299a66e2c0a88c6d2d9a131611789a544d3b7e5710bbc19254fdff129624b87"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a2de5ccd5cea15012e02e998ca560e279b04606f2d9520d2b3316b23e1948e66.json b/rust/cloud-storage/chat/.sqlx/query-a2de5ccd5cea15012e02e998ca560e279b04606f2d9520d2b3316b23e1948e66.json
new file mode 100644
index 0000000000..35c6872f1a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a2de5ccd5cea15012e02e998ca560e279b04606f2d9520d2b3316b23e1948e66.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM entity_access\n WHERE source_id = ANY($1) AND entity_id = $2 AND entity_type = $3 AND source_type = 'user'\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "a2de5ccd5cea15012e02e998ca560e279b04606f2d9520d2b3316b23e1948e66"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a39eae1006cfea2c75cd5535ca05790dc40b7534736632062d8167c7f450a830.json b/rust/cloud-storage/chat/.sqlx/query-a39eae1006cfea2c75cd5535ca05790dc40b7534736632062d8167c7f450a830.json
new file mode 100644
index 0000000000..1c414e492b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a39eae1006cfea2c75cd5535ca05790dc40b7534736632062d8167c7f450a830.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id\n FROM comms_channels\n WHERE channel_type = 'direct_message'\n AND EXISTS (\n SELECT 1\n FROM comms_channel_participants cp\n WHERE cp.channel_id = comms_channels.id\n AND cp.user_id = $1\n )\n AND EXISTS (\n SELECT 1\n FROM comms_channel_participants cp\n WHERE cp.channel_id = comms_channels.id\n AND cp.user_id = $2\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "a39eae1006cfea2c75cd5535ca05790dc40b7534736632062d8167c7f450a830"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a4e8e05298b394cc80ac1f866854a945a8d67e1d18153d4f0128108ce65212f4.json b/rust/cloud-storage/chat/.sqlx/query-a4e8e05298b394cc80ac1f866854a945a8d67e1d18153d4f0128108ce65212f4.json
new file mode 100644
index 0000000000..bec5852ddc
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a4e8e05298b394cc80ac1f866854a945a8d67e1d18153d4f0128108ce65212f4.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"ExperimentLog\" (experiment_id, user_id, \"group\")\n VALUES ($1, $2, $3)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Varchar"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "a4e8e05298b394cc80ac1f866854a945a8d67e1d18153d4f0128108ce65212f4"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a50dbd446eb87217f71d275788a2c2f7ad1583ff17bc8b32145d6863070aa63a.json b/rust/cloud-storage/chat/.sqlx/query-a50dbd446eb87217f71d275788a2c2f7ad1583ff17bc8b32145d6863070aa63a.json
new file mode 100644
index 0000000000..ce74fe57d6
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a50dbd446eb87217f71d275788a2c2f7ad1583ff17bc8b32145d6863070aa63a.json
@@ -0,0 +1,71 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id,\n channel_id,\n sender_id,\n content,\n created_at,\n updated_at,\n thread_id,\n edited_at as \"edited_at: chrono::DateTime<chrono::Utc>\",\n deleted_at as \"deleted_at: chrono::DateTime<chrono::Utc>\"\n FROM comms_messages\n WHERE channel_id = (SELECT channel_id FROM comms_messages WHERE id=$1)\n AND\n created_at < (SELECT created_at FROM comms_messages WHERE id=$1)\n ORDER BY created_at DESC\n LIMIT $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "channel_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "sender_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "content",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "thread_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 7,
+ "name": "edited_at: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true,
+ true
+ ]
+ },
+ "hash": "a50dbd446eb87217f71d275788a2c2f7ad1583ff17bc8b32145d6863070aa63a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a5801ca350ee73d531d912e4dcc1935265af572afbbf60702a4521e4c19b8468.json b/rust/cloud-storage/chat/.sqlx/query-a5801ca350ee73d531d912e4dcc1935265af572afbbf60702a4521e4c19b8468.json
new file mode 100644
index 0000000000..a01572c827
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a5801ca350ee73d531d912e4dcc1935265af572afbbf60702a4521e4c19b8468.json
@@ -0,0 +1,46 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n sp.id as id,\n sp.\"isPublic\" as is_public,\n sp.\"publicAccessLevel\" as \"public_access_level?\",\n m.\"user_id\" as owner,\n COALESCE(\n json_agg(json_build_object(\n 'channel_id', csp.\"channel_id\",\n 'access_level', csp.\"access_level\"\n )) FILTER (WHERE csp.\"channel_id\" IS NOT NULL),\n '[]'\n ) as \"channel_share_permissions?\"\n FROM\n \"MacroPromptPermission\" mpp\n JOIN \"SharePermission\" sp ON mpp.\"share_permission_id\" = sp.id\n JOIN \"MacroPrompt\" m ON mpp.\"macro_prompt_id\" = m.id\n LEFT JOIN \"ChannelSharePermission\" csp ON csp.\"share_permission_id\" = sp.id\n WHERE\n mpp.\"macro_prompt_id\" = $1\n GROUP BY\n sp.id, m.\"user_id\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "is_public",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 2,
+ "name": "public_access_level?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "channel_share_permissions?",
+ "type_info": "Json"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ true,
+ false,
+ null
+ ]
+ },
+ "hash": "a5801ca350ee73d531d912e4dcc1935265af572afbbf60702a4521e4c19b8468"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a5cc2431d45e9bbd7e6c60a2bfb7a6533d6f7c8d051ca997a7e0db53314d5f80.json b/rust/cloud-storage/chat/.sqlx/query-a5cc2431d45e9bbd7e6c60a2bfb7a6533d6f7c8d051ca997a7e0db53314d5f80.json
new file mode 100644
index 0000000000..8e933bf7c0
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a5cc2431d45e9bbd7e6c60a2bfb7a6533d6f7c8d051ca997a7e0db53314d5f80.json
@@ -0,0 +1,27 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO comms_channel_participants (channel_id, user_id, role)\n VALUES ($1, $2, $3)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ {
+ "Custom": {
+ "name": "comms_participant_role",
+ "kind": {
+ "Enum": [
+ "owner",
+ "admin",
+ "member"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "a5cc2431d45e9bbd7e6c60a2bfb7a6533d6f7c8d051ca997a7e0db53314d5f80"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a5d9f358b5382c0eaed918f903bc6aa328f527e6e47d649c37dfcf1c9f3a7139.json b/rust/cloud-storage/chat/.sqlx/query-a5d9f358b5382c0eaed918f903bc6aa328f527e6e47d649c37dfcf1c9f3a7139.json
new file mode 100644
index 0000000000..7626c0a06b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a5d9f358b5382c0eaed918f903bc6aa328f527e6e47d649c37dfcf1c9f3a7139.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET seen_at = NOW()\n WHERE user_id = $1 AND notification_id = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "a5d9f358b5382c0eaed918f903bc6aa328f527e6e47d649c37dfcf1c9f3a7139"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a63428b959703fdc38fa28667db9b2268827d7ce92ca55d21b38ba2a7a8b3c1c.json b/rust/cloud-storage/chat/.sqlx/query-a63428b959703fdc38fa28667db9b2268827d7ce92ca55d21b38ba2a7a8b3c1c.json
new file mode 100644
index 0000000000..53ea78a4fc
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a63428b959703fdc38fa28667db9b2268827d7ce92ca55d21b38ba2a7a8b3c1c.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"Experiment\" WHERE id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "a63428b959703fdc38fa28667db9b2268827d7ce92ca55d21b38ba2a7a8b3c1c"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a68a6810f0b80a1ade36fc644c6f44fb02848a8f4200a900679efb26e1d0cb70.json b/rust/cloud-storage/chat/.sqlx/query-a68a6810f0b80a1ade36fc644c6f44fb02848a8f4200a900679efb26e1d0cb70.json
new file mode 100644
index 0000000000..5c3bd4dd8b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a68a6810f0b80a1ade36fc644c6f44fb02848a8f4200a900679efb26e1d0cb70.json
@@ -0,0 +1,26 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n id,\n description \n FROM \"Permission\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "description",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": []
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "a68a6810f0b80a1ade36fc644c6f44fb02848a8f4200a900679efb26e1d0cb70"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a7355d80810653b6b813ebd3c132579b6ba0f419f72b68d08cc2183e9d0d6341.json b/rust/cloud-storage/chat/.sqlx/query-a7355d80810653b6b813ebd3c132579b6ba0f419f72b68d08cc2183e9d0d6341.json
new file mode 100644
index 0000000000..c4418378e0
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a7355d80810653b6b813ebd3c132579b6ba0f419f72b68d08cc2183e9d0d6341.json
@@ -0,0 +1,20 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT COUNT(*) as \"count\"\n FROM \"User\" u\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "count",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": []
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "a7355d80810653b6b813ebd3c132579b6ba0f419f72b68d08cc2183e9d0d6341"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a765f217add20532a937d9f7987ea56ce1f80c9cb9236bc3dc83c73b346ffe79.json b/rust/cloud-storage/chat/.sqlx/query-a765f217add20532a937d9f7987ea56ce1f80c9cb9236bc3dc83c73b346ffe79.json
new file mode 100644
index 0000000000..cffbe7653a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a765f217add20532a937d9f7987ea56ce1f80c9cb9236bc3dc83c73b346ffe79.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n sender_id\n FROM comms_messages\n WHERE id = $1\n ORDER BY created_at ASC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "sender_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "a765f217add20532a937d9f7987ea56ce1f80c9cb9236bc3dc83c73b346ffe79"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a7f90096050e550d15ef11bbc56a3cd79e1a80bc3f46cd063d0ff94d9b76f252.json b/rust/cloud-storage/chat/.sqlx/query-a7f90096050e550d15ef11bbc56a3cd79e1a80bc3f46cd063d0ff94d9b76f252.json
new file mode 100644
index 0000000000..8bc55d69f6
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a7f90096050e550d15ef11bbc56a3cd79e1a80bc3f46cd063d0ff94d9b76f252.json
@@ -0,0 +1,57 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n user_id,\n channel_id,\n joined_at,\n left_at,\n role as \"role: DbParticipantRole\"\n FROM comms_channel_participants\n WHERE channel_id = $1\n ORDER BY joined_at DESC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "channel_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "joined_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 3,
+ "name": "left_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 4,
+ "name": "role: DbParticipantRole",
+ "type_info": {
+ "Custom": {
+ "name": "comms_participant_role",
+ "kind": {
+ "Enum": [
+ "owner",
+ "admin",
+ "member"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ false
+ ]
+ },
+ "hash": "a7f90096050e550d15ef11bbc56a3cd79e1a80bc3f46cd063d0ff94d9b76f252"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24.json b/rust/cloud-storage/chat/.sqlx/query-a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24.json
new file mode 100644
index 0000000000..f214362a1f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'call'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE id in (\n SELECT share_permission_id\n FROM calls\n WHERE id = $1\n UNION ALL\n SELECT share_permission_id\n FROM call_records\n WHERE id = $1\n LIMIT 1\n )\n AND \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a96916366e8c54b1ba978b2fa7cc54b2e1681ebbcbd9bb030768983d6ce966b6.json b/rust/cloud-storage/chat/.sqlx/query-a96916366e8c54b1ba978b2fa7cc54b2e1681ebbcbd9bb030768983d6ce966b6.json
new file mode 100644
index 0000000000..69534d565a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a96916366e8c54b1ba978b2fa7cc54b2e1681ebbcbd9bb030768983d6ce966b6.json
@@ -0,0 +1,35 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id, document_id, location\n FROM \"UserDocumentViewLocation\"\n WHERE user_id = $1 AND document_id = $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "location",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "a96916366e8c54b1ba978b2fa7cc54b2e1681ebbcbd9bb030768983d6ce966b6"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a97451b5645b8265597f438d8fc78e9b0e2f2228c5d6a7453122eb59fa90f64a.json b/rust/cloud-storage/chat/.sqlx/query-a97451b5645b8265597f438d8fc78e9b0e2f2228c5d6a7453122eb59fa90f64a.json
new file mode 100644
index 0000000000..3027e28949
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a97451b5645b8265597f438d8fc78e9b0e2f2228c5d6a7453122eb59fa90f64a.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n sp.id as id\n FROM\n \"DocumentPermission\" dp\n JOIN \"SharePermission\" sp ON dp.\"sharePermissionId\" = sp.id\n WHERE\n dp.\"documentId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "a97451b5645b8265597f438d8fc78e9b0e2f2228c5d6a7453122eb59fa90f64a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a9822aca7429a3fd0c2ab83450b7e23bac9bcae5ebd973db3ef6016100721bb7.json b/rust/cloud-storage/chat/.sqlx/query-a9822aca7429a3fd0c2ab83450b7e23bac9bcae5ebd973db3ef6016100721bb7.json
new file mode 100644
index 0000000000..0fd2576284
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a9822aca7429a3fd0c2ab83450b7e23bac9bcae5ebd973db3ef6016100721bb7.json
@@ -0,0 +1,48 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.\"id\" as \"chat_id\",\n m.id as \"message_id\",\n c.\"userId\" as \"user_id\",\n c.\"createdAt\" as \"created_at\",\n c.\"updatedAt\" as \"updated_at\"\n FROM\n \"ChatMessage\" m\n JOIN\n \"Chat\" c on c.\"id\" = m.\"chatId\"\n WHERE\n c.\"userId\" = ANY($1) AND c.\"deletedAt\" IS NULL\n ORDER BY\n m.\"createdAt\" DESC\n LIMIT $2\n OFFSET $3\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "chat_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "message_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 4,
+ "name": "updated_at",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "a9822aca7429a3fd0c2ab83450b7e23bac9bcae5ebd973db3ef6016100721bb7"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-a991a3a468c02f27709b7a45f27518c828b88bc4ca913019d9d4802395e7a22a.json b/rust/cloud-storage/chat/.sqlx/query-a991a3a468c02f27709b7a45f27518c828b88bc4ca913019d9d4802395e7a22a.json
new file mode 100644
index 0000000000..6c1bc17b21
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-a991a3a468c02f27709b7a45f27518c828b88bc4ca913019d9d4802395e7a22a.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Project\" SET \"parentId\" = NULL WHERE \"id\" = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "a991a3a468c02f27709b7a45f27518c828b88bc4ca913019d9d4802395e7a22a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-aac44fedc7a698d155114e4b84cf3cf60de7edc46f5bd7d943873cf2809ade77.json b/rust/cloud-storage/chat/.sqlx/query-aac44fedc7a698d155114e4b84cf3cf60de7edc46f5bd7d943873cf2809ade77.json
new file mode 100644
index 0000000000..824f91dced
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-aac44fedc7a698d155114e4b84cf3cf60de7edc46f5bd7d943873cf2809ade77.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n u.\"id\" as id\n FROM \"Project\" p\n INNER JOIN \"UserHistory\" uh ON uh.\"itemId\" = p.\"id\" AND uh.\"itemType\" = 'project'\n INNER JOIN \"User\" u ON u.id = uh.\"userId\"\n WHERE p.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "aac44fedc7a698d155114e4b84cf3cf60de7edc46f5bd7d943873cf2809ade77"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ab1cdc9cf83712efd50e720fd9835fdfe36277075384044c8f7f3e8ce810c236.json b/rust/cloud-storage/chat/.sqlx/query-ab1cdc9cf83712efd50e720fd9835fdfe36277075384044c8f7f3e8ce810c236.json
new file mode 100644
index 0000000000..89579ab1a1
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ab1cdc9cf83712efd50e720fd9835fdfe36277075384044c8f7f3e8ce810c236.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"macro_user_email_verification\" SET \"macro_user_id\" = $1 WHERE \"macro_user_id\" = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "ab1cdc9cf83712efd50e720fd9835fdfe36277075384044c8f7f3e8ce810c236"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ab5316751a9b8b8f14e8319811749dfa6bc98f42ecb46ee9d3c20ca2daf43e44.json b/rust/cloud-storage/chat/.sqlx/query-ab5316751a9b8b8f14e8319811749dfa6bc98f42ecb46ee9d3c20ca2daf43e44.json
new file mode 100644
index 0000000000..d365439d22
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ab5316751a9b8b8f14e8319811749dfa6bc98f42ecb46ee9d3c20ca2daf43e44.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT macro_user_id, profile_picture as \"profile_picture!\", profile_picture_hash FROM macro_user_info\n WHERE macro_user_id = ANY($1) and profile_picture IS NOT NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "macro_user_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "profile_picture!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "profile_picture_hash",
+ "type_info": "Varchar"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "UuidArray"
+ ]
+ },
+ "nullable": [
+ false,
+ true,
+ true
+ ]
+ },
+ "hash": "ab5316751a9b8b8f14e8319811749dfa6bc98f42ecb46ee9d3c20ca2daf43e44"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10.json b/rust/cloud-storage/chat/.sqlx/query-ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10.json
new file mode 100644
index 0000000000..b0fb258d2d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT l.macro_id\n FROM email_threads et\n JOIN email_links l ON et.link_id = l.id\n WHERE et.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "macro_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ac52ec341d9ff2b334df144dfcba1195b845609b557d278290359a0e6170c10d.json b/rust/cloud-storage/chat/.sqlx/query-ac52ec341d9ff2b334df144dfcba1195b845609b557d278290359a0e6170c10d.json
new file mode 100644
index 0000000000..19f6ad325a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ac52ec341d9ff2b334df144dfcba1195b845609b557d278290359a0e6170c10d.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"entity_access\"\n WHERE \"entity_id\" = $1 AND \"entity_type\" = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "ac52ec341d9ff2b334df144dfcba1195b845609b557d278290359a0e6170c10d"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-acce87ece376ef3d87f7de83d626da15b53d400bc7d362f4ef8846e055ed8e0c.json b/rust/cloud-storage/chat/.sqlx/query-acce87ece376ef3d87f7de83d626da15b53d400bc7d362f4ef8846e055ed8e0c.json
new file mode 100644
index 0000000000..01d19417ca
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-acce87ece376ef3d87f7de83d626da15b53d400bc7d362f4ef8846e055ed8e0c.json
@@ -0,0 +1,29 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)\n VALUES ($1, $2, $3, 'user', $4)\n ON CONFLICT (entity_id, entity_type, source_id, source_type)\n WHERE granted_from_project_id IS NULL\n DO UPDATE SET access_level = EXCLUDED.access_level, updated_at = NOW()\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text",
+ {
+ "Custom": {
+ "name": "\"AccessLevel\"",
+ "kind": {
+ "Enum": [
+ "view",
+ "comment",
+ "edit",
+ "owner"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "acce87ece376ef3d87f7de83d626da15b53d400bc7d362f4ef8846e055ed8e0c"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ad0e23af0a67a769bf40b3ab388c21c001e01d1691861d8b9df950b03bdb2f4b.json b/rust/cloud-storage/chat/.sqlx/query-ad0e23af0a67a769bf40b3ab388c21c001e01d1691861d8b9df950b03bdb2f4b.json
new file mode 100644
index 0000000000..77bae849be
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ad0e23af0a67a769bf40b3ab388c21c001e01d1691861d8b9df950b03bdb2f4b.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n COUNT(id) as count\n FROM\n in_progress_user_link\n WHERE\n macro_user_id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "count",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "ad0e23af0a67a769bf40b3ab388c21c001e01d1691861d8b9df950b03bdb2f4b"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ade8f82fdb3feffe37acb0e67a7e39aac513e2b7ae7c7aabaa9ac59f270dbffc.json b/rust/cloud-storage/chat/.sqlx/query-ade8f82fdb3feffe37acb0e67a7e39aac513e2b7ae7c7aabaa9ac59f270dbffc.json
new file mode 100644
index 0000000000..98d3bf1b47
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ade8f82fdb3feffe37acb0e67a7e39aac513e2b7ae7c7aabaa9ac59f270dbffc.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"Document\" \n WHERE id = ANY($1)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "ade8f82fdb3feffe37acb0e67a7e39aac513e2b7ae7c7aabaa9ac59f270dbffc"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-aeaa28037abd84dfb5393969479d30335566b4207d7e9af61c00d31abea4a790.json b/rust/cloud-storage/chat/.sqlx/query-aeaa28037abd84dfb5393969479d30335566b4207d7e9af61c00d31abea4a790.json
similarity index 100%
rename from rust/cloud-storage/macro_db_client/.sqlx/query-aeaa28037abd84dfb5393969479d30335566b4207d7e9af61c00d31abea4a790.json
rename to rust/cloud-storage/chat/.sqlx/query-aeaa28037abd84dfb5393969479d30335566b4207d7e9af61c00d31abea4a790.json
diff --git a/rust/cloud-storage/chat/.sqlx/query-af221abca7c795e8be43765273da50af55ed9b7f069ee43fa7149deb8425f6bf.json b/rust/cloud-storage/chat/.sqlx/query-af221abca7c795e8be43765273da50af55ed9b7f069ee43fa7149deb8425f6bf.json
new file mode 100644
index 0000000000..f86bbc7421
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-af221abca7c795e8be43765273da50af55ed9b7f069ee43fa7149deb8425f6bf.json
@@ -0,0 +1,71 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id,\n name,\n channel_type AS \"channel_type: ChannelType\",\n org_id,\n created_at,\n updated_at,\n owner_id\n FROM comms_channels\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 2,
+ "name": "channel_type: ChannelType",
+ "type_info": {
+ "Custom": {
+ "name": "comms_channel_type",
+ "kind": {
+ "Enum": [
+ "public",
+ "organization",
+ "private",
+ "direct_message",
+ "team"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 3,
+ "name": "org_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "owner_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ true,
+ false,
+ true,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "af221abca7c795e8be43765273da50af55ed9b7f069ee43fa7149deb8425f6bf"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-af5a4cf73fd08698bfe9a04e6bb4441ac2b9c20b0697d52467e0a12c17f8e473.json b/rust/cloud-storage/chat/.sqlx/query-af5a4cf73fd08698bfe9a04e6bb4441ac2b9c20b0697d52467e0a12c17f8e473.json
new file mode 100644
index 0000000000..8777fe8d9b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-af5a4cf73fd08698bfe9a04e6bb4441ac2b9c20b0697d52467e0a12c17f8e473.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n u.id,\n u.\"organizationId\" as organization_id\n FROM\n \"User\" u\n WHERE\n u.email = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "organization_id",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ true
+ ]
+ },
+ "hash": "af5a4cf73fd08698bfe9a04e6bb4441ac2b9c20b0697d52467e0a12c17f8e473"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b00d96876f6101270b5de19e4cfa219f542dd6c24ecf785b30ef8749c0443373.json b/rust/cloud-storage/chat/.sqlx/query-b00d96876f6101270b5de19e4cfa219f542dd6c24ecf785b30ef8749c0443373.json
new file mode 100644
index 0000000000..ee71889852
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b00d96876f6101270b5de19e4cfa219f542dd6c24ecf785b30ef8749c0443373.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO macro_user_info (macro_user_id, first_name, last_name)\n VALUES ($1, $2, $3)\n ON CONFLICT (macro_user_id)\n DO UPDATE SET \n first_name = COALESCE(EXCLUDED.first_name, macro_user_info.first_name),\n last_name = COALESCE(EXCLUDED.last_name, macro_user_info.last_name)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "b00d96876f6101270b5de19e4cfa219f542dd6c24ecf785b30ef8749c0443373"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-b14a19253757e1e650c626bbda138092b21c2437a80b46dd5a4c8c87825f3126.json b/rust/cloud-storage/chat/.sqlx/query-b14a19253757e1e650c626bbda138092b21c2437a80b46dd5a4c8c87825f3126.json
similarity index 100%
rename from rust/cloud-storage/macro_db_client/.sqlx/query-b14a19253757e1e650c626bbda138092b21c2437a80b46dd5a4c8c87825f3126.json
rename to rust/cloud-storage/chat/.sqlx/query-b14a19253757e1e650c626bbda138092b21c2437a80b46dd5a4c8c87825f3126.json
diff --git a/rust/cloud-storage/chat/.sqlx/query-b1512adda253fc7e653344f6a679a4c78af368aa2134b235f8e1f046daa197bc.json b/rust/cloud-storage/chat/.sqlx/query-b1512adda253fc7e653344f6a679a4c78af368aa2134b235f8e1f046daa197bc.json
new file mode 100644
index 0000000000..396c983fd4
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b1512adda253fc7e653344f6a679a4c78af368aa2134b235f8e1f046daa197bc.json
@@ -0,0 +1,76 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.id,\n c.name,\n c.model,\n c.\"tokenCount\" as \"token_count\",\n c.\"userId\" as \"user_id\",\n c.\"createdAt\"::timestamptz as \"created_at\",\n c.\"updatedAt\"::timestamptz as \"updated_at\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\"\n FROM \"Chat\" c\n WHERE c.\"userId\" = $1 AND c.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "model",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "token_count",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 4,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 9,
+ "name": "is_persistent",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ false,
+ null,
+ null,
+ null,
+ true,
+ false
+ ]
+ },
+ "hash": "b1512adda253fc7e653344f6a679a4c78af368aa2134b235f8e1f046daa197bc"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b1766b649fb0b0307cb41db8adbfd996ffa1262e0a6ba8a8e1c58414759a1fec.json b/rust/cloud-storage/chat/.sqlx/query-b1766b649fb0b0307cb41db8adbfd996ffa1262e0a6ba8a8e1c58414759a1fec.json
new file mode 100644
index 0000000000..b722895ef4
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b1766b649fb0b0307cb41db8adbfd996ffa1262e0a6ba8a8e1c58414759a1fec.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Document\"\n SET \"updatedAt\" = NOW()\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "b1766b649fb0b0307cb41db8adbfd996ffa1262e0a6ba8a8e1c58414759a1fec"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815.json b/rust/cloud-storage/chat/.sqlx/query-b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815.json
new file mode 100644
index 0000000000..aa74e2b98b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'email_thread'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"EmailThreadPermission\" WHERE \"threadId\" = $3\n )\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b288dfc8e7703bdfb49bc1066c290743da8653dc50e3d388697e429308afeafa.json b/rust/cloud-storage/chat/.sqlx/query-b288dfc8e7703bdfb49bc1066c290743da8653dc50e3d388697e429308afeafa.json
new file mode 100644
index 0000000000..8844ec6411
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b288dfc8e7703bdfb49bc1066c290743da8653dc50e3d388697e429308afeafa.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT c.id\n FROM comms_channels c\n INNER JOIN comms_channel_participants cp ON cp.channel_id = c.id \n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n AND c.id = ANY($2::uuid[])\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "b288dfc8e7703bdfb49bc1066c290743da8653dc50e3d388697e429308afeafa"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b29f648b6a5be28708366ba264bab55518d34313519a62edf4174269606b1b1c.json b/rust/cloud-storage/chat/.sqlx/query-b29f648b6a5be28708366ba264bab55518d34313519a62edf4174269606b1b1c.json
new file mode 100644
index 0000000000..d4fe58887c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b29f648b6a5be28708366ba264bab55518d34313519a62edf4174269606b1b1c.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"UserHistory\" WHERE \"itemId\" = ANY($1) AND \"itemType\" = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "b29f648b6a5be28708366ba264bab55518d34313519a62edf4174269606b1b1c"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b3d2194b79197b2d5e02ee8b7c243b70c598adf488d805325475770ae3b7c51e.json b/rust/cloud-storage/chat/.sqlx/query-b3d2194b79197b2d5e02ee8b7c243b70c598adf488d805325475770ae3b7c51e.json
new file mode 100644
index 0000000000..5564261909
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b3d2194b79197b2d5e02ee8b7c243b70c598adf488d805325475770ae3b7c51e.json
@@ -0,0 +1,29 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n u.id,\n u.\"stripeCustomerId\" as \"stripe_customer_id\"\n FROM \"User\" u\n WHERE u.\"macro_user_id\" IS NULL\n AND u.id > $1\n ORDER BY u.id ASC\n LIMIT $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "stripe_customer_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ true
+ ]
+ },
+ "hash": "b3d2194b79197b2d5e02ee8b7c243b70c598adf488d805325475770ae3b7c51e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b3f9f3696438bd2ad8754650d87d7bbf32e70d3d173a748a07eacdb4e42841eb.json b/rust/cloud-storage/chat/.sqlx/query-b3f9f3696438bd2ad8754650d87d7bbf32e70d3d173a748a07eacdb4e42841eb.json
new file mode 100644
index 0000000000..e5d913399d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b3f9f3696438bd2ad8754650d87d7bbf32e70d3d173a748a07eacdb4e42841eb.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO notification_user_device_registration (id, user_id, device_token, device_endpoint, device_type)\n VALUES ($1, $2, $3, $4, $5)\n ON CONFLICT (device_endpoint) DO UPDATE SET user_id = $2, device_token = $3, device_type = $5, updated_at = NOW()\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text",
+ "Text",
+ {
+ "Custom": {
+ "name": "notification_device_type_option",
+ "kind": {
+ "Enum": [
+ "ios",
+ "android"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "b3f9f3696438bd2ad8754650d87d7bbf32e70d3d173a748a07eacdb4e42841eb"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b42c868de92630b2d5ee37fc64299df3d949da660e009f35c480ba9fb19c9e07.json b/rust/cloud-storage/chat/.sqlx/query-b42c868de92630b2d5ee37fc64299df3d949da660e009f35c480ba9fb19c9e07.json
new file mode 100644
index 0000000000..a93030266b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b42c868de92630b2d5ee37fc64299df3d949da660e009f35c480ba9fb19c9e07.json
@@ -0,0 +1,65 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Thread\" t\n SET \"updatedAt\" = NOW()\n WHERE t.\"documentId\" = $1 AND t.\"deletedAt\" IS NULL AND t.id = $2\n RETURNING\n t.id as thread_id, \n t.resolved, \n t.\"documentId\" as document_id, \n t.\"createdAt\"::timestamptz as created_at, \n t.\"updatedAt\"::timestamptz as updated_at, \n t.\"deletedAt\"::timestamptz as deleted_at, \n t.metadata, \n t.owner\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "resolved",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 4,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "metadata",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 7,
+ "name": "owner",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ true,
+ false
+ ]
+ },
+ "hash": "b42c868de92630b2d5ee37fc64299df3d949da660e009f35c480ba9fb19c9e07"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b5578ab6da001f418fe8ff216616b79eb80caf8e2677fcf4e7127151060a50ea.json b/rust/cloud-storage/chat/.sqlx/query-b5578ab6da001f418fe8ff216616b79eb80caf8e2677fcf4e7127151060a50ea.json
new file mode 100644
index 0000000000..2c70220aed
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b5578ab6da001f418fe8ff216616b79eb80caf8e2677fcf4e7127151060a50ea.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id as \"channel_id\"\n FROM\n comms_channels\n ORDER BY\n created_at ASC\n LIMIT $1\n OFFSET $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "channel_id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "b5578ab6da001f418fe8ff216616b79eb80caf8e2677fcf4e7127151060a50ea"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b55c3a778e4ed824b71b4e26b20ebf12413a8a0bf8fee05fa130afb72c55ee41.json b/rust/cloud-storage/chat/.sqlx/query-b55c3a778e4ed824b71b4e26b20ebf12413a8a0bf8fee05fa130afb72c55ee41.json
new file mode 100644
index 0000000000..f902aa8188
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b55c3a778e4ed824b71b4e26b20ebf12413a8a0bf8fee05fa130afb72c55ee41.json
@@ -0,0 +1,52 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n id, \n owner, \n text as content, \n \"createdAt\" as created_at, \n \"updatedAt\" as updated_at,\n \"order\"\n FROM \"Comment\" \n WHERE \"threadId\" = $1\n ORDER BY \"order\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "content",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 4,
+ "name": "updated_at",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 5,
+ "name": "order",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "b55c3a778e4ed824b71b4e26b20ebf12413a8a0bf8fee05fa130afb72c55ee41"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524.json b/rust/cloud-storage/chat/.sqlx/query-b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524.json
new file mode 100644
index 0000000000..be13d76b25
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'document'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"DocumentPermission\" WHERE \"documentId\" = $3\n ) \n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b57aac0fecf4aa66721fe3596797e1256c960fed355a37cba8c9c1eeb630a5b6.json b/rust/cloud-storage/chat/.sqlx/query-b57aac0fecf4aa66721fe3596797e1256c960fed355a37cba8c9c1eeb630a5b6.json
new file mode 100644
index 0000000000..c55d8a1a72
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b57aac0fecf4aa66721fe3596797e1256c960fed355a37cba8c9c1eeb630a5b6.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "DELETE FROM \"entity_access\" WHERE \"entity_id\" = $1 AND \"entity_type\" = $2",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "b57aac0fecf4aa66721fe3596797e1256c960fed355a37cba8c9c1eeb630a5b6"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b62a8743ac8151822dcb51e80c61f9c9496412cf76d6fb5158fdc5510f59464d.json b/rust/cloud-storage/chat/.sqlx/query-b62a8743ac8151822dcb51e80c61f9c9496412cf76d6fb5158fdc5510f59464d.json
new file mode 100644
index 0000000000..f7f36883d1
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b62a8743ac8151822dcb51e80c61f9c9496412cf76d6fb5158fdc5510f59464d.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.id\n FROM\n \"Chat\" c\n WHERE\n c.id = ANY($1)\n AND c.\"projectId\" = ANY($2)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "b62a8743ac8151822dcb51e80c61f9c9496412cf76d6fb5158fdc5510f59464d"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b662ef77f95aaa2a86030fbed4f11de74d311cc1a6096e49372e6cc18581b523.json b/rust/cloud-storage/chat/.sqlx/query-b662ef77f95aaa2a86030fbed4f11de74d311cc1a6096e49372e6cc18581b523.json
new file mode 100644
index 0000000000..2a3e8026a3
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b662ef77f95aaa2a86030fbed4f11de74d311cc1a6096e49372e6cc18581b523.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"ChatPermission\" (\"chatId\", \"sharePermissionId\")\n VALUES ($1, $2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "b662ef77f95aaa2a86030fbed4f11de74d311cc1a6096e49372e6cc18581b523"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b6705d3675950d0bbbd4a0ba10f7716a24694cfd98741fc0508d607684b1c8a9.json b/rust/cloud-storage/chat/.sqlx/query-b6705d3675950d0bbbd4a0ba10f7716a24694cfd98741fc0508d607684b1c8a9.json
new file mode 100644
index 0000000000..1168d26a34
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b6705d3675950d0bbbd4a0ba10f7716a24694cfd98741fc0508d607684b1c8a9.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE notification_message_receipt\n SET failed = true, failed_at = NOW()\n WHERE message_id = $1\n RETURNING user_id, notification_id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "b6705d3675950d0bbbd4a0ba10f7716a24694cfd98741fc0508d607684b1c8a9"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b69f3eab9c2048f5fe6bb31bf4c47f85169af66827f2b09287099c14a1a6e0db.json b/rust/cloud-storage/chat/.sqlx/query-b69f3eab9c2048f5fe6bb31bf4c47f85169af66827f2b09287099c14a1a6e0db.json
new file mode 100644
index 0000000000..3b75a10e75
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b69f3eab9c2048f5fe6bb31bf4c47f85169af66827f2b09287099c14a1a6e0db.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT b.id as \"id?\"\n FROM \"DocumentBom\" b\n WHERE b.\"documentId\" = $1\n ORDER BY b.\"createdAt\" DESC\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id?",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "b69f3eab9c2048f5fe6bb31bf4c47f85169af66827f2b09287099c14a1a6e0db"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b7234825305171a78e8d113745b271492fc7c2921b36730ce9331249d55d300c.json b/rust/cloud-storage/chat/.sqlx/query-b7234825305171a78e8d113745b271492fc7c2921b36730ce9331249d55d300c.json
new file mode 100644
index 0000000000..c75041f6fc
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b7234825305171a78e8d113745b271492fc7c2921b36730ce9331249d55d300c.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO comms_reactions (message_id, emoji, user_id)\n VALUES ($1, $2, $3)\n ON CONFLICT DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Varchar",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "b7234825305171a78e8d113745b271492fc7c2921b36730ce9331249d55d300c"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b8342cf8ccfe95aad527ddf5cc49aef347e35bb2b023a820d85a2e85caaf7b61.json b/rust/cloud-storage/chat/.sqlx/query-b8342cf8ccfe95aad527ddf5cc49aef347e35bb2b023a820d85a2e85caaf7b61.json
new file mode 100644
index 0000000000..db9e518ea9
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b8342cf8ccfe95aad527ddf5cc49aef347e35bb2b023a820d85a2e85caaf7b61.json
@@ -0,0 +1,64 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n t.id as thread_id, \n t.resolved, \n t.\"documentId\" as document_id, \n t.\"createdAt\"::timestamptz as created_at, \n t.\"updatedAt\"::timestamptz as updated_at, \n t.\"deletedAt\"::timestamptz as deleted_at, \n t.metadata, \n t.owner\n FROM \"Thread\" t\n WHERE t.\"documentId\" = $1 AND t.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "resolved",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 4,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "metadata",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 7,
+ "name": "owner",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ true,
+ false
+ ]
+ },
+ "hash": "b8342cf8ccfe95aad527ddf5cc49aef347e35bb2b023a820d85a2e85caaf7b61"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b85f38b29d0f452ddb8d83e3c57c25b4d5733d4bc21770570cdc8412d47ffe65.json b/rust/cloud-storage/chat/.sqlx/query-b85f38b29d0f452ddb8d83e3c57c25b4d5733d4bc21770570cdc8412d47ffe65.json
new file mode 100644
index 0000000000..40570f2367
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b85f38b29d0f452ddb8d83e3c57c25b4d5733d4bc21770570cdc8412d47ffe65.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"id\"\n FROM \"User\"\n WHERE \"email\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "b85f38b29d0f452ddb8d83e3c57c25b4d5733d4bc21770570cdc8412d47ffe65"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b8b631cf3afd7c73b5645635212bb851ba19858a47a17b0ffcbe4f15cd177cb4.json b/rust/cloud-storage/chat/.sqlx/query-b8b631cf3afd7c73b5645635212bb851ba19858a47a17b0ffcbe4f15cd177cb4.json
new file mode 100644
index 0000000000..b938c355ee
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b8b631cf3afd7c73b5645635212bb851ba19858a47a17b0ffcbe4f15cd177cb4.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"sharePermissionId\" as share_permission_id\n FROM \"DocumentPermission\"\n WHERE \"documentId\"=$1",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "share_permission_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "b8b631cf3afd7c73b5645635212bb851ba19858a47a17b0ffcbe4f15cd177cb4"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b905b3cbb97bbfc8262ffb91023db7f703b0994d6d519fbab0fdb67ea2df5877.json b/rust/cloud-storage/chat/.sqlx/query-b905b3cbb97bbfc8262ffb91023db7f703b0994d6d519fbab0fdb67ea2df5877.json
new file mode 100644
index 0000000000..1037b40923
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b905b3cbb97bbfc8262ffb91023db7f703b0994d6d519fbab0fdb67ea2df5877.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.name,\n c.\"userId\" as user_id\n FROM\n \"Chat\" c\n WHERE\n c.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "b905b3cbb97bbfc8262ffb91023db7f703b0994d6d519fbab0fdb67ea2df5877"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157.json b/rust/cloud-storage/chat/.sqlx/query-b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157.json
new file mode 100644
index 0000000000..d560cb7eb3
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'chat'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ChatPermission\" WHERE \"chatId\" = $3\n )\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ba4127d1e61f849f9429fdfedae68131fa26405dbacb0b1afe9a6f52e50fa57e.json b/rust/cloud-storage/chat/.sqlx/query-ba4127d1e61f849f9429fdfedae68131fa26405dbacb0b1afe9a6f52e50fa57e.json
new file mode 100644
index 0000000000..da597ed870
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ba4127d1e61f849f9429fdfedae68131fa26405dbacb0b1afe9a6f52e50fa57e.json
@@ -0,0 +1,27 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO comms_channel_participants (channel_id, role, user_id)\n VALUES ($1, $2, $3)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ {
+ "Custom": {
+ "name": "comms_participant_role",
+ "kind": {
+ "Enum": [
+ "owner",
+ "admin",
+ "member"
+ ]
+ }
+ }
+ },
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "ba4127d1e61f849f9429fdfedae68131fa26405dbacb0b1afe9a6f52e50fa57e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-bb6de5a7f1c778acc5c27a0080037992ac2805137ee19f9385894688e6b8a62c.json b/rust/cloud-storage/chat/.sqlx/query-bb6de5a7f1c778acc5c27a0080037992ac2805137ee19f9385894688e6b8a62c.json
new file mode 100644
index 0000000000..ae26eaad0e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-bb6de5a7f1c778acc5c27a0080037992ac2805137ee19f9385894688e6b8a62c.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT name FROM \"Project\" WHERE id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "name",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "bb6de5a7f1c778acc5c27a0080037992ac2805137ee19f9385894688e6b8a62c"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-bc4d60efeffa6cba398a37db8ff7204bcffd809e425e9236b897b5efa9c7eebc.json b/rust/cloud-storage/chat/.sqlx/query-bc4d60efeffa6cba398a37db8ff7204bcffd809e425e9236b897b5efa9c7eebc.json
new file mode 100644
index 0000000000..db2ad0be84
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-bc4d60efeffa6cba398a37db8ff7204bcffd809e425e9236b897b5efa9c7eebc.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id\n FROM \"User\"\n WHERE email = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "bc4d60efeffa6cba398a37db8ff7204bcffd809e425e9236b897b5efa9c7eebc"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682.json b/rust/cloud-storage/chat/.sqlx/query-bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682.json
new file mode 100644
index 0000000000..3ed3f3db5e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE id in (SELECT share_permission_id\n FROM calls\n WHERE id = $1\n UNION ALL\n SELECT share_permission_id\n FROM call_records\n WHERE id = $1\n LIMIT 1)\n AND \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-be483cff20705eb58c47cd4de412aea80ce9a658dfe055f146a38ed9e64effaf.json b/rust/cloud-storage/chat/.sqlx/query-be483cff20705eb58c47cd4de412aea80ce9a658dfe055f146a38ed9e64effaf.json
new file mode 100644
index 0000000000..54a8ba7d73
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-be483cff20705eb58c47cd4de412aea80ce9a658dfe055f146a38ed9e64effaf.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Experiment\" SET active = true AND started_at = NOW() WHERE id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "be483cff20705eb58c47cd4de412aea80ce9a658dfe055f146a38ed9e64effaf"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-be5dc669b45165beefffe0645813f38c805d6f49150d66c8a7325c524bebc854.json b/rust/cloud-storage/chat/.sqlx/query-be5dc669b45165beefffe0645813f38c805d6f49150d66c8a7325c524bebc854.json
new file mode 100644
index 0000000000..1119ce64a1
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-be5dc669b45165beefffe0645813f38c805d6f49150d66c8a7325c524bebc854.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"ChannelSharePermission\"\n WHERE \"share_permission_id\" = $1\n AND \"channel_id\" = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "be5dc669b45165beefffe0645813f38c805d6f49150d66c8a7325c524bebc854"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-bec08349f3e01393e7e83846f1ca4077390d22923bff328a9d8a24275832a57d.json b/rust/cloud-storage/chat/.sqlx/query-bec08349f3e01393e7e83846f1ca4077390d22923bff328a9d8a24275832a57d.json
new file mode 100644
index 0000000000..fdce5f7ae8
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-bec08349f3e01393e7e83846f1ca4077390d22923bff328a9d8a24275832a57d.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"macro_user_email_verification\" (\"macro_user_id\", \"email\", \"is_verified\")\n VALUES ($1, $2, $3)\n ON CONFLICT (\"email\") DO UPDATE SET \"macro_user_id\" = $1, \"is_verified\" = $3\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Bool"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "bec08349f3e01393e7e83846f1ca4077390d22923bff328a9d8a24275832a57d"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-bf1d580e15f077862173d3efc800666d9fc7e79b8fa8619ba43bd1315c506e0b.json b/rust/cloud-storage/chat/.sqlx/query-bf1d580e15f077862173d3efc800666d9fc7e79b8fa8619ba43bd1315c506e0b.json
new file mode 100644
index 0000000000..9eaff6b6b7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-bf1d580e15f077862173d3efc800666d9fc7e79b8fa8619ba43bd1315c506e0b.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"Chat\"\n WHERE id = ANY($1)",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "bf1d580e15f077862173d3efc800666d9fc7e79b8fa8619ba43bd1315c506e0b"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c07f82d525eeaafefce4b65769b2c750743ed9c04ca6ea8a5fd1a6d3a5fe2d17.json b/rust/cloud-storage/chat/.sqlx/query-c07f82d525eeaafefce4b65769b2c750743ed9c04ca6ea8a5fd1a6d3a5fe2d17.json
new file mode 100644
index 0000000000..03df2b01f3
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c07f82d525eeaafefce4b65769b2c750743ed9c04ca6ea8a5fd1a6d3a5fe2d17.json
@@ -0,0 +1,26 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n m.id \n FROM \n \"ChatMessage\" m\n JOIN \n \"Chat\" c on c.\"id\" = m.\"chatId\"\n WHERE\n \"userId\" = $1\n AND\n m.\"updatedAt\" <= $2\n AND \n m.\"updatedAt\" >= $3\n AND \n \"role\" = 'user'\n \n ORDER BY \n m.\"updatedAt\" DESC\n LIMIT \n $4\n OFFSET $5\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Timestamp",
+ "Timestamp",
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "c07f82d525eeaafefce4b65769b2c750743ed9c04ca6ea8a5fd1a6d3a5fe2d17"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c09f00249c17f61948c81a3e7b679b3d1f9ac387ba98d351ff4e99995e3e783f.json b/rust/cloud-storage/chat/.sqlx/query-c09f00249c17f61948c81a3e7b679b3d1f9ac387ba98d351ff4e99995e3e783f.json
new file mode 100644
index 0000000000..31d66f5bc3
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c09f00249c17f61948c81a3e7b679b3d1f9ac387ba98d351ff4e99995e3e783f.json
@@ -0,0 +1,35 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n m.content as \"content\",\n c.name as \"name\",\n m.role as \"role\"\n FROM\n \"ChatMessage\" m\n JOIN\n \"Chat\" c on c.\"id\" = m.\"chatId\"\n WHERE\n m.id = $1 AND m.\"chatId\" = $2 AND c.\"deletedAt\" IS NULL AND c.\"isPersistent\" = false\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "content",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "role",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "c09f00249c17f61948c81a3e7b679b3d1f9ac387ba98d351ff4e99995e3e783f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c0b0f58e6b2129250821f51fcb1ebe9d876c2e251f04f0aa9b1c0942d73a4e0d.json b/rust/cloud-storage/chat/.sqlx/query-c0b0f58e6b2129250821f51fcb1ebe9d876c2e251f04f0aa9b1c0942d73a4e0d.json
new file mode 100644
index 0000000000..658c35ffa3
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c0b0f58e6b2129250821f51fcb1ebe9d876c2e251f04f0aa9b1c0942d73a4e0d.json
@@ -0,0 +1,58 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n p.id,\n p.name,\n p.\"userId\" as user_id, -- createor of the project\n p.\"parentId\" as parent_id,\n p.\"createdAt\"::timestamptz as created_at,\n p.\"updatedAt\"::timestamptz as updated_at,\n p.\"deletedAt\"::timestamptz as deleted_at\n FROM \"UserHistory\" up\n INNER JOIN \"Project\" p ON up.\"itemId\" = p.id AND up.\"itemType\" = 'project'\n WHERE up.\"userId\" = $1 AND p.\"deletedAt\" IS NULL AND p.\"uploadPending\" = false\n ORDER BY p.\"updatedAt\" DESC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "parent_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "c0b0f58e6b2129250821f51fcb1ebe9d876c2e251f04f0aa9b1c0942d73a4e0d"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c17d5fb574b826a4615cd339d550302bcd20260c4d2d82e49167e5c7c7e77958.json b/rust/cloud-storage/chat/.sqlx/query-c17d5fb574b826a4615cd339d550302bcd20260c4d2d82e49167e5c7c7e77958.json
new file mode 100644
index 0000000000..be9247eda4
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c17d5fb574b826a4615cd339d550302bcd20260c4d2d82e49167e5c7c7e77958.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "SELECT\n \"tokenCount\" as token_count\n FROM\n \"DocumentText\"\n WHERE\n \"documentId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "token_count",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "c17d5fb574b826a4615cd339d550302bcd20260c4d2d82e49167e5c7c7e77958"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c18576c18caa0b7e23198ee55981cb8d7b9859dfe4272a92cbb29a4b64a1d695.json b/rust/cloud-storage/chat/.sqlx/query-c18576c18caa0b7e23198ee55981cb8d7b9859dfe4272a92cbb29a4b64a1d695.json
new file mode 100644
index 0000000000..f81d0eeecc
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c18576c18caa0b7e23198ee55981cb8d7b9859dfe4272a92cbb29a4b64a1d695.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.name,\n d.owner\n FROM\n \"Document\" d\n WHERE\n d.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "c18576c18caa0b7e23198ee55981cb8d7b9859dfe4272a92cbb29a4b64a1d695"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c1bc29d0f7278ed6a027978d51a6e15d8be6d62ead3408dc6641866a9230935d.json b/rust/cloud-storage/chat/.sqlx/query-c1bc29d0f7278ed6a027978d51a6e15d8be6d62ead3408dc6641866a9230935d.json
new file mode 100644
index 0000000000..8d3fe9e37e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c1bc29d0f7278ed6a027978d51a6e15d8be6d62ead3408dc6641866a9230935d.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT COUNT(*) as \"count\"\n FROM \"Document\" d\n WHERE owner = $1 AND d.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "count",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "c1bc29d0f7278ed6a027978d51a6e15d8be6d62ead3408dc6641866a9230935d"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c2a48995144a813f912bbba9c9f5b91e1b413978e8262f7db56a6a27fa5ceaf0.json b/rust/cloud-storage/chat/.sqlx/query-c2a48995144a813f912bbba9c9f5b91e1b413978e8262f7db56a6a27fa5ceaf0.json
new file mode 100644
index 0000000000..c8aed48f72
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c2a48995144a813f912bbba9c9f5b91e1b413978e8262f7db56a6a27fa5ceaf0.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT c.id as comment_id\n FROM \"Comment\" c\n JOIN \"Thread\" t ON c.\"threadId\" = t.id\n WHERE t.id = $1 AND c.\"deletedAt\" IS NULL\n ORDER BY c.\"order\", c.\"createdAt\" ASC\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "comment_id",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "c2a48995144a813f912bbba9c9f5b91e1b413978e8262f7db56a6a27fa5ceaf0"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c2f19d911d10a576d01505d6da90f66fad4698c52efa69d3b4a03324c09b87a7.json b/rust/cloud-storage/chat/.sqlx/query-c2f19d911d10a576d01505d6da90f66fad4698c52efa69d3b4a03324c09b87a7.json
new file mode 100644
index 0000000000..0596339115
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c2f19d911d10a576d01505d6da90f66fad4698c52efa69d3b4a03324c09b87a7.json
@@ -0,0 +1,65 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.\"id\" as \"item_id!\",\n c.\"createdAt\" as \"created_at!\",\n c.\"updatedAt\" as \"updated_at!\",\n c.\"deletedAt\" as \"deleted_at?\",\n uh.\"updatedAt\" as \"viewed_at?\",\n c.\"projectId\" as \"project_id?\",\n c.\"userId\" as \"user_id\",\n c.\"name\"\n FROM\n \"Chat\" c\n LEFT JOIN\n \"UserHistory\" uh ON uh.\"itemId\" = c.\"id\"\n AND uh.\"userId\" = $1\n AND uh.\"itemType\" = 'chat'\n WHERE\n c.\"id\" = ANY($2)\n ORDER BY\n c.\"updatedAt\" DESC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "created_at!",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 2,
+ "name": "updated_at!",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 3,
+ "name": "deleted_at?",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 4,
+ "name": "viewed_at?",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 5,
+ "name": "project_id?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 7,
+ "name": "name",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ false,
+ true,
+ false,
+ false
+ ]
+ },
+ "hash": "c2f19d911d10a576d01505d6da90f66fad4698c52efa69d3b4a03324c09b87a7"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c3f9152d242ae679d87961e306f319ac0035e078be790795eed823a95095c7cc.json b/rust/cloud-storage/chat/.sqlx/query-c3f9152d242ae679d87961e306f319ac0035e078be790795eed823a95095c7cc.json
new file mode 100644
index 0000000000..736ecd78b6
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c3f9152d242ae679d87961e306f319ac0035e078be790795eed823a95095c7cc.json
@@ -0,0 +1,29 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id, \"organizationId\" as \"organization_id?\"\n FROM \"User\"\n WHERE \"macro_user_id\" = $1\n AND email = $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "organization_id?",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ true
+ ]
+ },
+ "hash": "c3f9152d242ae679d87961e306f319ac0035e078be790795eed823a95095c7cc"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c415f922985187174693b51466423fa1d2ed8c301776a9778c4947a9d84590e1.json b/rust/cloud-storage/chat/.sqlx/query-c415f922985187174693b51466423fa1d2ed8c301776a9778c4947a9d84590e1.json
new file mode 100644
index 0000000000..69b4971298
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c415f922985187174693b51466423fa1d2ed8c301776a9778c4947a9d84590e1.json
@@ -0,0 +1,79 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"Comment\" AS c \n (\"threadId\", \"owner\", \"text\", \"metadata\")\n VALUES ($1, $2, $3, $4)\n RETURNING\n c.id as comment_id, \n c.\"threadId\" as thread_id, \n c.owner, \n c.sender, \n c.text, \n c.metadata, \n c.\"createdAt\"::timestamptz as created_at, \n c.\"updatedAt\"::timestamptz as updated_at, \n c.\"deletedAt\"::timestamptz as deleted_at, \n c.order\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "comment_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "sender",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "text",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "metadata",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "order",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Text",
+ "Text",
+ "Jsonb"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ false,
+ true,
+ null,
+ null,
+ null,
+ true
+ ]
+ },
+ "hash": "c415f922985187174693b51466423fa1d2ed8c301776a9778c4947a9d84590e1"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c5b5b22cfde385f2d03eebbf25a1f08e02d42d09810994f84a250e2f43cc5acf.json b/rust/cloud-storage/chat/.sqlx/query-c5b5b22cfde385f2d03eebbf25a1f08e02d42d09810994f84a250e2f43cc5acf.json
new file mode 100644
index 0000000000..8b087037ad
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c5b5b22cfde385f2d03eebbf25a1f08e02d42d09810994f84a250e2f43cc5acf.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.\"documentId\" as \"document_id\",\n d.content as \"content\",\n d.\"tokenCount\" as \"token_count\"\n FROM\n \"DocumentText\" d\n WHERE\n d.\"documentId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "content",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "token_count",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "c5b5b22cfde385f2d03eebbf25a1f08e02d42d09810994f84a250e2f43cc5acf"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c621293c78043e724b4e44f821ef3cc9e4d74a48075918e24327172256a5ad15.json b/rust/cloud-storage/chat/.sqlx/query-c621293c78043e724b4e44f821ef3cc9e4d74a48075918e24327172256a5ad15.json
new file mode 100644
index 0000000000..0b73aaff33
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c621293c78043e724b4e44f821ef3cc9e4d74a48075918e24327172256a5ad15.json
@@ -0,0 +1,17 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO macro_user (id, username, stripe_customer_id, email)\n VALUES ($1, $2, $3, $4)\n ON CONFLICT (\"id\") DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "c621293c78043e724b4e44f821ef3cc9e4d74a48075918e24327172256a5ad15"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c6a0afdba2b194e96e3b51935deeeca109ccd45ecae97f97cb61bd9fdd7c470a.json b/rust/cloud-storage/chat/.sqlx/query-c6a0afdba2b194e96e3b51935deeeca109ccd45ecae97f97cb61bd9fdd7c470a.json
new file mode 100644
index 0000000000..833a22de08
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c6a0afdba2b194e96e3b51935deeeca109ccd45ecae97f97cb61bd9fdd7c470a.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT pp.\"sharePermissionId\" as id\n FROM \"ProjectPermission\" pp\n WHERE\n pp.\"projectId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "c6a0afdba2b194e96e3b51935deeeca109ccd45ecae97f97cb61bd9fdd7c470a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c792af1d4fe131a623828fcae21eba7b17a7ee70d1ff44892c747061478cee89.json b/rust/cloud-storage/chat/.sqlx/query-c792af1d4fe131a623828fcae21eba7b17a7ee70d1ff44892c747061478cee89.json
new file mode 100644
index 0000000000..fe3708f959
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c792af1d4fe131a623828fcae21eba7b17a7ee70d1ff44892c747061478cee89.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT COUNT(*) as \"count\"\n FROM \"Chat\"\n WHERE \"userId\" = $1 AND \"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "count",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "c792af1d4fe131a623828fcae21eba7b17a7ee70d1ff44892c747061478cee89"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c858541d6cbadae374ef95f2c69a582d76bd73ae439d3d3e6f1cf4e482b9ff55.json b/rust/cloud-storage/chat/.sqlx/query-c858541d6cbadae374ef95f2c69a582d76bd73ae439d3d3e6f1cf4e482b9ff55.json
new file mode 100644
index 0000000000..b67166da2e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c858541d6cbadae374ef95f2c69a582d76bd73ae439d3d3e6f1cf4e482b9ff55.json
@@ -0,0 +1,112 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n pa.uuid, \n pa.\"documentId\" as document_id, \n pa.owner, \n pa.\"threadId\" as thread_id, \n pa.page, \n pa.\"originalPage\" as original_page, \n pa.\"originalIndex\" as original_index, \n pa.\"xPct\" as x_pct, \n pa.\"yPct\" as y_pct, \n pa.\"widthPct\" as width_pct, \n pa.\"heightPct\" as height_pct,\n pa.rotation, \n pa.\"allowableEdits\" as allowable_edits,\n pa.\"wasEdited\" as was_edited,\n pa.\"wasDeleted\" as was_deleted,\n pa.\"shouldLockOnSave\" as should_lock_on_save\n FROM \"PdfPlaceableCommentAnchor\" pa\n JOIN \"Thread\" t ON pa.\"threadId\" = t.id\n WHERE pa.\"documentId\" = $1\n AND t.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 4,
+ "name": "page",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 5,
+ "name": "original_page",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 6,
+ "name": "original_index",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 7,
+ "name": "x_pct",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 8,
+ "name": "y_pct",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 9,
+ "name": "width_pct",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 10,
+ "name": "height_pct",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 11,
+ "name": "rotation",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 12,
+ "name": "allowable_edits",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 13,
+ "name": "was_edited",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 14,
+ "name": "was_deleted",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 15,
+ "name": "should_lock_on_save",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "c858541d6cbadae374ef95f2c69a582d76bd73ae439d3d3e6f1cf4e482b9ff55"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c8dac77aedb5609a57ce5ee03d97f7e3c28fa0e94f2563e99d82f306cf6530e5.json b/rust/cloud-storage/chat/.sqlx/query-c8dac77aedb5609a57ce5ee03d97f7e3c28fa0e94f2563e99d82f306cf6530e5.json
new file mode 100644
index 0000000000..31ebb1fc30
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c8dac77aedb5609a57ce5ee03d97f7e3c28fa0e94f2563e99d82f306cf6530e5.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\nDELETE FROM \"PdfHighlightAnchor\" WHERE \"documentId\" = $1;\n",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "c8dac77aedb5609a57ce5ee03d97f7e3c28fa0e94f2563e99d82f306cf6530e5"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476.json b/rust/cloud-storage/chat/.sqlx/query-c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476.json
new file mode 100644
index 0000000000..1216b39a3c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'project'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" = $3\n )\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c922ac06eee1109006d3bf676ab8b8341b10cfee0b725409138cfdde038712aa.json b/rust/cloud-storage/chat/.sqlx/query-c922ac06eee1109006d3bf676ab8b8341b10cfee0b725409138cfdde038712aa.json
new file mode 100644
index 0000000000..29b18e9923
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c922ac06eee1109006d3bf676ab8b8341b10cfee0b725409138cfdde038712aa.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Thread\"\n SET \"deletedAt\" = NOW()\n WHERE id = $1 and \"deletedAt\" IS NULL\n RETURNING \"deletedAt\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "deletedAt",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "c922ac06eee1109006d3bf676ab8b8341b10cfee0b725409138cfdde038712aa"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-c9fce1ac31e4e4f9992809c650e85fe45f4dc1e66d4b5a846c734b308c74fa70.json b/rust/cloud-storage/chat/.sqlx/query-c9fce1ac31e4e4f9992809c650e85fe45f4dc1e66d4b5a846c734b308c74fa70.json
new file mode 100644
index 0000000000..4c2fb23429
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-c9fce1ac31e4e4f9992809c650e85fe45f4dc1e66d4b5a846c734b308c74fa70.json
@@ -0,0 +1,128 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id as \"document_id\",\n d.owner as \"owner\",\n d.name as \"document_name\",\n COALESCE(di.id, db.id) as \"document_version_id!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"createdAt\"::timestamptz as \"created_at\",\n d.\"updatedAt\"::timestamptz as \"updated_at\",\n d.\"fileType\" as \"file_type\",\n db.bom_parts as \"document_bom?\",\n di.modification_data as \"modification_data?\",\n d.\"projectId\" as \"project_id?\",\n p.name as \"project_name?\",\n di.sha as \"sha?\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n d.\"deletedAt\"::timestamptz as deleted_at\n FROM\n \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN LATERAL (\n SELECT\n i.id,\n i.sha,\n i.\"createdAt\",\n (\n SELECT\n imod.\"modificationData\"\n FROM\n \"DocumentInstanceModificationData\" imod\n WHERE\n imod.\"documentInstanceId\" = i.id\n ) as modification_data,\n i.\"updatedAt\"\n FROM\n \"DocumentInstance\" i\n WHERE\n i.\"documentId\" = d.id\n AND\n i.id = $2\n ) di ON true\n LEFT JOIN LATERAL (\n SELECT\n b.id,\n (\n SELECT\n json_agg(\n json_build_object(\n 'id', bp.id,\n 'sha', bp.sha,\n 'path', bp.path\n )\n )\n FROM\n \"BomPart\" bp\n WHERE\n bp.\"documentBomId\" = b.id\n ) as bom_parts\n FROM\n \"DocumentBom\" b\n WHERE\n b.\"documentId\" = d.id\n AND\n b.id = $2\n ) db ON d.\"fileType\" = 'docx'\n LEFT JOIN LATERAL (\n SELECT\n p.name\n FROM \"Project\" p\n WHERE p.id = d.\"projectId\"\n ) p ON d.\"projectId\" IS NOT NULL\n WHERE\n d.id = $1\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "document_version_id!",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 4,
+ "name": "branched_from_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "branched_from_version_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 6,
+ "name": "document_family_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 7,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 10,
+ "name": "document_bom?",
+ "type_info": "Json"
+ },
+ {
+ "ordinal": 11,
+ "name": "modification_data?",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 12,
+ "name": "project_id?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 13,
+ "name": "project_name?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 14,
+ "name": "sha?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 15,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 16,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ null,
+ true,
+ true,
+ true,
+ null,
+ null,
+ true,
+ null,
+ null,
+ true,
+ false,
+ false,
+ false,
+ null
+ ]
+ },
+ "hash": "c9fce1ac31e4e4f9992809c650e85fe45f4dc1e66d4b5a846c734b308c74fa70"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580.json b/rust/cloud-storage/chat/.sqlx/query-cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580.json
new file mode 100644
index 0000000000..ddcaf87146
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT cp.channel_id::text FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "channel_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-cad30765c51a8985f2d1235bcefaea7994099835b4b10ad06d9bb36f18e594da.json b/rust/cloud-storage/chat/.sqlx/query-cad30765c51a8985f2d1235bcefaea7994099835b4b10ad06d9bb36f18e594da.json
new file mode 100644
index 0000000000..6daf9e6fe2
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-cad30765c51a8985f2d1235bcefaea7994099835b4b10ad06d9bb36f18e594da.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"ChatAttachment\" (\"attachmentType\", \"attachmentId\", \"chatId\")\n VALUES ($1, $2, $3)\n RETURNING id;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "cad30765c51a8985f2d1235bcefaea7994099835b4b10ad06d9bb36f18e594da"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-cb37182733a71e6939495eb29d0ab6544c02094129fc9c7e921dd5280d78047a.json b/rust/cloud-storage/chat/.sqlx/query-cb37182733a71e6939495eb29d0ab6544c02094129fc9c7e921dd5280d78047a.json
new file mode 100644
index 0000000000..6213530d30
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-cb37182733a71e6939495eb29d0ab6544c02094129fc9c7e921dd5280d78047a.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.\"content\"\n FROM \"DocumentProcessResult\" d\n JOIN \"JobToDocumentProcessResult\" j ON d.id = j.\"documentProcessResultId\"\n WHERE j.\"jobId\" = $1 AND d.\"documentId\" = $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "content",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "cb37182733a71e6939495eb29d0ab6544c02094129fc9c7e921dd5280d78047a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-cbe989d8428852cbc096f4f28398b5c5352f1fc2369890ab77d90fb643b8d4c4.json b/rust/cloud-storage/chat/.sqlx/query-cbe989d8428852cbc096f4f28398b5c5352f1fc2369890ab77d90fb643b8d4c4.json
new file mode 100644
index 0000000000..8ab1279285
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-cbe989d8428852cbc096f4f28398b5c5352f1fc2369890ab77d90fb643b8d4c4.json
@@ -0,0 +1,64 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id,\n message_id as \"message_id: Uuid\",\n channel_id as \"channel_id: Uuid\",\n entity_type,\n entity_id,\n width,\n height,\n created_at\n FROM comms_attachments\n WHERE channel_id = $1\n ORDER BY created_at ASC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "message_id: Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "channel_id: Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 3,
+ "name": "entity_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 4,
+ "name": "entity_id",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 5,
+ "name": "width",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 6,
+ "name": "height",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 7,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true,
+ false
+ ]
+ },
+ "hash": "cbe989d8428852cbc096f4f28398b5c5352f1fc2369890ab77d90fb643b8d4c4"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-cc388518e9c137d9c849d408300cd2d4687d41e8fd09e04edf0f4861d48a3e62.json b/rust/cloud-storage/chat/.sqlx/query-cc388518e9c137d9c849d408300cd2d4687d41e8fd09e04edf0f4861d48a3e62.json
new file mode 100644
index 0000000000..81608c6bd3
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-cc388518e9c137d9c849d408300cd2d4687d41e8fd09e04edf0f4861d48a3e62.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Comment\"\n SET \"deletedAt\" = NOW()\n WHERE \"id\" = $1 AND \"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Int8"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "cc388518e9c137d9c849d408300cd2d4687d41e8fd09e04edf0f4861d48a3e62"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-cc55e105bd5f6916a779d57ed7e4379c7fdaca83a33355842cf8b0b29d25a517.json b/rust/cloud-storage/chat/.sqlx/query-cc55e105bd5f6916a779d57ed7e4379c7fdaca83a33355842cf8b0b29d25a517.json
new file mode 100644
index 0000000000..6c7c3948d2
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-cc55e105bd5f6916a779d57ed7e4379c7fdaca83a33355842cf8b0b29d25a517.json
@@ -0,0 +1,127 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id as \"document_id\",\n d.owner as \"owner\",\n COALESCE(db.id, di.id) as \"document_version_id!\",\n d.name as \"document_name\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"createdAt\"::timestamptz as \"created_at\",\n d.\"updatedAt\"::timestamptz as \"updated_at\",\n d.\"fileType\" as \"file_type\",\n db.bom_parts as \"document_bom?\",\n di.modification_data as \"modification_data?\",\n d.\"projectId\" as \"project_id\",\n p.name as \"project_name?\",\n di.sha as \"sha?\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM\n \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN LATERAL (\n SELECT\n i.id,\n i.sha,\n i.\"createdAt\",\n (\n SELECT\n imod.\"modificationData\"\n FROM\n \"DocumentInstanceModificationData\" imod\n WHERE\n imod.\"documentInstanceId\" = i.id\n ) as modification_data,\n i.\"updatedAt\"\n FROM\n \"DocumentInstance\" i\n WHERE\n i.\"documentId\" = d.id\n ORDER BY\n i.\"createdAt\" DESC\n LIMIT 1\n ) di ON true\n LEFT JOIN LATERAL (\n SELECT\n b.id,\n (\n SELECT\n json_agg(\n json_build_object(\n 'id', bp.id,\n 'sha', bp.sha,\n 'path', bp.path\n )\n )\n FROM\n \"BomPart\" bp\n WHERE\n bp.\"documentBomId\" = b.id\n ) as bom_parts\n FROM\n \"DocumentBom\" b\n WHERE\n b.\"documentId\" = d.id\n ORDER BY\n b.\"createdAt\" DESC\n LIMIT 1\n ) db ON d.\"fileType\" = 'docx'\n LEFT JOIN LATERAL (\n SELECT\n p.name\n FROM \"Project\" p\n WHERE p.id = d.\"projectId\"\n ) p ON d.\"projectId\" IS NOT NULL\n WHERE\n d.id = $1\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_version_id!",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 3,
+ "name": "document_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "branched_from_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "branched_from_version_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 6,
+ "name": "document_family_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 7,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 10,
+ "name": "document_bom?",
+ "type_info": "Json"
+ },
+ {
+ "ordinal": 11,
+ "name": "modification_data?",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 12,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 13,
+ "name": "project_name?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 14,
+ "name": "sha?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 15,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 16,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ null,
+ false,
+ true,
+ true,
+ true,
+ null,
+ null,
+ true,
+ null,
+ null,
+ true,
+ false,
+ false,
+ false,
+ null
+ ]
+ },
+ "hash": "cc55e105bd5f6916a779d57ed7e4379c7fdaca83a33355842cf8b0b29d25a517"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-cc7926b302ce23fa4e727b6986ec14253589d794894668f4eaf078ec8a5d4ca8.json b/rust/cloud-storage/chat/.sqlx/query-cc7926b302ce23fa4e727b6986ec14253589d794894668f4eaf078ec8a5d4ca8.json
new file mode 100644
index 0000000000..5ac7889fce
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-cc7926b302ce23fa4e727b6986ec14253589d794894668f4eaf078ec8a5d4ca8.json
@@ -0,0 +1,40 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n phr.top,\n phr.left,\n phr.width,\n phr.height\n FROM \"PdfHighlightRect\" phr \n WHERE phr.\"pdfHighlightAnchorId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "top",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 1,
+ "name": "left",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 2,
+ "name": "width",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 3,
+ "name": "height",
+ "type_info": "Float8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "cc7926b302ce23fa4e727b6986ec14253589d794894668f4eaf078ec8a5d4ca8"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ccc0496ce34f87e79360098eba2eeee80a42eab9217c57dfde6a972b458e609e.json b/rust/cloud-storage/chat/.sqlx/query-ccc0496ce34f87e79360098eba2eeee80a42eab9217c57dfde6a972b458e609e.json
new file mode 100644
index 0000000000..9190908373
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ccc0496ce34f87e79360098eba2eeee80a42eab9217c57dfde6a972b458e609e.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM comms_entity_mentions\n WHERE entity_id = ANY($1) AND source_entity_id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "ccc0496ce34f87e79360098eba2eeee80a42eab9217c57dfde6a972b458e609e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-cd0fcad5f9177a5b57fa20cdf5996f4ea4bd008a19afc916a1147fca76b6d5b4.json b/rust/cloud-storage/chat/.sqlx/query-cd0fcad5f9177a5b57fa20cdf5996f4ea4bd008a19afc916a1147fca76b6d5b4.json
new file mode 100644
index 0000000000..488a2cccd5
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-cd0fcad5f9177a5b57fa20cdf5996f4ea4bd008a19afc916a1147fca76b6d5b4.json
@@ -0,0 +1,42 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"DocumentInstance\" (\"documentId\", \"sha\", \"createdAt\", \"updatedAt\")\n VALUES ($1, $2, $3, $3)\n RETURNING id, sha, \"createdAt\"::timestamptz as created_at, \"updatedAt\"::timestamptz as updated_at;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "sha",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 3,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Timestamp"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ null,
+ null
+ ]
+ },
+ "hash": "cd0fcad5f9177a5b57fa20cdf5996f4ea4bd008a19afc916a1147fca76b6d5b4"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-cd2334cf312dee1e9b230cce0d7b26999ba3ac23f89c8882c144d4c9a657e235.json b/rust/cloud-storage/chat/.sqlx/query-cd2334cf312dee1e9b230cce0d7b26999ba3ac23f89c8882c144d4c9a657e235.json
new file mode 100644
index 0000000000..945fd5a6db
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-cd2334cf312dee1e9b230cce0d7b26999ba3ac23f89c8882c144d4c9a657e235.json
@@ -0,0 +1,35 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH requested_ids AS (\n SELECT UNNEST($2::text[]) as id\n ),\n user_links AS (\n SELECT id as link_id\n FROM email_links\n WHERE macro_id = $1\n ),\n users_found AS (\n SELECT\n u.id as user_profile_id,\n mui.first_name as mui_first_name,\n mui.last_name as mui_last_name\n FROM requested_ids req\n JOIN \"User\" u ON u.id = req.id\n LEFT JOIN macro_user_info mui ON u.macro_user_id = mui.macro_user_id\n ),\n contacts_requested AS (\n SELECT\n req.id as user_profile_id,\n ec.name as contact_name\n FROM requested_ids req\n CROSS JOIN user_links li\n JOIN email_contacts ec\n ON ec.link_id = li.link_id\n AND ec.email_address = REPLACE(req.id, 'macro|', '')\n AND ec.name IS NOT NULL\n )\n SELECT DISTINCT ON (user_profile_id)\n user_profile_id as \"user_profile_id!\",\n CASE\n -- If Macro has either first or last name (non-\"N/A\"), use Macro for BOTH fields.\n WHEN NULLIF(mui_first_name, 'N/A') IS NOT NULL\n OR NULLIF(mui_last_name, 'N/A') IS NOT NULL\n THEN NULLIF(mui_first_name, 'N/A')\n -- Otherwise fall back to email contact name parsing.\n ELSE SPLIT_PART(contact_name, ' ', 1)\n END as \"first_name\",\n CASE\n -- If Macro has either first or last name (non-\"N/A\"), use Macro for BOTH fields.\n WHEN NULLIF(mui_first_name, 'N/A') IS NOT NULL\n OR NULLIF(mui_last_name, 'N/A') IS NOT NULL\n THEN NULLIF(mui_last_name, 'N/A')\n -- Otherwise fall back to email contact name parsing.\n ELSE CASE\n WHEN POSITION(' ' IN contact_name) > 0\n THEN NULLIF(TRIM(SUBSTRING(contact_name FROM POSITION(' ' IN contact_name) + 1)), '')\n ELSE NULL\n END\n END as \"last_name\"\n FROM (\n -- Users in User table with contact fallback (in case user hasn't set name in Macro)\n SELECT\n uf.user_profile_id,\n uf.mui_first_name,\n uf.mui_last_name,\n cr.contact_name\n FROM users_found uf\n LEFT JOIN contacts_requested cr ON cr.user_profile_id = uf.user_profile_id\n\n UNION ALL\n\n -- People only in email_contacts (haven't joined Macro yet)\n SELECT\n cr.user_profile_id,\n NULL::text as mui_first_name,\n NULL::text as mui_last_name,\n cr.contact_name\n FROM contacts_requested cr\n WHERE NOT EXISTS (\n SELECT 1\n FROM users_found uf\n WHERE uf.user_profile_id = cr.user_profile_id\n )\n ) combined\n ORDER BY user_profile_id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_profile_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "first_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "last_name",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "cd2334cf312dee1e9b230cce0d7b26999ba3ac23f89c8882c144d4c9a657e235"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-cd39c593bdca8f628570365a8aa6787d34173da3b114c61b2cddc69b7d197819.json b/rust/cloud-storage/chat/.sqlx/query-cd39c593bdca8f628570365a8aa6787d34173da3b114c61b2cddc69b7d197819.json
new file mode 100644
index 0000000000..a140edbf63
--- /dev/null
+++ b/rust/cloud-storage/chat/.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/chat/.sqlx/query-cd3ae40ade95369aeeffcd17cd99301e0c36f4d600917c7573137e15688b1f68.json b/rust/cloud-storage/chat/.sqlx/query-cd3ae40ade95369aeeffcd17cd99301e0c36f4d600917c7573137e15688b1f68.json
new file mode 100644
index 0000000000..fbeee80ef8
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-cd3ae40ade95369aeeffcd17cd99301e0c36f4d600917c7573137e15688b1f68.json
@@ -0,0 +1,26 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"PdfHighlightRect\" (\n \"top\", \"left\", \"width\", \"height\", \"pdfHighlightAnchorId\"\n )\n VALUES ($1, $2, $3, $4, $5)\n RETURNING id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Float8",
+ "Float8",
+ "Float8",
+ "Float8",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "cd3ae40ade95369aeeffcd17cd99301e0c36f4d600917c7573137e15688b1f68"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-cd98a8eb1ebdeb28951774b9daf0a9f05967d0adb106e93608b3b5a64adae02a.json b/rust/cloud-storage/chat/.sqlx/query-cd98a8eb1ebdeb28951774b9daf0a9f05967d0adb106e93608b3b5a64adae02a.json
new file mode 100644
index 0000000000..e7498491d6
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-cd98a8eb1ebdeb28951774b9daf0a9f05967d0adb106e93608b3b5a64adae02a.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n bp.sha\n FROM \"BomPart\" bp\n WHERE bp.\"documentBomId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "sha",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "cd98a8eb1ebdeb28951774b9daf0a9f05967d0adb106e93608b3b5a64adae02a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ce218da82b99295aed3a609a21f5feaf304a4d50bbabe9151bb0bbaef7bcef16.json b/rust/cloud-storage/chat/.sqlx/query-ce218da82b99295aed3a609a21f5feaf304a4d50bbabe9151bb0bbaef7bcef16.json
new file mode 100644
index 0000000000..1331a9c60a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ce218da82b99295aed3a609a21f5feaf304a4d50bbabe9151bb0bbaef7bcef16.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n entity_type,\n entity_id\n FROM\n comms_entity_mentions\n WHERE\n source_entity_id = $1 AND source_entity_type = 'message'\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "entity_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 1,
+ "name": "entity_id",
+ "type_info": "Varchar"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "ce218da82b99295aed3a609a21f5feaf304a4d50bbabe9151bb0bbaef7bcef16"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-cef69d1963846d65ce695cbc2d5a97a325f4081b69a3b8a7d1a481ed69f86bf0.json b/rust/cloud-storage/chat/.sqlx/query-cef69d1963846d65ce695cbc2d5a97a325f4081b69a3b8a7d1a481ed69f86bf0.json
new file mode 100644
index 0000000000..eaf11d058d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-cef69d1963846d65ce695cbc2d5a97a325f4081b69a3b8a7d1a481ed69f86bf0.json
@@ -0,0 +1,78 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Comment\" c\n SET \"text\" = $1, \"metadata\" = $2, \"updatedAt\" = NOW()\n WHERE \"id\" = $3 AND \"deletedAt\" IS NULL\n RETURNING \n c.id as comment_id, \n c.\"threadId\" as thread_id, \n c.owner, \n c.sender, \n c.text, \n c.metadata, \n c.\"createdAt\"::timestamptz as created_at, \n c.\"updatedAt\"::timestamptz as updated_at, \n c.\"deletedAt\"::timestamptz as deleted_at, \n c.order\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "comment_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "sender",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "text",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "metadata",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "order",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Jsonb",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ false,
+ true,
+ null,
+ null,
+ null,
+ true
+ ]
+ },
+ "hash": "cef69d1963846d65ce695cbc2d5a97a325f4081b69a3b8a7d1a481ed69f86bf0"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-cf095b171e7a5b06335671a0ffe392c7e93978451b4ae208a23ab27c3b10c1b7.json b/rust/cloud-storage/chat/.sqlx/query-cf095b171e7a5b06335671a0ffe392c7e93978451b4ae208a23ab27c3b10c1b7.json
new file mode 100644
index 0000000000..c4c3783762
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-cf095b171e7a5b06335671a0ffe392c7e93978451b4ae208a23ab27c3b10c1b7.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Chat\" SET \"tokenCount\" = $1\n WHERE id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "cf095b171e7a5b06335671a0ffe392c7e93978451b4ae208a23ab27c3b10c1b7"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-cf1161cb3ef4f573dd8e15092ebedc6cfa7e0f8b9f8b3c3a698991d37860c76f.json b/rust/cloud-storage/chat/.sqlx/query-cf1161cb3ef4f573dd8e15092ebedc6cfa7e0f8b9f8b3c3a698991d37860c76f.json
new file mode 100644
index 0000000000..ca358e80ad
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-cf1161cb3ef4f573dd8e15092ebedc6cfa7e0f8b9f8b3c3a698991d37860c76f.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.name as \"name?\",\n c.owner_id\n FROM\n \"comms_channels\" c\n WHERE\n c.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "name?",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ true,
+ false
+ ]
+ },
+ "hash": "cf1161cb3ef4f573dd8e15092ebedc6cfa7e0f8b9f8b3c3a698991d37860c76f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-cfbec090ff3b62415ec0c215aa52bdafe162fb8c8fd217a8fcaf613e39525b0f.json b/rust/cloud-storage/chat/.sqlx/query-cfbec090ff3b62415ec0c215aa52bdafe162fb8c8fd217a8fcaf613e39525b0f.json
new file mode 100644
index 0000000000..e17bd1ee56
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-cfbec090ff3b62415ec0c215aa52bdafe162fb8c8fd217a8fcaf613e39525b0f.json
@@ -0,0 +1,69 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id as \"document_id!\",\n d.name as \"document_name!\",\n d.\"fileType\" as file_type,\n d.owner as \"owner!\",\n d.\"updatedAt\"::timestamptz as \"updated_at\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n CASE \n WHEN dt.sub_type = 'task' \n AND ep_status.values->'value' ? $2\n THEN true \n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL \n END as \"is_completed\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status \n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id \n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $3\n WHERE\n d.\"id\" = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "document_name!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "owner!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 6,
+ "name": "is_completed",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ true,
+ false,
+ null,
+ true,
+ null
+ ]
+ },
+ "hash": "cfbec090ff3b62415ec0c215aa52bdafe162fb8c8fd217a8fcaf613e39525b0f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d0150fe28f8fe11bbc69c475a6fc3277a1ced2c563a2e2bc98a742ef71da40fc.json b/rust/cloud-storage/chat/.sqlx/query-d0150fe28f8fe11bbc69c475a6fc3277a1ced2c563a2e2bc98a742ef71da40fc.json
new file mode 100644
index 0000000000..50a8a3cc0d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d0150fe28f8fe11bbc69c475a6fc3277a1ced2c563a2e2bc98a742ef71da40fc.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n sp.id as id\n FROM\n \"ChatPermission\" cp\n JOIN \"SharePermission\" sp ON cp.\"sharePermissionId\" = sp.id\n WHERE\n cp.\"chatId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "d0150fe28f8fe11bbc69c475a6fc3277a1ced2c563a2e2bc98a742ef71da40fc"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d0de0e065ad2c62601b5d401357d295c602e8ea01dc164bd95c7ed30a7726a54.json b/rust/cloud-storage/chat/.sqlx/query-d0de0e065ad2c62601b5d401357d295c602e8ea01dc164bd95c7ed30a7726a54.json
new file mode 100644
index 0000000000..3c5e0b3b93
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d0de0e065ad2c62601b5d401357d295c602e8ea01dc164bd95c7ed30a7726a54.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"hasOnboardingDocuments\"::boolean\n FROM \"User\"\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "hasOnboardingDocuments",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "d0de0e065ad2c62601b5d401357d295c602e8ea01dc164bd95c7ed30a7726a54"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d0e25ec078af21bc5a7771937ed5bfc9d190e4154c906fae3e67846c308332dd.json b/rust/cloud-storage/chat/.sqlx/query-d0e25ec078af21bc5a7771937ed5bfc9d190e4154c906fae3e67846c308332dd.json
new file mode 100644
index 0000000000..a6b6058037
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d0e25ec078af21bc5a7771937ed5bfc9d190e4154c906fae3e67846c308332dd.json
@@ -0,0 +1,38 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"Chat\" (\"userId\", name, model, \"projectId\", \"isPersistent\")\n VALUES ($1, $2, $3, $4, $5)\n RETURNING id, \"createdAt\"::timestamptz as created_at, \"updatedAt\"::timestamptz as updated_at;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 2,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Text",
+ "Text",
+ "Bool"
+ ]
+ },
+ "nullable": [
+ false,
+ null,
+ null
+ ]
+ },
+ "hash": "d0e25ec078af21bc5a7771937ed5bfc9d190e4154c906fae3e67846c308332dd"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d0e2ccb572c57cb856c6d68e739aa5cf85994ae8af80af65ade5f879f837cc6a.json b/rust/cloud-storage/chat/.sqlx/query-d0e2ccb572c57cb856c6d68e739aa5cf85994ae8af80af65ade5f879f837cc6a.json
new file mode 100644
index 0000000000..de8322f023
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d0e2ccb572c57cb856c6d68e739aa5cf85994ae8af80af65ade5f879f837cc6a.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT content FROM \"DocumentText\" WHERE \"documentId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "content",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "d0e2ccb572c57cb856c6d68e739aa5cf85994ae8af80af65ade5f879f837cc6a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d0f5de1518cf48faa63380a71ff6633e40c9a0d9f8e87262e31fa218400752a7.json b/rust/cloud-storage/chat/.sqlx/query-d0f5de1518cf48faa63380a71ff6633e40c9a0d9f8e87262e31fa218400752a7.json
new file mode 100644
index 0000000000..90383258c6
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d0f5de1518cf48faa63380a71ff6633e40c9a0d9f8e87262e31fa218400752a7.json
@@ -0,0 +1,27 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"MacroPrompt\" (user_id, title, prompt, icon, color, required_docs)\n VALUES ($1, $2, $3, $4, $5, $6)\n RETURNING id;\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Text",
+ "Text",
+ "Text",
+ "Int4"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "d0f5de1518cf48faa63380a71ff6633e40c9a0d9f8e87262e31fa218400752a7"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d138759f663ddea66b623d88820383631011b1c3cbd5d36e137dbd0c5442f456.json b/rust/cloud-storage/chat/.sqlx/query-d138759f663ddea66b623d88820383631011b1c3cbd5d36e137dbd0c5442f456.json
new file mode 100644
index 0000000000..f864dfe1a1
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d138759f663ddea66b623d88820383631011b1c3cbd5d36e137dbd0c5442f456.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM\n in_progress_email_link\n WHERE\n created_at < $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Timestamp"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "d138759f663ddea66b623d88820383631011b1c3cbd5d36e137dbd0c5442f456"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d162c039601a7fe5f829eeaedb6cd324c875cdc9e74287873ec41a9fd495e696.json b/rust/cloud-storage/chat/.sqlx/query-d162c039601a7fe5f829eeaedb6cd324c875cdc9e74287873ec41a9fd495e696.json
new file mode 100644
index 0000000000..a8872a64c6
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d162c039601a7fe5f829eeaedb6cd324c875cdc9e74287873ec41a9fd495e696.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"OrganizationRetentionPolicy\" (organization_id, retention_days)\n VALUES ($1, $2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Int4",
+ "Int4"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "d162c039601a7fe5f829eeaedb6cd324c875cdc9e74287873ec41a9fd495e696"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d3f415b0ff9b73a69fae932e99e3a2b24145f15e940d79721f00b76864fee3da.json b/rust/cloud-storage/chat/.sqlx/query-d1d1519e0bdb30ddcbaa6d602bc04617613bb21df0e7728150e74b4125d28a59.json
similarity index 51%
rename from rust/cloud-storage/chat/.sqlx/query-d3f415b0ff9b73a69fae932e99e3a2b24145f15e940d79721f00b76864fee3da.json
rename to rust/cloud-storage/chat/.sqlx/query-d1d1519e0bdb30ddcbaa6d602bc04617613bb21df0e7728150e74b4125d28a59.json
index 9bfa5673f3..12ed677b43 100644
--- a/rust/cloud-storage/chat/.sqlx/query-d3f415b0ff9b73a69fae932e99e3a2b24145f15e940d79721f00b76864fee3da.json
+++ b/rust/cloud-storage/chat/.sqlx/query-d1d1519e0bdb30ddcbaa6d602bc04617613bb21df0e7728150e74b4125d28a59.json
@@ -1,11 +1,10 @@
{
"db_name": "PostgreSQL",
- "query": "\n INSERT INTO \"UserItemAccess\" (\n \"id\",\n \"user_id\",\n \"item_id\",\n \"item_type\",\n \"access_level\",\n \"created_at\",\n \"updated_at\"\n )\n VALUES ($1, $2, $3, 'chat', $4, NOW(), NOW())\n ",
+ "query": "\n INSERT INTO \"ChannelSharePermission\" (\"share_permission_id\", \"channel_id\", \"access_level\")\n VALUES ($1, $2, $3)\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
- "Uuid",
"Text",
"Text",
{
@@ -25,5 +24,5 @@
},
"nullable": []
},
- "hash": "d3f415b0ff9b73a69fae932e99e3a2b24145f15e940d79721f00b76864fee3da"
+ "hash": "d1d1519e0bdb30ddcbaa6d602bc04617613bb21df0e7728150e74b4125d28a59"
}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d20bc5b5dfecf0a2ef4b7d77b9090ad28584cd0a1fd24460096b6a5097a870ac.json b/rust/cloud-storage/chat/.sqlx/query-d20bc5b5dfecf0a2ef4b7d77b9090ad28584cd0a1fd24460096b6a5097a870ac.json
new file mode 100644
index 0000000000..f3780614e0
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d20bc5b5dfecf0a2ef4b7d77b9090ad28584cd0a1fd24460096b6a5097a870ac.json
@@ -0,0 +1,97 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n un.user_id as owner_id,\n un.notification_id,\n n.event_item_id,\n n.event_item_type,\n un.sent,\n un.done,\n un.created_at::timestamptz as \"created_at!\",\n un.seen_at::timestamptz as viewed_at,\n un.created_at::timestamptz as \"updated_at!\",\n un.deleted_at::timestamptz,\n n.metadata as \"notification_metadata: serde_json::Value\",\n n.notification_event_type as notification_event_type,\n n.sender_id as sender_id\n FROM user_notification un\n JOIN notification n ON n.id = un.notification_id\n WHERE un.user_id = $1\n AND un.deleted_at IS NULL\n AND un.done = false\n AND (($3::timestamptz IS NULL)\n OR (un.created_at, un.notification_id) < ($3, $4))\n ORDER BY un.created_at DESC, un.notification_id DESC\n LIMIT $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "owner_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "event_item_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "event_item_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "sent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 5,
+ "name": "done",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "notification_metadata: serde_json::Value",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 11,
+ "name": "notification_event_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 12,
+ "name": "sender_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Int8",
+ "Timestamptz",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ null,
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "d20bc5b5dfecf0a2ef4b7d77b9090ad28584cd0a1fd24460096b6a5097a870ac"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d28ddb488fda49824849b20068fcd7a04e53c34dffafdfbe30cd14bee456010a.json b/rust/cloud-storage/chat/.sqlx/query-d28ddb488fda49824849b20068fcd7a04e53c34dffafdfbe30cd14bee456010a.json
new file mode 100644
index 0000000000..2ba85cd921
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d28ddb488fda49824849b20068fcd7a04e53c34dffafdfbe30cd14bee456010a.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT DISTINCT(m.sender_id) as id\n FROM comms_channel_participants cp\n JOIN comms_channels c ON c.id = cp.channel_id\n JOIN comms_messages m ON m.channel_id = c.id \n WHERE (m.id = $1 OR m.thread_id = $1) AND cp.left_at IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "d28ddb488fda49824849b20068fcd7a04e53c34dffafdfbe30cd14bee456010a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d31d574569460a9137ba589cfb552f811f014cd6ef1d0b3f9bea3074a478f785.json b/rust/cloud-storage/chat/.sqlx/query-d31d574569460a9137ba589cfb552f811f014cd6ef1d0b3f9bea3074a478f785.json
new file mode 100644
index 0000000000..6367646aaf
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d31d574569460a9137ba589cfb552f811f014cd6ef1d0b3f9bea3074a478f785.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT 1\n FROM \"Thread\" t\n WHERE t.id = $1 AND t.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "?column?",
+ "type_info": "Int4"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "d31d574569460a9137ba589cfb552f811f014cd6ef1d0b3f9bea3074a478f785"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d4fc8cb85acc88cc8c342220506921a23d5de6a44ed9e4af285f49f4e44d174f.json b/rust/cloud-storage/chat/.sqlx/query-d4fc8cb85acc88cc8c342220506921a23d5de6a44ed9e4af285f49f4e44d174f.json
new file mode 100644
index 0000000000..092343da7f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d4fc8cb85acc88cc8c342220506921a23d5de6a44ed9e4af285f49f4e44d174f.json
@@ -0,0 +1,46 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n p.id,\n p.\"userId\" as user_id,\n p.\"name\" as name,\n p.\"parentId\" as parent_id,\n p.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Project\" p\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": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "parent_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ null
+ ]
+ },
+ "hash": "d4fc8cb85acc88cc8c342220506921a23d5de6a44ed9e4af285f49f4e44d174f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d504950303eab672518c9c99ee3df3044ca299f2a677c812b11592fc9b2fe6cd.json b/rust/cloud-storage/chat/.sqlx/query-d504950303eab672518c9c99ee3df3044ca299f2a677c812b11592fc9b2fe6cd.json
new file mode 100644
index 0000000000..b44ec41281
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d504950303eab672518c9c99ee3df3044ca299f2a677c812b11592fc9b2fe6cd.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.name\n FROM\n \"Chat\" c\n WHERE\n c.id = $1 AND c.\"deletedAt\" IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "name",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "d504950303eab672518c9c99ee3df3044ca299f2a677c812b11592fc9b2fe6cd"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d5c0095efa9c8162d511f1f9b1b2d44bfd717c8761fcb3c8561cd6c292b1eea4.json b/rust/cloud-storage/chat/.sqlx/query-d5c0095efa9c8162d511f1f9b1b2d44bfd717c8761fcb3c8561cd6c292b1eea4.json
new file mode 100644
index 0000000000..df9d45c1ad
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d5c0095efa9c8162d511f1f9b1b2d44bfd717c8761fcb3c8561cd6c292b1eea4.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"InstructionsDocuments\" (\"documentId\", \"userId\")\n VALUES ($1, $2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "d5c0095efa9c8162d511f1f9b1b2d44bfd717c8761fcb3c8561cd6c292b1eea4"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-d5f7d33eed11e9b58ca5b830b806700d28c3d345b03bddf1e5a290f84072571d.json b/rust/cloud-storage/chat/.sqlx/query-d5f7d33eed11e9b58ca5b830b806700d28c3d345b03bddf1e5a290f84072571d.json
similarity index 100%
rename from rust/cloud-storage/macro_db_client/.sqlx/query-d5f7d33eed11e9b58ca5b830b806700d28c3d345b03bddf1e5a290f84072571d.json
rename to rust/cloud-storage/chat/.sqlx/query-d5f7d33eed11e9b58ca5b830b806700d28c3d345b03bddf1e5a290f84072571d.json
diff --git a/rust/cloud-storage/chat/.sqlx/query-d5fbd2557b6759572b20117681fac9c4d0b723c7a7abfa0fd92ae362ea32b88f.json b/rust/cloud-storage/chat/.sqlx/query-d5fbd2557b6759572b20117681fac9c4d0b723c7a7abfa0fd92ae362ea32b88f.json
new file mode 100644
index 0000000000..bbc3e3d461
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d5fbd2557b6759572b20117681fac9c4d0b723c7a7abfa0fd92ae362ea32b88f.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"is_verified\"\n FROM \"macro_user_email_verification\"\n WHERE \"email\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "is_verified",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "d5fbd2557b6759572b20117681fac9c4d0b723c7a7abfa0fd92ae362ea32b88f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d6b6e32ff0004295738c15f2cf449cf2edec9087e56452c7078c497fcbb90422.json b/rust/cloud-storage/chat/.sqlx/query-d6b6e32ff0004295738c15f2cf449cf2edec9087e56452c7078c497fcbb90422.json
new file mode 100644
index 0000000000..de1b867bcf
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d6b6e32ff0004295738c15f2cf449cf2edec9087e56452c7078c497fcbb90422.json
@@ -0,0 +1,69 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id,\n email,\n team_id,\n team_role as \"team_role!: TeamRole\",\n invited_by,\n created_at as \"created_at!: chrono::DateTime<chrono::Utc>\",\n last_sent_at as \"last_sent_at!: chrono::DateTime<chrono::Utc>\"\n FROM team_invite\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "email",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "team_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 3,
+ "name": "team_role!: TeamRole",
+ "type_info": {
+ "Custom": {
+ "name": "team_role",
+ "kind": {
+ "Enum": [
+ "member",
+ "admin",
+ "owner"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 4,
+ "name": "invited_by",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "created_at!: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 6,
+ "name": "last_sent_at!: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "d6b6e32ff0004295738c15f2cf449cf2edec9087e56452c7078c497fcbb90422"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d6e62d780e55c6597e725a12a3785ba2c222905943458d205112e1e064a0bcc9.json b/rust/cloud-storage/chat/.sqlx/query-d6e62d780e55c6597e725a12a3785ba2c222905943458d205112e1e064a0bcc9.json
new file mode 100644
index 0000000000..c6522e433f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d6e62d780e55c6597e725a12a3785ba2c222905943458d205112e1e064a0bcc9.json
@@ -0,0 +1,40 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n \"threadId\" as thread_id,\n \"sharePermissionId\" as share_permission_id,\n \"userId\" as user_id,\n \"projectId\" as project_id\n FROM \"EmailThreadPermission\"\n WHERE \"threadId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "thread_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "share_permission_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "project_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "d6e62d780e55c6597e725a12a3785ba2c222905943458d205112e1e064a0bcc9"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d792ba8c4730364e650045395d110e6acda592d3e27ecac39f93370bacccd7a7.json b/rust/cloud-storage/chat/.sqlx/query-d792ba8c4730364e650045395d110e6acda592d3e27ecac39f93370bacccd7a7.json
new file mode 100644
index 0000000000..fb99ecd6dc
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d792ba8c4730364e650045395d110e6acda592d3e27ecac39f93370bacccd7a7.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"allowListOnly\" as allow_list_only\n FROM \"Organization\"\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "allow_list_only",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int4"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "d792ba8c4730364e650045395d110e6acda592d3e27ecac39f93370bacccd7a7"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d7c799b9e8432474ef422195e5e17f6cd611c9845f2830ab6ded46a4d640d362.json b/rust/cloud-storage/chat/.sqlx/query-d7c799b9e8432474ef422195e5e17f6cd611c9845f2830ab6ded46a4d640d362.json
new file mode 100644
index 0000000000..819e90ee19
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d7c799b9e8432474ef422195e5e17f6cd611c9845f2830ab6ded46a4d640d362.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"id\"\n FROM \"User\"\n WHERE \"id\" = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "d7c799b9e8432474ef422195e5e17f6cd611c9845f2830ab6ded46a4d640d362"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d7f495dccb8ccbbb1852b75eb6f8c4886d163b9864ed3cdb0b52b95b4f8325f7.json b/rust/cloud-storage/chat/.sqlx/query-d7f495dccb8ccbbb1852b75eb6f8c4886d163b9864ed3cdb0b52b95b4f8325f7.json
new file mode 100644
index 0000000000..6a73801e19
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d7f495dccb8ccbbb1852b75eb6f8c4886d163b9864ed3cdb0b52b95b4f8325f7.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id\n FROM comms_channels\n WHERE channel_type = 'private'\n AND (\n (\n SELECT COUNT(*)\n FROM comms_channel_participants cp\n WHERE cp.channel_id = comms_channels.id\n AND cp.user_id = ANY($1)\n ) = CARDINALITY($1)\n AND (\n SELECT COUNT(*)\n FROM comms_channel_participants\n WHERE channel_id = comms_channels.id\n ) = CARDINALITY($1)\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "d7f495dccb8ccbbb1852b75eb6f8c4886d163b9864ed3cdb0b52b95b4f8325f7"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d81549c7156fb08cde5260f6196eb6a80bb82c9640845a835c6d32eea7e6dcad.json b/rust/cloud-storage/chat/.sqlx/query-d81549c7156fb08cde5260f6196eb6a80bb82c9640845a835c6d32eea7e6dcad.json
new file mode 100644
index 0000000000..a51efcbe83
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d81549c7156fb08cde5260f6196eb6a80bb82c9640845a835c6d32eea7e6dcad.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"ExperimentLog\"\n SET completed = true\n WHERE user_id = $1 AND experiment_id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "d81549c7156fb08cde5260f6196eb6a80bb82c9640845a835c6d32eea7e6dcad"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d85a61dc12daaeb6515164755b6b3b48822a19d72f4126e5be12bfa34aa22d0f.json b/rust/cloud-storage/chat/.sqlx/query-d85a61dc12daaeb6515164755b6b3b48822a19d72f4126e5be12bfa34aa22d0f.json
new file mode 100644
index 0000000000..1e2772ce54
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d85a61dc12daaeb6515164755b6b3b48822a19d72f4126e5be12bfa34aa22d0f.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id,\n name,\n owner_id\n FROM team\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "d85a61dc12daaeb6515164755b6b3b48822a19d72f4126e5be12bfa34aa22d0f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d8bd24cd40bf28ba54dcc3a846931d4e00fbc7854d8f315b87f70dfdc44cb901.json b/rust/cloud-storage/chat/.sqlx/query-d8bd24cd40bf28ba54dcc3a846931d4e00fbc7854d8f315b87f70dfdc44cb901.json
new file mode 100644
index 0000000000..2347731904
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d8bd24cd40bf28ba54dcc3a846931d4e00fbc7854d8f315b87f70dfdc44cb901.json
@@ -0,0 +1,17 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"Pin\" (\"userId\", \"pinnedItemId\", \"pinnedItemType\", \"pinIndex\", \"createdAt\", \"updatedAt\")\n VALUES ($1, $2, $3, $4, NOW(), NOW())\n ON CONFLICT (\"userId\", \"pinnedItemId\", \"pinnedItemType\") DO UPDATE\n SET \"updatedAt\" = NOW();\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Text",
+ "Int4"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "d8bd24cd40bf28ba54dcc3a846931d4e00fbc7854d8f315b87f70dfdc44cb901"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d970eeb5bb4aebc43674b6ad89fb00c04c18f94145346063a2b012c1104afa53.json b/rust/cloud-storage/chat/.sqlx/query-d970eeb5bb4aebc43674b6ad89fb00c04c18f94145346063a2b012c1104afa53.json
new file mode 100644
index 0000000000..0046c78ad0
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d970eeb5bb4aebc43674b6ad89fb00c04c18f94145346063a2b012c1104afa53.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT COUNT(*) as \"count\"\n FROM \"Pin\"\n WHERE \"userId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "count",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "d970eeb5bb4aebc43674b6ad89fb00c04c18f94145346063a2b012c1104afa53"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-d9b1cf736916e61816697e8fec5f803458408bf5d03a4bfe18351b0191a2f9e7.json b/rust/cloud-storage/chat/.sqlx/query-d9b1cf736916e61816697e8fec5f803458408bf5d03a4bfe18351b0191a2f9e7.json
new file mode 100644
index 0000000000..4b1f76efda
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-d9b1cf736916e61816697e8fec5f803458408bf5d03a4bfe18351b0191a2f9e7.json
@@ -0,0 +1,27 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO team_user (team_id, user_id, team_role)\n VALUES ($1, $2, $3)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ {
+ "Custom": {
+ "name": "team_role",
+ "kind": {
+ "Enum": [
+ "member",
+ "admin",
+ "owner"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "d9b1cf736916e61816697e8fec5f803458408bf5d03a4bfe18351b0191a2f9e7"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-da6586a61ad110e335c8b5a9c6c840cee4f1db25c7b9b4f5a1157ef655fe1575.json b/rust/cloud-storage/chat/.sqlx/query-da6586a61ad110e335c8b5a9c6c840cee4f1db25c7b9b4f5a1157ef655fe1575.json
new file mode 100644
index 0000000000..20e342f48c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-da6586a61ad110e335c8b5a9c6c840cee4f1db25c7b9b4f5a1157ef655fe1575.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"DocumentPermission\" (\"documentId\", \"sharePermissionId\")\n VALUES ($1, $2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "da6586a61ad110e335c8b5a9c6c840cee4f1db25c7b9b4f5a1157ef655fe1575"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-da98ce3985fbf5eaed5300bb94b3354c7b4bd005b9e5657a702bd39846ff0917.json b/rust/cloud-storage/chat/.sqlx/query-da98ce3985fbf5eaed5300bb94b3354c7b4bd005b9e5657a702bd39846ff0917.json
new file mode 100644
index 0000000000..3c55abed30
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-da98ce3985fbf5eaed5300bb94b3354c7b4bd005b9e5657a702bd39846ff0917.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO document_sub_type (document_id, sub_type) \n VALUES ($1, $2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "da98ce3985fbf5eaed5300bb94b3354c7b4bd005b9e5657a702bd39846ff0917"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-dae0d3d0cdf09f727a8b7c3ecc9f3ae64ea91023d356c47232736672cd1ba5ec.json b/rust/cloud-storage/chat/.sqlx/query-dae0d3d0cdf09f727a8b7c3ecc9f3ae64ea91023d356c47232736672cd1ba5ec.json
new file mode 100644
index 0000000000..c2eff32a5e
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-dae0d3d0cdf09f727a8b7c3ecc9f3ae64ea91023d356c47232736672cd1ba5ec.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"BlockedEmail\" (email)\n SELECT email FROM unnest($1::text[]) AS email\n ON CONFLICT (email) DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "dae0d3d0cdf09f727a8b7c3ecc9f3ae64ea91023d356c47232736672cd1ba5ec"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-db297e24e3ed1e94c27121977d81813bbe4cde5e5b7bec42e424c72db0e27e73.json b/rust/cloud-storage/chat/.sqlx/query-db297e24e3ed1e94c27121977d81813bbe4cde5e5b7bec42e424c72db0e27e73.json
new file mode 100644
index 0000000000..d197caf563
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-db297e24e3ed1e94c27121977d81813bbe4cde5e5b7bec42e424c72db0e27e73.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id FROM user_notification_type_preference\n WHERE notification_event_type = $1 AND user_id = ANY($2)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "db297e24e3ed1e94c27121977d81813bbe4cde5e5b7bec42e424c72db0e27e73"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-dbd4d7f9b102138d0deed045cc058e4d56350e854923cabc4e7a6881a6de9be4.json b/rust/cloud-storage/chat/.sqlx/query-dbd4d7f9b102138d0deed045cc058e4d56350e854923cabc4e7a6881a6de9be4.json
new file mode 100644
index 0000000000..e9054feea5
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-dbd4d7f9b102138d0deed045cc058e4d56350e854923cabc4e7a6881a6de9be4.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access with source_ids (user, teams, channels)\n SELECT access_level::text FROM entity_access\n WHERE source_id = ANY(ARRAY(\n SELECT cp.channel_id::text FROM comms_channel_participants cp\n WHERE cp.user_id = $3 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $3\n UNION ALL\n SELECT $3\n ))\n AND entity_id = $1\n AND entity_type = 'chat'\n UNION ALL\n -- Source 2: Select the publicAccessLevel (which is already text).\n SELECT \"publicAccessLevel\" as access_level\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true AND \"publicAccessLevel\" IS NOT NULL AND id IN (\n SELECT \"sharePermissionId\" FROM \"ChatPermission\" WHERE \"chatId\" = $2\n )\n ) as all_levels\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "dbd4d7f9b102138d0deed045cc058e4d56350e854923cabc4e7a6881a6de9be4"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-dc09f10b914618441e30f7b1e12c60d684f1a422d5cd1de162b6f657c8ddfa98.json b/rust/cloud-storage/chat/.sqlx/query-dc09f10b914618441e30f7b1e12c60d684f1a422d5cd1de162b6f657c8ddfa98.json
new file mode 100644
index 0000000000..cbd759ab9a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-dc09f10b914618441e30f7b1e12c60d684f1a422d5cd1de162b6f657c8ddfa98.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT c.id, c.\"createdAt\" as created_at, c.\"updatedAt\" as updated_at\n FROM \"Comment\" c\n JOIN \"Thread\" t ON c.\"threadId\" = t.id\n WHERE t.\"documentId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "created_at",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 2,
+ "name": "updated_at",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "dc09f10b914618441e30f7b1e12c60d684f1a422d5cd1de162b6f657c8ddfa98"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-dc8363500c41804887b52ba9bab5fe1745738d475322e937d4553623a8294dc6.json b/rust/cloud-storage/chat/.sqlx/query-dc8363500c41804887b52ba9bab5fe1745738d475322e937d4553623a8294dc6.json
new file mode 100644
index 0000000000..5c5ea59ceb
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-dc8363500c41804887b52ba9bab5fe1745738d475322e937d4553623a8294dc6.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"ChatMessage\" (\"chatId\", \"createdAt\", \"updatedAt\", \"content\", \"role\", \"model\")\n SELECT $1, \"createdAt\", \"updatedAt\", \"content\", \"role\", \"model\"\n FROM \"ChatMessage\"\n WHERE \"chatId\"=$2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "dc8363500c41804887b52ba9bab5fe1745738d475322e937d4553623a8294dc6"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-de8dbe51fdbaeeb8ac8c8af8627c6838a4054a719ac6b54f6f7acb53a9353a3a.json b/rust/cloud-storage/chat/.sqlx/query-de8dbe51fdbaeeb8ac8c8af8627c6838a4054a719ac6b54f6f7acb53a9353a3a.json
new file mode 100644
index 0000000000..d798a0af26
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-de8dbe51fdbaeeb8ac8c8af8627c6838a4054a719ac6b54f6f7acb53a9353a3a.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Document\"\n SET \"deletedAt\" = NULL\n WHERE id = $1\n RETURNING owner as owner\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "owner",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "de8dbe51fdbaeeb8ac8c8af8627c6838a4054a719ac6b54f6f7acb53a9353a3a"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-df4f91b8a401ff941c7b57f910979e0ec39a507de612ff7887172062237f29ce.json b/rust/cloud-storage/chat/.sqlx/query-df4f91b8a401ff941c7b57f910979e0ec39a507de612ff7887172062237f29ce.json
new file mode 100644
index 0000000000..9f8f5e53d4
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-df4f91b8a401ff941c7b57f910979e0ec39a507de612ff7887172062237f29ce.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Project\" SET \"deletedAt\" = NULL WHERE id = ANY($1);\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "df4f91b8a401ff941c7b57f910979e0ec39a507de612ff7887172062237f29ce"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-df7d76d4a45e69846e1023646321e5e667acc5d95bb68f0e2e1d127cec0da0eb.json b/rust/cloud-storage/chat/.sqlx/query-df7d76d4a45e69846e1023646321e5e667acc5d95bb68f0e2e1d127cec0da0eb.json
new file mode 100644
index 0000000000..5608624d22
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-df7d76d4a45e69846e1023646321e5e667acc5d95bb68f0e2e1d127cec0da0eb.json
@@ -0,0 +1,46 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n ca.id,\n ca.\"attachmentType\" as \"attachment_type: AttachmentType\",\n ca.\"attachmentId\" as \"attachment_id\",\n ca.\"chatId\" as \"chat_id\",\n ca.\"messageId\" as \"message_id\"\n FROM\n \"ChatAttachment\" ca\n WHERE\n ca.\"id\" = $1\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "attachment_type: AttachmentType",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "attachment_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "chat_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "message_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ true
+ ]
+ },
+ "hash": "df7d76d4a45e69846e1023646321e5e667acc5d95bb68f0e2e1d127cec0da0eb"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-dfccb13f0d0abe2be31bb40067f2e4c29fe260e81d13c017b8bc4fae2b94703f.json b/rust/cloud-storage/chat/.sqlx/query-dfccb13f0d0abe2be31bb40067f2e4c29fe260e81d13c017b8bc4fae2b94703f.json
new file mode 100644
index 0000000000..e646e8765d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-dfccb13f0d0abe2be31bb40067f2e4c29fe260e81d13c017b8bc4fae2b94703f.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"Project\"\n SET \"uploadPending\" = false\n WHERE id = ANY($1)\n RETURNING id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "dfccb13f0d0abe2be31bb40067f2e4c29fe260e81d13c017b8bc4fae2b94703f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e005d05a4d52c32e5e7a2b4b6cfda3b6809a01149579c45d3bcbf921e155dd25.json b/rust/cloud-storage/chat/.sqlx/query-e005d05a4d52c32e5e7a2b4b6cfda3b6809a01149579c45d3bcbf921e155dd25.json
new file mode 100644
index 0000000000..71ddec2104
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e005d05a4d52c32e5e7a2b4b6cfda3b6809a01149579c45d3bcbf921e155dd25.json
@@ -0,0 +1,70 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id as \"document_id\",\n d.owner,\n d.name as \"document_name\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"projectId\" as \"project_id\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM\n \"Document\" d\n WHERE\n d.id = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "branched_from_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "branched_from_version_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 5,
+ "name": "document_family_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 6,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 7,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ true,
+ true,
+ true,
+ true,
+ null
+ ]
+ },
+ "hash": "e005d05a4d52c32e5e7a2b4b6cfda3b6809a01149579c45d3bcbf921e155dd25"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e11187ed1bd1944597258bbdefa8ec23de215edc1de1d020d418e2e89b17424e.json b/rust/cloud-storage/chat/.sqlx/query-e11187ed1bd1944597258bbdefa8ec23de215edc1de1d020d418e2e89b17424e.json
new file mode 100644
index 0000000000..155a235c83
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e11187ed1bd1944597258bbdefa8ec23de215edc1de1d020d418e2e89b17424e.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"OrganizationDefaultSharePermission\"\n WHERE \"organization_id\" = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Int4"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "e11187ed1bd1944597258bbdefa8ec23de215edc1de1d020d418e2e89b17424e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e17eb13c62a13ec9d5355a6f632b414792f6d87963138b7969b6a8f179e508a1.json b/rust/cloud-storage/chat/.sqlx/query-e17eb13c62a13ec9d5355a6f632b414792f6d87963138b7969b6a8f179e508a1.json
new file mode 100644
index 0000000000..15dd620397
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e17eb13c62a13ec9d5355a6f632b414792f6d87963138b7969b6a8f179e508a1.json
@@ -0,0 +1,40 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n id,\n email,\n \"organizationId\" as \"organization_id?\",\n macro_user_id as \"macro_user_id?\"\n FROM \"User\"\n WHERE \"email\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "email",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "organization_id?",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 3,
+ "name": "macro_user_id?",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ true,
+ false
+ ]
+ },
+ "hash": "e17eb13c62a13ec9d5355a6f632b414792f6d87963138b7969b6a8f179e508a1"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e1f9c3663588dbc2e59aa729190c477b8ae7e89dde630c125c1364ee211c454b.json b/rust/cloud-storage/chat/.sqlx/query-e1f9c3663588dbc2e59aa729190c477b8ae7e89dde630c125c1364ee211c454b.json
new file mode 100644
index 0000000000..5b3d78de3a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e1f9c3663588dbc2e59aa729190c477b8ae7e89dde630c125c1364ee211c454b.json
@@ -0,0 +1,26 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"macro_user\" (\"id\", \"username\", \"stripe_customer_id\", \"email\", \"has_trialed\")\n VALUES ($1, $2, $3, $4, $5)\n RETURNING id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text",
+ "Text",
+ "Bool"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "e1f9c3663588dbc2e59aa729190c477b8ae7e89dde630c125c1364ee211c454b"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e1fc9c7524d0d20844d2cad0402fd1a2058e31c5692d66a0107d9a45c9d83f7b.json b/rust/cloud-storage/chat/.sqlx/query-e1fc9c7524d0d20844d2cad0402fd1a2058e31c5692d66a0107d9a45c9d83f7b.json
new file mode 100644
index 0000000000..7448650148
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e1fc9c7524d0d20844d2cad0402fd1a2058e31c5692d66a0107d9a45c9d83f7b.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE comms_channels\n SET name = $1\n WHERE id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Varchar",
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "e1fc9c7524d0d20844d2cad0402fd1a2058e31c5692d66a0107d9a45c9d83f7b"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e263f6ef753e7f2c2debc7f63c8658670ee906d1814f037f1c20e3569ecfd270.json b/rust/cloud-storage/chat/.sqlx/query-e263f6ef753e7f2c2debc7f63c8658670ee906d1814f037f1c20e3569ecfd270.json
new file mode 100644
index 0000000000..5d79450654
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e263f6ef753e7f2c2debc7f63c8658670ee906d1814f037f1c20e3569ecfd270.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"User\"\n SET \"hasOnboardingDocuments\" = $1\n WHERE id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Bool",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "e263f6ef753e7f2c2debc7f63c8658670ee906d1814f037f1c20e3569ecfd270"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e2ce5bac0954c6b635a707279d36b926dfeea6482a19a9fc7911fb5487714cd7.json b/rust/cloud-storage/chat/.sqlx/query-e2ce5bac0954c6b635a707279d36b926dfeea6482a19a9fc7911fb5487714cd7.json
new file mode 100644
index 0000000000..aaf62f0e21
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e2ce5bac0954c6b635a707279d36b926dfeea6482a19a9fc7911fb5487714cd7.json
@@ -0,0 +1,40 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "SELECT * FROM comms_reactions WHERE message_id = ANY($1)",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "message_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "emoji",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 2,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "UuidArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "e2ce5bac0954c6b635a707279d36b926dfeea6482a19a9fc7911fb5487714cd7"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e33fa0c9cec501d3d4a9c98d1c80717756b395ffb54f82d50691520065eb6036.json b/rust/cloud-storage/chat/.sqlx/query-e33fa0c9cec501d3d4a9c98d1c80717756b395ffb54f82d50691520065eb6036.json
new file mode 100644
index 0000000000..057a1963fc
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e33fa0c9cec501d3d4a9c98d1c80717756b395ffb54f82d50691520065eb6036.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"Pin\" WHERE \"pinnedItemId\" = ANY($1)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "e33fa0c9cec501d3d4a9c98d1c80717756b395ffb54f82d50691520065eb6036"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437.json b/rust/cloud-storage/chat/.sqlx/query-e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437.json
new file mode 100644
index 0000000000..3ac1b029f6
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"EmailThreadPermission\" WHERE \"threadId\" = $1\n )\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e4bd72019eaf76d30d907a1fb8b3811f1d4c96c7049794890f30b1e831381010.json b/rust/cloud-storage/chat/.sqlx/query-e4bd72019eaf76d30d907a1fb8b3811f1d4c96c7049794890f30b1e831381010.json
new file mode 100644
index 0000000000..99718ab20d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e4bd72019eaf76d30d907a1fb8b3811f1d4c96c7049794890f30b1e831381010.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n u.id as user_profile_id, \n mui.first_name, \n mui.last_name\n FROM macro_user_info mui\n JOIN \"User\" u ON mui.macro_user_id = u.macro_user_id\n WHERE u.id = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_profile_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "first_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "last_name",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ true,
+ true
+ ]
+ },
+ "hash": "e4bd72019eaf76d30d907a1fb8b3811f1d4c96c7049794890f30b1e831381010"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e52ca994b4107db7e434502dc1f370666bf2efa34290ee8f1a6c89330b29522e.json b/rust/cloud-storage/chat/.sqlx/query-e52ca994b4107db7e434502dc1f370666bf2efa34290ee8f1a6c89330b29522e.json
new file mode 100644
index 0000000000..4c4e54cbd8
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e52ca994b4107db7e434502dc1f370666bf2efa34290ee8f1a6c89330b29522e.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"OrganizationInvitation\" (\"organization_id\", \"email\")\n VALUES ($1, $2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Int4",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "e52ca994b4107db7e434502dc1f370666bf2efa34290ee8f1a6c89330b29522e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e54d13b2e6e397c0f1fbc83ea7dea28d255c30f360759bf57b7d0b31294c785f.json b/rust/cloud-storage/chat/.sqlx/query-e54d13b2e6e397c0f1fbc83ea7dea28d255c30f360759bf57b7d0b31294c785f.json
new file mode 100644
index 0000000000..d8c8d36d0b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e54d13b2e6e397c0f1fbc83ea7dea28d255c30f360759bf57b7d0b31294c785f.json
@@ -0,0 +1,18 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"UserHistory\" (\"userId\", \"itemId\", \"itemType\", \"createdAt\", \"updatedAt\")\n SELECT * FROM UNNEST($1::text[], $2::text[], $3::text[], $4::timestamptz[], $5::timestamptz[])\n ON CONFLICT (\"userId\", \"itemId\", \"itemType\") DO UPDATE\n SET \"updatedAt\" = EXCLUDED.\"updatedAt\"\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "TextArray",
+ "TextArray",
+ "TimestamptzArray",
+ "TimestamptzArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "e54d13b2e6e397c0f1fbc83ea7dea28d255c30f360759bf57b7d0b31294c785f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e58e7758d9e066abfb5c6d0e5d14ccd7925ff91159a77cc1bf4c94f8e910f2b1.json b/rust/cloud-storage/chat/.sqlx/query-e58e7758d9e066abfb5c6d0e5d14ccd7925ff91159a77cc1bf4c94f8e910f2b1.json
new file mode 100644
index 0000000000..1da6bbfcbe
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e58e7758d9e066abfb5c6d0e5d14ccd7925ff91159a77cc1bf4c94f8e910f2b1.json
@@ -0,0 +1,70 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO comms_attachments (id, message_id, channel_id, entity_type, entity_id, width, height)\n SELECT * FROM UNNEST($1::uuid[], $2::uuid[], $3::uuid[], $4::varchar[], $5::varchar[], $6::int[], $7::int[])\n RETURNING\n id,\n message_id,\n channel_id,\n entity_type,\n entity_id,\n width,\n height,\n created_at\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "message_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "channel_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 3,
+ "name": "entity_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 4,
+ "name": "entity_id",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 5,
+ "name": "width",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 6,
+ "name": "height",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 7,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "UuidArray",
+ "UuidArray",
+ "UuidArray",
+ "VarcharArray",
+ "VarcharArray",
+ "Int4Array",
+ "Int4Array"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true,
+ false
+ ]
+ },
+ "hash": "e58e7758d9e066abfb5c6d0e5d14ccd7925ff91159a77cc1bf4c94f8e910f2b1"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e694a7861bbcbc4102b2335afa8d201e0b71608319da53a9551cf3c83fbf1487.json b/rust/cloud-storage/chat/.sqlx/query-e694a7861bbcbc4102b2335afa8d201e0b71608319da53a9551cf3c83fbf1487.json
new file mode 100644
index 0000000000..5c9497b6af
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e694a7861bbcbc4102b2335afa8d201e0b71608319da53a9551cf3c83fbf1487.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id\n FROM\n \"Document\" d\n WHERE\n d.id = ANY($1)\n AND d.\"owner\" = ANY($2)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "e694a7861bbcbc4102b2335afa8d201e0b71608319da53a9551cf3c83fbf1487"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e74177df51e1bd70b1e0cc19543d3533e96935ca54673f809c0720ea530faeac.json b/rust/cloud-storage/chat/.sqlx/query-e74177df51e1bd70b1e0cc19543d3533e96935ca54673f809c0720ea530faeac.json
new file mode 100644
index 0000000000..f7464854d5
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e74177df51e1bd70b1e0cc19543d3533e96935ca54673f809c0720ea530faeac.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM team_invite\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "e74177df51e1bd70b1e0cc19543d3533e96935ca54673f809c0720ea530faeac"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e7beaf1aca82261875e7d9886fa6b1b6e4ed2a281d8b1571e8edd83bbe890721.json b/rust/cloud-storage/chat/.sqlx/query-e7beaf1aca82261875e7d9886fa6b1b6e4ed2a281d8b1571e8edd83bbe890721.json
new file mode 100644
index 0000000000..46cf44d494
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e7beaf1aca82261875e7d9886fa6b1b6e4ed2a281d8b1571e8edd83bbe890721.json
@@ -0,0 +1,63 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO comms_entity_mentions (id, source_entity_type, source_entity_id, entity_type, entity_id, user_id)\n VALUES ($1, $2, $3, $4, $5, $6)\n RETURNING id, source_entity_type, source_entity_id, entity_type, entity_id, user_id, created_at\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "source_entity_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 2,
+ "name": "source_entity_id",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 3,
+ "name": "entity_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 4,
+ "name": "entity_id",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 5,
+ "name": "user_id",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Varchar",
+ "Varchar",
+ "Varchar",
+ "Varchar",
+ "Varchar"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ false
+ ]
+ },
+ "hash": "e7beaf1aca82261875e7d9886fa6b1b6e4ed2a281d8b1571e8edd83bbe890721"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e82694bed350dc3b7b22de00e655dfabb45e608cfd9a0a5a463fc6e1792393f2.json b/rust/cloud-storage/chat/.sqlx/query-e82694bed350dc3b7b22de00e655dfabb45e608cfd9a0a5a463fc6e1792393f2.json
new file mode 100644
index 0000000000..c73a91ea4d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e82694bed350dc3b7b22de00e655dfabb45e608cfd9a0a5a463fc6e1792393f2.json
@@ -0,0 +1,119 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH updated AS (\n UPDATE \"PdfHighlightAnchor\"\n SET \"threadId\" = $1\n WHERE uuid = $2\n RETURNING uuid, \"threadId\"\n )\n SELECT \n ph.uuid, \n ph.\"documentId\" as document_id,\n ph.owner, \n updated.\"threadId\" as thread_id, \n ph.page, \n ph.red,\n ph.green, \n ph.blue, \n ph.alpha, \n ph.type as highlight_type, \n ph.text, \n ph.\"pageViewportWidth\" as page_viewport_width, \n ph.\"pageViewportHeight\" as page_viewport_height, \n ph.\"createdAt\"::timestamptz as created_at, \n ph.\"updatedAt\"::timestamptz as updated_at, \n ph.\"deletedAt\"::timestamptz as deleted_at, \n array_agg((phr.id, phr.top, phr.left, phr.width, phr.height)) as \"highlight_rects!: Vec<PdfHighlightRect>\"\n FROM updated \n JOIN \"PdfHighlightAnchor\" ph ON updated.uuid = ph.uuid\n JOIN \"PdfHighlightRect\" phr ON ph.uuid = phr.\"pdfHighlightAnchorId\"\n GROUP BY ph.uuid, ph.owner, updated.\"threadId\", ph.page, ph.red, ph.green, ph.blue, ph.alpha, ph.type, ph.text, ph.\"pageViewportWidth\", ph.\"pageViewportHeight\", ph.\"createdAt\", ph.\"updatedAt\", ph.\"deletedAt\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "thread_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 4,
+ "name": "page",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 5,
+ "name": "red",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 6,
+ "name": "green",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 7,
+ "name": "blue",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 8,
+ "name": "alpha",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 9,
+ "name": "highlight_type",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 10,
+ "name": "text",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 11,
+ "name": "page_viewport_width",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 12,
+ "name": "page_viewport_height",
+ "type_info": "Float8"
+ },
+ {
+ "ordinal": 13,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 14,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 15,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 16,
+ "name": "highlight_rects!: Vec<PdfHighlightRect>",
+ "type_info": "RecordArray"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "e82694bed350dc3b7b22de00e655dfabb45e608cfd9a0a5a463fc6e1792393f2"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e8633dfaa07a4420442beb666625c7af4b6e8db0ea192d08aa971b20ebe69eb4.json b/rust/cloud-storage/chat/.sqlx/query-e8633dfaa07a4420442beb666625c7af4b6e8db0ea192d08aa971b20ebe69eb4.json
new file mode 100644
index 0000000000..7b0116f0b2
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e8633dfaa07a4420442beb666625c7af4b6e8db0ea192d08aa971b20ebe69eb4.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"Project\" \n WHERE id = ANY($1)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "e8633dfaa07a4420442beb666625c7af4b6e8db0ea192d08aa971b20ebe69eb4"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-e89719852a1e6166dbcebe6190a79a830b0e0a98c92967f15c2a89b96871bbd4.json b/rust/cloud-storage/chat/.sqlx/query-e89719852a1e6166dbcebe6190a79a830b0e0a98c92967f15c2a89b96871bbd4.json
new file mode 100644
index 0000000000..30b3a2d488
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-e89719852a1e6166dbcebe6190a79a830b0e0a98c92967f15c2a89b96871bbd4.json
@@ -0,0 +1,52 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n industry,\n title,\n \"firstName\" as first_name,\n \"lastName\" as last_name,\n \"profilePicture\" as profile_picture,\n \"profilePictureHash\" as profile_picture_hash\n FROM \"User\"\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "industry",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 1,
+ "name": "title",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 2,
+ "name": "first_name",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 3,
+ "name": "last_name",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 4,
+ "name": "profile_picture",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "profile_picture_hash",
+ "type_info": "Varchar"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true,
+ true,
+ true,
+ true,
+ true,
+ true
+ ]
+ },
+ "hash": "e89719852a1e6166dbcebe6190a79a830b0e0a98c92967f15c2a89b96871bbd4"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ebb5fcd2dc97d8c2f1ea17927db39e0fd0419594e068b4d43eaaddca5e46f6b0.json b/rust/cloud-storage/chat/.sqlx/query-ebb5fcd2dc97d8c2f1ea17927db39e0fd0419594e068b4d43eaaddca5e46f6b0.json
new file mode 100644
index 0000000000..9481eb3d97
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ebb5fcd2dc97d8c2f1ea17927db39e0fd0419594e068b4d43eaaddca5e46f6b0.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n di.id, \n d.uploaded\n FROM \"DocumentInstance\" di\n JOIN \"Document\" d ON di.\"documentId\" = d.id\n WHERE di.\"documentId\" = $1\n ORDER BY di.\"createdAt\" DESC\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 1,
+ "name": "uploaded",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "ebb5fcd2dc97d8c2f1ea17927db39e0fd0419594e068b4d43eaaddca5e46f6b0"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-eca33c5ab9f2376095116048cfe1e12319afb194d75977f5de4118c87dd433ed.json b/rust/cloud-storage/chat/.sqlx/query-eca33c5ab9f2376095116048cfe1e12319afb194d75977f5de4118c87dd433ed.json
new file mode 100644
index 0000000000..c380fde1f6
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-eca33c5ab9f2376095116048cfe1e12319afb194d75977f5de4118c87dd433ed.json
@@ -0,0 +1,65 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $2 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $2\n UNION ALL\n SELECT $2\n )\n SELECT\n entity_id::text as \"entity_id!\",\n entity_type as \"entity_type!\",\n source_id as \"source_id!\",\n access_level as \"access_level!: AccessLevel\",\n created_at as \"created_at!: DateTime<Utc>\",\n updated_at as \"updated_at!: DateTime<Utc>\"\n FROM entity_access\n WHERE source_id = ANY(SELECT source_id FROM user_source_ids)\n AND entity_id = $1\n AND entity_type = 'document'\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "entity_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "entity_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "source_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "access_level!: AccessLevel",
+ "type_info": {
+ "Custom": {
+ "name": "\"AccessLevel\"",
+ "kind": {
+ "Enum": [
+ "view",
+ "comment",
+ "edit",
+ "owner"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at!: DateTime<Utc>",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at!: DateTime<Utc>",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null,
+ false,
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "eca33c5ab9f2376095116048cfe1e12319afb194d75977f5de4118c87dd433ed"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ecccdffab47c2a500f64baee0488afa6d87a4f32cb7c852318de504fa6d20b2f.json b/rust/cloud-storage/chat/.sqlx/query-ecccdffab47c2a500f64baee0488afa6d87a4f32cb7c852318de504fa6d20b2f.json
new file mode 100644
index 0000000000..9c0571f3ec
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ecccdffab47c2a500f64baee0488afa6d87a4f32cb7c852318de504fa6d20b2f.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"SharePermission\"\n WHERE id IN (\n SELECT \"sharePermissionId\"\n FROM \"ProjectPermission\"\n WHERE \"projectId\" = ANY($1)\n )\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "ecccdffab47c2a500f64baee0488afa6d87a4f32cb7c852318de504fa6d20b2f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ecfb4ae58128a90c615fb3c25c24aaa6dab70b4a4e90b23913f297d806a06a7e.json b/rust/cloud-storage/chat/.sqlx/query-ecfb4ae58128a90c615fb3c25c24aaa6dab70b4a4e90b23913f297d806a06a7e.json
new file mode 100644
index 0000000000..07a1ab68c7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ecfb4ae58128a90c615fb3c25c24aaa6dab70b4a4e90b23913f297d806a06a7e.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM comms_channels\n WHERE id = $1\n AND EXISTS (\n SELECT 1 FROM comms_channel_participants\n WHERE channel_id = $1\n AND user_id = $2\n AND role = 'owner'::comms_participant_role\n )\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "ecfb4ae58128a90c615fb3c25c24aaa6dab70b4a4e90b23913f297d806a06a7e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ed2f2e964af409b89eceb93c1b4ee3364dbb75bdc22047789492b8f73b3e2491.json b/rust/cloud-storage/chat/.sqlx/query-ed2f2e964af409b89eceb93c1b4ee3364dbb75bdc22047789492b8f73b3e2491.json
new file mode 100644
index 0000000000..4c202caa69
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ed2f2e964af409b89eceb93c1b4ee3364dbb75bdc22047789492b8f73b3e2491.json
@@ -0,0 +1,72 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id,\n channel_id,\n sender_id,\n content,\n created_at,\n updated_at,\n thread_id,\n edited_at as \"edited_at: chrono::DateTime<chrono::Utc>\",\n deleted_at as \"deleted_at: chrono::DateTime<chrono::Utc>\"\n FROM (\n SELECT *\n FROM comms_messages\n WHERE channel_id = $1\n AND ($2::timestamptz IS NULL OR created_at >= $2)\n ORDER BY created_at DESC\n LIMIT $3\n ) AS latest_messages\n ORDER BY created_at ASC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "channel_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "sender_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "content",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "thread_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 7,
+ "name": "edited_at: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at: chrono::DateTime<chrono::Utc>",
+ "type_info": "Timestamp"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Timestamptz",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true,
+ true
+ ]
+ },
+ "hash": "ed2f2e964af409b89eceb93c1b4ee3364dbb75bdc22047789492b8f73b3e2491"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ed817d80e4f40fc10b32eb79e9fba0a0dd46cc9b31980dba5a76dfb4540d6cd3.json b/rust/cloud-storage/chat/.sqlx/query-ed817d80e4f40fc10b32eb79e9fba0a0dd46cc9b31980dba5a76dfb4540d6cd3.json
new file mode 100644
index 0000000000..19bb7c918a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ed817d80e4f40fc10b32eb79e9fba0a0dd46cc9b31980dba5a76dfb4540d6cd3.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"jobId\" as job_id, \"jobType\" as job_type FROM \"UploadJob\" WHERE \"documentId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "job_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "job_type",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "ed817d80e4f40fc10b32eb79e9fba0a0dd46cc9b31980dba5a76dfb4540d6cd3"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ed8fbc6860616548698e4134d1f4404c910188de8a57899dd6cadea50025b4bf.json b/rust/cloud-storage/chat/.sqlx/query-ed8fbc6860616548698e4134d1f4404c910188de8a57899dd6cadea50025b4bf.json
new file mode 100644
index 0000000000..e5fa9a9e1a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ed8fbc6860616548698e4134d1f4404c910188de8a57899dd6cadea50025b4bf.json
@@ -0,0 +1,35 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"PdfHighlightAnchor\" (\n \"documentId\", \"owner\", \"page\", \"red\", \"green\", \"blue\", \"alpha\", \n \"type\", \"text\", \"pageViewportWidth\", \"pageViewportHeight\", \n \"threadId\", \"createdAt\", \"updatedAt\"\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)\n RETURNING uuid\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "uuid",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Int4",
+ "Int4",
+ "Int4",
+ "Int4",
+ "Float8",
+ "Int4",
+ "Text",
+ "Float8",
+ "Float8",
+ "Int8",
+ "Timestamp",
+ "Timestamp"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "ed8fbc6860616548698e4134d1f4404c910188de8a57899dd6cadea50025b4bf"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-eec442b23af1030f7f161a304469b00fa7c2c474980361fbc5d98839dc40773f.json b/rust/cloud-storage/chat/.sqlx/query-eec442b23af1030f7f161a304469b00fa7c2c474980361fbc5d98839dc40773f.json
new file mode 100644
index 0000000000..27c368ad1f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-eec442b23af1030f7f161a304469b00fa7c2c474980361fbc5d98839dc40773f.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"Chat\" \n WHERE id = ANY($1)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "eec442b23af1030f7f161a304469b00fa7c2c474980361fbc5d98839dc40773f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ef1c943a49c710bf357a4946bc9836b8f94e41153e09be1b64120d8b5d5834b9.json b/rust/cloud-storage/chat/.sqlx/query-ef1c943a49c710bf357a4946bc9836b8f94e41153e09be1b64120d8b5d5834b9.json
new file mode 100644
index 0000000000..4cce0a41ea
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ef1c943a49c710bf357a4946bc9836b8f94e41153e09be1b64120d8b5d5834b9.json
@@ -0,0 +1,61 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n c.id as channel_id,\n c.name as channel_name,\n c.channel_type as \"channel_type: ChannelType\",\n (\n SELECT COUNT(*) \n FROM comms_channel_participants cp_count \n WHERE cp_count.channel_id = c.id \n AND cp_count.left_at IS NULL\n ) as \"participants!: i32\",\n CASE WHEN (\n c.channel_type = 'public'\n OR\n (c.channel_type = 'organization' AND $3::bigint IS NOT NULL AND c.org_id = $3)\n OR\n (c.channel_type IN ('private', 'direct_message', 'team') AND EXISTS (\n SELECT 1 FROM comms_channel_participants cp \n WHERE cp.channel_id = c.id \n AND cp.user_id = $2\n AND cp.left_at IS NULL\n ))\n ) THEN true ELSE false END as \"has_access!: bool\"\n FROM\n comms_channels c\n WHERE\n c.id::text = ANY($1)\n AND (c.channel_type != 'organization' OR $3::bigint IS NOT NULL)\n GROUP BY \n c.id,\n c.name,\n c.channel_type,\n c.org_id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "channel_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "channel_name",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 2,
+ "name": "channel_type: ChannelType",
+ "type_info": {
+ "Custom": {
+ "name": "comms_channel_type",
+ "kind": {
+ "Enum": [
+ "public",
+ "organization",
+ "private",
+ "direct_message",
+ "team"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 3,
+ "name": "participants!: i32",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 4,
+ "name": "has_access!: bool",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "Text",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ true,
+ false,
+ null,
+ null
+ ]
+ },
+ "hash": "ef1c943a49c710bf357a4946bc9836b8f94e41153e09be1b64120d8b5d5834b9"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ef427e34315b97ade2b38516eb477af19b53c578df995fbbcef546aaba55176d.json b/rust/cloud-storage/chat/.sqlx/query-ef427e34315b97ade2b38516eb477af19b53c578df995fbbcef546aaba55176d.json
new file mode 100644
index 0000000000..7044065d55
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ef427e34315b97ade2b38516eb477af19b53c578df995fbbcef546aaba55176d.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id FROM \"Project\" WHERE \"userId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "ef427e34315b97ade2b38516eb477af19b53c578df995fbbcef546aaba55176d"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-efc06b0244fc40aa8fbf3721d76886d7b8909f3150f779b64a56a456027c0d26.json b/rust/cloud-storage/chat/.sqlx/query-efc06b0244fc40aa8fbf3721d76886d7b8909f3150f779b64a56a456027c0d26.json
new file mode 100644
index 0000000000..848a23ff17
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-efc06b0244fc40aa8fbf3721d76886d7b8909f3150f779b64a56a456027c0d26.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"UserDocumentViewLocation\"\n WHERE user_id = $1 AND document_id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "efc06b0244fc40aa8fbf3721d76886d7b8909f3150f779b64a56a456027c0d26"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-efc740cd935fb67ef5c2a75b3c37cf16bf09d6e52e5f6e5c5b107ef8244a141d.json b/rust/cloud-storage/chat/.sqlx/query-efc740cd935fb67ef5c2a75b3c37cf16bf09d6e52e5f6e5c5b107ef8244a141d.json
new file mode 100644
index 0000000000..1cbb49a96b
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-efc740cd935fb67ef5c2a75b3c37cf16bf09d6e52e5f6e5c5b107ef8244a141d.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO user_notification (notification_id, user_id)\n SELECT $1, user_id\n FROM UNNEST($2::text[]) as user_id\n RETURNING created_at::timestamptz as \"created_at!\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "efc740cd935fb67ef5c2a75b3c37cf16bf09d6e52e5f6e5c5b107ef8244a141d"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-f1346adcde7c4a86859ebc936ac4c8ae492febce05ce35df78bced81c1070f01.json b/rust/cloud-storage/chat/.sqlx/query-f1346adcde7c4a86859ebc936ac4c8ae492febce05ce35df78bced81c1070f01.json
new file mode 100644
index 0000000000..2a382f9975
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-f1346adcde7c4a86859ebc936ac4c8ae492febce05ce35df78bced81c1070f01.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM macro_user\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "f1346adcde7c4a86859ebc936ac4c8ae492febce05ce35df78bced81c1070f01"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-f2a71de44d62190ec6ccad44b2e3a5b00bf57e5f0b948b2d882d2d036375d913.json b/rust/cloud-storage/chat/.sqlx/query-f2a71de44d62190ec6ccad44b2e3a5b00bf57e5f0b948b2d882d2d036375d913.json
new file mode 100644
index 0000000000..c793fa1d88
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-f2a71de44d62190ec6ccad44b2e3a5b00bf57e5f0b948b2d882d2d036375d913.json
@@ -0,0 +1,27 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO comms_channel_participants (channel_id, role, user_id)\n VALUES ($1, $2, $3)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ {
+ "Custom": {
+ "name": "comms_participant_role",
+ "kind": {
+ "Enum": [
+ "owner",
+ "admin",
+ "member"
+ ]
+ }
+ }
+ },
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "f2a71de44d62190ec6ccad44b2e3a5b00bf57e5f0b948b2d882d2d036375d913"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-f2c563a84ecf4b347e19eed2770c9593db5cf4bba24c234e9179f741a920d4d5.json b/rust/cloud-storage/chat/.sqlx/query-f2c563a84ecf4b347e19eed2770c9593db5cf4bba24c234e9179f741a920d4d5.json
new file mode 100644
index 0000000000..b9194ba12f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-f2c563a84ecf4b347e19eed2770c9593db5cf4bba24c234e9179f741a920d4d5.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"macro_user_id\" as \"macro_user_id!\", \"id\"\n FROM \"User\"\n WHERE \"email\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "macro_user_id!",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "f2c563a84ecf4b347e19eed2770c9593db5cf4bba24c234e9179f741a920d4d5"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-f360ad52de6c2f6b0c60902cbcb7ebad2671fe50f6425314bf3c007d01f53884.json b/rust/cloud-storage/chat/.sqlx/query-f360ad52de6c2f6b0c60902cbcb7ebad2671fe50f6425314bf3c007d01f53884.json
new file mode 100644
index 0000000000..70f8666277
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-f360ad52de6c2f6b0c60902cbcb7ebad2671fe50f6425314bf3c007d01f53884.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"comms_channel_participants\"\n WHERE channel_id = $1 AND user_id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "f360ad52de6c2f6b0c60902cbcb7ebad2671fe50f6425314bf3c007d01f53884"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-f3c74398e522602a72523704c37edbd92ada98d1c5b00dd4052db371fd191598.json b/rust/cloud-storage/chat/.sqlx/query-f3c74398e522602a72523704c37edbd92ada98d1c5b00dd4052db371fd191598.json
new file mode 100644
index 0000000000..4142c2a694
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-f3c74398e522602a72523704c37edbd92ada98d1c5b00dd4052db371fd191598.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE \"User\"\n SET macro_user_id = $2\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "f3c74398e522602a72523704c37edbd92ada98d1c5b00dd4052db371fd191598"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-f3e53dd531be738b881df199783a2beded3bd378038cbd6f012080ac77c5291b.json b/rust/cloud-storage/chat/.sqlx/query-f3e53dd531be738b881df199783a2beded3bd378038cbd6f012080ac77c5291b.json
new file mode 100644
index 0000000000..39180b3b0f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-f3e53dd531be738b881df199783a2beded3bd378038cbd6f012080ac77c5291b.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET deleted_at = NOW()\n WHERE user_id = $1 AND notification_id = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "f3e53dd531be738b881df199783a2beded3bd378038cbd6f012080ac77c5291b"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-f563f31f8ae4a8aa31c1753bcdb3e57e37cf0accc398cde5340483b03f749893.json b/rust/cloud-storage/chat/.sqlx/query-f563f31f8ae4a8aa31c1753bcdb3e57e37cf0accc398cde5340483b03f749893.json
new file mode 100644
index 0000000000..317349cb37
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-f563f31f8ae4a8aa31c1753bcdb3e57e37cf0accc398cde5340483b03f749893.json
@@ -0,0 +1,34 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT team_role as \"team_role!: TeamRole\"\n FROM team_user\n WHERE team_id = $1 AND user_id = $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "team_role!: TeamRole",
+ "type_info": {
+ "Custom": {
+ "name": "team_role",
+ "kind": {
+ "Enum": [
+ "member",
+ "admin",
+ "owner"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "f563f31f8ae4a8aa31c1753bcdb3e57e37cf0accc398cde5340483b03f749893"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-f61fae90a53682f217091f1ecbdaa60d2eb5b7b0ff90863b0d0dc288779a5f7f.json b/rust/cloud-storage/chat/.sqlx/query-f61fae90a53682f217091f1ecbdaa60d2eb5b7b0ff90863b0d0dc288779a5f7f.json
new file mode 100644
index 0000000000..54d8bc401c
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-f61fae90a53682f217091f1ecbdaa60d2eb5b7b0ff90863b0d0dc288779a5f7f.json
@@ -0,0 +1,86 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n c.\"id\" as \"item_id!\",\n c.\"owner\" as \"owner\",\n c.\"fileType\" as \"file_type\",\n c.\"name\" as \"file_name\",\n c.\"createdAt\" as \"created_at!\",\n c.\"updatedAt\" as \"updated_at!\",\n c.\"deletedAt\" as \"deleted_at?\",\n uh.\"updatedAt\" as \"viewed_at?\",\n c.\"projectId\" as \"project_id?\",\n dt.sub_type as \"sub_type?: DocumentSubType\"\n FROM\n \"Document\" c\n LEFT JOIN document_sub_type dt ON dt.document_id = c.id\n LEFT JOIN\n \"UserHistory\" uh ON uh.\"itemId\" = c.\"id\"\n AND uh.\"userId\" = $1\n AND uh.\"itemType\" = 'document'\n WHERE\n c.\"id\" = ANY($2)\n ORDER BY\n c.\"updatedAt\" DESC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "file_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "created_at!",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 5,
+ "name": "updated_at!",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 6,
+ "name": "deleted_at?",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 7,
+ "name": "viewed_at?",
+ "type_info": "Timestamp"
+ },
+ {
+ "ordinal": 8,
+ "name": "project_id?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 9,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ true,
+ false,
+ false,
+ false,
+ true,
+ false,
+ true,
+ false
+ ]
+ },
+ "hash": "f61fae90a53682f217091f1ecbdaa60d2eb5b7b0ff90863b0d0dc288779a5f7f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-f6c0addc618fb161405a1a989f2cacd0718c070eb2ee345d524abe7ba8b5b35e.json b/rust/cloud-storage/chat/.sqlx/query-f6c0addc618fb161405a1a989f2cacd0718c070eb2ee345d524abe7ba8b5b35e.json
new file mode 100644
index 0000000000..0d013147f7
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-f6c0addc618fb161405a1a989f2cacd0718c070eb2ee345d524abe7ba8b5b35e.json
@@ -0,0 +1,46 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n sp.id as id,\n sp.\"isPublic\" as is_public,\n sp.\"publicAccessLevel\" as \"public_access_level?\",\n p.\"userId\" as owner,\n COALESCE(\n json_agg(json_build_object(\n 'channel_id', csp.\"channel_id\",\n 'access_level', csp.\"access_level\"\n )) FILTER (WHERE csp.\"channel_id\" IS NOT NULL),\n '[]'\n ) as \"channel_share_permissions?\"\n FROM\n \"ProjectPermission\" pp\n JOIN \"SharePermission\" sp ON pp.\"sharePermissionId\" = sp.id\n JOIN \"Project\" p ON pp.\"projectId\" = p.id\n LEFT JOIN \"ChannelSharePermission\" csp ON csp.\"share_permission_id\" = sp.id\n WHERE\n pp.\"projectId\" = $1\n GROUP BY\n sp.id, p.\"userId\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "is_public",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 2,
+ "name": "public_access_level?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "channel_share_permissions?",
+ "type_info": "Json"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ true,
+ false,
+ null
+ ]
+ },
+ "hash": "f6c0addc618fb161405a1a989f2cacd0718c070eb2ee345d524abe7ba8b5b35e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-f77a2e12f69d9ca98e0ddf9bc9c10b9c54cb028c0f723b18c05231eafe5722af.json b/rust/cloud-storage/chat/.sqlx/query-f77a2e12f69d9ca98e0ddf9bc9c10b9c54cb028c0f723b18c05231eafe5722af.json
new file mode 100644
index 0000000000..6cdb842426
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-f77a2e12f69d9ca98e0ddf9bc9c10b9c54cb028c0f723b18c05231eafe5722af.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"ChatPermission\"\n WHERE \"sharePermissionId\" = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "f77a2e12f69d9ca98e0ddf9bc9c10b9c54cb028c0f723b18c05231eafe5722af"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-f7d8f36ace58fb884736c3568cfb78ecce5d0bafb3be445dd141b2ca21865578.json b/rust/cloud-storage/chat/.sqlx/query-f7d8f36ace58fb884736c3568cfb78ecce5d0bafb3be445dd141b2ca21865578.json
new file mode 100644
index 0000000000..642afda53f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-f7d8f36ace58fb884736c3568cfb78ecce5d0bafb3be445dd141b2ca21865578.json
@@ -0,0 +1,46 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n ca.id,\n ca.\"chatId\" as \"chat_id\",\n ca.\"attachmentId\" as \"attachment_id\",\n ca.\"attachmentType\" as \"attachment_type: AttachmentType\",\n ca.\"messageId\" as \"message_id\"\n FROM\n \"ChatAttachment\" ca\n WHERE ca.\"chatId\" = $1\n ORDER BY ca.id ASC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "chat_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "attachment_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "attachment_type: AttachmentType",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "message_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ true,
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "f7d8f36ace58fb884736c3568cfb78ecce5d0bafb3be445dd141b2ca21865578"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-f97467addd6684e98f641dabde769092e981121feea08d55de4cd41762f1fa1e.json b/rust/cloud-storage/chat/.sqlx/query-f97467addd6684e98f641dabde769092e981121feea08d55de4cd41762f1fa1e.json
new file mode 100644
index 0000000000..31c8f80def
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-f97467addd6684e98f641dabde769092e981121feea08d55de4cd41762f1fa1e.json
@@ -0,0 +1,26 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"Thread\" (\"owner\", \"documentId\", \"createdAt\", \"updatedAt\", \"resolved\")\n VALUES ($1, $2, $3, $4, $5)\n RETURNING id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Timestamp",
+ "Timestamp",
+ "Bool"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "f97467addd6684e98f641dabde769092e981121feea08d55de4cd41762f1fa1e"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-f994c62400d14f223c8be523136c008a34cde0310e6f57130a9ccd538f9d7866.json b/rust/cloud-storage/chat/.sqlx/query-f994c62400d14f223c8be523136c008a34cde0310e6f57130a9ccd538f9d7866.json
new file mode 100644
index 0000000000..f3e671dfa5
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-f994c62400d14f223c8be523136c008a34cde0310e6f57130a9ccd538f9d7866.json
@@ -0,0 +1,40 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n e.source_entity_id::uuid as \"message_id!: uuid::Uuid\",\n e.entity_type as \"entity_type!\",\n e.entity_id as \"entity_id!\",\n e.created_at as \"created_at!\"\n FROM comms_entity_mentions e\n JOIN comms_messages m ON e.source_entity_id = m.id::text\n WHERE e.source_entity_type = 'message'\n AND m.channel_id = $1\n AND m.deleted_at IS NULL\n ORDER BY e.created_at DESC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "message_id!: uuid::Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "entity_type!",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 2,
+ "name": "entity_id!",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 3,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "f994c62400d14f223c8be523136c008a34cde0310e6f57130a9ccd538f9d7866"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-f9f7a7f7bf87cffd10d68d891874a0a270de769b42747942090f55ac86c78574.json b/rust/cloud-storage/chat/.sqlx/query-f9f7a7f7bf87cffd10d68d891874a0a270de769b42747942090f55ac86c78574.json
new file mode 100644
index 0000000000..75e27686b5
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-f9f7a7f7bf87cffd10d68d891874a0a270de769b42747942090f55ac86c78574.json
@@ -0,0 +1,52 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"messageId\" as \"message_id\",\n \"url\",\n \"title\",\n \"description\",\n \"favicon_url\",\n \"image_url\"\n FROM \"WebAnnotations\" wa\n INNER JOIN \"ChatMessage\" cm ON cm.id = wa.\"messageId\"\n WHERE cm.\"chatId\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "message_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "url",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "title",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "description",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "favicon_url",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "image_url",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true,
+ false,
+ false,
+ true,
+ true,
+ true
+ ]
+ },
+ "hash": "f9f7a7f7bf87cffd10d68d891874a0a270de769b42747942090f55ac86c78574"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-fa1bd94a6aca08ddbb856f2c42327e8397a42089600571a38981bfa11b7796d4.json b/rust/cloud-storage/chat/.sqlx/query-fa1bd94a6aca08ddbb856f2c42327e8397a42089600571a38981bfa11b7796d4.json
new file mode 100644
index 0000000000..b22ba93a90
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-fa1bd94a6aca08ddbb856f2c42327e8397a42089600571a38981bfa11b7796d4.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"OrganizationEmailMatches\" (\"organizationId\", \"email\")\n VALUES ($1, $2)\n ON CONFLICT (\"email\") DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Int4",
+ "Varchar"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "fa1bd94a6aca08ddbb856f2c42327e8397a42089600571a38981bfa11b7796d4"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-fa24799c4889a98bfb62a1987d1fe93975169bfeb0cdbecb04dac3f31288570f.json b/rust/cloud-storage/chat/.sqlx/query-fa24799c4889a98bfb62a1987d1fe93975169bfeb0cdbecb04dac3f31288570f.json
new file mode 100644
index 0000000000..afb3979b4f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-fa24799c4889a98bfb62a1987d1fe93975169bfeb0cdbecb04dac3f31288570f.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "DELETE FROM \"DocumentInstance\" WHERE id = $2 and \"documentId\" = $1",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Int8"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "fa24799c4889a98bfb62a1987d1fe93975169bfeb0cdbecb04dac3f31288570f"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-faa0297c270e2643d9f8523a4331c4cd24bd39b97dcde6411ace461d6c61a8b0.json b/rust/cloud-storage/chat/.sqlx/query-faa0297c270e2643d9f8523a4331c4cd24bd39b97dcde6411ace461d6c61a8b0.json
new file mode 100644
index 0000000000..7af45e1045
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-faa0297c270e2643d9f8523a4331c4cd24bd39b97dcde6411ace461d6c61a8b0.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM comms_attachments\n WHERE id = ANY($1)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "UuidArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "faa0297c270e2643d9f8523a4331c4cd24bd39b97dcde6411ace461d6c61a8b0"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-fab6b92c5781874261b3c3ca673d0bf0ad8155e25cf77aa57dafdcb133f30509.json b/rust/cloud-storage/chat/.sqlx/query-fab6b92c5781874261b3c3ca673d0bf0ad8155e25cf77aa57dafdcb133f30509.json
new file mode 100644
index 0000000000..1f209218c3
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-fab6b92c5781874261b3c3ca673d0bf0ad8155e25cf77aa57dafdcb133f30509.json
@@ -0,0 +1,31 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT sub_type as \"sub_type: DocumentSubType\" FROM document_sub_type WHERE document_id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "sub_type: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "fab6b92c5781874261b3c3ca673d0bf0ad8155e25cf77aa57dafdcb133f30509"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-fc0a71fe3ce6804e5f2b80e78c108aba496434dc78909951f7c1bd86f9c56ec0.json b/rust/cloud-storage/chat/.sqlx/query-fc0a71fe3ce6804e5f2b80e78c108aba496434dc78909951f7c1bd86f9c56ec0.json
new file mode 100644
index 0000000000..fcef9aca61
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-fc0a71fe3ce6804e5f2b80e78c108aba496434dc78909951f7c1bd86f9c56ec0.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"SharePermission\" sp\n USING \"ProjectPermission\" pp \n WHERE pp.\"sharePermissionId\" = sp.id\n AND pp.\"projectId\" = ANY($1)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "fc0a71fe3ce6804e5f2b80e78c108aba496434dc78909951f7c1bd86f9c56ec0"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-fc8a4a51536361c5b5c0a742ba268fff2908654b8bb53923320e7fabe244b467.json b/rust/cloud-storage/chat/.sqlx/query-fc8a4a51536361c5b5c0a742ba268fff2908654b8bb53923320e7fabe244b467.json
new file mode 100644
index 0000000000..decc4d20e9
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-fc8a4a51536361c5b5c0a742ba268fff2908654b8bb53923320e7fabe244b467.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n (SELECT COUNT(*) FROM \"DocumentInstance\" WHERE \"documentId\" = $1) +\n (SELECT COUNT(*) FROM \"DocumentBom\" WHERE \"documentId\" = $1) AS total_count\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "total_count",
+ "type_info": "Int8"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "fc8a4a51536361c5b5c0a742ba268fff2908654b8bb53923320e7fabe244b467"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-fc9cc90bb37368b293d46d43efd16c178a9865c5926e4195249eb22e2a4a91b3.json b/rust/cloud-storage/chat/.sqlx/query-fc9cc90bb37368b293d46d43efd16c178a9865c5926e4195249eb22e2a4a91b3.json
new file mode 100644
index 0000000000..fbcc874a9d
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-fc9cc90bb37368b293d46d43efd16c178a9865c5926e4195249eb22e2a4a91b3.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \"id\", \"userId\" as user_id FROM \"Chat\" WHERE \"projectId\" = ANY($1) AND \"deletedAt\" IS NOT NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "fc9cc90bb37368b293d46d43efd16c178a9865c5926e4195249eb22e2a4a91b3"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-fcb8fda242203a9ff6044c928c4edbcb50fd47035cee6880001fb874b67e9c73.json b/rust/cloud-storage/chat/.sqlx/query-fcb8fda242203a9ff6044c928c4edbcb50fd47035cee6880001fb874b67e9c73.json
new file mode 100644
index 0000000000..cc4bb224fc
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-fcb8fda242203a9ff6044c928c4edbcb50fd47035cee6880001fb874b67e9c73.json
@@ -0,0 +1,70 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id as \"document_id\",\n d.owner,\n d.name as \"document_name\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"projectId\" as \"project_id\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM\n \"Document\" d\n WHERE\n d.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "branched_from_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "branched_from_version_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 5,
+ "name": "document_family_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 6,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 7,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 8,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ true,
+ true,
+ true,
+ true,
+ null
+ ]
+ },
+ "hash": "fcb8fda242203a9ff6044c928c4edbcb50fd47035cee6880001fb874b67e9c73"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-fcd4b67db8a3a8de51b0bb55880c5934f900adbadcc5549165e709cb1cd345b5.json b/rust/cloud-storage/chat/.sqlx/query-fcd4b67db8a3a8de51b0bb55880c5934f900adbadcc5549165e709cb1cd345b5.json
new file mode 100644
index 0000000000..51893d429f
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-fcd4b67db8a3a8de51b0bb55880c5934f900adbadcc5549165e709cb1cd345b5.json
@@ -0,0 +1,128 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n d.id as document_id,\n d.owner as owner,\n d.name as document_name,\n COALESCE(db.id, di.id) as \"document_version_id!\",\n d.\"branchedFromId\" as \"branched_from_id?\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id?\",\n d.\"documentFamilyId\" as \"document_family_id?\",\n d.\"fileType\" as file_type,\n d.\"createdAt\"::timestamptz as created_at,\n d.\"updatedAt\"::timestamptz as updated_at,\n d.\"deletedAt\"::timestamptz as deleted_at,\n db.bom_parts as \"document_bom?\",\n di.modification_data as \"modification_data?\",\n d.\"projectId\" as \"project_id?\",\n p.name as \"project_name?\",\n di.sha as \"sha?\",\n dt.sub_type as \"sub_type?: DocumentSubType\"\n FROM\n \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN LATERAL (\n SELECT\n b.id,\n (\n SELECT\n json_agg(\n json_build_object(\n 'id', bp.id,\n 'sha', bp.sha,\n 'path', bp.path\n )\n )\n FROM\n \"BomPart\" bp\n WHERE\n bp.\"documentBomId\" = b.id\n ) as bom_parts\n FROM\n \"DocumentBom\" b\n WHERE\n b.\"documentId\" = d.id\n ORDER BY\n b.\"createdAt\" DESC\n LIMIT 1\n ) db ON d.\"fileType\" = 'docx'\n LEFT JOIN LATERAL (\n SELECT\n i.id,\n i.\"documentId\",\n i.\"sha\",\n i.\"createdAt\",\n (\n SELECT\n imod.\"modificationData\"\n FROM\n \"DocumentInstanceModificationData\" imod\n WHERE\n imod.\"documentInstanceId\" = i.id\n ) as modification_data,\n i.\"updatedAt\"\n FROM\n \"DocumentInstance\" i\n WHERE\n i.\"documentId\" = d.id\n ORDER BY\n i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON d.\"fileType\" IS DISTINCT FROM 'docx'\n LEFT JOIN \"Project\" p ON p.id = d.\"projectId\"\n WHERE\n d.\"deletedAt\" IS NULL\n ORDER BY d.\"createdAt\" DESC\n LIMIT $1 OFFSET $2\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "document_version_id!",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 4,
+ "name": "branched_from_id?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "branched_from_version_id?",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 6,
+ "name": "document_family_id?",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 7,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 8,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 11,
+ "name": "document_bom?",
+ "type_info": "Json"
+ },
+ {
+ "ordinal": 12,
+ "name": "modification_data?",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 13,
+ "name": "project_id?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 14,
+ "name": "project_name?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 15,
+ "name": "sha?",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 16,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ null,
+ true,
+ true,
+ true,
+ true,
+ null,
+ null,
+ null,
+ null,
+ null,
+ true,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "fcd4b67db8a3a8de51b0bb55880c5934f900adbadcc5549165e709cb1cd345b5"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-fd65e80e68a17871a3a3ef4bd1bab20faaf6ba24f55172486a74aaec3da480f4.json b/rust/cloud-storage/chat/.sqlx/query-fd65e80e68a17871a3a3ef4bd1bab20faaf6ba24f55172486a74aaec3da480f4.json
new file mode 100644
index 0000000000..6819822606
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-fd65e80e68a17871a3a3ef4bd1bab20faaf6ba24f55172486a74aaec3da480f4.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"entity_access\"\n WHERE (entity_id = ANY($1) AND entity_type = $2)\n OR granted_from_project_id = ANY($3)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "UuidArray",
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "fd65e80e68a17871a3a3ef4bd1bab20faaf6ba24f55172486a74aaec3da480f4"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-fe93b3b50a3a64b8b354903858cfef2cdff408625fa1a592977996a81e8b3f3c.json b/rust/cloud-storage/chat/.sqlx/query-fe93b3b50a3a64b8b354903858cfef2cdff408625fa1a592977996a81e8b3f3c.json
new file mode 100644
index 0000000000..caa1a7dfef
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-fe93b3b50a3a64b8b354903858cfef2cdff408625fa1a592977996a81e8b3f3c.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO \"MacroPromptPermission\" (\"macro_prompt_id\", \"share_permission_id\")\n VALUES ($1, $2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "fe93b3b50a3a64b8b354903858cfef2cdff408625fa1a592977996a81e8b3f3c"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ff7d21bb92d1ed078738e8190acee79c3e0b64c8c4a507719aa78405325cad76.json b/rust/cloud-storage/chat/.sqlx/query-ff7d21bb92d1ed078738e8190acee79c3e0b64c8c4a507719aa78405325cad76.json
new file mode 100644
index 0000000000..6c75d8252a
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ff7d21bb92d1ed078738e8190acee79c3e0b64c8c4a507719aa78405325cad76.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT \n d.name \n FROM \"Document\" d\n WHERE d.\"id\" = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "name",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "ff7d21bb92d1ed078738e8190acee79c3e0b64c8c4a507719aa78405325cad76"
+}
diff --git a/rust/cloud-storage/chat/.sqlx/query-ffb324854a460dd540e7c0849f87741bc7947c8473dba0fb39c61ee8be80950c.json b/rust/cloud-storage/chat/.sqlx/query-ffb324854a460dd540e7c0849f87741bc7947c8473dba0fb39c61ee8be80950c.json
new file mode 100644
index 0000000000..cc13e43e45
--- /dev/null
+++ b/rust/cloud-storage/chat/.sqlx/query-ffb324854a460dd540e7c0849f87741bc7947c8473dba0fb39c61ee8be80950c.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"Thread\" WHERE \"documentId\" = $1;\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "ffb324854a460dd540e7c0849f87741bc7947c8473dba0fb39c61ee8be80950c"
+}
diff --git a/rust/cloud-storage/chat/Cargo.toml b/rust/cloud-storage/chat/Cargo.toml
index 9f3f7222c6..eed90913e4 100644
--- a/rust/cloud-storage/chat/Cargo.toml
+++ b/rust/cloud-storage/chat/Cargo.toml
@@ -6,13 +6,14 @@ version = "0.1.0"
[features]
default = ["inbound", "outbound", "ports"]
-inbound = ["dep:axum", "dep:model_user", "dep:roles_and_permissions", "entity_access/inbound", "ports"]
-outbound = [
- "dep:macro_share_permissions",
- "dep:macro_uuid",
- "dep:sqlx",
+inbound = [
+ "dep:axum",
+ "dep:model_user",
+ "dep:roles_and_permissions",
+ "entity_access/inbound",
"ports",
]
+outbound = ["dep:entity_access_db_utils", "dep:macro_uuid", "dep:sqlx", "ports"]
ports = []
[dependencies]
@@ -22,8 +23,14 @@ ai_toolset = { path = "../ai_toolset" }
anyhow = { workspace = true }
chrono = { workspace = true }
entity_access = { path = "../entity_access", default-features = false }
+entity_access_db_utils = { path = "../entity_access_db_utils", optional = true }
+entity_access_management = { path = "../entity_access_management", default-features = false, features = [
+ "ports",
+] }
macro_user_id = { path = "../macro_user_id" }
model = { path = "../model" }
+model-entity = { path = "../model-entity" }
+models_entity_access_management = { path = "../models_entity_access_management", default-features = false }
models_permissions = { path = "../models_permissions" }
serde = { workspace = true }
serde_json = { workspace = true }
@@ -31,6 +38,7 @@ thiserror = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
unicode-segmentation = { workspace = true }
+uuid = { workspace = true }
# Inbound (HTTP handlers)
axum = { workspace = true, optional = true }
@@ -39,7 +47,6 @@ roles_and_permissions = { path = "../roles_and_permissions", optional = true, de
utoipa = { workspace = true }
# Outbound (database adapters)
-macro_share_permissions = { path = "../macro_share_permissions", optional = true }
sqlx = { workspace = true, optional = true }
macro_uuid = { path = "../macro_uuid", optional = true }
diff --git a/rust/cloud-storage/chat/justfile b/rust/cloud-storage/chat/justfile
new file mode 100644
index 0000000000..d5a52bc432
--- /dev/null
+++ b/rust/cloud-storage/chat/justfile
@@ -0,0 +1,6 @@
+DATABASE_URL := "postgres://user:password@localhost:5432/macrodb"
+
+mod sqlx '../sqlx.just'
+
+prepare_db:
+ just sqlx::prepare_db {{ DATABASE_URL }}
diff --git a/rust/cloud-storage/chat/src/domain/ports.rs b/rust/cloud-storage/chat/src/domain/ports.rs
index 563ee43b6b..43f1134b12 100644
--- a/rust/cloud-storage/chat/src/domain/ports.rs
+++ b/rust/cloud-storage/chat/src/domain/ports.rs
@@ -81,6 +81,12 @@ pub trait ChatRepo: Send + Sync + 'static {
args: PatchChatArgs,
) -> impl std::future::Future<Output = Result<(), ChatErr>> + Send;
+ /// Update a project's `updatedAt` timestamp.
+ fn update_project_modified(
+ &self,
+ project_id: &str,
+ ) -> impl std::future::Future<Output = Result<(), ChatErr>> + Send;
+
/// Patch a message's content.
fn patch_message(
&self,
diff --git a/rust/cloud-storage/chat/src/domain/service.rs b/rust/cloud-storage/chat/src/domain/service.rs
index 3eb51e8395..35bcbafae2 100644
--- a/rust/cloud-storage/chat/src/domain/service.rs
+++ b/rust/cloud-storage/chat/src/domain/service.rs
@@ -9,13 +9,15 @@ use ai_toolset::{AsyncToolSet, RequestContext, tool_object::UserToolResponse};
use entity_access::domain::models::{
EditAccessLevel, EntityAccessReceipt, OwnerAccessLevel, ViewAccessLevel,
};
+use entity_access_management::domain::ports::EntityAccessManagementService;
use macro_user_id::user_id::MacroUserIdStr;
+use model_entity::EntityType;
use models_permissions::share_permission::SharePermissionV2;
use std::sync::Arc;
use unicode_segmentation::UnicodeSegmentation;
/// Concrete service implementation that delegates to a [`ChatRepo`]
-pub struct ChatServiceImpl<R, ToolSetContext>
+pub struct ChatServiceImpl<R, ToolSetContext, Eam>
where
ToolSetContext: Clone + Send + Sync + 'static,
{
@@ -23,9 +25,11 @@ where
toolset: Arc<AsyncToolSet<ToolSetContext>>,
context: ToolSetContext,
repo: R,
+ entity_access_management_service: Eam,
}
-impl<R: ChatRepo, ToolSetContext> ChatServiceImpl<R, ToolSetContext>
+impl<R: ChatRepo, ToolSetContext, Eam: EntityAccessManagementService>
+ ChatServiceImpl<R, ToolSetContext, Eam>
where
ToolSetContext: Clone + Send + Sync + 'static,
{
@@ -34,16 +38,19 @@ where
repo: R,
toolset: Arc<AsyncToolSet<ToolSetContext>>,
context: ToolSetContext,
+ entity_access_management_service: Eam,
) -> Self {
Self {
repo,
toolset,
context,
+ entity_access_management_service,
}
}
}
-impl<R: ChatRepo, ToolSetContext> ChatService for ChatServiceImpl<R, ToolSetContext>
+impl<R: ChatRepo, ToolSetContext, Eam: EntityAccessManagementService> ChatService
+ for ChatServiceImpl<R, ToolSetContext, Eam>
where
ToolSetContext: Clone + Send + Sync + 'static,
{
@@ -57,7 +64,27 @@ where
return Err(ChatErr::BadRequest("name too long".to_string()));
}
- self.repo.create(user_id, args).await
+ let project_id = args.project_id.clone();
+ let chat_id = self.repo.create(user_id, args).await?;
+
+ if let Some(project_id) = &project_id
+ && !project_id.is_empty()
+ && let (Ok(chat_uuid), Ok(project_uuid)) = (
+ uuid::Uuid::parse_str(&chat_id),
+ uuid::Uuid::parse_str(project_id),
+ )
+ {
+ let _ = self
+ .entity_access_management_service
+ .add_entity_to_project(&chat_uuid, EntityType::Chat, &project_uuid)
+ .await
+ .inspect_err(|e| tracing::error!(error=?e, project_id=?project_id, "unable to update entity access for project"));
+ let _ = self.repo.update_project_modified(project_id).await.inspect_err(
+ |e| tracing::error!(error=?e, project_id=?project_id, "unable to update project modified date"),
+ );
+ }
+
+ Ok(chat_id)
}
#[tracing::instrument(err, skip(self))]
@@ -106,7 +133,32 @@ where
entity_access_receipt: EntityAccessReceipt<OwnerAccessLevel>,
) -> Result<(), ChatErr> {
let chat_id = &entity_access_receipt.entity().entity_id;
- self.repo.delete(chat_id).await
+ let project_id = self
+ .repo
+ .get_metadata(chat_id)
+ .await
+ .ok()
+ .and_then(|c| c.project_id);
+ self.repo.delete(chat_id).await?;
+
+ if let Some(project_id) = &project_id
+ && !project_id.is_empty()
+ && let (Ok(chat_uuid), Ok(project_uuid)) = (
+ uuid::Uuid::parse_str(chat_id),
+ uuid::Uuid::parse_str(project_id),
+ )
+ {
+ let _ = self
+ .entity_access_management_service
+ .remove_entity_from_project(&chat_uuid, EntityType::Chat, &project_uuid)
+ .await
+ .inspect_err(|e| tracing::error!(error=?e, project_id=?project_id, "unable to remove entity from project"));
+ let _ = self.repo.update_project_modified(project_id).await.inspect_err(
+ |e| tracing::error!(error=?e, project_id=?project_id, "unable to update project modified date"),
+ );
+ }
+
+ Ok(())
}
#[tracing::instrument(err, skip(self))]
@@ -115,7 +167,32 @@ where
entity_access_receipt: EntityAccessReceipt<OwnerAccessLevel>,
) -> Result<(), ChatErr> {
let chat_id = &entity_access_receipt.entity().entity_id;
- self.repo.permanently_delete(chat_id).await
+ let project_id = self
+ .repo
+ .get_metadata(chat_id)
+ .await
+ .ok()
+ .and_then(|c| c.project_id);
+ self.repo.permanently_delete(chat_id).await?;
+
+ if let Some(project_id) = &project_id
+ && !project_id.is_empty()
+ && let (Ok(chat_uuid), Ok(project_uuid)) = (
+ uuid::Uuid::parse_str(chat_id),
+ uuid::Uuid::parse_str(project_id),
+ )
+ {
+ let _ = self
+ .entity_access_management_service
+ .remove_entity_from_project(&chat_uuid, EntityType::Chat, &project_uuid)
+ .await
+ .inspect_err(|e| tracing::error!(error=?e, project_id=?project_id, "unable to remove entity from project"));
+ let _ = self.repo.update_project_modified(project_id).await.inspect_err(
+ |e| tracing::error!(error=?e, project_id=?project_id, "unable to update project modified date"),
+ );
+ }
+
+ Ok(())
}
#[tracing::instrument(err, skip(self))]
@@ -131,7 +208,57 @@ where
}
let user_id = entity_access_receipt.get_authenticated_user()?;
let chat_id = &entity_access_receipt.entity().entity_id;
- self.repo.patch(user_id.to_owned(), chat_id, args).await
+
+ let old_project_id = self
+ .repo
+ .get_metadata(chat_id)
+ .await
+ .ok()
+ .and_then(|c| c.project_id);
+ let new_project_id = args.project_id.clone();
+ let project_changing =
+ new_project_id.is_some() && new_project_id.as_deref() != old_project_id.as_deref();
+
+ self.repo.patch(user_id.to_owned(), chat_id, args).await?;
+
+ // Remove from old project (only if the project is actually changing)
+ if project_changing
+ && let Some(old_project_id) = &old_project_id
+ && !old_project_id.is_empty()
+ && let (Ok(chat_uuid), Ok(old_uuid)) = (
+ uuid::Uuid::parse_str(chat_id),
+ uuid::Uuid::parse_str(old_project_id),
+ )
+ {
+ let _ = self
+ .entity_access_management_service
+ .remove_entity_from_project(&chat_uuid, EntityType::Chat, &old_uuid)
+ .await
+ .inspect_err(|e| tracing::error!(error=?e, project_id=?old_project_id, "unable to remove entity from project"));
+ let _ = self.repo.update_project_modified(old_project_id).await.inspect_err(
+ |e| tracing::error!(error=?e, project_id=?old_project_id, "unable to update project modified date"),
+ );
+ }
+
+ // Add to new project's entity access + bump modified timestamp
+ if let Some(new_project_id) = &new_project_id
+ && !new_project_id.is_empty()
+ && let (Ok(chat_uuid), Ok(new_uuid)) = (
+ uuid::Uuid::parse_str(chat_id),
+ uuid::Uuid::parse_str(new_project_id),
+ )
+ {
+ let _ = self
+ .entity_access_management_service
+ .add_entity_to_project(&chat_uuid, EntityType::Chat, &new_uuid)
+ .await
+ .inspect_err(|e| tracing::error!(error=?e, project_id=?new_project_id, "unable to add entity to project"));
+ let _ = self.repo.update_project_modified(new_project_id).await.inspect_err(
+ |e| tracing::error!(error=?e, project_id=?new_project_id, "unable to update project modified date"),
+ );
+ }
+
+ Ok(())
}
#[tracing::instrument(err, skip(self))]
@@ -295,7 +422,8 @@ where
}
}
-impl<R: ChatRepo, ToolSetContext> ChatServiceImpl<R, ToolSetContext>
+impl<R: ChatRepo, ToolSetContext, Eam: EntityAccessManagementService>
+ ChatServiceImpl<R, ToolSetContext, Eam>
where
ToolSetContext: Clone + Send + Sync + 'static,
{
diff --git a/rust/cloud-storage/chat/src/outbound/postgres/mod.rs b/rust/cloud-storage/chat/src/outbound/postgres/mod.rs
index 65678e2019..65df9887d8 100644
--- a/rust/cloud-storage/chat/src/outbound/postgres/mod.rs
+++ b/rust/cloud-storage/chat/src/outbound/postgres/mod.rs
@@ -94,14 +94,16 @@ impl ChatRepo for PgChatRepo {
.await
.map_err(to_chat_err)?;
- queries::insert_user_item_access::insert_user_item_access(
+ entity_access_db_utils::insert_entity_access_row(
&mut tx,
- user_id.copied(),
- &chat_id,
- AccessLevel::Owner,
+ &macro_uuid::string_to_uuid(&chat_id).unwrap(),
+ entity_access_db_utils::EntityType::Chat,
+ user_id.as_ref(),
+ entity_access_db_utils::EntityAccessSourceType::User,
+ entity_access_db_utils::AccessLevel::Owner,
)
.await
- .map_err(to_chat_err)?;
+ .map_err(|e| ChatErr::Unknown(e.into()))?;
tx.commit().await.map_err(|e| {
tracing::error!(error=?e, "create_chat transaction error");
@@ -193,14 +195,16 @@ impl ChatRepo for PgChatRepo {
.await
.map_err(to_chat_err)?;
- queries::insert_user_item_access::insert_user_item_access(
+ entity_access_db_utils::insert_entity_access_row(
&mut tx,
- user_id.copied(),
- &chat_id,
- AccessLevel::Owner,
+ &macro_uuid::string_to_uuid(&chat_id).unwrap(),
+ entity_access_db_utils::EntityType::Chat,
+ user_id.as_ref(),
+ entity_access_db_utils::EntityAccessSourceType::User,
+ entity_access_db_utils::AccessLevel::Owner,
)
.await
- .map_err(to_chat_err)?;
+ .map_err(|e| ChatErr::Unknown(e.into()))?;
queries::copy_messages::copy_messages(&mut tx, source_chat_id, &chat_id)
.await
@@ -293,22 +297,19 @@ impl ChatRepo for PgChatRepo {
)
.await
.map_err(to_chat_err)?;
-
- macro_share_permissions::user_item_access::update_user_item_access(
- &mut tx,
- user_id.as_ref(),
- chat_id,
- "chat",
- share_permission,
- )
- .await
- .map_err(to_chat_err)?;
}
tx.commit().await.map_err(|e| ChatErr::Unknown(e.into()))?;
Ok(())
}
+ #[tracing::instrument(err, skip(self))]
+ async fn update_project_modified(&self, project_id: &str) -> Result<(), ChatErr> {
+ queries::update_project_modified::update_project_modified(&self.pool, project_id)
+ .await
+ .map_err(to_chat_err)
+ }
+
#[tracing::instrument(err, skip(self))]
async fn patch_message(
&self,
diff --git a/rust/cloud-storage/chat/src/outbound/postgres/queries/edit_share_permission.rs b/rust/cloud-storage/chat/src/outbound/postgres/queries/edit_share_permission.rs
index 5f5e55f72c..6ba9020f34 100644
--- a/rust/cloud-storage/chat/src/outbound/postgres/queries/edit_share_permission.rs
+++ b/rust/cloud-storage/chat/src/outbound/postgres/queries/edit_share_permission.rs
@@ -1,5 +1,6 @@
//! Edit share permissions for a chat.
+use model_entity::EntityType;
use models_permissions::share_permission::UpdateSharePermissionRequestV2;
use models_permissions::share_permission::channel_share_permission::{
ChannelSharePermission, UpdateChannelSharePermission, UpdateOperation,
@@ -33,13 +34,14 @@ pub(crate) async fn edit_chat_permission(
.fetch_one(tx.as_mut())
.await?;
- edit_share_permission(tx, &share_id, share_permission).await
+ edit_share_permission(tx, chat_id, &share_id, share_permission).await
}
/// Update a `SharePermission` row and its channel share permissions.
#[tracing::instrument(err, skip(tx))]
async fn edit_share_permission(
tx: &mut Transaction<'_, Postgres>,
+ chat_id: &str,
share_permission_id: &str,
share_permission: &UpdateSharePermissionRequestV2,
) -> anyhow::Result<()> {
@@ -100,6 +102,14 @@ async fn edit_share_permission(
if let Some(channel_share_permissions) = share_permission.channel_share_permissions.as_ref() {
edit_channel_share_permissions(tx, share_permission_id, channel_share_permissions).await?;
+
+ entity_access_db_utils::update_entity_access_channel_share_permissions(
+ tx,
+ &macro_uuid::string_to_uuid(chat_id).unwrap(),
+ EntityType::Chat,
+ channel_share_permissions,
+ )
+ .await?;
}
Ok(())
diff --git a/rust/cloud-storage/chat/src/outbound/postgres/queries/get_access_level.rs b/rust/cloud-storage/chat/src/outbound/postgres/queries/get_access_level.rs
index 567298fedf..869f3211b1 100644
--- a/rust/cloud-storage/chat/src/outbound/postgres/queries/get_access_level.rs
+++ b/rust/cloud-storage/chat/src/outbound/postgres/queries/get_access_level.rs
@@ -3,24 +3,48 @@
use models_permissions::share_permission::access_level::AccessLevel;
use std::str::FromStr;
-/// Get the user's access level on a chat from the `UserItemAccess` table.
+/// Get the user's access level on a chat from the `entity_access` table.
+///
+/// Checks access via all of the user's source IDs (direct user ID, team
+/// memberships, and channel participations) and returns the highest level found.
#[tracing::instrument(err, skip(pool))]
pub(crate) async fn get_access_level(
pool: &sqlx::PgPool,
user_id: &str,
chat_id: &str,
) -> anyhow::Result<AccessLevel> {
+ let entity_id = macro_uuid::string_to_uuid(chat_id).unwrap();
let level = sqlx::query_scalar!(
r#"
- SELECT "access_level"::text
- FROM "UserItemAccess"
- WHERE "user_id" = $1 AND "item_id" = $2 AND "item_type" = 'chat'
+ SELECT access_level::text
+ FROM entity_access
+ WHERE source_id = ANY(ARRAY(
+ SELECT cp.channel_id::text FROM comms_channel_participants cp
+ WHERE cp.user_id = $1 AND cp.left_at IS NULL
+ UNION ALL
+ SELECT t.team_id::text FROM team_user t
+ WHERE t.user_id = $1
+ UNION ALL
+ SELECT $1
+ ))
+ AND entity_id = $2
+ AND entity_type = 'chat'
+ ORDER BY
+ CASE access_level::text
+ WHEN 'owner' THEN 4
+ WHEN 'edit' THEN 3
+ WHEN 'comment' THEN 2
+ WHEN 'view' THEN 1
+ ELSE 0
+ END DESC
+ LIMIT 1
"#,
user_id,
- chat_id,
+ entity_id,
)
- .fetch_one(pool)
+ .fetch_optional(pool)
.await?
+ .flatten()
.unwrap_or_default();
Ok(AccessLevel::from_str(&level).unwrap_or(AccessLevel::View))
diff --git a/rust/cloud-storage/chat/src/outbound/postgres/queries/insert_user_item_access.rs b/rust/cloud-storage/chat/src/outbound/postgres/queries/insert_user_item_access.rs
deleted file mode 100644
index 57ee59dbcb..0000000000
--- a/rust/cloud-storage/chat/src/outbound/postgres/queries/insert_user_item_access.rs
+++ /dev/null
@@ -1,39 +0,0 @@
-//! Grant a user access to a chat.
-
-use macro_user_id::user_id::MacroUserIdStr;
-use models_permissions::share_permission::access_level::AccessLevel;
-use sqlx::{Postgres, Transaction};
-
-/// Insert an access record granting the user the given access level on a chat.
-#[tracing::instrument(err, skip(tx))]
-pub(crate) async fn insert_user_item_access(
- tx: &mut Transaction<'_, Postgres>,
- user_id: MacroUserIdStr<'_>,
- chat_id: &str,
- access_level: AccessLevel,
-) -> anyhow::Result<()> {
- let id = macro_uuid::generate_uuid_v7();
-
- sqlx::query!(
- r#"
- INSERT INTO "UserItemAccess" (
- "id",
- "user_id",
- "item_id",
- "item_type",
- "access_level",
- "created_at",
- "updated_at"
- )
- VALUES ($1, $2, $3, 'chat', $4, NOW(), NOW())
- "#,
- id,
- user_id.as_ref(),
- chat_id,
- access_level as _,
- )
- .execute(tx.as_mut())
- .await?;
-
- Ok(())
-}
diff --git a/rust/cloud-storage/chat/src/outbound/postgres/queries/mod.rs b/rust/cloud-storage/chat/src/outbound/postgres/queries/mod.rs
index e434dd2d30..ea8df65a24 100644
--- a/rust/cloud-storage/chat/src/outbound/postgres/queries/mod.rs
+++ b/rust/cloud-storage/chat/src/outbound/postgres/queries/mod.rs
@@ -10,11 +10,11 @@ pub(crate) mod get_messages;
pub(crate) mod get_permissions;
pub(crate) mod get_web_citations;
pub(crate) mod insert_chat;
-pub(crate) mod insert_user_item_access;
pub(crate) mod patch_chat;
pub(crate) mod permanently_delete_chat;
pub(crate) mod revert_delete_chat;
pub(crate) mod soft_delete_chat;
pub(crate) mod update_message_content;
+pub(crate) mod update_project_modified;
pub(crate) mod upsert_item_last_accessed;
pub(crate) mod upsert_user_history;
diff --git a/rust/cloud-storage/chat/src/outbound/postgres/queries/permanently_delete_chat.rs b/rust/cloud-storage/chat/src/outbound/postgres/queries/permanently_delete_chat.rs
index 0551189a31..4fe51e0a72 100644
--- a/rust/cloud-storage/chat/src/outbound/postgres/queries/permanently_delete_chat.rs
+++ b/rust/cloud-storage/chat/src/outbound/postgres/queries/permanently_delete_chat.rs
@@ -1,5 +1,6 @@
//! Permanently delete a chat and all associated data.
+use model_entity::EntityType;
use sqlx::{Postgres, Transaction};
/// Hard-delete a chat: remove pins, history, permissions, access, and the chat row.
@@ -38,8 +39,9 @@ pub(crate) async fn permanently_delete_chat(
.await?;
sqlx::query!(
- r#"DELETE FROM "UserItemAccess" WHERE "item_id" = $1 AND "item_type" = 'chat'"#,
- chat_id,
+ r#"DELETE FROM "entity_access" WHERE "entity_id" = $1 AND "entity_type" = $2"#,
+ macro_uuid::string_to_uuid(chat_id).unwrap(),
+ EntityType::Chat.as_ref(),
)
.execute(tx.as_mut())
.await?;
diff --git a/rust/cloud-storage/chat/src/outbound/postgres/queries/update_project_modified.rs b/rust/cloud-storage/chat/src/outbound/postgres/queries/update_project_modified.rs
new file mode 100644
index 0000000000..528c2c2b47
--- /dev/null
+++ b/rust/cloud-storage/chat/src/outbound/postgres/queries/update_project_modified.rs
@@ -0,0 +1,17 @@
+//! Bump a project's `updatedAt` timestamp.
+
+/// Update a project's `updatedAt` to `NOW()`.
+#[tracing::instrument(err, skip(pool))]
+pub(crate) async fn update_project_modified(
+ pool: &sqlx::PgPool,
+ project_id: &str,
+) -> anyhow::Result<()> {
+ sqlx::query!(
+ r#"UPDATE "Project" SET "updatedAt" = NOW() WHERE id = $1"#,
+ project_id,
+ )
+ .execute(pool)
+ .await?;
+
+ Ok(())
+}
diff --git a/rust/cloud-storage/chat/src/outbound/postgres/test.rs b/rust/cloud-storage/chat/src/outbound/postgres/test.rs
index ecbfb2e162..b28027a9e0 100644
--- a/rust/cloud-storage/chat/src/outbound/postgres/test.rs
+++ b/rust/cloud-storage/chat/src/outbound/postgres/test.rs
@@ -97,12 +97,12 @@ async fn create_chat_creates_user_item_access(pool: Pool<Postgres>) {
let row = sqlx::query(
r#"
SELECT "access_level"::text as "access_level"
- FROM "UserItemAccess"
- WHERE "user_id" = $1 AND "item_id" = $2 AND "item_type" = 'chat'
+ FROM "entity_access"
+ WHERE "source_id" = $1 AND "entity_id" = $2
"#,
)
.bind("macro|[email protected]")
- .bind(&chat_id)
+ .bind(macro_uuid::string_to_uuid(&chat_id).unwrap())
.fetch_one(&pool)
.await
.unwrap();
@@ -379,15 +379,16 @@ async fn permanently_delete_chat_removes_user_item_access(pool: Pool<Postgres>)
repo.permanently_delete(&chat_id).await.unwrap();
- let count: (i64,) = sqlx::query_as(
- r#"SELECT COUNT(*) FROM "UserItemAccess" WHERE "item_id" = $1 AND "item_type" = 'chat'"#,
+ let count: i64 = sqlx::query!(
+ r#"SELECT COUNT(id) AS result FROM "entity_access" WHERE "entity_id" = $1"#,
+ &macro_uuid::string_to_uuid(&chat_id).unwrap(),
)
- .bind(&chat_id)
+ .map(|r| r.result.unwrap_or(0))
.fetch_one(&pool)
.await
.unwrap();
- assert_eq!(count.0, 0);
+ assert_eq!(count, 0);
}
#[sqlx::test(
diff --git a/rust/cloud-storage/comms_service/Cargo.toml b/rust/cloud-storage/comms_service/Cargo.toml
index 5c784eb95f..5bcc9769af 100644
--- a/rust/cloud-storage/comms_service/Cargo.toml
+++ b/rust/cloud-storage/comms_service/Cargo.toml
@@ -38,10 +38,12 @@ comms_db_client = { path = "../comms_db_client", optional = true }
connection_gateway_client = { path = "../connection_gateway_client" }
doppleganger = { workspace = true }
entity_access = { path = "../entity_access" }
+entity_access_db_utils = { path = "../entity_access_db_utils" }
frecency = { path = "../frecency", features = ["postgres"] }
futures = { workspace = true }
http-body-util = { workspace = true }
jsonwebtoken.workspace = true
+last_online_tracker = { path = "../last_online_tracker" }
macro_auth = { path = "../macro_auth" }
macro_aws_config = { path = "../macro_aws_config" }
macro_axum_utils = { path = "../macro_axum_utils" }
@@ -62,7 +64,6 @@ model_notifications = { path = "../model_notifications" }
models_comms = { path = "../models_comms" }
models_opensearch = { path = "../models_opensearch" }
models_permissions = { path = "../models_permissions" }
-last_online_tracker = { path = "../last_online_tracker" }
notification_hex = { path = "../notification", package = "notification" }
reqwest.workspace = true
secretsmanager_client = { path = "../secretsmanager_client" }
diff --git a/rust/cloud-storage/comms_service/src/api/channels/add_participants.rs b/rust/cloud-storage/comms_service/src/api/channels/add_participants.rs
index 6f066edf33..87e483dd83 100644
--- a/rust/cloud-storage/comms_service/src/api/channels/add_participants.rs
+++ b/rust/cloud-storage/comms_service/src/api/channels/add_participants.rs
@@ -3,7 +3,6 @@ use crate::api::context::{AppState, ChannelImpl};
use crate::api::extractors::{
ChannelId, ChannelMember, ChannelName, ChannelParticipants, ChannelTypeExtractor,
};
-use crate::channel_permissions;
use crate::notification as comms_notification;
use anyhow::Result;
use axum::extract::Json;
@@ -83,22 +82,6 @@ pub async fn handler(
})?;
}
- let start = std::time::Instant::now();
- channel_permissions::add_permissions_for_channel_users(
- &ctx.db,
- &channel_id.to_string(),
- &participants,
- )
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "unable to add permissions for channel items");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- "unable to add permissions for channel items".to_string(),
- )
- })?;
- tracing::info!(elapsed=?start.elapsed(), "added user channel permissions");
-
// There should always be participants, but better safe than sorry
let metadata = CommonChannelMetadata {
channel_type: model_notifications::ChannelType::mirror(channel_type),
diff --git a/rust/cloud-storage/comms_service/src/api/channels/remove_participants.rs b/rust/cloud-storage/comms_service/src/api/channels/remove_participants.rs
index 03b00c66bb..04efbeef8c 100644
--- a/rust/cloud-storage/comms_service/src/api/channels/remove_participants.rs
+++ b/rust/cloud-storage/comms_service/src/api/channels/remove_participants.rs
@@ -1,6 +1,5 @@
use crate::api::context::AppState;
use crate::api::extractors::{ChannelId, ChannelMember, ChannelTypeExtractor};
-use crate::channel_permissions;
use anyhow::Result;
use axum::extract::Json;
use axum::{extract::State, http::StatusCode};
@@ -66,21 +65,5 @@ pub async fn handler(
})?;
}
- let start = std::time::Instant::now();
- channel_permissions::remove_permissions_for_channel_users(
- &ctx.db,
- &channel_id.to_string(),
- &req.participants,
- )
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "unable to remove permissions for channel items");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- "unable to remove permissions for channel items".to_string(),
- )
- })?;
- tracing::info!(elapsed=?start.elapsed(), "removed user channel permissions");
-
Ok(StatusCode::OK)
}
diff --git a/rust/cloud-storage/comms_service/src/channel_permissions.rs b/rust/cloud-storage/comms_service/src/channel_permissions.rs
index 937d85d216..217412bf22 100644
--- a/rust/cloud-storage/comms_service/src/channel_permissions.rs
+++ b/rust/cloud-storage/comms_service/src/channel_permissions.rs
@@ -8,10 +8,11 @@ use entity_access::domain::models::EntityType;
use entity_access::domain::ports::EntityAccessService;
use macro_user_id::user_id::MacroUserIdStr;
use models_permissions::share_permission::access_level::AccessLevel;
-use models_permissions::user_item_access::UserItemAccess;
+use models_permissions::share_permission::channel_share_permission::{
+ UpdateChannelSharePermission, UpdateOperation,
+};
use sqlx::PgPool;
use std::str::FromStr;
-use uuid::Uuid;
/// Updates the channel share permission for an item shared in a channel message.
///
@@ -29,11 +30,17 @@ pub async fn update_channel_share_permission(
item_id: &str,
item_type: &str,
) -> anyhow::Result<()> {
+ // The item id should be a uuid
+ let entity_id = macro_uuid::string_to_uuid(item_id)?;
+
// If the item type is not a supported shareable item type, return success early
if model::item::ShareableItemType::from_str(item_type).is_err() {
return Ok(());
}
+ // TODO: we should make everything here use the transaction
+ let mut transaction = db.begin().await?;
+
// Ensure thread share permissions exist before getting access level
if item_type == "thread" {
macro_middleware::cloud_storage::thread::ensure_thread_exists::insert_thread_share_permissions(db, item_id)
@@ -47,7 +54,7 @@ pub async fn update_channel_share_permission(
"chat" => EntityType::Chat,
"project" => EntityType::Project,
"thread" => EntityType::EmailThread,
- "channel" => EntityType::Channel,
+ "call" => EntityType::Call,
_ => anyhow::bail!("unsupported item type: {}", item_type),
};
@@ -92,132 +99,17 @@ pub async fn update_channel_share_permission(
}
}
- // This flow means the channel share permission is new - the user shared the item directly
- // through a channel message. Grant all channel participants view access.
- let channel_uuid = Uuid::parse_str(channel_id).context("failed to parse channel_id as UUID")?;
-
- let channel_participants =
- comms_db_client::participants::get_participants::get_participants(db, &channel_uuid)
- .await
- .context("failed to get channel participants")?
- .into_iter()
- .filter_map(|p| match p.left_at {
- // If the user left we should not update their user item access
- Some(_) => None,
- None => Some(p.user_id),
- })
- .collect::<Vec<_>>();
-
- macro_db_client::item_access::insert::upsert_user_item_access_bulk(
- db,
- &channel_participants,
- item_id,
- item_type,
- channel_share_permission_access_level,
- Some(channel_uuid),
+ entity_access_db_utils::update_entity_access_channel_share_permissions(
+ &mut transaction,
+ &entity_id,
+ entity_type,
+ &[UpdateChannelSharePermission {
+ channel_id: channel_id.to_string(),
+ operation: UpdateOperation::Add,
+ access_level: Some(channel_share_permission_access_level),
+ }],
)
- .await
- .context("failed to insert user item access rows")?;
+ .await?;
Ok(())
}
-
-/// Adds permissions for users who have been added to a channel.
-///
-/// When users are added to a channel, they need to be granted access to all items
-/// that have been shared with that channel.
-#[tracing::instrument(skip(db))]
-pub async fn add_permissions_for_channel_users(
- db: &PgPool,
- channel_id: &str,
- user_ids: &[String],
-) -> anyhow::Result<()> {
- if user_ids.is_empty() {
- return Ok(());
- }
-
- let channel_uuid =
- macro_uuid::string_to_uuid(channel_id).context("failed to parse channel_id as UUID")?;
-
- let mut items_to_insert: Vec<UserItemAccess> = Vec::new();
-
- // Get all channel share permissions for the channel
- let csps = macro_db_client::share_permission::channel_permission::get::get_channel_share_permissions_by_channel_id(
- db,
- channel_id,
- )
- .await
- .context("failed to get channel share permissions for channel")?;
-
- let csp_ids = csps
- .iter()
- .map(|csp| csp.share_permission_id.clone())
- .collect::<Vec<_>>();
-
- if csp_ids.is_empty() {
- return Ok(());
- }
-
- // Get all items matching the channel share permission IDs
- let item_type_map =
- macro_db_client::share_permission::get::get_items_by_share_permission_ids(db, &csp_ids)
- .await
- .context("failed to get items for share permission ids")?;
-
- // For each item, add an entry for each user into UserItemAccess
- for csp in csps {
- if let Some((item_id, item_type)) = item_type_map.get(&csp.share_permission_id) {
- for user_id in user_ids.iter() {
- items_to_insert.push(UserItemAccess {
- id: macro_uuid::generate_uuid_v7(),
- user_id: user_id.to_string(),
- item_id: item_id.to_string(),
- item_type: item_type.to_string(),
- access_level: csp.access_level,
- granted_from_channel_id: Some(channel_uuid),
- created_at: chrono::Utc::now(),
- updated_at: chrono::Utc::now(),
- });
- }
- }
- }
-
- if !items_to_insert.is_empty() {
- // Insert into database
- macro_db_client::item_access::insert::insert_user_item_access_batch(db, &items_to_insert)
- .await
- .context("failed to insert user item access records")?;
- }
-
- Ok(())
-}
-
-/// Removes permissions for users who have been removed from a channel.
-///
-/// When users are removed from a channel, their access to items granted through
-/// that channel should be revoked.
-#[tracing::instrument(skip(db))]
-pub async fn remove_permissions_for_channel_users(
- db: &PgPool,
- channel_id: &str,
- user_ids: &[String],
-) -> anyhow::Result<u64> {
- if user_ids.is_empty() {
- return Ok(0);
- }
-
- let channel_uuid =
- macro_uuid::string_to_uuid(channel_id).context("failed to parse channel_id as UUID")?;
-
- // Delete all UserItemAccess records for these users granted from this channel
- let rows_affected =
- macro_db_client::item_access::delete::delete_user_item_access_by_channel_and_users(
- db,
- channel_uuid,
- user_ids,
- )
- .await
- .context("failed to delete user item access records")?;
-
- Ok(rows_affected)
-}
diff --git a/rust/cloud-storage/delete_chat_handler/.sqlx/query-9cd17d2d44969a4c8812e94980b0b5c438569bd6d3ef57e23fb5393dee4c3780.json b/rust/cloud-storage/delete_chat_handler/.sqlx/query-9cd17d2d44969a4c8812e94980b0b5c438569bd6d3ef57e23fb5393dee4c3780.json
deleted file mode 100644
index dd0c6a4fb4..0000000000
--- a/rust/cloud-storage/delete_chat_handler/.sqlx/query-9cd17d2d44969a4c8812e94980b0b5c438569bd6d3ef57e23fb5393dee4c3780.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n DELETE FROM \"UserItemAccess\"\n WHERE \"item_id\" = $1 AND \"item_type\" = $2\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text",
- "Text"
- ]
- },
- "nullable": []
- },
- "hash": "9cd17d2d44969a4c8812e94980b0b5c438569bd6d3ef57e23fb5393dee4c3780"
-}
diff --git a/rust/cloud-storage/delete_chat_handler/.sqlx/query-ac52ec341d9ff2b334df144dfcba1195b845609b557d278290359a0e6170c10d.json b/rust/cloud-storage/delete_chat_handler/.sqlx/query-ac52ec341d9ff2b334df144dfcba1195b845609b557d278290359a0e6170c10d.json
new file mode 100644
index 0000000000..19f6ad325a
--- /dev/null
+++ b/rust/cloud-storage/delete_chat_handler/.sqlx/query-ac52ec341d9ff2b334df144dfcba1195b845609b557d278290359a0e6170c10d.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"entity_access\"\n WHERE \"entity_id\" = $1 AND \"entity_type\" = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "ac52ec341d9ff2b334df144dfcba1195b845609b557d278290359a0e6170c10d"
+}
diff --git a/rust/cloud-storage/delete_chat_handler/Cargo.toml b/rust/cloud-storage/delete_chat_handler/Cargo.toml
index c5fd917135..173b5c302e 100644
--- a/rust/cloud-storage/delete_chat_handler/Cargo.toml
+++ b/rust/cloud-storage/delete_chat_handler/Cargo.toml
@@ -9,6 +9,7 @@ anyhow = { workspace = true }
aws_lambda_events = { workspace = true, features = ["sqs"] }
lambda_runtime = { workspace = true }
macro_entrypoint = { path = "../macro_entrypoint" }
+macro_uuid = { path = "../macro_uuid" }
openssl = { workspace = true }
sqlx = { workspace = true }
tokio = { workspace = true }
diff --git a/rust/cloud-storage/delete_chat_handler/justfile b/rust/cloud-storage/delete_chat_handler/justfile
index 756e290719..ae57d70f25 100644
--- a/rust/cloud-storage/delete_chat_handler/justfile
+++ b/rust/cloud-storage/delete_chat_handler/justfile
@@ -1,7 +1,23 @@
lambda_name := file_name(justfile_directory())
+DATABASE_URL := "postgres://user:password@localhost:5432/macrodb"
+
+mod sqlx '../sqlx.just'
+force_drop_db:
+ echo "y" | just sqlx::drop_db {{ DATABASE_URL }}
+
+check:
+ SQLX_OFFLINE=true cargo check
+
+create_db:
+ just sqlx::create_db {{ DATABASE_URL }}
+
+# Prepare DB for offline cache for docker image
+prepare_db:
+ just sqlx::prepare_db {{ DATABASE_URL }}
+
test:
cargo test --all-features
build:
- SQLX_OFFLINE=true cargo lambda build --release --bin {{lambda_name}} --output-format zip
\ No newline at end of file
+ SQLX_OFFLINE=true cargo lambda build --release --bin {{lambda_name}} --output-format zip
diff --git a/rust/cloud-storage/delete_chat_handler/migrations/20240325143515_basic_schema_for_testing.sql b/rust/cloud-storage/delete_chat_handler/migrations/20240325143515_basic_schema_for_testing.sql
index 635caf3b05..2d0d932fa2 100644
--- a/rust/cloud-storage/delete_chat_handler/migrations/20240325143515_basic_schema_for_testing.sql
+++ b/rust/cloud-storage/delete_chat_handler/migrations/20240325143515_basic_schema_for_testing.sql
@@ -3,295 +3,3257 @@
-- Changes here WILL NOT ever make it into the dev/production db.
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
-CREATE TABLE "Organization"
-(
- "id" INTEGER PRIMARY KEY,
- "name" TEXT UNIQUE NOT NULL
-);
-
-CREATE TABLE "OrganizationRetentionPolicy"
-(
- "id" BIGSERIAL PRIMARY KEY,
- "organization_id" INTEGER UNIQUE NOT NULL,
- "retention_days" INTEGER,
- FOREIGN KEY ("organization_id") REFERENCES "Organization" ("id") ON DELETE CASCADE
-);
-
-CREATE TABLE "User"
-(
- "id" TEXT PRIMARY KEY,
- "email" TEXT UNIQUE NOT NULL,
- "name" TEXT,
- "stripeCustomerId" TEXT UNIQUE,
- "organizationId" INTEGER,
- FOREIGN KEY ("organizationId") REFERENCES "Organization" ("id") ON DELETE SET NULL
-);
-
-CREATE TABLE "Permission"
-(
- "id" TEXT PRIMARY KEY,
- "description" TEXT
-);
-
-CREATE TABLE "Role"
-(
- "id" TEXT PRIMARY KEY,
- "description" TEXT
-);
-
-CREATE TABLE "RolesOnPermissions"
-(
- "permissionId" TEXT,
- "roleId" TEXT,
- PRIMARY KEY ("permissionId", "roleId"),
- CONSTRAINT "fk_permission" FOREIGN KEY ("permissionId") REFERENCES "Permission" ("id"),
- CONSTRAINT "fk_role_permissions" FOREIGN KEY ("roleId") REFERENCES "Role" ("id")
-);
-
-CREATE TABLE "RolesOnUsers"
-(
- "userId" TEXT,
- "roleId" TEXT,
- PRIMARY KEY ("userId", "roleId"),
- CONSTRAINT "fk_user" FOREIGN KEY ("userId") REFERENCES "User" ("id"),
- CONSTRAINT "fk_role_users" FOREIGN KEY ("roleId") REFERENCES "Role" ("id")
-);
-
-CREATE TABLE "DocumentFamily"
-(
- "id" BIGSERIAL PRIMARY KEY,
- "rootDocumentId" TEXT NOT NULL
-);
-
-CREATE TABLE "Project"
-(
- "id" TEXT PRIMARY KEY DEFAULT uuid_generate_v4(),
- "name" TEXT NOT NULL,
- "userId" TEXT NOT NULL,
- "parentId" TEXT,
- "createdAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- "updatedAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- "deletedAt" TIMESTAMPTZ,
- FOREIGN KEY ("parentId") REFERENCES "Project" ("id"),
- FOREIGN KEY ("userId") REFERENCES "User" ("id")
-);
-
--- Document table
-CREATE TABLE "Document"
-(
- -- Setting to type text as UUID was causing tests to fail and I didn't want to debug it
- "id" TEXT PRIMARY KEY DEFAULT uuid_generate_v4(),
- "name" TEXT NOT NULL,
- "owner" TEXT NOT NULL,
- "fileType" TEXT NOT NULL,
- -- Setting to type text as UUID was causing tests to fail and I didn't want to debug it
- "branchedFromId" TEXT,
- "branchedFromVersionId" BIGINT,
- "documentFamilyId" BIGINT,
- "createdAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- "updatedAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- "deletedAt" TIMESTAMPTZ,
- "projectId" TEXT,
- FOREIGN KEY ("owner") REFERENCES "User" ("id"),
- FOREIGN KEY ("projectId") REFERENCES "Project" ("id")
-);
-CREATE INDEX idx_document_project_id ON "Document" ("projectId");
-
-CREATE TABLE "Macrotation"
-(
- "id" TEXT PRIMARY KEY,
- "parentId" TEXT,
- "documentId" TEXT NOT NULL,
- "userId" TEXT NOT NULL,
- "linkSharePosition" TEXT,
- "highlightedText" TEXT,
- "image" TEXT,
- "comment" TEXT,
- "hexCode" TEXT,
- "section" TEXT,
- "location" TEXT,
- "order" INTEGER,
- "createdAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- "updatedAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- FOREIGN KEY ("documentId") REFERENCES "Document" ("id") ON DELETE CASCADE,
- FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE,
- FOREIGN KEY ("parentId") REFERENCES "Macrotation" ("id") ON DELETE CASCADE
-);
-
--- DocumentInstance table
-CREATE TABLE "DocumentInstance"
-(
- "id" BIGSERIAL PRIMARY KEY,
- "revisionName" TEXT,
- -- Setting to type text as UUID was causing tests to fail and I didn't want to debug it
- "documentId" TEXT NOT NULL,
- "createdAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- "updatedAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- "sha" TEXT NOT NULL,
- FOREIGN KEY ("documentId") REFERENCES "Document" ("id") ON DELETE CASCADE
-);
-
-CREATE TABLE "DocumentInstanceModificationData"
-(
- "id" BIGSERIAL PRIMARY KEY,
- "documentInstanceId" BIGSERIAL NOT NULL,
- "modificationData" JSONB NOT NULL,
- "createdAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- "updatedAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- FOREIGN KEY ("documentInstanceId") REFERENCES "DocumentInstance" ("id") ON DELETE CASCADE
-);
-
-CREATE TABLE "DocumentBom"
-(
- "id" BIGSERIAL PRIMARY KEY,
- "revisionName" TEXT,
- -- Setting to type text as UUID was causing tests to fail and I didn't want to debug it
- "documentId" TEXT NOT NULL,
- "createdAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- "updatedAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- FOREIGN KEY ("documentId") REFERENCES "Document" ("id") ON DELETE CASCADE
-);
-
-CREATE TABLE "BomPart"
-(
- "id" TEXT PRIMARY KEY DEFAULT uuid_generate_v4(),
- "sha" TEXT NOT NULL,
- "path" TEXT NOT NULL,
- "documentBomId" BIGSERIAL NOT NULL,
- "createdAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- "updatedAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- FOREIGN KEY ("documentBomId") REFERENCES "DocumentBom" ("id") ON DELETE CASCADE
-);
-
-CREATE TABLE "DocumentProcessResult"
-(
- "id" BIGSERIAL PRIMARY KEY,
- "documentId" TEXT NOT NULL,
- "jobType" TEXT NOT NULL,
- "content" TEXT NOT NULL,
- FOREIGN KEY ("documentId") REFERENCES "Document" ("id") ON DELETE CASCADE
-);
-
-CREATE TABLE "JobToDocumentProcessResult"
-(
- "jobId" TEXT NOT NULL,
- "documentProcessResultId" BIGSERIAL NOT NULL,
- FOREIGN KEY ("documentProcessResultId") REFERENCES "DocumentProcessResult" ("id") ON DELETE CASCADE
-);
-
-CREATE TABLE "UserHistory"
-(
- "userId" TEXT NOT NULL,
- "itemId" TEXT NOT NULL,
- "itemType" TEXT NOT NULL,
- "createdAt" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
- "updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
- FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE,
- UNIQUE ("userId", "itemId", "itemType")
-);
-
-CREATE TABLE "ItemLastAccessed"
-(
- "item_id" TEXT NOT NULL,
- "item_type" TEXT NOT NULL,
- "last_accessed" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
- UNIQUE ("item_id", "item_type")
-);
-
-CREATE TABLE "Pin"
-(
- "userId" TEXT NOT NULL,
- "pinnedItemId" TEXT NOT NULL,
- "pinnedItemType" TEXT NOT NULL,
- "pinIndex" INTEGER NOT NULL,
- "createdAt" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
- "updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
- FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE,
- UNIQUE ("userId", "pinnedItemId", "pinnedItemType")
-);
-
-CREATE TABLE "DocxUploadJob"
-(
- "id" BIGSERIAL PRIMARY KEY,
- "jobId" TEXT NOT NULL,
- "documentId" TEXT,
- "createdAt" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
-);
-
-CREATE TABLE "Chat"
-(
- "id" TEXT PRIMARY KEY DEFAULT uuid_generate_v4(),
- "name" TEXT NOT NULL,
- "userId" TEXT NOT NULL,
- "createdAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- "updatedAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- "projectId" TEXT,
- "model" TEXT,
- FOREIGN KEY ("projectId") REFERENCES "Project" ("id") ON DELETE SET NULL,
- FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE
-);
-CREATE INDEX idx_chat_project_id ON "Chat" ("projectId");
-
-CREATE TABLE "ChatMessage"
-(
- "id" TEXT PRIMARY KEY UNIQUE NOT NULL DEFAULT uuid_generate_v4(),
- "content" TEXT NOT NULL,
- "role" TEXT NOT NULL,
- "chatId" TEXT NOT NULL,
- "createdAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- "updatedAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- FOREIGN KEY ("chatId") REFERENCES "Chat" ("id") ON DELETE CASCADE
-);
-
-CREATE TABLE "SharePermission"
-(
- "id" TEXT PRIMARY KEY DEFAULT uuid_generate_v4(),
- "isPublic" BOOLEAN NOT NULL,
- "publicAccessLevel" TEXT,
- "createdAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
- "updatedAt" TIMESTAMPTZ NOT NULL DEFAULT NOW()
-);
-
-CREATE TABLE "DocumentPermission"
-(
- "documentId" TEXT NOT NULL UNIQUE,
- "sharePermissionId" TEXT NOT NULL UNIQUE,
- PRIMARY KEY ("documentId", "sharePermissionId"),
- FOREIGN KEY ("documentId") REFERENCES "Document" ("id") ON DELETE CASCADE,
- FOREIGN KEY ("sharePermissionId") REFERENCES "SharePermission" ("id") ON DELETE CASCADE
-);
-
-CREATE TABLE "ChatPermission"
-(
- "chatId" TEXT NOT NULL UNIQUE,
- "sharePermissionId" TEXT NOT NULL UNIQUE,
- PRIMARY KEY ("chatId", "sharePermissionId"),
- FOREIGN KEY ("chatId") REFERENCES "Chat" ("id") ON DELETE CASCADE,
- FOREIGN KEY ("sharePermissionId") REFERENCES "SharePermission" ("id") ON DELETE CASCADE
-);
-
-CREATE TABLE "ProjectPermission"
-(
- "projectId" TEXT NOT NULL UNIQUE,
- "sharePermissionId" TEXT NOT NULL UNIQUE,
- PRIMARY KEY ("projectId", "sharePermissionId"),
- FOREIGN KEY ("projectId") REFERENCES "Project" ("id") ON DELETE CASCADE,
- FOREIGN KEY ("sharePermissionId") REFERENCES "SharePermission" ("id") ON DELETE CASCADE
-);
-CREATE INDEX idx_project_permission_project_id ON "ProjectPermission" ("projectId");
-
-CREATE TABLE "ChatAttachment"
-(
- "id" TEXT PRIMARY KEY DEFAULT uuid_generate_v4(),
- "attachmentType" TEXT NOT NULL,
- "attachmentId" TEXT NOT NULL,
- "chatId" TEXT,
- "messageId" TEXT
-);
-
-CREATE TABLE "DocumentText"
-(
- "id" BIGSERIAL PRIMARY KEY,
- "content" TEXT NOT NULL,
- "documentId" TEXT NOT NULL
+CREATE EXTENSION IF NOT EXISTS btree_gin WITH SCHEMA public;
+
+CREATE EXTENSION IF NOT EXISTS pg_stat_statements WITH SCHEMA public;
+
+CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public;
+
+CREATE TYPE public."AccessLevel" AS ENUM (
+ 'view',
+ 'comment',
+ 'edit',
+ 'owner'
+);
+
+CREATE TYPE public."OrganizationItJobType" AS ENUM (
+ 'UPDATE',
+ 'REMOVE'
+);
+
+CREATE TYPE public."OrganizationStatus" AS ENUM (
+ 'PILOT',
+ 'ENTERPRISE'
+);
+
+CREATE TYPE public."SetAsDefault" AS ENUM (
+ 'ASK',
+ 'FORCE',
+ 'HIDE'
+);
+
+CREATE TYPE public.anchor_table_name AS ENUM (
+ 'PdfPlaceableCommentAnchor',
+ 'PdfHighlightAnchor'
+);
+
+CREATE TYPE public.comms_channel_type AS ENUM (
+ 'public',
+ 'organization',
+ 'private',
+ 'direct_message',
+ 'team'
+);
+
+CREATE TYPE public.comms_participant_role AS ENUM (
+ 'owner',
+ 'admin',
+ 'member'
+);
+
+CREATE TYPE public.document_sub_type_value AS ENUM (
+ 'task'
+);
+
+CREATE TYPE public.email_backfill_job_status AS ENUM (
+ 'Init',
+ 'InProgress',
+ 'Complete',
+ 'Cancelled',
+ 'Failed'
+);
+
+CREATE TYPE public.email_backfill_message_status AS ENUM (
+ 'InProgress',
+ 'Completed',
+ 'Failed',
+ 'Cancelled'
+);
+
+CREATE TYPE public.email_backfill_thread_status AS ENUM (
+ 'InProgress',
+ 'Skipped',
+ 'Completed',
+ 'Failed',
+ 'Cancelled'
+);
+
+CREATE TYPE public.email_label_list_visibility_enum AS ENUM (
+ 'LabelShow',
+ 'LabelShowIfUnread',
+ 'LabelHide'
+);
+
+CREATE TYPE public.email_label_type_enum AS ENUM (
+ 'System',
+ 'User'
+);
+
+CREATE TYPE public.email_message_list_visibility_enum AS ENUM (
+ 'Show',
+ 'Hide'
+);
+
+CREATE TYPE public.email_recipient_type AS ENUM (
+ 'TO',
+ 'CC',
+ 'BCC'
+);
+
+CREATE TYPE public.email_user_provider_enum AS ENUM (
+ 'GMAIL'
+);
+
+CREATE TYPE public.entity_access_source_type AS ENUM (
+ 'channel',
+ 'team',
+ 'user'
+);
+
+CREATE TYPE public.insights_backfill_batch_status AS ENUM (
+ 'Queued',
+ 'InProgress',
+ 'Complete',
+ 'Failed'
+);
+
+CREATE TYPE public.insights_backfill_job_status AS ENUM (
+ 'Init',
+ 'InProgress',
+ 'Complete',
+ 'Cancelled',
+ 'Failed'
+);
+
+CREATE TYPE public.notification_device_type_option AS ENUM (
+ 'ios',
+ 'android'
+);
+
+CREATE TYPE public.property_data_type AS ENUM (
+ 'BOOLEAN',
+ 'DATE',
+ 'NUMBER',
+ 'STRING',
+ 'SELECT_NUMBER',
+ 'SELECT_STRING',
+ 'ENTITY',
+ 'LINK'
+);
+
+CREATE TYPE public.property_entity_type AS ENUM (
+ 'CHANNEL',
+ 'CHAT',
+ 'DOCUMENT',
+ 'PROJECT',
+ 'THREAD',
+ 'USER',
+ 'COMPANY',
+ 'TASK'
+);
+
+CREATE TYPE public.team_role AS ENUM (
+ 'member',
+ 'admin',
+ 'owner'
+);
+
+CREATE TYPE public.team_user_tier AS ENUM (
+ 'haiku',
+ 'sonnet',
+ 'opus'
+);
+
+CREATE FUNCTION public.check_property_name_not_system() RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ IF NEW.is_system = FALSE AND EXISTS (
+ SELECT 1 FROM property_definitions
+ WHERE is_system = TRUE AND LOWER(display_name) = LOWER(NEW.display_name)
+ ) THEN
+ RAISE EXCEPTION 'Cannot create custom property with reserved system property name: %', NEW.display_name;
+ END IF;
+ RETURN NEW;
+END;
+$$;
+
+CREATE FUNCTION public.delete_orphaned_property_definition() RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+ BEGIN
+ IF NEW.organization_id IS NULL AND NEW.user_id IS NULL THEN
+ DELETE FROM property_definitions WHERE id = NEW.id;
+ RETURN NULL;
+ END IF;
+ RETURN NEW;
+ END;
+$$;
+
+CREATE FUNCTION public.delete_share_permission_on_call_record_delete() RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ DELETE FROM "SharePermission" WHERE id = OLD.share_permission_id;
+ RETURN OLD;
+END;
+$$;
+
+CREATE FUNCTION public.ecsi_delete_message() RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ DELETE FROM email_contact_search_index WHERE message_id = OLD.id;
+ RETURN OLD;
+END;
+$$;
+
+CREATE FUNCTION public.ecsi_delete_recipient() RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ DELETE FROM email_contact_search_index
+ WHERE message_id = OLD.message_id
+ AND contact_type = OLD.recipient_type::text
+ AND contact_email = (SELECT email_address FROM email_contacts WHERE id = OLD.contact_id);
+ RETURN OLD;
+END;
+$$;
+
+CREATE FUNCTION public.ecsi_populate_from() RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ IF NEW.from_contact_id IS NOT NULL THEN
+ INSERT INTO email_contact_search_index
+ (link_id, thread_id, message_id, contact_name, contact_email, contact_type)
+ SELECT NEW.link_id, NEW.thread_id, NEW.id,
+ COALESCE(NEW.from_name, c.name), c.email_address, 'FROM'
+ FROM email_contacts c
+ WHERE c.id = NEW.from_contact_id
+ ON CONFLICT (message_id, contact_email, contact_type) DO UPDATE SET
+ contact_name = EXCLUDED.contact_name;
+ END IF;
+ RETURN NEW;
+END;
+$$;
+
+CREATE FUNCTION public.ecsi_populate_recipient() RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO email_contact_search_index
+ (link_id, thread_id, message_id, contact_name, contact_email, contact_type)
+ SELECT m.link_id, m.thread_id, m.id,
+ COALESCE(NEW.name, c.name), c.email_address, NEW.recipient_type::text
+ FROM email_messages m
+ JOIN email_contacts c ON c.id = NEW.contact_id
+ WHERE m.id = NEW.message_id
+ ON CONFLICT (message_id, contact_email, contact_type) DO UPDATE SET
+ contact_name = EXCLUDED.contact_name;
+ RETURN NEW;
+END;
+$$;
+
+CREATE FUNCTION public.ecsi_update_contact_name() RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ UPDATE email_contact_search_index idx
+ SET contact_name = NEW.name
+ FROM email_messages m
+ WHERE idx.message_id = m.id
+ AND idx.contact_type = 'FROM'
+ AND m.from_contact_id = NEW.id
+ AND m.from_name IS NULL;
+
+ UPDATE email_contact_search_index idx
+ SET contact_name = NEW.name
+ FROM email_message_recipients mr
+ JOIN email_messages m ON m.id = mr.message_id
+ WHERE idx.message_id = mr.message_id
+ AND idx.contact_type = mr.recipient_type::text
+ AND mr.contact_id = NEW.id
+ AND mr.name IS NULL;
+
+ RETURN NEW;
+END;
+$$;
+
+CREATE SEQUENCE _sqlx_test.database_ids
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+CREATE TABLE _sqlx_test.databases (
+ db_name text NOT NULL,
+ test_path text NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL
+);
+
+CREATE TABLE public."Artifact" (
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ digest text NOT NULL,
+ "messageId" text NOT NULL,
+ "documentId" text,
+ name text,
+ "userId" text NOT NULL
+);
+
+CREATE TABLE public."BlockedEmail" (
+ email text NOT NULL
+);
+
+CREATE TABLE public."BomPart" (
+ id text DEFAULT gen_random_uuid() NOT NULL,
+ sha text NOT NULL,
+ path text NOT NULL,
+ "documentBomId" bigint NOT NULL,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+CREATE TABLE public."ChannelSharePermission" (
+ channel_id text NOT NULL,
+ share_permission_id text NOT NULL,
+ access_level public."AccessLevel" NOT NULL
+);
+
+CREATE TABLE public."Chat" (
+ id text DEFAULT gen_random_uuid() NOT NULL,
+ "userId" text NOT NULL,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "updatedAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "deletedAt" timestamp(3) without time zone,
+ name text NOT NULL,
+ model text DEFAULT 'gpt-4o'::text NOT NULL,
+ "tokenCount" bigint,
+ "projectId" text,
+ "isPersistent" boolean DEFAULT false NOT NULL
+);
+
+CREATE TABLE public."ChatAttachment" (
+ id text DEFAULT gen_random_uuid() NOT NULL,
+ "attachmentType" text NOT NULL,
+ "attachmentId" text NOT NULL,
+ "chatId" text,
+ "messageId" text
+);
+
+CREATE TABLE public."ChatMessage" (
+ id text DEFAULT gen_random_uuid() NOT NULL,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "updatedAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ content jsonb NOT NULL,
+ role text NOT NULL,
+ "chatId" text NOT NULL,
+ model text
+);
+
+CREATE TABLE public."ChatPermission" (
+ "chatId" text NOT NULL,
+ "sharePermissionId" text NOT NULL
+);
+
+CREATE TABLE public."Comment" (
+ id bigint NOT NULL,
+ "threadId" bigint NOT NULL,
+ owner text NOT NULL,
+ sender text,
+ text text NOT NULL,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "updatedAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "deletedAt" timestamp(3) without time zone,
+ "order" integer,
+ metadata jsonb
+);
+
+CREATE SEQUENCE public."Comment_id_seq"
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."Comment_id_seq" OWNED BY public."Comment".id;
+
+CREATE TABLE public."Document" (
+ id text DEFAULT gen_random_uuid() NOT NULL,
+ name text NOT NULL,
+ owner text NOT NULL,
+ "fileType" text,
+ "branchedFromId" text,
+ "branchedFromVersionId" bigint,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "updatedAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "deletedAt" timestamp(3) without time zone,
+ uploaded boolean DEFAULT false NOT NULL,
+ "documentFamilyId" bigint,
+ "projectId" text
+);
+
+CREATE TABLE public."DocumentBom" (
+ id bigint NOT NULL,
+ "revisionName" text,
+ "documentId" text NOT NULL,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "updatedAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+CREATE SEQUENCE public."DocumentBom_id_seq"
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."DocumentBom_id_seq" OWNED BY public."DocumentBom".id;
+
+CREATE TABLE public."DocumentFamily" (
+ id bigint NOT NULL,
+ "rootDocumentId" text NOT NULL
+);
+
+CREATE SEQUENCE public."DocumentFamily_id_seq"
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."DocumentFamily_id_seq" OWNED BY public."DocumentFamily".id;
+
+CREATE TABLE public."DocumentInstance" (
+ id bigint NOT NULL,
+ "revisionName" text,
+ "documentId" text NOT NULL,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "updatedAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ sha text NOT NULL
+);
+
+CREATE TABLE public."DocumentInstanceModificationData" (
+ id bigint NOT NULL,
+ "documentInstanceId" bigint NOT NULL,
+ "modificationData" jsonb NOT NULL,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "updatedAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "pdfPlaceableCommentMigratedAt" timestamp(3) without time zone,
+ "pdfHighlightMigratedAt" timestamp(3) without time zone
+);
+
+CREATE SEQUENCE public."DocumentInstanceModificationData_id_seq"
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."DocumentInstanceModificationData_id_seq" OWNED BY public."DocumentInstanceModificationData".id;
+
+CREATE SEQUENCE public."DocumentInstance_id_seq"
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."DocumentInstance_id_seq" OWNED BY public."DocumentInstance".id;
+
+CREATE TABLE public."DocumentPermission" (
+ "documentId" text NOT NULL,
+ "sharePermissionId" text NOT NULL
+);
+
+CREATE TABLE public."DocumentProcessResult" (
+ id bigint NOT NULL,
+ "documentId" text NOT NULL,
+ "jobType" text NOT NULL,
+ content text NOT NULL
+);
+
+CREATE SEQUENCE public."DocumentProcessResult_id_seq"
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."DocumentProcessResult_id_seq" OWNED BY public."DocumentProcessResult".id;
+
+CREATE TABLE public."DocumentSummary" (
+ id text DEFAULT gen_random_uuid() NOT NULL,
+ summary text NOT NULL,
+ document_id text NOT NULL,
+ version_id text NOT NULL,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+CREATE TABLE public."DocumentText" (
+ id bigint NOT NULL,
+ content text NOT NULL,
+ "documentId" text NOT NULL,
+ "tokenCount" bigint DEFAULT 0 NOT NULL
+);
+
+CREATE TABLE public."DocumentTextParts" (
+ id text NOT NULL,
+ reference text NOT NULL,
+ "documentId" text NOT NULL
+);
+
+CREATE SEQUENCE public."DocumentText_id_seq"
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."DocumentText_id_seq" OWNED BY public."DocumentText".id;
+
+CREATE TABLE public."DocumentView" (
+ id bigint NOT NULL,
+ document_id text NOT NULL,
+ user_id text,
+ created_at timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+CREATE SEQUENCE public."DocumentView_id_seq"
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."DocumentView_id_seq" OWNED BY public."DocumentView".id;
+
+CREATE TABLE public."EmailInsightsBackfillBatch" (
+ id text NOT NULL,
+ "insightsBackfillJobId" text NOT NULL,
+ "sqsMessageId" text,
+ "threadIds" text[],
+ "totalThreads" integer NOT NULL,
+ status public.insights_backfill_batch_status DEFAULT 'Queued'::public.insights_backfill_batch_status NOT NULL,
+ "insightsGeneratedCount" integer DEFAULT 0 NOT NULL,
+ "insightIds" text[],
+ "errorMessage" text,
+ "queuedAt" timestamp(3) without time zone,
+ "startedAt" timestamp(3) without time zone,
+ "completedAt" timestamp(3) without time zone,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "updatedAt" timestamp(3) without time zone NOT NULL
+);
+
+CREATE TABLE public."EmailInsightsBackfillJob" (
+ id text NOT NULL,
+ "userId" text NOT NULL,
+ "threadsProcessedCount" integer DEFAULT 0 NOT NULL,
+ "insightsGeneratedCount" integer DEFAULT 0 NOT NULL,
+ status public.insights_backfill_job_status DEFAULT 'Init'::public.insights_backfill_job_status NOT NULL,
+ "completedAt" timestamp(3) without time zone,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "updatedAt" timestamp(3) without time zone NOT NULL
+);
+
+CREATE TABLE public."EmailThreadPermission" (
+ "threadId" text NOT NULL,
+ "sharePermissionId" text NOT NULL,
+ "userId" text NOT NULL,
+ "projectId" text
+);
+
+CREATE TABLE public."EnterpriseEmailContacts" (
+ id integer NOT NULL,
+ "organizationId" integer NOT NULL,
+ "firstName" text NOT NULL,
+ "lastName" text NOT NULL,
+ email text NOT NULL
+);
+
+CREATE SEQUENCE public."EnterpriseEmailContacts_id_seq"
+ AS integer
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."EnterpriseEmailContacts_id_seq" OWNED BY public."EnterpriseEmailContacts".id;
+
+CREATE TABLE public."EnterpriseIManageTenants" (
+ id integer NOT NULL,
+ "organizationId" integer NOT NULL,
+ tenant_uri text NOT NULL,
+ nickname text NOT NULL
+);
+
+CREATE SEQUENCE public."EnterpriseIManageTenants_id_seq"
+ AS integer
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."EnterpriseIManageTenants_id_seq" OWNED BY public."EnterpriseIManageTenants".id;
+
+CREATE TABLE public."EnterpriseRules" (
+ id integer NOT NULL,
+ "organizationId" integer NOT NULL,
+ "autoSetAsDefaultApp" boolean DEFAULT false NOT NULL,
+ "disableAutoUpdate" boolean DEFAULT false NOT NULL,
+ "setAsDefault" public."SetAsDefault" DEFAULT 'ASK'::public."SetAsDefault" NOT NULL,
+ "setAsDefaultDocx" public."SetAsDefault" DEFAULT 'ASK'::public."SetAsDefault" NOT NULL
+);
+
+CREATE SEQUENCE public."EnterpriseRules_id_seq"
+ AS integer
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."EnterpriseRules_id_seq" OWNED BY public."EnterpriseRules".id;
+
+CREATE TABLE public."Experiment" (
+ id text NOT NULL,
+ active boolean DEFAULT false NOT NULL,
+ started_at timestamp(3) without time zone,
+ ended_at timestamp(3) without time zone
+);
+
+CREATE TABLE public."ExperimentLog" (
+ experiment_id text NOT NULL,
+ user_id text NOT NULL,
+ "group" character varying(1) NOT NULL,
+ completed boolean DEFAULT false NOT NULL
+);
+
+CREATE TABLE public."InsightContext" (
+ id text DEFAULT gen_random_uuid() NOT NULL,
+ "providerSource" text NOT NULL,
+ "userId" text NOT NULL,
+ "resourceId" text NOT NULL,
+ "updatedAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ consumed boolean DEFAULT false NOT NULL
+);
+
+CREATE TABLE public."InstructionsDocuments" (
+ "documentId" text NOT NULL,
+ "userId" text NOT NULL
+);
+
+CREATE TABLE public."ItemLastAccessed" (
+ item_id text NOT NULL,
+ item_type text NOT NULL,
+ last_accessed timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+CREATE TABLE public."JobToDocumentProcessResult" (
+ "jobId" text NOT NULL,
+ "documentProcessResultId" bigint NOT NULL,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+CREATE TABLE public."MacroPrompt" (
+ id text DEFAULT gen_random_uuid() NOT NULL,
+ title text NOT NULL,
+ prompt text NOT NULL,
+ icon text NOT NULL,
+ color text NOT NULL,
+ required_docs integer,
+ user_id text NOT NULL,
+ created_at timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ updated_at timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+CREATE TABLE public."MacroPromptAttachment" (
+ id text DEFAULT gen_random_uuid() NOT NULL,
+ attachment_type text NOT NULL,
+ attachment_id text NOT NULL,
+ macro_prompt_id text NOT NULL
+);
+
+CREATE TABLE public."MacroPromptPermission" (
+ macro_prompt_id text NOT NULL,
+ share_permission_id text NOT NULL
+);
+
+CREATE TABLE public."Organization" (
+ id integer NOT NULL,
+ name text NOT NULL,
+ "emailToolDomain" text,
+ "stripeCustomerId" text,
+ status public."OrganizationStatus" DEFAULT 'PILOT'::public."OrganizationStatus" NOT NULL,
+ seats integer,
+ "allowListOnly" boolean,
+ "llmProviders" text,
+ "netDocumentsEnabled" boolean DEFAULT false NOT NULL
+);
+
+CREATE TABLE public."OrganizationBilling" (
+ id integer NOT NULL,
+ "organizationId" integer NOT NULL,
+ email text NOT NULL
+);
+
+CREATE SEQUENCE public."OrganizationBilling_id_seq"
+ AS integer
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."OrganizationBilling_id_seq" OWNED BY public."OrganizationBilling".id;
+
+CREATE TABLE public."OrganizationDefaultSharePermission" (
+ id bigint NOT NULL,
+ organization_id integer NOT NULL,
+ is_public boolean DEFAULT false NOT NULL,
+ public_access_level text,
+ organization_access_enabled boolean DEFAULT false NOT NULL,
+ organization_access_level text
+);
+
+CREATE SEQUENCE public."OrganizationDefaultSharePermission_id_seq"
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."OrganizationDefaultSharePermission_id_seq" OWNED BY public."OrganizationDefaultSharePermission".id;
+
+CREATE TABLE public."OrganizationEmailMatches" (
+ email character varying(100) NOT NULL,
+ "organizationId" integer NOT NULL
+);
+
+CREATE TABLE public."OrganizationIT" (
+ email text NOT NULL,
+ "organizationId" integer NOT NULL
+);
+
+CREATE TABLE public."OrganizationInvitation" (
+ id bigint NOT NULL,
+ email text NOT NULL,
+ organization_id integer NOT NULL
+);
+
+CREATE SEQUENCE public."OrganizationInvitation_id_seq"
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."OrganizationInvitation_id_seq" OWNED BY public."OrganizationInvitation".id;
+
+CREATE TABLE public."OrganizationItJob" (
+ id integer NOT NULL,
+ "taskArn" text,
+ "taskType" public."OrganizationItJobType" NOT NULL,
+ "organizationId" integer NOT NULL
+);
+
+CREATE SEQUENCE public."OrganizationItJob_id_seq"
+ AS integer
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."OrganizationItJob_id_seq" OWNED BY public."OrganizationItJob".id;
+
+CREATE TABLE public."OrganizationRetentionPolicy" (
+ id bigint NOT NULL,
+ organization_id integer NOT NULL,
+ retention_days integer
+);
+
+CREATE SEQUENCE public."OrganizationRetentionPolicy_id_seq"
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."OrganizationRetentionPolicy_id_seq" OWNED BY public."OrganizationRetentionPolicy".id;
+
+CREATE SEQUENCE public."Organization_id_seq"
+ AS integer
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."Organization_id_seq" OWNED BY public."Organization".id;
+
+CREATE TABLE public."PdfHighlightAnchor" (
+ uuid uuid DEFAULT gen_random_uuid() NOT NULL,
+ "documentId" text NOT NULL,
+ owner text NOT NULL,
+ page integer NOT NULL,
+ red integer NOT NULL,
+ green integer NOT NULL,
+ blue integer NOT NULL,
+ alpha double precision NOT NULL,
+ type integer NOT NULL,
+ text text NOT NULL,
+ "pageViewportWidth" double precision NOT NULL,
+ "pageViewportHeight" double precision NOT NULL,
+ "threadId" bigint,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "updatedAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "deletedAt" timestamp(3) without time zone
+);
+
+CREATE TABLE public."PdfHighlightRect" (
+ id bigint NOT NULL,
+ top double precision NOT NULL,
+ "left" double precision NOT NULL,
+ width double precision NOT NULL,
+ height double precision NOT NULL,
+ "pdfHighlightAnchorId" uuid NOT NULL
+);
+
+CREATE SEQUENCE public."PdfHighlightRect_id_seq"
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."PdfHighlightRect_id_seq" OWNED BY public."PdfHighlightRect".id;
+
+CREATE TABLE public."PdfPlaceableCommentAnchor" (
+ uuid uuid DEFAULT gen_random_uuid() NOT NULL,
+ "documentId" text NOT NULL,
+ owner text NOT NULL,
+ "allowableEdits" jsonb,
+ page integer NOT NULL,
+ "wasEdited" boolean NOT NULL,
+ "wasDeleted" boolean NOT NULL,
+ "shouldLockOnSave" boolean NOT NULL,
+ "originalPage" integer NOT NULL,
+ "originalIndex" integer NOT NULL,
+ "xPct" double precision NOT NULL,
+ "yPct" double precision NOT NULL,
+ "widthPct" double precision NOT NULL,
+ "heightPct" double precision NOT NULL,
+ rotation double precision NOT NULL,
+ "threadId" bigint NOT NULL
+);
+
+CREATE TABLE public."Permission" (
+ id text NOT NULL,
+ description text NOT NULL
+);
+
+CREATE TABLE public."Pin" (
+ "userId" text NOT NULL,
+ "pinnedItemId" text NOT NULL,
+ "pinnedItemType" text NOT NULL,
+ "pinIndex" integer NOT NULL,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "updatedAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+CREATE TABLE public."Project" (
+ id text DEFAULT gen_random_uuid() NOT NULL,
+ name text NOT NULL,
+ "userId" text NOT NULL,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "updatedAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "parentId" text,
+ "deletedAt" timestamp(3) without time zone,
+ "uploadPending" boolean DEFAULT false NOT NULL,
+ "uploadRequestId" text
+);
+
+CREATE TABLE public."ProjectPermission" (
+ "projectId" text NOT NULL,
+ "sharePermissionId" text NOT NULL
+);
+
+CREATE TABLE public."Role" (
+ id text NOT NULL,
+ description text NOT NULL
+);
+
+CREATE TABLE public."RolesOnOrganizations" (
+ "organizationId" integer NOT NULL,
+ "roleId" text NOT NULL
+);
+
+CREATE TABLE public."RolesOnPermissions" (
+ "permissionId" text NOT NULL,
+ "roleId" text NOT NULL
+);
+
+CREATE TABLE public."RolesOnUsers" (
+ "userId" text NOT NULL,
+ "roleId" text NOT NULL
+);
+
+CREATE TABLE public."SharePermission" (
+ id text DEFAULT gen_random_uuid() NOT NULL,
+ "isPublic" boolean NOT NULL,
+ "publicAccessLevel" text,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "updatedAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+CREATE TABLE public."Thread" (
+ id bigint NOT NULL,
+ owner text NOT NULL,
+ "documentId" text NOT NULL,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "updatedAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "deletedAt" timestamp(3) without time zone,
+ metadata jsonb,
+ resolved boolean DEFAULT false NOT NULL
+);
+
+CREATE TABLE public."ThreadAnchor" (
+ "threadId" bigint NOT NULL,
+ "anchorId" uuid NOT NULL,
+ "anchorTableName" public.anchor_table_name NOT NULL
+);
+
+CREATE SEQUENCE public."Thread_id_seq"
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."Thread_id_seq" OWNED BY public."Thread".id;
+
+CREATE TABLE public."UploadJob" (
+ id bigint NOT NULL,
+ "jobId" text NOT NULL,
+ "jobType" text NOT NULL,
+ "documentId" text,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+CREATE SEQUENCE public."UploadJob_id_seq"
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public."UploadJob_id_seq" OWNED BY public."UploadJob".id;
+
+CREATE TABLE public."User" (
+ id text NOT NULL,
+ email text NOT NULL,
+ name text,
+ "group" character varying(1),
+ "hasChromeExt" boolean DEFAULT false NOT NULL,
+ "organizationId" integer,
+ "stripeCustomerId" text,
+ "tutorialComplete" boolean DEFAULT false NOT NULL,
+ "hasOnboardingDocuments" boolean DEFAULT false NOT NULL,
+ industry character varying(255),
+ title character varying(20),
+ "firstName" character varying(100),
+ "lastName" character varying(100),
+ "profilePicture" text,
+ "profilePictureHash" character varying(40),
+ macro_user_id uuid NOT NULL,
+ "aiDataConsent" boolean DEFAULT false NOT NULL
+);
+
+CREATE TABLE public."UserApiKey" (
+ key text NOT NULL,
+ user_id text NOT NULL
+);
+
+CREATE TABLE public."UserDocumentViewLocation" (
+ user_id text NOT NULL,
+ document_id text NOT NULL,
+ location text NOT NULL,
+ updated_at timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+CREATE TABLE public."UserHistory" (
+ "userId" text NOT NULL,
+ "itemId" text NOT NULL,
+ "itemType" text NOT NULL,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "updatedAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+CREATE TABLE public."UserInsightBatch" (
+ id text DEFAULT gen_random_uuid() NOT NULL,
+ "userId" text NOT NULL,
+ "insightIds" text[],
+ "totalChars" integer NOT NULL,
+ "estimatedTokens" integer NOT NULL,
+ "rankingContext" jsonb,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "expiresAt" timestamp(3) without time zone NOT NULL,
+ version integer DEFAULT 1 NOT NULL
+);
+
+CREATE TABLE public."UserInsights" (
+ id text DEFAULT gen_random_uuid() NOT NULL,
+ content text NOT NULL,
+ source text NOT NULL,
+ "sourceLocation" jsonb,
+ generated boolean DEFAULT true NOT NULL,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "updatedAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ "spanStart" timestamp(3) without time zone,
+ "spanEnd" timestamp(3) without time zone,
+ confidence integer,
+ "insightType" text,
+ "relevanceKeywords" text[],
+ "userId" text NOT NULL
+);
+
+CREATE TABLE public."UserItemAccess" (
+ id uuid NOT NULL,
+ user_id text NOT NULL,
+ item_id text NOT NULL,
+ item_type text NOT NULL,
+ granted_from_channel_id uuid,
+ access_level public."AccessLevel" NOT NULL,
+ created_at timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ updated_at timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ granted_from_team_id uuid
+);
+
+CREATE TABLE public."WebAnnotations" (
+ id text DEFAULT gen_random_uuid() NOT NULL,
+ "messageId" text,
+ url text NOT NULL,
+ title text NOT NULL,
+ publish_date timestamp(3) without time zone,
+ description text,
+ favicon_url text,
+ image_url text,
+ "chatId" text
+);
+
+CREATE TABLE public."WebsocketConnectionPermissions" (
+ "connectionId" text NOT NULL,
+ "userId" text,
+ permissions jsonb NOT NULL,
+ "createdAt" timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+CREATE TABLE public._sqlx_migrations (
+ version bigint NOT NULL,
+ description text NOT NULL,
+ installed_on timestamp with time zone DEFAULT now() NOT NULL,
+ success boolean NOT NULL,
+ checksum bytea NOT NULL,
+ execution_time bigint NOT NULL
+);
+
+CREATE TABLE public.account_merge_request (
+ id uuid NOT NULL,
+ code text NOT NULL,
+ macro_user_id uuid NOT NULL,
+ created_at timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ to_merge_macro_user_id uuid NOT NULL
+);
+
+CREATE TABLE public.active_streams (
+ entity_id text NOT NULL,
+ stream_key text NOT NULL
+);
+
+CREATE TABLE public.call_participants (
+ call_id uuid NOT NULL,
+ user_id text NOT NULL,
+ joined_at timestamp with time zone DEFAULT now() NOT NULL,
+ left_at timestamp with time zone
+);
+
+CREATE TABLE public.call_record_participants (
+ call_record_id uuid NOT NULL,
+ user_id text NOT NULL,
+ joined_at timestamp with time zone NOT NULL,
+ left_at timestamp with time zone
+);
+
+CREATE TABLE public.call_record_transcripts (
+ id uuid DEFAULT gen_random_uuid() NOT NULL,
+ call_record_id uuid NOT NULL,
+ segment_id text,
+ speaker_id text NOT NULL,
+ content text NOT NULL,
+ started_at timestamp with time zone NOT NULL,
+ ended_at timestamp with time zone,
+ sequence_num integer NOT NULL
+);
+
+CREATE TABLE public.call_records (
+ id uuid NOT NULL,
+ channel_id uuid NOT NULL,
+ room_name text NOT NULL,
+ created_by text NOT NULL,
+ started_at timestamp with time zone NOT NULL,
+ ended_at timestamp with time zone DEFAULT now() NOT NULL,
+ duration_ms bigint NOT NULL,
+ recording_url text,
+ egress_id text,
+ share_permission_id text NOT NULL
+);
+
+CREATE TABLE public.call_transcripts (
+ id uuid DEFAULT gen_random_uuid() NOT NULL,
+ call_id uuid NOT NULL,
+ segment_id text NOT NULL,
+ speaker_id text NOT NULL,
+ content text NOT NULL,
+ started_at timestamp with time zone NOT NULL,
+ ended_at timestamp with time zone,
+ sequence_num integer NOT NULL
+);
+
+CREATE TABLE public.calls (
+ id uuid NOT NULL,
+ channel_id uuid NOT NULL,
+ room_name text NOT NULL,
+ created_by text NOT NULL,
+ egress_id text,
+ recording_url text,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ share_permission_id text NOT NULL
+);
+
+CREATE TABLE public.channel_notification_email_sent (
+ channel_id uuid NOT NULL,
+ user_id text NOT NULL,
+ created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+CREATE TABLE public.comms_activity (
+ id uuid NOT NULL,
+ user_id text NOT NULL,
+ channel_id uuid NOT NULL,
+ created_at timestamp without time zone DEFAULT now() NOT NULL,
+ updated_at timestamp without time zone DEFAULT now() NOT NULL,
+ viewed_at timestamp without time zone,
+ interacted_at timestamp without time zone
+);
+
+CREATE TABLE public.comms_attachments (
+ id uuid NOT NULL,
+ message_id uuid NOT NULL,
+ entity_type character varying(32) NOT NULL,
+ entity_id character varying NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ channel_id uuid NOT NULL,
+ width integer,
+ height integer
+);
+
+CREATE TABLE public.comms_channel_participants (
+ channel_id uuid NOT NULL,
+ role public.comms_participant_role NOT NULL,
+ user_id text NOT NULL,
+ joined_at timestamp with time zone DEFAULT now() NOT NULL,
+ left_at timestamp with time zone
+);
+
+CREATE TABLE public.comms_channels (
+ id uuid NOT NULL,
+ name character varying(255),
+ channel_type public.comms_channel_type NOT NULL,
+ org_id bigint,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL,
+ owner_id text NOT NULL,
+ team_id uuid,
+ CONSTRAINT valid_channel_name CHECK ((((channel_type = 'direct_message'::public.comms_channel_type) AND (name IS NULL)) OR ((channel_type = ANY (ARRAY['public'::public.comms_channel_type, 'organization'::public.comms_channel_type, 'team'::public.comms_channel_type])) AND (name IS NOT NULL)) OR (channel_type = 'private'::public.comms_channel_type))),
+ CONSTRAINT valid_org_channel CHECK ((((channel_type = 'organization'::public.comms_channel_type) AND (org_id IS NOT NULL)) OR ((channel_type <> 'organization'::public.comms_channel_type) AND (org_id IS NULL)))),
+ CONSTRAINT valid_team_channel CHECK ((((channel_type = 'team'::public.comms_channel_type) AND (team_id IS NOT NULL)) OR ((channel_type <> 'team'::public.comms_channel_type) AND (team_id IS NULL))))
+);
+
+CREATE TABLE public.comms_entity_mentions (
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ entity_type character varying(32) NOT NULL,
+ entity_id character varying NOT NULL,
+ source_entity_type character varying(32) NOT NULL,
+ source_entity_id character varying NOT NULL,
+ id uuid DEFAULT gen_random_uuid() NOT NULL,
+ user_id character varying
+);
+
+CREATE TABLE public.comms_messages (
+ id uuid NOT NULL,
+ channel_id uuid NOT NULL,
+ thread_id uuid,
+ sender_id text NOT NULL,
+ content text NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL,
+ edited_at timestamp without time zone,
+ deleted_at timestamp without time zone
+);
+
+CREATE TABLE public.comms_reactions (
+ message_id uuid NOT NULL,
+ emoji character varying(32) NOT NULL,
+ user_id text NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL
+);
+
+CREATE TABLE public.contacts_connections (
+ id integer NOT NULL,
+ user1 text NOT NULL,
+ user2 text NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL,
+ CONSTRAINT contacts_connections_check CHECK ((user1 <= (user2 COLLATE "C")))
+);
+
+CREATE SEQUENCE public.contacts_connections_id_seq
+ AS integer
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public.contacts_connections_id_seq OWNED BY public.contacts_connections.id;
+
+CREATE TABLE public.document_email (
+ document_id text NOT NULL,
+ email_attachment_id uuid NOT NULL
+);
+
+CREATE TABLE public.document_sub_type (
+ document_id text NOT NULL,
+ sub_type public.document_sub_type_value NOT NULL
+);
+
+CREATE TABLE public.email_attachments (
+ id uuid NOT NULL,
+ message_id uuid NOT NULL,
+ provider_attachment_id text,
+ filename character varying(512),
+ mime_type character varying(255),
+ size_bytes bigint,
+ content_id character varying(255),
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ upload_claimed_at timestamp with time zone
+);
+
+CREATE TABLE public.email_attachments_drafts (
+ id uuid NOT NULL,
+ draft_id uuid NOT NULL,
+ file_name text NOT NULL,
+ content_type text NOT NULL,
+ sha text NOT NULL,
+ size integer NOT NULL,
+ s3_key text NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL
+);
+
+CREATE TABLE public.email_attachments_fwd (
+ message_id uuid NOT NULL,
+ attachment_id uuid NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL
+);
+
+CREATE TABLE public.email_attachments_sfs (
+ id uuid NOT NULL,
+ attachment_id uuid,
+ sfs_id uuid NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL
+);
+
+CREATE TABLE public.email_backfill_jobs (
+ id uuid NOT NULL,
+ link_id uuid,
+ threads_requested_limit integer,
+ total_threads integer DEFAULT 0 NOT NULL,
+ status public.email_backfill_job_status DEFAULT 'Init'::public.email_backfill_job_status NOT NULL,
+ threads_retrieved_count integer DEFAULT 0 NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL,
+ fusionauth_user_id text NOT NULL
+);
+
+CREATE TABLE public.email_contact_search_index (
+ link_id uuid NOT NULL,
+ thread_id uuid NOT NULL,
+ message_id uuid NOT NULL,
+ contact_name text,
+ contact_email text NOT NULL,
+ contact_type text NOT NULL
+);
+
+CREATE TABLE public.email_contacts (
+ id uuid NOT NULL,
+ link_id uuid NOT NULL,
+ email_address character varying(320) NOT NULL,
+ name character varying(255),
+ original_photo_url text,
+ sfs_photo_url text,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL
+);
+
+CREATE TABLE public.email_filters (
+ id uuid DEFAULT gen_random_uuid() NOT NULL,
+ link_id uuid NOT NULL,
+ email_address character varying(320),
+ email_domain character varying(255),
+ is_important boolean NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ CONSTRAINT email_filters_address_xor_domain_chk CHECK ((((email_address IS NOT NULL) AND (TRIM(BOTH FROM email_address) <> ''::text)) <> ((email_domain IS NOT NULL) AND (TRIM(BOTH FROM email_domain) <> ''::text)))),
+ CONSTRAINT email_filters_email_domain_format_chk CHECK (((email_domain IS NULL) OR ((TRIM(BOTH FROM email_domain) <> ''::text) AND (POSITION(('@'::text) IN (email_domain)) = 0))))
+);
+
+CREATE TABLE public.email_gmail_histories (
+ link_id uuid NOT NULL,
+ history_id text NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL
+);
+
+CREATE TABLE public.email_labels (
+ id uuid NOT NULL,
+ link_id uuid NOT NULL,
+ provider_label_id text NOT NULL,
+ name character varying(255) NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ message_list_visibility public.email_message_list_visibility_enum DEFAULT 'Show'::public.email_message_list_visibility_enum NOT NULL,
+ label_list_visibility public.email_label_list_visibility_enum DEFAULT 'LabelShow'::public.email_label_list_visibility_enum NOT NULL,
+ type public.email_label_type_enum DEFAULT 'User'::public.email_label_type_enum NOT NULL
+);
+
+CREATE TABLE public.email_links (
+ id uuid NOT NULL,
+ macro_id text NOT NULL,
+ fusionauth_user_id text NOT NULL,
+ email_address character varying(320) NOT NULL,
+ provider public.email_user_provider_enum NOT NULL,
+ is_sync_active boolean DEFAULT true NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL
+);
+
+CREATE TABLE public.email_message_labels (
+ message_id uuid NOT NULL,
+ label_id uuid NOT NULL
+);
+
+CREATE TABLE public.email_message_recipients (
+ message_id uuid NOT NULL,
+ contact_id uuid NOT NULL,
+ recipient_type public.email_recipient_type NOT NULL,
+ name character varying(255)
)
+WITH (autovacuum_vacuum_cost_delay='10', autovacuum_vacuum_cost_limit='200', autovacuum_vacuum_scale_factor='0.02', autovacuum_vacuum_threshold='5000', autovacuum_analyze_scale_factor='0.01', autovacuum_analyze_threshold='5000');
+
+CREATE TABLE public.email_messages (
+ id uuid NOT NULL,
+ provider_id text,
+ thread_id uuid NOT NULL,
+ provider_thread_id text,
+ link_id uuid NOT NULL,
+ provider_history_id text,
+ internal_date_ts timestamp with time zone,
+ snippet text,
+ size_estimate bigint,
+ subject text,
+ from_contact_id uuid,
+ sent_at timestamp with time zone,
+ has_attachments boolean DEFAULT false NOT NULL,
+ is_read boolean DEFAULT false NOT NULL,
+ is_starred boolean DEFAULT false NOT NULL,
+ is_sent boolean DEFAULT false NOT NULL,
+ is_draft boolean DEFAULT false NOT NULL,
+ body_text text,
+ body_html_sanitized text,
+ body_macro text,
+ headers_jsonb jsonb,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL,
+ global_id text,
+ replying_to_id uuid,
+ from_name character varying(255)
+);
+
+CREATE TABLE public.email_scheduled_messages (
+ link_id uuid NOT NULL,
+ message_id uuid NOT NULL,
+ send_time timestamp with time zone NOT NULL,
+ sent boolean DEFAULT false NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL,
+ processing boolean DEFAULT false NOT NULL
+);
+
+CREATE TABLE public.email_settings (
+ link_id uuid NOT NULL,
+ signature_on_replies_forwards boolean DEFAULT false NOT NULL,
+ created_at timestamp without time zone DEFAULT now() NOT NULL,
+ updated_at timestamp without time zone DEFAULT now() NOT NULL
+);
+
+CREATE TABLE public.email_sfs_mappings (
+ source text NOT NULL,
+ destination text NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL
+);
+
+CREATE TABLE public.email_sync_tokens (
+ link_id uuid NOT NULL,
+ contacts_sync_token character varying(255),
+ other_contacts_sync_token character varying(255)
+);
+
+CREATE TABLE public.email_threads (
+ id uuid NOT NULL,
+ provider_id text,
+ link_id uuid NOT NULL,
+ inbox_visible boolean DEFAULT false NOT NULL,
+ is_read boolean DEFAULT false NOT NULL,
+ latest_inbound_message_ts timestamp with time zone,
+ latest_outbound_message_ts timestamp with time zone,
+ latest_non_spam_message_ts timestamp with time zone,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL,
+ project_id text
+);
+
+CREATE TABLE public.email_user_history (
+ link_id uuid NOT NULL,
+ thread_id uuid NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL
+);
+
+CREATE TABLE public.entity_access (
+ id bigint NOT NULL,
+ entity_id uuid NOT NULL,
+ entity_type text NOT NULL,
+ source_id text NOT NULL,
+ source_type public.entity_access_source_type NOT NULL,
+ access_level public."AccessLevel" NOT NULL,
+ granted_from_project_id text,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL
+);
+
+CREATE SEQUENCE public.entity_access_id_seq
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public.entity_access_id_seq OWNED BY public.entity_access.id;
+
+CREATE TABLE public.entity_properties (
+ id uuid NOT NULL,
+ entity_id text NOT NULL,
+ entity_type public.property_entity_type NOT NULL,
+ property_definition_id uuid NOT NULL,
+ "values" jsonb,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL,
+ CONSTRAINT check_values_structure CHECK ((("values" IS NULL) OR ((("values" ->> 'type'::text) = ANY (ARRAY['Boolean'::text, 'Number'::text, 'String'::text, 'Date'::text])) AND (jsonb_typeof(("values" -> 'value'::text)) <> 'array'::text)) OR ((("values" ->> 'type'::text) = ANY (ARRAY['SelectOption'::text, 'EntityReference'::text, 'Link'::text])) AND (jsonb_typeof(("values" -> 'value'::text)) = 'array'::text))))
+);
+
+CREATE TABLE public.excluded_default_view (
+ id uuid NOT NULL,
+ user_id text NOT NULL,
+ default_view_id text NOT NULL
+);
+
+CREATE TABLE public.frecency_aggregates (
+ id bigint NOT NULL,
+ entity_id text NOT NULL,
+ entity_type text NOT NULL,
+ user_id text NOT NULL,
+ event_count integer DEFAULT 0 NOT NULL,
+ frecency_score double precision DEFAULT 0.0 NOT NULL,
+ first_event timestamp with time zone NOT NULL,
+ recent_events jsonb DEFAULT '[]'::jsonb NOT NULL
+);
+
+CREATE SEQUENCE public.frecency_aggregates_id_seq
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public.frecency_aggregates_id_seq OWNED BY public.frecency_aggregates.id;
+
+CREATE TABLE public.frecency_events (
+ id bigint NOT NULL,
+ user_id text NOT NULL,
+ entity_type text NOT NULL,
+ event_type text NOT NULL,
+ "timestamp" timestamp with time zone NOT NULL,
+ connection_id text NOT NULL,
+ entity_id text NOT NULL,
+ was_processed boolean DEFAULT false NOT NULL
+);
+
+CREATE SEQUENCE public.frecency_events_id_seq
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+ALTER SEQUENCE public.frecency_events_id_seq OWNED BY public.frecency_events.id;
+
+CREATE TABLE public.github_app_installation_team (
+ id text NOT NULL,
+ team_id uuid NOT NULL,
+ installed_by text NOT NULL
+);
+
+CREATE TABLE public.github_links (
+ id uuid NOT NULL,
+ macro_id text NOT NULL,
+ fusionauth_user_id uuid NOT NULL,
+ github_username character varying(255) NOT NULL,
+ github_user_id text NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL
+);
+
+CREATE TABLE public.github_pr_tasks (
+ id uuid NOT NULL,
+ github_key text NOT NULL,
+ task_id text NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL
+);
+
+CREATE TABLE public.id_mapping (
+ source_id text NOT NULL,
+ target_id text NOT NULL,
+ created_at timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+CREATE TABLE public.in_progress_email_link (
+ id uuid NOT NULL,
+ email text NOT NULL,
+ macro_user_id uuid NOT NULL,
+ created_at timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+CREATE TABLE public.in_progress_user_link (
+ id uuid NOT NULL,
+ macro_user_id uuid NOT NULL,
+ created_at timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+CREATE TABLE public.macro_user (
+ id uuid NOT NULL,
+ username text NOT NULL,
+ email text NOT NULL,
+ stripe_customer_id text NOT NULL,
+ has_trialed boolean DEFAULT true NOT NULL
+);
+
+CREATE TABLE public.macro_user_email_verification (
+ macro_user_id uuid NOT NULL,
+ email text NOT NULL,
+ is_verified boolean DEFAULT false NOT NULL
+);
+
+CREATE TABLE public.macro_user_info (
+ macro_user_id uuid NOT NULL,
+ industry text,
+ title text,
+ first_name text,
+ last_name text,
+ profile_picture text,
+ profile_picture_hash character varying(40)
+);
+
+CREATE TABLE public.memory (
+ id uuid NOT NULL,
+ user_id text NOT NULL,
+ memory text NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL
+);
+
+CREATE TABLE public.notification (
+ id uuid NOT NULL,
+ notification_event_type character varying(255) NOT NULL,
+ event_item_id text NOT NULL,
+ event_item_type text NOT NULL,
+ service_sender text NOT NULL,
+ created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
+ sender_id text,
+ apns_collapse_key text
+);
+
+CREATE TABLE public.notification_email_sent (
+ user_id text NOT NULL,
+ sent_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
+);
+
+CREATE TABLE public.notification_email_unsubscribe (
+ email text NOT NULL
+);
+
+CREATE TABLE public.notification_email_unsubscribe_code (
+ email text NOT NULL,
+ code uuid NOT NULL
+);
+
+CREATE TABLE public.notification_message_receipt (
+ message_id text NOT NULL,
+ user_id text NOT NULL,
+ notification_id uuid NOT NULL,
+ failed boolean DEFAULT false NOT NULL,
+ created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ failed_at timestamp without time zone
+);
+
+CREATE TABLE public.notification_user_device_registration (
+ id uuid NOT NULL,
+ user_id text NOT NULL,
+ device_token text NOT NULL,
+ device_endpoint text NOT NULL,
+ device_type public.notification_device_type_option NOT NULL,
+ created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ last_used_at timestamp without time zone
+);
+
+CREATE TABLE public.property_definitions (
+ id uuid NOT NULL,
+ organization_id integer,
+ user_id text,
+ display_name text NOT NULL,
+ data_type public.property_data_type NOT NULL,
+ is_multi_select boolean NOT NULL,
+ specific_entity_type public.property_entity_type,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL,
+ is_system boolean DEFAULT false NOT NULL,
+ CONSTRAINT owned_by_org_or_user_or_system CHECK (((is_system = true) OR (organization_id IS NOT NULL) OR (user_id IS NOT NULL)))
+);
+
+CREATE TABLE public.property_options (
+ id uuid NOT NULL,
+ property_definition_id uuid NOT NULL,
+ display_order integer DEFAULT 0 NOT NULL,
+ number_value double precision,
+ string_value text,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ updated_at timestamp with time zone DEFAULT now() NOT NULL,
+ CONSTRAINT check_option_value_set CHECK ((((number_value IS NOT NULL) AND (string_value IS NULL)) OR ((number_value IS NULL) AND (string_value IS NOT NULL))))
+);
+
+CREATE TABLE public.referral_tracking (
+ id uuid NOT NULL,
+ referrer_id uuid NOT NULL,
+ referred_id uuid NOT NULL,
+ status text NOT NULL,
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
+ CONSTRAINT referral_tracking_no_self_referral CHECK ((referrer_id <> referred_id))
+);
+
+CREATE TABLE public.saved_view (
+ id uuid NOT NULL,
+ user_id text NOT NULL,
+ name text NOT NULL,
+ config jsonb NOT NULL,
+ created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ updated_at timestamp with time zone NOT NULL
+);
+
+CREATE TABLE public.team (
+ id uuid NOT NULL,
+ name text NOT NULL,
+ owner_id text NOT NULL,
+ subscription_id text,
+ seat_count integer DEFAULT 0 NOT NULL
+);
+
+CREATE TABLE public.team_invite (
+ id uuid NOT NULL,
+ email text NOT NULL,
+ team_id uuid NOT NULL,
+ team_role public.team_role DEFAULT 'member'::public.team_role NOT NULL,
+ invited_by text NOT NULL,
+ created_at timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ last_sent_at timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ tier public.team_user_tier DEFAULT 'haiku'::public.team_user_tier NOT NULL
+);
+
+CREATE TABLE public.team_user (
+ user_id text NOT NULL,
+ team_id uuid NOT NULL,
+ team_role public.team_role NOT NULL,
+ tier public.team_user_tier DEFAULT 'haiku'::public.team_user_tier NOT NULL
+);
+
+CREATE TABLE public.user_mute_notification (
+ user_id text NOT NULL
+);
+
+CREATE TABLE public.user_notification (
+ user_id text NOT NULL,
+ notification_id uuid NOT NULL,
+ created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
+ sent boolean DEFAULT false NOT NULL,
+ seen_at timestamp without time zone,
+ deleted_at timestamp without time zone,
+ done boolean DEFAULT false NOT NULL,
+ is_important_v0 boolean DEFAULT false NOT NULL
+);
+
+CREATE TABLE public.user_notification_item_unsubscribe (
+ user_id text NOT NULL,
+ item_id text NOT NULL,
+ item_type text NOT NULL
+);
+
+CREATE TABLE public.user_notification_type_preference (
+ user_id text NOT NULL,
+ notification_event_type character varying(255) NOT NULL
+);
+
+ALTER TABLE ONLY public."Comment" ALTER COLUMN id SET DEFAULT nextval('public."Comment_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."DocumentBom" ALTER COLUMN id SET DEFAULT nextval('public."DocumentBom_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."DocumentFamily" ALTER COLUMN id SET DEFAULT nextval('public."DocumentFamily_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."DocumentInstance" ALTER COLUMN id SET DEFAULT nextval('public."DocumentInstance_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."DocumentInstanceModificationData" ALTER COLUMN id SET DEFAULT nextval('public."DocumentInstanceModificationData_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."DocumentProcessResult" ALTER COLUMN id SET DEFAULT nextval('public."DocumentProcessResult_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."DocumentText" ALTER COLUMN id SET DEFAULT nextval('public."DocumentText_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."DocumentView" ALTER COLUMN id SET DEFAULT nextval('public."DocumentView_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."EnterpriseEmailContacts" ALTER COLUMN id SET DEFAULT nextval('public."EnterpriseEmailContacts_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."EnterpriseIManageTenants" ALTER COLUMN id SET DEFAULT nextval('public."EnterpriseIManageTenants_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."EnterpriseRules" ALTER COLUMN id SET DEFAULT nextval('public."EnterpriseRules_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."Organization" ALTER COLUMN id SET DEFAULT nextval('public."Organization_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."OrganizationBilling" ALTER COLUMN id SET DEFAULT nextval('public."OrganizationBilling_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."OrganizationDefaultSharePermission" ALTER COLUMN id SET DEFAULT nextval('public."OrganizationDefaultSharePermission_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."OrganizationInvitation" ALTER COLUMN id SET DEFAULT nextval('public."OrganizationInvitation_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."OrganizationItJob" ALTER COLUMN id SET DEFAULT nextval('public."OrganizationItJob_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."OrganizationRetentionPolicy" ALTER COLUMN id SET DEFAULT nextval('public."OrganizationRetentionPolicy_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."PdfHighlightRect" ALTER COLUMN id SET DEFAULT nextval('public."PdfHighlightRect_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."Thread" ALTER COLUMN id SET DEFAULT nextval('public."Thread_id_seq"'::regclass);
+
+ALTER TABLE ONLY public."UploadJob" ALTER COLUMN id SET DEFAULT nextval('public."UploadJob_id_seq"'::regclass);
+
+ALTER TABLE ONLY public.contacts_connections ALTER COLUMN id SET DEFAULT nextval('public.contacts_connections_id_seq'::regclass);
+
+ALTER TABLE ONLY public.entity_access ALTER COLUMN id SET DEFAULT nextval('public.entity_access_id_seq'::regclass);
+
+ALTER TABLE ONLY public.frecency_aggregates ALTER COLUMN id SET DEFAULT nextval('public.frecency_aggregates_id_seq'::regclass);
+
+ALTER TABLE ONLY public.frecency_events ALTER COLUMN id SET DEFAULT nextval('public.frecency_events_id_seq'::regclass);
+
+ALTER TABLE ONLY _sqlx_test.databases
+ ADD CONSTRAINT databases_pkey PRIMARY KEY (db_name);
+
+ALTER TABLE ONLY public."Artifact"
+ ADD CONSTRAINT "Artifact_pkey" PRIMARY KEY ("messageId", digest);
+
+ALTER TABLE ONLY public."BlockedEmail"
+ ADD CONSTRAINT "BlockedEmail_pkey" PRIMARY KEY (email);
+
+ALTER TABLE ONLY public."BomPart"
+ ADD CONSTRAINT "BomPart_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."ChannelSharePermission"
+ ADD CONSTRAINT "ChannelSharePermission_pkey" PRIMARY KEY (channel_id, share_permission_id);
+
+ALTER TABLE ONLY public."ChatAttachment"
+ ADD CONSTRAINT "ChatAttachment_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."ChatMessage"
+ ADD CONSTRAINT "ChatMessage_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."ChatPermission"
+ ADD CONSTRAINT "ChatPermission_pkey" PRIMARY KEY ("chatId");
+
+ALTER TABLE ONLY public."Chat"
+ ADD CONSTRAINT "Chat_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."Comment"
+ ADD CONSTRAINT "Comment_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."DocumentBom"
+ ADD CONSTRAINT "DocumentBom_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."DocumentFamily"
+ ADD CONSTRAINT "DocumentFamily_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."DocumentInstanceModificationData"
+ ADD CONSTRAINT "DocumentInstanceModificationData_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."DocumentInstance"
+ ADD CONSTRAINT "DocumentInstance_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."DocumentPermission"
+ ADD CONSTRAINT "DocumentPermission_pkey" PRIMARY KEY ("documentId");
+
+ALTER TABLE ONLY public."DocumentProcessResult"
+ ADD CONSTRAINT "DocumentProcessResult_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."DocumentSummary"
+ ADD CONSTRAINT "DocumentSummary_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."DocumentTextParts"
+ ADD CONSTRAINT "DocumentTextParts_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."DocumentText"
+ ADD CONSTRAINT "DocumentText_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."DocumentView"
+ ADD CONSTRAINT "DocumentView_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."Document"
+ ADD CONSTRAINT "Document_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."EmailInsightsBackfillBatch"
+ ADD CONSTRAINT "EmailInsightsBackfillBatch_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."EmailInsightsBackfillJob"
+ ADD CONSTRAINT "EmailInsightsBackfillJob_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."EmailThreadPermission"
+ ADD CONSTRAINT "EmailThreadPermission_pkey" PRIMARY KEY ("threadId");
+
+ALTER TABLE ONLY public."EnterpriseEmailContacts"
+ ADD CONSTRAINT "EnterpriseEmailContacts_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."EnterpriseIManageTenants"
+ ADD CONSTRAINT "EnterpriseIManageTenants_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."EnterpriseRules"
+ ADD CONSTRAINT "EnterpriseRules_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."ExperimentLog"
+ ADD CONSTRAINT "ExperimentLog_pkey" PRIMARY KEY (user_id, experiment_id);
+
+ALTER TABLE ONLY public."Experiment"
+ ADD CONSTRAINT "Experiment_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."InsightContext"
+ ADD CONSTRAINT "InsightContext_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."InstructionsDocuments"
+ ADD CONSTRAINT "InstructionsDocuments_pkey" PRIMARY KEY ("documentId");
+
+ALTER TABLE ONLY public."ItemLastAccessed"
+ ADD CONSTRAINT "ItemLastAccessed_pkey" PRIMARY KEY (item_id, item_type);
+
+ALTER TABLE ONLY public."JobToDocumentProcessResult"
+ ADD CONSTRAINT "JobToDocumentProcessResult_pkey" PRIMARY KEY ("jobId", "documentProcessResultId");
+
+ALTER TABLE ONLY public."MacroPromptAttachment"
+ ADD CONSTRAINT "MacroPromptAttachment_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."MacroPromptPermission"
+ ADD CONSTRAINT "MacroPromptPermission_pkey" PRIMARY KEY (macro_prompt_id);
+
+ALTER TABLE ONLY public."MacroPrompt"
+ ADD CONSTRAINT "MacroPrompt_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."OrganizationBilling"
+ ADD CONSTRAINT "OrganizationBilling_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."OrganizationDefaultSharePermission"
+ ADD CONSTRAINT "OrganizationDefaultSharePermission_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."OrganizationEmailMatches"
+ ADD CONSTRAINT "OrganizationEmailMatches_pkey" PRIMARY KEY (email);
+
+ALTER TABLE ONLY public."OrganizationInvitation"
+ ADD CONSTRAINT "OrganizationInvitation_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."OrganizationItJob"
+ ADD CONSTRAINT "OrganizationItJob_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."OrganizationRetentionPolicy"
+ ADD CONSTRAINT "OrganizationRetentionPolicy_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."Organization"
+ ADD CONSTRAINT "Organization_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."PdfHighlightAnchor"
+ ADD CONSTRAINT "PdfHighlightAnchor_pkey" PRIMARY KEY (uuid);
+
+ALTER TABLE ONLY public."PdfHighlightRect"
+ ADD CONSTRAINT "PdfHighlightRect_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."PdfPlaceableCommentAnchor"
+ ADD CONSTRAINT "PdfPlaceableCommentAnchor_pkey" PRIMARY KEY (uuid);
+
+ALTER TABLE ONLY public."Permission"
+ ADD CONSTRAINT "Permission_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."Pin"
+ ADD CONSTRAINT "Pin_pkey" PRIMARY KEY ("userId", "pinnedItemId", "pinnedItemType");
+
+ALTER TABLE ONLY public."ProjectPermission"
+ ADD CONSTRAINT "ProjectPermission_pkey" PRIMARY KEY ("projectId");
+
+ALTER TABLE ONLY public."Project"
+ ADD CONSTRAINT "Project_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."Role"
+ ADD CONSTRAINT "Role_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."RolesOnOrganizations"
+ ADD CONSTRAINT "RolesOnOrganizations_pkey" PRIMARY KEY ("organizationId", "roleId");
+
+ALTER TABLE ONLY public."RolesOnPermissions"
+ ADD CONSTRAINT "RolesOnPermissions_pkey" PRIMARY KEY ("permissionId", "roleId");
+
+ALTER TABLE ONLY public."RolesOnUsers"
+ ADD CONSTRAINT "RolesOnUsers_pkey" PRIMARY KEY ("userId", "roleId");
+
+ALTER TABLE ONLY public."SharePermission"
+ ADD CONSTRAINT "SharePermission_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."Thread"
+ ADD CONSTRAINT "Thread_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."UploadJob"
+ ADD CONSTRAINT "UploadJob_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."UserApiKey"
+ ADD CONSTRAINT "UserApiKey_pkey" PRIMARY KEY (user_id, key);
+
+ALTER TABLE ONLY public."UserDocumentViewLocation"
+ ADD CONSTRAINT "UserDocumentViewLocation_pkey" PRIMARY KEY (user_id, document_id);
+
+ALTER TABLE ONLY public."UserHistory"
+ ADD CONSTRAINT "UserHistory_pkey" PRIMARY KEY ("userId", "itemId", "itemType");
+
+ALTER TABLE ONLY public."UserInsightBatch"
+ ADD CONSTRAINT "UserInsightBatch_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."UserInsights"
+ ADD CONSTRAINT "UserInsights_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."UserItemAccess"
+ ADD CONSTRAINT "UserItemAccess_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."User"
+ ADD CONSTRAINT "User_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."WebAnnotations"
+ ADD CONSTRAINT "WebAnnotations_pkey" PRIMARY KEY (id);
+
+ALTER TABLE ONLY public."WebsocketConnectionPermissions"
+ ADD CONSTRAINT "WebsocketConnectionPermissions_pkey" PRIMARY KEY ("connectionId");
+
+ALTER TABLE ONLY public._sqlx_migrations
+ ADD CONSTRAINT _sqlx_migrations_pkey PRIMARY KEY (version);
+
+ALTER TABLE ONLY public.account_merge_request
+ ADD CONSTRAINT account_merge_request_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.active_streams
+ ADD CONSTRAINT active_streams_pkey PRIMARY KEY (entity_id, stream_key);
+
+ALTER TABLE ONLY public.call_participants
+ ADD CONSTRAINT call_participants_pkey PRIMARY KEY (call_id, user_id);
+
+ALTER TABLE ONLY public.call_record_participants
+ ADD CONSTRAINT call_record_participants_pkey PRIMARY KEY (call_record_id, user_id);
+
+ALTER TABLE ONLY public.call_record_transcripts
+ ADD CONSTRAINT call_record_transcripts_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.call_records
+ ADD CONSTRAINT call_records_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.call_transcripts
+ ADD CONSTRAINT call_transcripts_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.call_transcripts
+ ADD CONSTRAINT call_transcripts_segment_unique UNIQUE (call_id, segment_id);
+
+ALTER TABLE ONLY public.calls
+ ADD CONSTRAINT calls_one_per_channel UNIQUE (channel_id);
+
+ALTER TABLE ONLY public.calls
+ ADD CONSTRAINT calls_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.channel_notification_email_sent
+ ADD CONSTRAINT channel_notification_email_sent_pkey PRIMARY KEY (channel_id, user_id);
+
+ALTER TABLE ONLY public.comms_activity
+ ADD CONSTRAINT comms_activity_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.comms_attachments
+ ADD CONSTRAINT comms_attachments_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.comms_channel_participants
+ ADD CONSTRAINT comms_channel_participants_pkey PRIMARY KEY (channel_id, user_id);
+
+ALTER TABLE ONLY public.comms_channels
+ ADD CONSTRAINT comms_channels_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.comms_entity_mentions
+ ADD CONSTRAINT comms_entity_mentions_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.comms_messages
+ ADD CONSTRAINT comms_messages_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.comms_reactions
+ ADD CONSTRAINT comms_reactions_pkey PRIMARY KEY (message_id, emoji, user_id);
+
+ALTER TABLE ONLY public.comms_activity
+ ADD CONSTRAINT comms_unique_user_channel UNIQUE (user_id, channel_id);
+
+ALTER TABLE ONLY public.contacts_connections
+ ADD CONSTRAINT contacts_connections_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.contacts_connections
+ ADD CONSTRAINT contacts_connections_user1_user2_key UNIQUE (user1, user2);
+
+ALTER TABLE ONLY public.document_email
+ ADD CONSTRAINT document_email_pkey PRIMARY KEY (document_id, email_attachment_id);
+
+ALTER TABLE ONLY public.document_sub_type
+ ADD CONSTRAINT document_sub_type_pkey PRIMARY KEY (document_id);
+
+ALTER TABLE ONLY public.email_contact_search_index
+ ADD CONSTRAINT ecsi_unique UNIQUE (message_id, contact_email, contact_type);
+
+ALTER TABLE ONLY public.email_attachments_drafts
+ ADD CONSTRAINT email_attachments_drafts_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.email_attachments_drafts
+ ADD CONSTRAINT email_attachments_drafts_s3_key_key UNIQUE (s3_key);
+
+ALTER TABLE ONLY public.email_attachments_fwd
+ ADD CONSTRAINT email_attachments_fwd_message_id_attachment_id_key UNIQUE (message_id, attachment_id);
+
+ALTER TABLE ONLY public.email_attachments
+ ADD CONSTRAINT email_attachments_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.email_attachments_sfs
+ ADD CONSTRAINT email_attachments_sfs_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.email_backfill_jobs
+ ADD CONSTRAINT email_backfill_job_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.email_contacts
+ ADD CONSTRAINT email_contacts_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.email_filters
+ ADD CONSTRAINT email_filters_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.email_gmail_histories
+ ADD CONSTRAINT email_gmail_histories_pkey PRIMARY KEY (link_id);
+
+ALTER TABLE ONLY public.email_labels
+ ADD CONSTRAINT email_labels_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.email_links
+ ADD CONSTRAINT email_links_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.email_message_labels
+ ADD CONSTRAINT email_message_labels_pkey PRIMARY KEY (message_id, label_id);
+
+ALTER TABLE ONLY public.email_message_recipients
+ ADD CONSTRAINT email_message_recipients_pkey PRIMARY KEY (message_id, contact_id, recipient_type);
+
+ALTER TABLE ONLY public.email_messages
+ ADD CONSTRAINT email_messages_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.email_scheduled_messages
+ ADD CONSTRAINT email_scheduled_messages_pkey PRIMARY KEY (link_id, message_id);
+
+ALTER TABLE ONLY public.email_settings
+ ADD CONSTRAINT email_settings_pkey PRIMARY KEY (link_id);
+
+ALTER TABLE ONLY public.email_sfs_mappings
+ ADD CONSTRAINT email_sfs_mappings_pkey PRIMARY KEY (source);
+
+ALTER TABLE ONLY public.email_sync_tokens
+ ADD CONSTRAINT email_sync_tokens_pkey PRIMARY KEY (link_id);
+
+ALTER TABLE ONLY public.email_threads
+ ADD CONSTRAINT email_threads_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.email_attachments
+ ADD CONSTRAINT email_uq_attachments_message_id_provider_attachment_id UNIQUE (message_id, provider_attachment_id);
+
+ALTER TABLE ONLY public.email_labels
+ ADD CONSTRAINT email_uq_labels_link_id_provider_label_id UNIQUE (link_id, provider_label_id);
+
+ALTER TABLE ONLY public.email_links
+ ADD CONSTRAINT email_uq_links_user_email_provider UNIQUE (fusionauth_user_id, email_address, provider);
+
+ALTER TABLE ONLY public.email_user_history
+ ADD CONSTRAINT email_user_history_pkey PRIMARY KEY (link_id, thread_id);
+
+ALTER TABLE ONLY public.entity_access
+ ADD CONSTRAINT entity_access_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.entity_properties
+ ADD CONSTRAINT entity_properties_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.excluded_default_view
+ ADD CONSTRAINT excluded_default_view_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.frecency_aggregates
+ ADD CONSTRAINT frecency_aggregates_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.frecency_events
+ ADD CONSTRAINT frecency_events_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.github_app_installation_team
+ ADD CONSTRAINT github_app_installation_team_pkey PRIMARY KEY (id, team_id);
+
+ALTER TABLE ONLY public.github_links
+ ADD CONSTRAINT github_links_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.github_pr_tasks
+ ADD CONSTRAINT github_pr_tasks_github_key_task_id_unique UNIQUE (github_key, task_id);
+
+ALTER TABLE ONLY public.github_pr_tasks
+ ADD CONSTRAINT github_pr_tasks_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.id_mapping
+ ADD CONSTRAINT id_mapping_pkey PRIMARY KEY (source_id);
+
+ALTER TABLE ONLY public.in_progress_email_link
+ ADD CONSTRAINT in_progress_email_link_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.in_progress_user_link
+ ADD CONSTRAINT in_progress_user_link_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.macro_user_email_verification
+ ADD CONSTRAINT macro_user_email_verification_pkey PRIMARY KEY (macro_user_id, email);
+
+ALTER TABLE ONLY public.macro_user_info
+ ADD CONSTRAINT macro_user_info_pkey PRIMARY KEY (macro_user_id);
+
+ALTER TABLE ONLY public.macro_user
+ ADD CONSTRAINT macro_user_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.memory
+ ADD CONSTRAINT memory_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.memory
+ ADD CONSTRAINT memory_user_id_unique UNIQUE (user_id);
+
+ALTER TABLE ONLY public.notification_email_sent
+ ADD CONSTRAINT notification_email_sent_pkey PRIMARY KEY (user_id);
+
+ALTER TABLE ONLY public.notification_email_unsubscribe_code
+ ADD CONSTRAINT notification_email_unsubscribe_code_code_key UNIQUE (code);
+
+ALTER TABLE ONLY public.notification_email_unsubscribe_code
+ ADD CONSTRAINT notification_email_unsubscribe_code_pkey PRIMARY KEY (email);
+
+ALTER TABLE ONLY public.notification_email_unsubscribe
+ ADD CONSTRAINT notification_email_unsubscribe_pkey PRIMARY KEY (email);
+
+ALTER TABLE ONLY public.notification_message_receipt
+ ADD CONSTRAINT notification_message_receipt_pkey PRIMARY KEY (message_id);
+
+ALTER TABLE ONLY public.notification
+ ADD CONSTRAINT notification_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.notification_user_device_registration
+ ADD CONSTRAINT notification_user_device_registration_device_endpoint_key UNIQUE (device_endpoint);
+
+ALTER TABLE ONLY public.notification_user_device_registration
+ ADD CONSTRAINT notification_user_device_registration_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.property_definitions
+ ADD CONSTRAINT property_definitions_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.property_options
+ ADD CONSTRAINT property_options_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.referral_tracking
+ ADD CONSTRAINT referral_tracking_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.saved_view
+ ADD CONSTRAINT saved_view_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.team_invite
+ ADD CONSTRAINT team_invite_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.team
+ ADD CONSTRAINT team_owner_id_unique UNIQUE (owner_id);
+
+ALTER TABLE ONLY public.team
+ ADD CONSTRAINT team_pkey PRIMARY KEY (id);
+
+ALTER TABLE ONLY public.team_user
+ ADD CONSTRAINT team_user_pkey PRIMARY KEY (user_id, team_id);
+
+ALTER TABLE ONLY public.team_user
+ ADD CONSTRAINT team_user_user_id_unique UNIQUE (user_id);
+
+ALTER TABLE ONLY public.entity_properties
+ ADD CONSTRAINT unique_entity_properties_assignment UNIQUE (entity_id, entity_type, property_definition_id);
+
+ALTER TABLE ONLY public.property_definitions
+ ADD CONSTRAINT unique_property_definitions_org_display_name UNIQUE (organization_id, display_name);
+
+ALTER TABLE ONLY public.property_definitions
+ ADD CONSTRAINT unique_property_definitions_user_display_name UNIQUE (user_id, display_name);
+
+ALTER TABLE ONLY public.property_options
+ ADD CONSTRAINT unique_property_options_number_value UNIQUE (property_definition_id, number_value);
+
+ALTER TABLE ONLY public.property_options
+ ADD CONSTRAINT unique_property_options_string_value UNIQUE (property_definition_id, string_value);
+
+ALTER TABLE ONLY public.frecency_aggregates
+ ADD CONSTRAINT unique_user_entity UNIQUE (user_id, entity_type, entity_id);
+
+ALTER TABLE ONLY public.user_mute_notification
+ ADD CONSTRAINT user_mute_notification_pkey PRIMARY KEY (user_id);
+
+ALTER TABLE ONLY public.user_notification_item_unsubscribe
+ ADD CONSTRAINT user_notification_item_unsubscribe_pkey PRIMARY KEY (user_id, item_id);
+
+ALTER TABLE ONLY public.user_notification
+ ADD CONSTRAINT user_notification_pkey PRIMARY KEY (user_id, notification_id);
+
+ALTER TABLE ONLY public.user_notification_type_preference
+ ADD CONSTRAINT user_notification_type_preference_pkey PRIMARY KEY (user_id, notification_event_type);
+
+CREATE INDEX databases_created_at ON _sqlx_test.databases USING btree (created_at);
+
+CREATE INDEX "Artifact_digest_idx" ON public."Artifact" USING btree (digest);
+
+CREATE INDEX "Artifact_documentId_idx" ON public."Artifact" USING btree ("documentId");
+
+CREATE INDEX "Artifact_userId_idx" ON public."Artifact" USING btree ("userId");
+
+CREATE INDEX "BomPart_documentBomId_idx" ON public."BomPart" USING btree ("documentBomId");
+
+CREATE INDEX "BomPart_sha_idx" ON public."BomPart" USING btree (sha);
+
+CREATE INDEX "ChannelSharePermission_channel_id_idx" ON public."ChannelSharePermission" USING btree (channel_id);
+
+CREATE INDEX "ChannelSharePermission_share_permission_id_idx" ON public."ChannelSharePermission" USING btree (share_permission_id);
+
+CREATE INDEX "ChatAttachment_attachmentType_attachmentId_idx" ON public."ChatAttachment" USING btree ("attachmentType", "attachmentId");
+
+CREATE INDEX "ChatAttachment_chatId_idx" ON public."ChatAttachment" USING btree ("chatId");
+
+CREATE INDEX "ChatAttachment_messageId_idx" ON public."ChatAttachment" USING btree ("messageId");
+
+CREATE INDEX "ChatMessage_chatId_idx" ON public."ChatMessage" USING btree ("chatId");
+
+CREATE UNIQUE INDEX "ChatPermission_chatId_key" ON public."ChatPermission" USING btree ("chatId");
+
+CREATE UNIQUE INDEX "ChatPermission_sharePermissionId_key" ON public."ChatPermission" USING btree ("sharePermissionId");
+
+CREATE INDEX "Chat_projectId_idx" ON public."Chat" USING btree ("projectId");
+
+CREATE INDEX "Chat_userId_idx" ON public."Chat" USING btree ("userId");
+
+CREATE INDEX "Comment_owner_idx" ON public."Comment" USING btree (owner);
+
+CREATE INDEX "Comment_threadId_createdAt_idx" ON public."Comment" USING btree ("threadId", "createdAt");
+
+CREATE INDEX "Comment_threadId_idx" ON public."Comment" USING btree ("threadId");
+
+CREATE INDEX "DocumentBom_documentId_idx" ON public."DocumentBom" USING btree ("documentId");
+
+CREATE INDEX "DocumentFamily_rootDocumentId_idx" ON public."DocumentFamily" USING btree ("rootDocumentId");
+
+CREATE INDEX "DocumentInstanceModificationData_documentInstanceId_idx" ON public."DocumentInstanceModificationData" USING btree ("documentInstanceId");
+
+CREATE INDEX "DocumentInstance_documentId_idx" ON public."DocumentInstance" USING btree ("documentId");
+
+CREATE UNIQUE INDEX "DocumentPermission_documentId_key" ON public."DocumentPermission" USING btree ("documentId");
+
+CREATE UNIQUE INDEX "DocumentPermission_sharePermissionId_key" ON public."DocumentPermission" USING btree ("sharePermissionId");
+
+CREATE INDEX "DocumentProcessResult_documentId_idx" ON public."DocumentProcessResult" USING btree ("documentId");
+
+CREATE UNIQUE INDEX "DocumentProcessResult_documentId_jobType_key" ON public."DocumentProcessResult" USING btree ("documentId", "jobType");
+
+CREATE INDEX "DocumentSummary_document_id_idx" ON public."DocumentSummary" USING btree (document_id);
+
+CREATE INDEX "DocumentTextParts_documentId_idx" ON public."DocumentTextParts" USING btree ("documentId");
+
+CREATE INDEX "DocumentText_documentId_idx" ON public."DocumentText" USING btree ("documentId");
+
+CREATE UNIQUE INDEX "DocumentText_documentId_key" ON public."DocumentText" USING btree ("documentId");
+
+CREATE INDEX "DocumentView_document_id_idx" ON public."DocumentView" USING btree (document_id);
+
+CREATE INDEX "DocumentView_user_id_idx" ON public."DocumentView" USING btree (user_id);
+
+CREATE INDEX "Document_branchedFromId_idx" ON public."Document" USING btree ("branchedFromId");
+
+CREATE INDEX "Document_documentFamilyId_idx" ON public."Document" USING btree ("documentFamilyId");
+
+CREATE INDEX "Document_owner_deletedAt_idx" ON public."Document" USING btree (owner, "deletedAt");
+
+CREATE INDEX "Document_owner_fileType_idx" ON public."Document" USING btree (owner, "fileType");
+
+CREATE INDEX "Document_owner_idx" ON public."Document" USING btree (owner);
+
+CREATE INDEX "Document_projectId_idx" ON public."Document" USING btree ("projectId");
+
+CREATE UNIQUE INDEX "EmailThreadPermission_sharePermissionId_key" ON public."EmailThreadPermission" USING btree ("sharePermissionId");
+
+CREATE UNIQUE INDEX "EmailThreadPermission_threadId_key" ON public."EmailThreadPermission" USING btree ("threadId");
+
+CREATE UNIQUE INDEX "EnterpriseRules_organizationId_key" ON public."EnterpriseRules" USING btree ("organizationId");
+
+CREATE INDEX "ExperimentLog_experiment_id_idx" ON public."ExperimentLog" USING btree (experiment_id);
+
+CREATE INDEX "ExperimentLog_user_id_idx" ON public."ExperimentLog" USING btree (user_id);
+
+CREATE UNIQUE INDEX "Experiment_id_key" ON public."Experiment" USING btree (id);
+
+CREATE INDEX "InstructionsDocuments_userId_idx" ON public."InstructionsDocuments" USING btree ("userId");
+
+CREATE UNIQUE INDEX "InstructionsDocuments_userId_key" ON public."InstructionsDocuments" USING btree ("userId");
+
+CREATE INDEX "ItemLastAccessed_item_id_idx" ON public."ItemLastAccessed" USING btree (item_id);
+
+CREATE INDEX "ItemLastAccessed_item_type_idx" ON public."ItemLastAccessed" USING btree (item_type);
+
+CREATE INDEX "JobToDocumentProcessResult_documentProcessResultId_idx" ON public."JobToDocumentProcessResult" USING btree ("documentProcessResultId");
+
+CREATE INDEX "JobToDocumentProcessResult_jobId_idx" ON public."JobToDocumentProcessResult" USING btree ("jobId");
+
+CREATE UNIQUE INDEX "JobToDocumentProcessResult_jobId_key" ON public."JobToDocumentProcessResult" USING btree ("jobId");
+
+CREATE INDEX "MacroPromptAttachment_attachment_type_attachment_id_idx" ON public."MacroPromptAttachment" USING btree (attachment_type, attachment_id);
+
+CREATE INDEX "MacroPromptAttachment_macro_prompt_id_idx" ON public."MacroPromptAttachment" USING btree (macro_prompt_id);
+
+CREATE UNIQUE INDEX "MacroPromptPermission_macro_prompt_id_key" ON public."MacroPromptPermission" USING btree (macro_prompt_id);
+
+CREATE UNIQUE INDEX "MacroPromptPermission_share_permission_id_key" ON public."MacroPromptPermission" USING btree (share_permission_id);
+
+CREATE INDEX "MacroPrompt_user_id_idx" ON public."MacroPrompt" USING btree (user_id);
+
+CREATE UNIQUE INDEX "OrganizationBilling_email_key" ON public."OrganizationBilling" USING btree (email);
+
+CREATE INDEX "OrganizationDefaultSharePermission_organization_id_idx" ON public."OrganizationDefaultSharePermission" USING btree (organization_id);
+
+CREATE UNIQUE INDEX "OrganizationDefaultSharePermission_organization_id_key" ON public."OrganizationDefaultSharePermission" USING btree (organization_id);
+
+CREATE INDEX "OrganizationEmailMatches_organizationId_idx" ON public."OrganizationEmailMatches" USING btree ("organizationId");
+
+CREATE UNIQUE INDEX "OrganizationIT_email_key" ON public."OrganizationIT" USING btree (email);
+
+CREATE INDEX "OrganizationInvitation_email_idx" ON public."OrganizationInvitation" USING btree (email);
+
+CREATE UNIQUE INDEX "OrganizationInvitation_organization_id_email_key" ON public."OrganizationInvitation" USING btree (organization_id, email);
+
+CREATE INDEX "OrganizationInvitation_organization_id_idx" ON public."OrganizationInvitation" USING btree (organization_id);
+
+CREATE UNIQUE INDEX "OrganizationItJob_organizationId_key" ON public."OrganizationItJob" USING btree ("organizationId");
+
+CREATE INDEX "OrganizationRetentionPolicy_organization_id_idx" ON public."OrganizationRetentionPolicy" USING btree (organization_id);
+
+CREATE UNIQUE INDEX "OrganizationRetentionPolicy_organization_id_key" ON public."OrganizationRetentionPolicy" USING btree (organization_id);
+
+CREATE UNIQUE INDEX "Organization_name_key" ON public."Organization" USING btree (name);
+
+CREATE UNIQUE INDEX "Organization_stripeCustomerId_key" ON public."Organization" USING btree ("stripeCustomerId");
+
+CREATE INDEX "PdfHighlightAnchor_documentId_idx" ON public."PdfHighlightAnchor" USING btree ("documentId");
+
+CREATE INDEX "PdfHighlightAnchor_owner_idx" ON public."PdfHighlightAnchor" USING btree (owner);
+
+CREATE INDEX "PdfHighlightAnchor_threadId_idx" ON public."PdfHighlightAnchor" USING btree ("threadId");
+
+CREATE INDEX "PdfHighlightRect_pdfHighlightAnchorId_idx" ON public."PdfHighlightRect" USING btree ("pdfHighlightAnchorId");
+
+CREATE INDEX "PdfPlaceableCommentAnchor_documentId_idx" ON public."PdfPlaceableCommentAnchor" USING btree ("documentId");
+
+CREATE INDEX "PdfPlaceableCommentAnchor_owner_idx" ON public."PdfPlaceableCommentAnchor" USING btree (owner);
+
+CREATE INDEX "PdfPlaceableCommentAnchor_threadId_idx" ON public."PdfPlaceableCommentAnchor" USING btree ("threadId");
+
+CREATE INDEX "Pin_pinnedItemId_idx" ON public."Pin" USING btree ("pinnedItemId");
+
+CREATE INDEX "Pin_userId_idx" ON public."Pin" USING btree ("userId");
+
+CREATE UNIQUE INDEX "ProjectPermission_projectId_key" ON public."ProjectPermission" USING btree ("projectId");
+
+CREATE UNIQUE INDEX "ProjectPermission_sharePermissionId_key" ON public."ProjectPermission" USING btree ("sharePermissionId");
+
+CREATE INDEX "Project_parentId_idx" ON public."Project" USING btree ("parentId");
+
+CREATE INDEX "Project_uploadPending_idx" ON public."Project" USING btree ("uploadPending");
+
+CREATE INDEX "Project_userId_idx" ON public."Project" USING btree ("userId");
+
+CREATE UNIQUE INDEX "ThreadAnchor_anchorId_key" ON public."ThreadAnchor" USING btree ("anchorId");
+
+CREATE UNIQUE INDEX "ThreadAnchor_threadId_key" ON public."ThreadAnchor" USING btree ("threadId");
+
+CREATE INDEX "Thread_documentId_idx" ON public."Thread" USING btree ("documentId");
+
+CREATE INDEX "Thread_owner_idx" ON public."Thread" USING btree (owner);
+
+CREATE INDEX "UploadJob_documentId_idx" ON public."UploadJob" USING btree ("documentId");
+
+CREATE INDEX "UploadJob_jobId_idx" ON public."UploadJob" USING btree ("jobId");
+
+CREATE INDEX "UserApiKey_key_idx" ON public."UserApiKey" USING btree (key);
+
+CREATE UNIQUE INDEX "UserApiKey_key_key" ON public."UserApiKey" USING btree (key);
+
+CREATE INDEX "UserApiKey_user_id_idx" ON public."UserApiKey" USING btree (user_id);
+
+CREATE INDEX "UserDocumentViewLocation_document_id_idx" ON public."UserDocumentViewLocation" USING btree (document_id);
+
+CREATE INDEX "UserDocumentViewLocation_user_id_idx" ON public."UserDocumentViewLocation" USING btree (user_id);
+
+CREATE INDEX "UserHistory_itemId_itemType_idx" ON public."UserHistory" USING btree ("itemId", "itemType");
+
+CREATE INDEX "UserHistory_userId_idx" ON public."UserHistory" USING btree ("userId");
+
+CREATE INDEX "UserHistory_userId_itemType_idx" ON public."UserHistory" USING btree ("userId", "itemType");
+
+CREATE INDEX "UserInsightBatch_expiresAt_idx" ON public."UserInsightBatch" USING btree ("expiresAt");
+
+CREATE INDEX "UserInsightBatch_userId_idx" ON public."UserInsightBatch" USING btree ("userId");
+
+CREATE UNIQUE INDEX "UserInsightBatch_userId_key" ON public."UserInsightBatch" USING btree ("userId");
+
+CREATE INDEX "UserInsights_userId_idx" ON public."UserInsights" USING btree ("userId");
+
+CREATE INDEX "UserItemAccess_granted_from_channel_id_idx" ON public."UserItemAccess" USING btree (granted_from_channel_id);
+
+CREATE INDEX "UserItemAccess_granted_from_team_id_idx" ON public."UserItemAccess" USING btree (granted_from_team_id);
+
+CREATE INDEX "UserItemAccess_item_id_idx" ON public."UserItemAccess" USING btree (item_id);
+
+CREATE INDEX "UserItemAccess_user_id_idx" ON public."UserItemAccess" USING btree (user_id);
+
+CREATE UNIQUE INDEX "UserItemAccess_user_id_item_id_item_type_granted_from_chann_key" ON public."UserItemAccess" USING btree (user_id, item_id, item_type, granted_from_channel_id);
+
+CREATE UNIQUE INDEX "UserItemAccess_user_id_item_id_item_type_granted_from_team_key" ON public."UserItemAccess" USING btree (user_id, item_id, item_type, granted_from_team_id);
+
+CREATE INDEX "User_email_idx" ON public."User" USING btree (email);
+
+CREATE UNIQUE INDEX "User_email_key" ON public."User" USING btree (email);
+
+CREATE UNIQUE INDEX "User_id_key" ON public."User" USING btree (id);
+
+CREATE INDEX "User_organizationId_idx" ON public."User" USING btree ("organizationId");
+
+CREATE UNIQUE INDEX "User_stripeCustomerId_key" ON public."User" USING btree ("stripeCustomerId");
+
+CREATE INDEX "WebAnnotations_chatId_idx" ON public."WebAnnotations" USING btree ("chatId");
+
+CREATE INDEX "WebAnnotations_messageId_idx" ON public."WebAnnotations" USING btree ("messageId");
+
+CREATE UNIQUE INDEX "WebsocketConnectionPermissions_connectionId_key" ON public."WebsocketConnectionPermissions" USING btree ("connectionId");
+
+CREATE INDEX account_merge_request_code_idx ON public.account_merge_request USING btree (code);
+
+CREATE INDEX account_merge_request_macro_user_id_idx ON public.account_merge_request USING btree (macro_user_id);
+
+CREATE INDEX account_merge_request_to_merge_macro_user_id_idx ON public.account_merge_request USING btree (to_merge_macro_user_id);
+
+CREATE UNIQUE INDEX account_merge_request_to_merge_macro_user_id_key ON public.account_merge_request USING btree (to_merge_macro_user_id);
+
+CREATE UNIQUE INDEX contacts_link_id_email_address_idx ON public.email_contacts USING btree (link_id, email_address);
+
+CREATE UNIQUE INDEX email_filters_link_id_email_address_uq ON public.email_filters USING btree (link_id, lower((email_address)::text)) WHERE (email_address IS NOT NULL);
+
+CREATE UNIQUE INDEX email_filters_link_id_email_domain_uq ON public.email_filters USING btree (link_id, lower((email_domain)::text)) WHERE (email_domain IS NOT NULL);
+
+CREATE UNIQUE INDEX email_links_macro_id_uq ON public.email_links USING btree (macro_id);
+
+CREATE INDEX entity_access_entity_id_entity_type_idx ON public.entity_access USING btree (entity_id, entity_type);
+
+CREATE INDEX entity_access_granted_from_project_id_idx ON public.entity_access USING btree (granted_from_project_id);
+
+CREATE INDEX entity_access_source_id_idx ON public.entity_access USING btree (source_id);
+
+CREATE UNIQUE INDEX entity_access_unique_with_project ON public.entity_access USING btree (entity_id, entity_type, source_id, source_type, granted_from_project_id) WHERE (granted_from_project_id IS NOT NULL);
+
+CREATE UNIQUE INDEX entity_access_unique_without_project ON public.entity_access USING btree (entity_id, entity_type, source_id, source_type) WHERE (granted_from_project_id IS NULL);
+
+CREATE INDEX github_app_installation_team_team_id_idx ON public.github_app_installation_team USING btree (team_id);
+
+CREATE INDEX id_mapping_target_id_idx ON public.id_mapping USING btree (target_id);
+
+CREATE INDEX idx_call_record_transcripts_call_record_id ON public.call_record_transcripts USING btree (call_record_id);
+
+CREATE INDEX idx_call_records_channel_id ON public.call_records USING btree (channel_id);
+
+CREATE INDEX idx_call_records_egress_id ON public.call_records USING btree (egress_id);
+
+CREATE INDEX idx_call_transcripts_call_id ON public.call_transcripts USING btree (call_id);
+
+CREATE INDEX idx_calls_channel_id ON public.calls USING btree (channel_id);
+
+CREATE INDEX idx_calls_room_name ON public.calls USING btree (room_name);
+
+CREATE INDEX idx_channel_notification_email_sent_channel ON public.channel_notification_email_sent USING btree (channel_id);
+
+CREATE INDEX idx_channel_notification_email_sent_user ON public.channel_notification_email_sent USING btree (user_id);
+
+CREATE INDEX idx_chat_name_trgm ON public."Chat" USING gin (name public.gin_trgm_ops);
+
+CREATE INDEX idx_comms_activity_channel_id_user_id ON public.comms_activity USING btree (user_id, channel_id);
+
+CREATE INDEX idx_comms_activity_channel_user ON public.comms_activity USING btree (channel_id, user_id);
+
+CREATE INDEX idx_comms_activity_user_times ON public.comms_activity USING btree (user_id, updated_at, created_at);
+
+CREATE INDEX idx_comms_attachments_channel_created ON public.comms_attachments USING btree (channel_id, created_at);
+
+CREATE INDEX idx_comms_attachments_channel_cursor ON public.comms_attachments USING btree (channel_id, created_at DESC, id DESC);
+
+CREATE INDEX idx_comms_attachments_channel_id ON public.comms_attachments USING btree (channel_id);
+
+CREATE INDEX idx_comms_attachments_entity_created ON public.comms_attachments USING btree (entity_type, entity_id, created_at DESC) INCLUDE (channel_id, message_id);
+
+CREATE INDEX idx_comms_attachments_message_id ON public.comms_attachments USING btree (message_id);
+
+CREATE INDEX idx_comms_channels_org_id ON public.comms_channels USING btree (org_id) WHERE (channel_type = 'organization'::public.comms_channel_type);
+
+CREATE INDEX idx_comms_channels_team_id ON public.comms_channels USING btree (team_id) WHERE (team_id IS NOT NULL);
+
+CREATE INDEX idx_comms_cp_active_by_channel_user ON public.comms_channel_participants USING btree (channel_id, user_id) WHERE (left_at IS NULL);
+
+CREATE INDEX idx_comms_entity_mentions_combination ON public.comms_entity_mentions USING btree (source_entity_type, source_entity_id, entity_type, entity_id);
+
+CREATE INDEX idx_comms_entity_mentions_created_at ON public.comms_entity_mentions USING btree (created_at DESC);
+
+CREATE INDEX idx_comms_entity_mentions_entity_type_id ON public.comms_entity_mentions USING btree (entity_type, entity_id) INCLUDE (source_entity_type, source_entity_id);
+
+CREATE INDEX idx_comms_entity_mentions_source ON public.comms_entity_mentions USING btree (source_entity_type, source_entity_id);
+
+CREATE INDEX idx_comms_entity_mentions_user_id ON public.comms_entity_mentions USING btree (user_id) WHERE (user_id IS NOT NULL);
+
+CREATE INDEX idx_comms_messages_active ON public.comms_messages USING btree (id) WHERE (deleted_at IS NULL);
+
+CREATE INDEX idx_comms_messages_channel_created_at_active ON public.comms_messages USING btree (channel_id, created_at DESC) WHERE (deleted_at IS NULL);
+
+CREATE INDEX idx_comms_messages_channel_id ON public.comms_messages USING btree (channel_id);
+
+CREATE INDEX idx_comms_messages_channel_timeline ON public.comms_messages USING btree (channel_id, created_at);
+
+CREATE INDEX idx_comms_messages_channel_toplevel_cursor ON public.comms_messages USING btree (channel_id, created_at DESC, id DESC) WHERE (thread_id IS NULL);
+
+CREATE INDEX idx_comms_messages_created_at_active ON public.comms_messages USING btree (created_at DESC) WHERE (deleted_at IS NULL);
+
+CREATE INDEX idx_comms_messages_sender_id ON public.comms_messages USING btree (sender_id);
+
+CREATE INDEX idx_comms_messages_thread_active_created ON public.comms_messages USING btree (thread_id, created_at DESC) WHERE ((thread_id IS NOT NULL) AND (deleted_at IS NULL));
+
+CREATE INDEX idx_comms_messages_thread_id ON public.comms_messages USING btree (thread_id) WHERE (thread_id IS NOT NULL);
+
+CREATE INDEX idx_comms_reactions_message_id ON public.comms_reactions USING btree (message_id);
+
+CREATE INDEX idx_contacts_connections_user1 ON public.contacts_connections USING btree (user1);
+
+CREATE INDEX idx_contacts_connections_user2 ON public.contacts_connections USING btree (user2);
+
+CREATE INDEX idx_document_email_attachment_id ON public.document_email USING btree (email_attachment_id);
+
+CREATE INDEX idx_document_id_covering ON public."Document" USING btree (id) INCLUDE ("updatedAt", "deletedAt");
+
+CREATE INDEX idx_document_name_trgm ON public."Document" USING gin (name public.gin_trgm_ops);
+
+CREATE INDEX idx_ecsi_link_email_trgm ON public.email_contact_search_index USING gin (link_id, contact_email public.gin_trgm_ops);
+
+CREATE INDEX idx_ecsi_link_name_trgm ON public.email_contact_search_index USING gin (link_id, contact_name public.gin_trgm_ops);
+
+CREATE INDEX idx_ecsi_link_thread ON public.email_contact_search_index USING btree (link_id, thread_id);
+
+CREATE INDEX idx_email_attachments_drafts_message_db_id ON public.email_attachments_drafts USING btree (draft_id);
+
+CREATE INDEX idx_email_attachments_fwd_attachment_id ON public.email_attachments_fwd USING btree (attachment_id);
+
+CREATE INDEX idx_email_attachments_message_id ON public.email_attachments USING btree (message_id);
+
+CREATE INDEX idx_email_attachments_sfs_attachment_id ON public.email_attachments_sfs USING btree (attachment_id);
+
+CREATE INDEX idx_email_contacts_email_address_trgm ON public.email_contacts USING gin (email_address public.gin_trgm_ops);
+
+CREATE INDEX idx_email_contacts_link_id_name ON public.email_contacts USING btree (link_id, name) WHERE (name IS NOT NULL);
+
+CREATE INDEX idx_email_contacts_name_trgm ON public.email_contacts USING gin (name public.gin_trgm_ops) WHERE (name IS NOT NULL);
+
+CREATE INDEX idx_email_filters_link_id ON public.email_filters USING btree (link_id);
+
+CREATE INDEX idx_email_labels_link_id ON public.email_labels USING btree (link_id);
+
+CREATE INDEX idx_email_labels_link_id_for_trash_lookup ON public.email_labels USING btree (link_id) WHERE ((name)::text = 'TRASH'::text);
+
+CREATE INDEX idx_email_labels_link_id_name ON public.email_labels USING btree (link_id, name);
+
+CREATE INDEX idx_email_labels_name ON public.email_labels USING btree (name);
+
+CREATE INDEX idx_email_links_active_provider_hash_bucket ON public.email_links USING btree (provider, ((abs(hashtext((id)::text)) % 24))) WHERE (is_sync_active = true);
+
+CREATE INDEX idx_email_links_email_provider ON public.email_links USING btree (lower((email_address)::text), provider);
+
+CREATE INDEX idx_email_links_fusionauth_user_active ON public.email_links USING btree (fusionauth_user_id, is_sync_active) WHERE (is_sync_active = true);
+
+CREATE INDEX idx_email_links_macro_id ON public.email_links USING btree (macro_id);
+
+CREATE INDEX idx_email_links_provider_active ON public.email_links USING btree (provider, is_sync_active) WHERE (is_sync_active = true);
+
+CREATE INDEX idx_email_message_labels_by_label ON public.email_message_labels USING btree (label_id, message_id);
+
+CREATE INDEX idx_email_message_recipients_contact_id ON public.email_message_recipients USING btree (contact_id);
+
+CREATE INDEX idx_email_message_recipients_name_trgm ON public.email_message_recipients USING gin (name public.gin_trgm_ops) WHERE (name IS NOT NULL);
+
+CREATE INDEX idx_email_messages_drafts_view ON public.email_messages USING btree (link_id, thread_id, internal_date_ts DESC) WHERE (is_draft = true);
+
+CREATE INDEX idx_email_messages_from_contact_id ON public.email_messages USING btree (from_contact_id);
+
+CREATE INDEX idx_email_messages_from_name_trgm ON public.email_messages USING gin (from_name public.gin_trgm_ops) WHERE (from_name IS NOT NULL);
+
+CREATE INDEX idx_email_messages_link_id ON public.email_messages USING btree (link_id);
+
+CREATE INDEX idx_email_messages_link_id_global_id ON public.email_messages USING btree (link_id, global_id);
+
+CREATE INDEX idx_email_messages_link_id_replying_to_id ON public.email_messages USING btree (link_id, replying_to_id);
+
+CREATE INDEX idx_email_messages_link_id_sent ON public.email_messages USING btree (link_id) WHERE (is_sent = true);
+
+CREATE INDEX idx_email_messages_link_id_thread_id_date_asc ON public.email_messages USING btree (link_id, thread_id, internal_date_ts);
+
+CREATE INDEX idx_email_messages_link_thread_date ON public.email_messages USING btree (link_id, thread_id, internal_date_ts DESC);
+
+CREATE INDEX idx_email_messages_replying_to_id ON public.email_messages USING btree (replying_to_id) WHERE (replying_to_id IS NOT NULL);
+
+CREATE INDEX idx_email_messages_sent_view ON public.email_messages USING btree (thread_id, internal_date_ts DESC) WHERE (is_sent = true);
+
+CREATE INDEX idx_email_messages_subject_trgm ON public.email_messages USING gin (subject public.gin_trgm_ops);
+
+CREATE INDEX idx_email_messages_thread_date_not_draft ON public.email_messages USING btree (thread_id, internal_date_ts DESC) WHERE (is_draft = false);
+
+CREATE INDEX idx_email_messages_thread_id_internal_date_asc ON public.email_messages USING btree (thread_id, internal_date_ts);
+
+CREATE INDEX idx_email_messages_thread_id_internal_date_ts ON public.email_messages USING btree (thread_id, internal_date_ts DESC);
+
+CREATE INDEX idx_email_scheduled_messages_send_time_sent ON public.email_scheduled_messages USING btree (send_time, sent);
+
+CREATE INDEX idx_email_sfs_mappings_destination ON public.email_sfs_mappings USING btree (destination);
+
+CREATE INDEX idx_email_threads_inbox_view_not_null ON public.email_threads USING btree (link_id, latest_inbound_message_ts DESC) WHERE ((inbox_visible = true) AND (latest_inbound_message_ts IS NOT NULL));
+
+CREATE INDEX idx_email_threads_link_id ON public.email_threads USING btree (link_id);
+
+CREATE INDEX idx_email_threads_non_spam_ts_id ON public.email_threads USING btree (link_id, latest_non_spam_message_ts DESC, id DESC) WHERE (latest_non_spam_message_ts IS NOT NULL);
+
+CREATE INDEX idx_email_threads_project_id ON public.email_threads USING btree (project_id);
+
+CREATE INDEX idx_email_threads_sent_view ON public.email_threads USING btree (link_id, latest_outbound_message_ts DESC) WHERE (latest_outbound_message_ts IS NOT NULL);
+
+CREATE INDEX idx_email_user_history_thread_id ON public.email_user_history USING btree (thread_id);
+
+CREATE INDEX idx_entity_properties_entity_id ON public.entity_properties USING btree (entity_id, entity_type);
+
+CREATE INDEX idx_entity_properties_property_definition_id ON public.entity_properties USING btree (property_definition_id);
+
+CREATE INDEX idx_entity_properties_values_gin ON public.entity_properties USING gin ("values" jsonb_path_ops);
+
+CREATE INDEX idx_frecency_aggregates_entity ON public.frecency_aggregates USING btree (user_id, entity_type, entity_id);
+
+CREATE INDEX idx_frecency_aggregates_user_score ON public.frecency_aggregates USING btree (user_id, frecency_score DESC);
+
+CREATE INDEX idx_frecency_events_unprocessed ON public.frecency_events USING btree (was_processed) WHERE (was_processed = false);
+
+CREATE INDEX idx_frecency_events_user_id ON public.frecency_events USING btree (user_id);
+
+CREATE INDEX idx_github_links_fusionauth_user_id ON public.github_links USING btree (fusionauth_user_id);
+
+CREATE INDEX idx_github_links_github_username ON public.github_links USING btree (github_username);
+
+CREATE INDEX idx_github_links_macro_id ON public.github_links USING btree (macro_id);
+
+CREATE INDEX idx_github_pr_tasks_github_key ON public.github_pr_tasks USING btree (github_key);
+
+CREATE INDEX idx_github_pr_tasks_task_id ON public.github_pr_tasks USING btree (task_id);
+
+CREATE INDEX idx_notification_event ON public.notification USING btree (event_item_id);
+
+CREATE INDEX idx_notification_event_item_type ON public.notification USING btree (event_item_type);
+
+CREATE INDEX idx_notification_event_type_id ON public.notification USING btree (event_item_type, event_item_id);
+
+CREATE INDEX idx_notification_message_receipt_user_notification ON public.notification_message_receipt USING btree (user_id, notification_id);
+
+CREATE INDEX idx_notification_user_device_registration_device_token ON public.notification_user_device_registration USING btree (device_token);
+
+CREATE INDEX idx_notification_user_device_registration_user ON public.notification_user_device_registration USING btree (user_id);
+
+CREATE INDEX idx_project_name_trgm ON public."Project" USING gin (name public.gin_trgm_ops);
+
+CREATE INDEX idx_property_definitions_organization_id ON public.property_definitions USING btree (organization_id) WHERE (organization_id IS NOT NULL);
+
+CREATE INDEX idx_property_definitions_user_id ON public.property_definitions USING btree (user_id) WHERE (user_id IS NOT NULL);
+
+CREATE INDEX idx_property_options_property_definition_id ON public.property_options USING btree (property_definition_id);
+
+CREATE UNIQUE INDEX idx_referral_tracking_referred_id ON public.referral_tracking USING btree (referred_id);
+
+CREATE INDEX idx_referral_tracking_referrer_id ON public.referral_tracking USING btree (referrer_id);
+
+CREATE INDEX idx_user_notif_type_pref_user ON public.user_notification_type_preference USING btree (user_id);
+
+CREATE INDEX idx_user_notification_active_filter ON public.user_notification USING btree (user_id, notification_id, done, seen_at) WHERE (deleted_at IS NULL);
+
+CREATE INDEX idx_user_notification_item_unsubscribe_item_id ON public.user_notification_item_unsubscribe USING btree (item_id);
+
+CREATE INDEX idx_user_notification_item_unsubscribe_user_id ON public.user_notification_item_unsubscribe USING btree (user_id);
+
+CREATE INDEX idx_user_notification_notification ON public.user_notification USING btree (notification_id);
+
+CREATE INDEX idx_user_notification_user ON public.user_notification USING btree (user_id);
+
+CREATE INDEX idx_views_user_id ON public.saved_view USING btree (user_id);
+
+CREATE UNIQUE INDEX in_progress_email_link_email_key ON public.in_progress_email_link USING btree (email);
+
+CREATE INDEX in_progress_user_link_macro_user_id_idx ON public.in_progress_user_link USING btree (macro_user_id);
+
+CREATE UNIQUE INDEX macro_user_email_key ON public.macro_user USING btree (email);
+
+CREATE UNIQUE INDEX macro_user_email_verification_email_key ON public.macro_user_email_verification USING btree (email);
+
+CREATE INDEX macro_user_email_verification_macro_user_id_idx ON public.macro_user_email_verification USING btree (macro_user_id);
+
+CREATE UNIQUE INDEX macro_user_stripe_customer_id_key ON public.macro_user USING btree (stripe_customer_id);
+
+CREATE UNIQUE INDEX macro_user_username_key ON public.macro_user USING btree (username);
+
+CREATE UNIQUE INDEX notification_email_unsubscribe_code_code_idx ON public.notification_email_unsubscribe_code USING btree (code);
+
+CREATE INDEX team_invite_email_idx ON public.team_invite USING btree (email);
+
+CREATE UNIQUE INDEX team_invite_email_team_id_key ON public.team_invite USING btree (email, team_id);
+
+CREATE INDEX team_invite_invited_by_idx ON public.team_invite USING btree (invited_by);
+
+CREATE INDEX team_invite_team_id_idx ON public.team_invite USING btree (team_id);
+
+CREATE INDEX team_owner_id_idx ON public.team USING btree (owner_id);
+
+CREATE INDEX team_user_team_id_idx ON public.team_user USING btree (team_id);
+
+CREATE INDEX team_user_user_id_idx ON public.team_user USING btree (user_id);
+
+CREATE UNIQUE INDEX uq_github_links_github_user_id ON public.github_links USING btree (github_user_id);
+
+CREATE UNIQUE INDEX uq_messages_link_id_provider_id ON public.email_messages USING btree (link_id, provider_id) WHERE (provider_id IS NOT NULL);
+
+CREATE UNIQUE INDEX uq_threads_link_id_provider_id ON public.email_threads USING btree (link_id, provider_id) WHERE (provider_id IS NOT NULL);
+
+CREATE TRIGGER check_orphaned_property_definition BEFORE UPDATE ON public.property_definitions FOR EACH ROW EXECUTE FUNCTION public.delete_orphaned_property_definition();
+
+CREATE TRIGGER prevent_system_property_name_conflict BEFORE INSERT OR UPDATE ON public.property_definitions FOR EACH ROW EXECUTE FUNCTION public.check_property_name_not_system();
+
+CREATE TRIGGER trg_delete_share_permission_call_record BEFORE DELETE ON public.call_records FOR EACH ROW EXECUTE FUNCTION public.delete_share_permission_on_call_record_delete();
+
+CREATE TRIGGER trg_ecsi_contact_name_update AFTER UPDATE OF name ON public.email_contacts FOR EACH ROW WHEN (((old.name)::text IS DISTINCT FROM (new.name)::text)) EXECUTE FUNCTION public.ecsi_update_contact_name();
+
+CREATE TRIGGER trg_ecsi_message_delete AFTER DELETE ON public.email_messages FOR EACH ROW EXECUTE FUNCTION public.ecsi_delete_message();
+
+CREATE TRIGGER trg_ecsi_message_from AFTER INSERT OR UPDATE OF from_contact_id, from_name ON public.email_messages FOR EACH ROW EXECUTE FUNCTION public.ecsi_populate_from();
+
+CREATE TRIGGER trg_ecsi_message_recipient AFTER INSERT ON public.email_message_recipients FOR EACH ROW EXECUTE FUNCTION public.ecsi_populate_recipient();
+
+CREATE TRIGGER trg_ecsi_message_recipient_delete AFTER DELETE ON public.email_message_recipients FOR EACH ROW EXECUTE FUNCTION public.ecsi_delete_recipient();
+
+ALTER TABLE ONLY public."Artifact"
+ ADD CONSTRAINT "Artifact_documentId_fkey" FOREIGN KEY ("documentId") REFERENCES public."Document"(id) ON UPDATE CASCADE ON DELETE SET NULL;
+
+ALTER TABLE ONLY public."Artifact"
+ ADD CONSTRAINT "Artifact_messageId_fkey" FOREIGN KEY ("messageId") REFERENCES public."ChatMessage"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."Artifact"
+ ADD CONSTRAINT "Artifact_userId_fkey" FOREIGN KEY ("userId") REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."BomPart"
+ ADD CONSTRAINT "BomPart_documentBomId_fkey" FOREIGN KEY ("documentBomId") REFERENCES public."DocumentBom"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."ChannelSharePermission"
+ ADD CONSTRAINT "ChannelSharePermission_share_permission_id_fkey" FOREIGN KEY (share_permission_id) REFERENCES public."SharePermission"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."ChatAttachment"
+ ADD CONSTRAINT "ChatAttachment_chatId_fkey" FOREIGN KEY ("chatId") REFERENCES public."Chat"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."ChatAttachment"
+ ADD CONSTRAINT "ChatAttachment_messageId_fkey" FOREIGN KEY ("messageId") REFERENCES public."ChatMessage"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."ChatMessage"
+ ADD CONSTRAINT "ChatMessage_chatId_fkey" FOREIGN KEY ("chatId") REFERENCES public."Chat"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."ChatPermission"
+ ADD CONSTRAINT "ChatPermission_chatId_fkey" FOREIGN KEY ("chatId") REFERENCES public."Chat"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."ChatPermission"
+ ADD CONSTRAINT "ChatPermission_sharePermissionId_fkey" FOREIGN KEY ("sharePermissionId") REFERENCES public."SharePermission"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."Chat"
+ ADD CONSTRAINT "Chat_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES public."Project"(id) ON UPDATE CASCADE ON DELETE SET NULL;
+
+ALTER TABLE ONLY public."Chat"
+ ADD CONSTRAINT "Chat_userId_fkey" FOREIGN KEY ("userId") REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."Comment"
+ ADD CONSTRAINT "Comment_owner_fkey" FOREIGN KEY (owner) REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."Comment"
+ ADD CONSTRAINT "Comment_threadId_fkey" FOREIGN KEY ("threadId") REFERENCES public."Thread"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."DocumentBom"
+ ADD CONSTRAINT "DocumentBom_documentId_fkey" FOREIGN KEY ("documentId") REFERENCES public."Document"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."DocumentInstanceModificationData"
+ ADD CONSTRAINT "DocumentInstanceModificationData_documentInstanceId_fkey" FOREIGN KEY ("documentInstanceId") REFERENCES public."DocumentInstance"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."DocumentInstance"
+ ADD CONSTRAINT "DocumentInstance_documentId_fkey" FOREIGN KEY ("documentId") REFERENCES public."Document"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."DocumentPermission"
+ ADD CONSTRAINT "DocumentPermission_documentId_fkey" FOREIGN KEY ("documentId") REFERENCES public."Document"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."DocumentPermission"
+ ADD CONSTRAINT "DocumentPermission_sharePermissionId_fkey" FOREIGN KEY ("sharePermissionId") REFERENCES public."SharePermission"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."DocumentProcessResult"
+ ADD CONSTRAINT "DocumentProcessResult_documentId_fkey" FOREIGN KEY ("documentId") REFERENCES public."Document"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."DocumentSummary"
+ ADD CONSTRAINT "DocumentSummary_document_id_fkey" FOREIGN KEY (document_id) REFERENCES public."Document"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."DocumentTextParts"
+ ADD CONSTRAINT "DocumentTextParts_documentId_fkey" FOREIGN KEY ("documentId") REFERENCES public."Document"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."DocumentText"
+ ADD CONSTRAINT "DocumentText_documentId_fkey" FOREIGN KEY ("documentId") REFERENCES public."Document"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."DocumentView"
+ ADD CONSTRAINT "DocumentView_document_id_fkey" FOREIGN KEY (document_id) REFERENCES public."Document"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."DocumentView"
+ ADD CONSTRAINT "DocumentView_user_id_fkey" FOREIGN KEY (user_id) REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."Document"
+ ADD CONSTRAINT "Document_documentFamilyId_fkey" FOREIGN KEY ("documentFamilyId") REFERENCES public."DocumentFamily"(id) ON UPDATE CASCADE ON DELETE SET NULL;
+
+ALTER TABLE ONLY public."Document"
+ ADD CONSTRAINT "Document_owner_fkey" FOREIGN KEY (owner) REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."Document"
+ ADD CONSTRAINT "Document_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES public."Project"(id) ON UPDATE CASCADE ON DELETE SET NULL;
+
+ALTER TABLE ONLY public."EmailInsightsBackfillBatch"
+ ADD CONSTRAINT "EmailInsightsBackfillBatch_insightsBackfillJobId_fkey" FOREIGN KEY ("insightsBackfillJobId") REFERENCES public."EmailInsightsBackfillJob"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."EmailInsightsBackfillJob"
+ ADD CONSTRAINT "EmailInsightsBackfillJob_userId_fkey" FOREIGN KEY ("userId") REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."EmailThreadPermission"
+ ADD CONSTRAINT "EmailThreadPermission_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES public."Project"(id) ON UPDATE CASCADE ON DELETE SET NULL;
+
+ALTER TABLE ONLY public."EmailThreadPermission"
+ ADD CONSTRAINT "EmailThreadPermission_sharePermissionId_fkey" FOREIGN KEY ("sharePermissionId") REFERENCES public."SharePermission"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."EnterpriseEmailContacts"
+ ADD CONSTRAINT "EnterpriseEmailContacts_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES public."Organization"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."EnterpriseIManageTenants"
+ ADD CONSTRAINT "EnterpriseIManageTenants_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES public."Organization"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."EnterpriseRules"
+ ADD CONSTRAINT "EnterpriseRules_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES public."Organization"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."ExperimentLog"
+ ADD CONSTRAINT "ExperimentLog_experiment_id_fkey" FOREIGN KEY (experiment_id) REFERENCES public."Experiment"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."ExperimentLog"
+ ADD CONSTRAINT "ExperimentLog_user_id_fkey" FOREIGN KEY (user_id) REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."InsightContext"
+ ADD CONSTRAINT "InsightContext_userId_fkey" FOREIGN KEY ("userId") REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."InstructionsDocuments"
+ ADD CONSTRAINT "InstructionsDocuments_documentId_fkey" FOREIGN KEY ("documentId") REFERENCES public."Document"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."InstructionsDocuments"
+ ADD CONSTRAINT "InstructionsDocuments_userId_fkey" FOREIGN KEY ("userId") REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."JobToDocumentProcessResult"
+ ADD CONSTRAINT "JobToDocumentProcessResult_documentProcessResultId_fkey" FOREIGN KEY ("documentProcessResultId") REFERENCES public."DocumentProcessResult"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."MacroPromptAttachment"
+ ADD CONSTRAINT "MacroPromptAttachment_macro_prompt_id_fkey" FOREIGN KEY (macro_prompt_id) REFERENCES public."MacroPrompt"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."MacroPromptPermission"
+ ADD CONSTRAINT "MacroPromptPermission_macro_prompt_id_fkey" FOREIGN KEY (macro_prompt_id) REFERENCES public."MacroPrompt"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."MacroPromptPermission"
+ ADD CONSTRAINT "MacroPromptPermission_share_permission_id_fkey" FOREIGN KEY (share_permission_id) REFERENCES public."SharePermission"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."MacroPrompt"
+ ADD CONSTRAINT "MacroPrompt_user_id_fkey" FOREIGN KEY (user_id) REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."OrganizationBilling"
+ ADD CONSTRAINT "OrganizationBilling_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES public."Organization"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."OrganizationDefaultSharePermission"
+ ADD CONSTRAINT "OrganizationDefaultSharePermission_organization_id_fkey" FOREIGN KEY (organization_id) REFERENCES public."Organization"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."OrganizationEmailMatches"
+ ADD CONSTRAINT "OrganizationEmailMatches_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES public."Organization"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."OrganizationIT"
+ ADD CONSTRAINT "OrganizationIT_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES public."Organization"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."OrganizationInvitation"
+ ADD CONSTRAINT "OrganizationInvitation_organization_id_fkey" FOREIGN KEY (organization_id) REFERENCES public."Organization"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."OrganizationItJob"
+ ADD CONSTRAINT "OrganizationItJob_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES public."Organization"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."OrganizationRetentionPolicy"
+ ADD CONSTRAINT "OrganizationRetentionPolicy_organization_id_fkey" FOREIGN KEY (organization_id) REFERENCES public."Organization"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."PdfHighlightAnchor"
+ ADD CONSTRAINT "PdfHighlightAnchor_documentId_fkey" FOREIGN KEY ("documentId") REFERENCES public."Document"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."PdfHighlightAnchor"
+ ADD CONSTRAINT "PdfHighlightAnchor_owner_fkey" FOREIGN KEY (owner) REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."PdfHighlightAnchor"
+ ADD CONSTRAINT "PdfHighlightAnchor_threadId_fkey" FOREIGN KEY ("threadId") REFERENCES public."Thread"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."PdfHighlightRect"
+ ADD CONSTRAINT "PdfHighlightRect_pdfHighlightAnchorId_fkey" FOREIGN KEY ("pdfHighlightAnchorId") REFERENCES public."PdfHighlightAnchor"(uuid) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."PdfPlaceableCommentAnchor"
+ ADD CONSTRAINT "PdfPlaceableCommentAnchor_documentId_fkey" FOREIGN KEY ("documentId") REFERENCES public."Document"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."PdfPlaceableCommentAnchor"
+ ADD CONSTRAINT "PdfPlaceableCommentAnchor_owner_fkey" FOREIGN KEY (owner) REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."PdfPlaceableCommentAnchor"
+ ADD CONSTRAINT "PdfPlaceableCommentAnchor_threadId_fkey" FOREIGN KEY ("threadId") REFERENCES public."Thread"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."Pin"
+ ADD CONSTRAINT "Pin_userId_fkey" FOREIGN KEY ("userId") REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."ProjectPermission"
+ ADD CONSTRAINT "ProjectPermission_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES public."Project"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."ProjectPermission"
+ ADD CONSTRAINT "ProjectPermission_sharePermissionId_fkey" FOREIGN KEY ("sharePermissionId") REFERENCES public."SharePermission"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."Project"
+ ADD CONSTRAINT "Project_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES public."Project"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."Project"
+ ADD CONSTRAINT "Project_userId_fkey" FOREIGN KEY ("userId") REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."RolesOnOrganizations"
+ ADD CONSTRAINT "RolesOnOrganizations_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES public."Organization"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."RolesOnOrganizations"
+ ADD CONSTRAINT "RolesOnOrganizations_roleId_fkey" FOREIGN KEY ("roleId") REFERENCES public."Role"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."RolesOnPermissions"
+ ADD CONSTRAINT "RolesOnPermissions_permissionId_fkey" FOREIGN KEY ("permissionId") REFERENCES public."Permission"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."RolesOnPermissions"
+ ADD CONSTRAINT "RolesOnPermissions_roleId_fkey" FOREIGN KEY ("roleId") REFERENCES public."Role"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."RolesOnUsers"
+ ADD CONSTRAINT "RolesOnUsers_roleId_fkey" FOREIGN KEY ("roleId") REFERENCES public."Role"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."RolesOnUsers"
+ ADD CONSTRAINT "RolesOnUsers_userId_fkey" FOREIGN KEY ("userId") REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."ThreadAnchor"
+ ADD CONSTRAINT "ThreadAnchor_threadId_fkey" FOREIGN KEY ("threadId") REFERENCES public."Thread"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."Thread"
+ ADD CONSTRAINT "Thread_documentId_fkey" FOREIGN KEY ("documentId") REFERENCES public."Document"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."Thread"
+ ADD CONSTRAINT "Thread_owner_fkey" FOREIGN KEY (owner) REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."UserApiKey"
+ ADD CONSTRAINT "UserApiKey_user_id_fkey" FOREIGN KEY (user_id) REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."UserDocumentViewLocation"
+ ADD CONSTRAINT "UserDocumentViewLocation_document_id_fkey" FOREIGN KEY (document_id) REFERENCES public."Document"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."UserDocumentViewLocation"
+ ADD CONSTRAINT "UserDocumentViewLocation_user_id_fkey" FOREIGN KEY (user_id) REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."UserHistory"
+ ADD CONSTRAINT "UserHistory_userId_fkey" FOREIGN KEY ("userId") REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."UserInsightBatch"
+ ADD CONSTRAINT "UserInsightBatch_userId_fkey" FOREIGN KEY ("userId") REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."UserInsights"
+ ADD CONSTRAINT "UserInsights_userId_fkey" FOREIGN KEY ("userId") REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."UserItemAccess"
+ ADD CONSTRAINT "UserItemAccess_granted_from_team_id_fkey" FOREIGN KEY (granted_from_team_id) REFERENCES public.team(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."User"
+ ADD CONSTRAINT "User_macro_user_id_fkey" FOREIGN KEY (macro_user_id) REFERENCES public.macro_user(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."User"
+ ADD CONSTRAINT "User_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES public."Organization"(id) ON UPDATE CASCADE ON DELETE SET NULL;
+
+ALTER TABLE ONLY public."WebAnnotations"
+ ADD CONSTRAINT "WebAnnotations_chatId_fkey" FOREIGN KEY ("chatId") REFERENCES public."Chat"(id) ON UPDATE CASCADE ON DELETE SET NULL;
+
+ALTER TABLE ONLY public."WebAnnotations"
+ ADD CONSTRAINT "WebAnnotations_messageId_fkey" FOREIGN KEY ("messageId") REFERENCES public."ChatMessage"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public."WebsocketConnectionPermissions"
+ ADD CONSTRAINT "WebsocketConnectionPermissions_userId_fkey" FOREIGN KEY ("userId") REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE SET NULL;
+
+ALTER TABLE ONLY public.account_merge_request
+ ADD CONSTRAINT account_merge_request_macro_user_id_fkey FOREIGN KEY (macro_user_id) REFERENCES public.macro_user(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.call_participants
+ ADD CONSTRAINT call_participants_call_id_fkey FOREIGN KEY (call_id) REFERENCES public.calls(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.call_record_participants
+ ADD CONSTRAINT call_record_participants_call_record_id_fkey FOREIGN KEY (call_record_id) REFERENCES public.call_records(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.call_record_transcripts
+ ADD CONSTRAINT call_record_transcripts_call_record_id_fkey FOREIGN KEY (call_record_id) REFERENCES public.call_records(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.call_records
+ ADD CONSTRAINT call_records_channel_id_fkey FOREIGN KEY (channel_id) REFERENCES public.comms_channels(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.call_records
+ ADD CONSTRAINT call_records_share_permission_id_fkey FOREIGN KEY (share_permission_id) REFERENCES public."SharePermission"(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.call_transcripts
+ ADD CONSTRAINT call_transcripts_call_id_fkey FOREIGN KEY (call_id) REFERENCES public.calls(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.calls
+ ADD CONSTRAINT calls_channel_id_fkey FOREIGN KEY (channel_id) REFERENCES public.comms_channels(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.calls
+ ADD CONSTRAINT calls_share_permission_id_fkey FOREIGN KEY (share_permission_id) REFERENCES public."SharePermission"(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.comms_attachments
+ ADD CONSTRAINT comms_attachments_channel_id_fkey FOREIGN KEY (channel_id) REFERENCES public.comms_channels(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.comms_attachments
+ ADD CONSTRAINT comms_attachments_message_id_fkey FOREIGN KEY (message_id) REFERENCES public.comms_messages(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.comms_channel_participants
+ ADD CONSTRAINT comms_channel_participants_channel_id_fkey FOREIGN KEY (channel_id) REFERENCES public.comms_channels(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.comms_channels
+ ADD CONSTRAINT comms_channels_team_id_fkey FOREIGN KEY (team_id) REFERENCES public.team(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.comms_messages
+ ADD CONSTRAINT comms_messages_channel_id_fkey FOREIGN KEY (channel_id) REFERENCES public.comms_channels(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.comms_messages
+ ADD CONSTRAINT comms_messages_thread_id_fkey FOREIGN KEY (thread_id) REFERENCES public.comms_messages(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.comms_reactions
+ ADD CONSTRAINT comms_reactions_message_id_fkey FOREIGN KEY (message_id) REFERENCES public.comms_messages(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.document_email
+ ADD CONSTRAINT document_email_document_id_fkey FOREIGN KEY (document_id) REFERENCES public."Document"(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.document_email
+ ADD CONSTRAINT document_email_email_attachment_id_fkey FOREIGN KEY (email_attachment_id) REFERENCES public.email_attachments(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.document_sub_type
+ ADD CONSTRAINT document_sub_type_document_id_fkey FOREIGN KEY (document_id) REFERENCES public."Document"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_attachments_drafts
+ ADD CONSTRAINT email_attachments_drafts_draft_id_fkey FOREIGN KEY (draft_id) REFERENCES public.email_messages(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_attachments_fwd
+ ADD CONSTRAINT email_attachments_fwd_attachment_id_fkey FOREIGN KEY (attachment_id) REFERENCES public.email_attachments(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_attachments_fwd
+ ADD CONSTRAINT email_attachments_fwd_message_id_fkey FOREIGN KEY (message_id) REFERENCES public.email_messages(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_attachments
+ ADD CONSTRAINT email_attachments_message_id_fkey FOREIGN KEY (message_id) REFERENCES public.email_messages(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_attachments_sfs
+ ADD CONSTRAINT email_attachments_sfs_attachment_id_fkey FOREIGN KEY (attachment_id) REFERENCES public.email_attachments(id) ON DELETE SET NULL;
+
+ALTER TABLE ONLY public.email_backfill_jobs
+ ADD CONSTRAINT email_backfill_job_link_id_fkey FOREIGN KEY (link_id) REFERENCES public.email_links(id) ON DELETE SET NULL;
+
+ALTER TABLE ONLY public.email_contacts
+ ADD CONSTRAINT email_contacts_link_id_fkey FOREIGN KEY (link_id) REFERENCES public.email_links(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_filters
+ ADD CONSTRAINT email_filters_link_id_fkey FOREIGN KEY (link_id) REFERENCES public.email_links(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_sync_tokens
+ ADD CONSTRAINT email_fk_sync_tokens_link_id FOREIGN KEY (link_id) REFERENCES public.email_links(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_gmail_histories
+ ADD CONSTRAINT email_gmail_histories_link_id_fkey FOREIGN KEY (link_id) REFERENCES public.email_links(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_labels
+ ADD CONSTRAINT email_labels_link_id_fkey FOREIGN KEY (link_id) REFERENCES public.email_links(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_message_labels
+ ADD CONSTRAINT email_message_labels_label_id_fkey FOREIGN KEY (label_id) REFERENCES public.email_labels(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_message_labels
+ ADD CONSTRAINT email_message_labels_message_id_fkey FOREIGN KEY (message_id) REFERENCES public.email_messages(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_message_recipients
+ ADD CONSTRAINT email_message_recipients_contact_id_fkey FOREIGN KEY (contact_id) REFERENCES public.email_contacts(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_message_recipients
+ ADD CONSTRAINT email_message_recipients_message_id_fkey FOREIGN KEY (message_id) REFERENCES public.email_messages(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_messages
+ ADD CONSTRAINT email_messages_from_contact_id_fkey FOREIGN KEY (from_contact_id) REFERENCES public.email_contacts(id) ON DELETE SET NULL;
+
+ALTER TABLE ONLY public.email_messages
+ ADD CONSTRAINT email_messages_link_id_fkey FOREIGN KEY (link_id) REFERENCES public.email_links(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_messages
+ ADD CONSTRAINT email_messages_replying_to_id_fkey FOREIGN KEY (replying_to_id) REFERENCES public.email_messages(id) ON DELETE SET NULL;
+
+ALTER TABLE ONLY public.email_messages
+ ADD CONSTRAINT email_messages_thread_id_fkey FOREIGN KEY (thread_id) REFERENCES public.email_threads(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_scheduled_messages
+ ADD CONSTRAINT email_scheduled_messages_link_id_fkey FOREIGN KEY (link_id) REFERENCES public.email_links(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_scheduled_messages
+ ADD CONSTRAINT email_scheduled_messages_message_id_fkey FOREIGN KEY (message_id) REFERENCES public.email_messages(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_settings
+ ADD CONSTRAINT email_settings_link_id_fkey FOREIGN KEY (link_id) REFERENCES public.email_links(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_threads
+ ADD CONSTRAINT email_threads_link_id_fkey FOREIGN KEY (link_id) REFERENCES public.email_links(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_threads
+ ADD CONSTRAINT email_threads_project_id_fkey FOREIGN KEY (project_id) REFERENCES public."Project"(id) ON UPDATE CASCADE ON DELETE SET NULL;
+
+ALTER TABLE ONLY public.email_user_history
+ ADD CONSTRAINT email_user_history_link_id_fkey FOREIGN KEY (link_id) REFERENCES public.email_links(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.email_user_history
+ ADD CONSTRAINT email_user_history_thread_id_fkey FOREIGN KEY (thread_id) REFERENCES public.email_threads(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.entity_access
+ ADD CONSTRAINT entity_access_granted_from_project_id_fkey FOREIGN KEY (granted_from_project_id) REFERENCES public."Project"(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.entity_properties
+ ADD CONSTRAINT entity_properties_property_definition_id_fkey FOREIGN KEY (property_definition_id) REFERENCES public.property_definitions(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.excluded_default_view
+ ADD CONSTRAINT excluded_default_view_user_id_fkey FOREIGN KEY (user_id) REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.notification_message_receipt
+ ADD CONSTRAINT fk_user_notification FOREIGN KEY (user_id, notification_id) REFERENCES public.user_notification(user_id, notification_id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.github_app_installation_team
+ ADD CONSTRAINT github_app_installation_team_installed_by_fkey FOREIGN KEY (installed_by) REFERENCES public."User"(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.github_app_installation_team
+ ADD CONSTRAINT github_app_installation_team_team_id_fkey FOREIGN KEY (team_id) REFERENCES public.team(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.github_links
+ ADD CONSTRAINT github_links_macro_id_fkey FOREIGN KEY (macro_id) REFERENCES public."User"(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.in_progress_email_link
+ ADD CONSTRAINT in_progress_email_link_macro_user_id_fkey FOREIGN KEY (macro_user_id) REFERENCES public.macro_user(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.in_progress_user_link
+ ADD CONSTRAINT in_progress_user_link_macro_user_id_fkey FOREIGN KEY (macro_user_id) REFERENCES public.macro_user(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.macro_user_email_verification
+ ADD CONSTRAINT macro_user_email_verification_macro_user_id_fkey FOREIGN KEY (macro_user_id) REFERENCES public.macro_user(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.macro_user_info
+ ADD CONSTRAINT macro_user_info_macro_user_id_fkey FOREIGN KEY (macro_user_id) REFERENCES public.macro_user(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.property_definitions
+ ADD CONSTRAINT property_definitions_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES public."Organization"(id) ON DELETE SET NULL;
+
+ALTER TABLE ONLY public.property_definitions
+ ADD CONSTRAINT property_definitions_user_id_fkey FOREIGN KEY (user_id) REFERENCES public."User"(id) ON DELETE SET NULL;
+
+ALTER TABLE ONLY public.property_options
+ ADD CONSTRAINT property_options_property_definition_id_fkey FOREIGN KEY (property_definition_id) REFERENCES public.property_definitions(id) ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.saved_view
+ ADD CONSTRAINT saved_view_user_id_fkey FOREIGN KEY (user_id) REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.team_invite
+ ADD CONSTRAINT team_invite_invited_by_fkey FOREIGN KEY (invited_by) REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.team_invite
+ ADD CONSTRAINT team_invite_team_id_fkey FOREIGN KEY (team_id) REFERENCES public.team(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.team
+ ADD CONSTRAINT team_owner_id_fkey FOREIGN KEY (owner_id) REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.team_user
+ ADD CONSTRAINT team_user_team_id_fkey FOREIGN KEY (team_id) REFERENCES public.team(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.team_user
+ ADD CONSTRAINT team_user_user_id_fkey FOREIGN KEY (user_id) REFERENCES public."User"(id) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.user_notification
+ ADD CONSTRAINT user_notification_notification_id_fkey FOREIGN KEY (notification_id) REFERENCES public.notification(id) ON DELETE CASCADE;
+
diff --git a/rust/cloud-storage/delete_chat_handler/src/service/db/delete_chat.rs b/rust/cloud-storage/delete_chat_handler/src/service/db/delete_chat.rs
index e93f8d3eb1..59d0b40f82 100644
--- a/rust/cloud-storage/delete_chat_handler/src/service/db/delete_chat.rs
+++ b/rust/cloud-storage/delete_chat_handler/src/service/db/delete_chat.rs
@@ -48,10 +48,10 @@ pub async fn delete_chat(db: sqlx::PgPool, chat_id: &str) -> anyhow::Result<()>
sqlx::query!(
r#"
- DELETE FROM "UserItemAccess"
- WHERE "item_id" = $1 AND "item_type" = $2
+ DELETE FROM "entity_access"
+ WHERE "entity_id" = $1 AND "entity_type" = $2
"#,
- chat_id,
+ macro_uuid::string_to_uuid(chat_id).unwrap(),
"chat",
)
.execute(&mut *transaction)
diff --git a/rust/cloud-storage/document_cognition_service/Cargo.toml b/rust/cloud-storage/document_cognition_service/Cargo.toml
index 5da1f0a6ce..64a91e0817 100644
--- a/rust/cloud-storage/document_cognition_service/Cargo.toml
+++ b/rust/cloud-storage/document_cognition_service/Cargo.toml
@@ -29,21 +29,20 @@ local_queue = []
[dependencies]
aho-corasick = "1.1.3"
-async-stream = { workspace = true }
-async-trait = { workspace = true }
ai = { path = "../ai" }
ai_format = { path = "../ai_format" }
ai_tools = { path = "../ai_tools" }
ai_toolset = { path = "../ai_toolset" }
anyhow = { workspace = true }
async-openai = { workspace = true }
-call = { path = "../call", default-features = false, features = ["ports"] }
-aws-sdk-secretsmanager = { workspace = true }
-macro_aws_config = { path = "../macro_aws_config", features = ["s3"] }
+async-stream = { workspace = true }
+async-trait = { workspace = true }
aws-sdk-dynamodb = { workspace = true }
aws-sdk-s3 = { workspace = true }
+aws-sdk-secretsmanager = { workspace = true }
aws-sdk-sqs = { workspace = true }
axum = { workspace = true, features = ["tower-log", "ws"] }
+call = { path = "../call", default-features = false, features = ["ports"] }
chat = { path = "../chat" }
chrono = { workspace = true }
comms = { path = "../comms", features = ["outbound"] }
@@ -54,9 +53,10 @@ document_cognition_service_client = { path = "../document_cognition_service_clie
document_storage_service_client = { path = "../document_storage_service_client" }
documents = { path = "../documents", features = ["ai_tools"] }
doppleganger = { workspace = true }
-entity_access = { path = "../entity_access" }
email = { path = "../email", features = ["outbound"] }
email_service_client = { path = "../email_service_client" }
+entity_access = { path = "../entity_access" }
+entity_access_management = { path = "../entity_access_management" }
frecency = { path = "../frecency", features = ["outbound", "postgres"] }
futures = { workspace = true }
http = { workspace = true }
@@ -66,29 +66,36 @@ lazy_static = { workspace = true }
lexical_client = { path = "../lexical_client" }
log = { workspace = true }
macro_auth = { path = "../macro_auth" }
-model-entity = { path = "../model-entity" }
+macro_aws_config = { path = "../macro_aws_config", features = ["s3"] }
macro_cors = { path = "../macro_cors" }
-memory = { path = "../memory" }
macro_db_client = { path = "../macro_db_client" }
macro_entrypoint = { path = "../macro_entrypoint" }
macro_env = { path = "../macro_env" }
macro_env_var = { path = "../macro_env_var" }
-notification = { path = "../notification" }
-properties = { path = "../properties", features = ["ai_tools"] }
macro_middleware = { path = "../macro_middleware", default-features = false, features = [
"auth",
"cloud_storage",
"user_permissions",
] }
macro_project_utils = { path = "../macro_project_utils" }
-macro_share_permissions = { path = "../macro_share_permissions" }
macro_user_id = { path = "../macro_user_id" }
macro_uuid = { path = "../macro_uuid" }
+memory = { path = "../memory" }
model = { path = "../model" }
+model-entity = { path = "../model-entity" }
model_notifications = { path = "../model_notifications" }
models_dcs = { path = "../models_dcs" }
models_opensearch = { path = "../models_opensearch" }
models_permissions = { path = "../models_permissions" }
+notification = { path = "../notification" }
+properties = { path = "../properties", features = ["ai_tools"] }
+readonly_pool = { path = "../readonly_pool" }
+redis = { workspace = true, features = [
+ "aio",
+ "streams",
+ "tokio-comp",
+ "tokio-native-tls-comp",
+] }
regex = { workspace = true }
reqwest.workspace = true
roles_and_permissions = { path = "../roles_and_permissions", default-features = false }
@@ -104,7 +111,6 @@ search_service_client = { path = "../search_service_client" }
secretsmanager_client = { path = "../secretsmanager_client" }
serde = { workspace = true }
serde_json = { workspace = true }
-readonly_pool = { path = "../readonly_pool" }
soup = { path = "../soup", features = ["outbound"] }
sqlx = { workspace = true }
sqs_client = { path = "../sqs_client", default-features = false, features = [
@@ -114,14 +120,8 @@ sqs_client = { path = "../sqs_client", default-features = false, features = [
"gmail",
"search",
] }
-stream = { path = "../stream" }
-redis = { workspace = true, features = [
- "streams",
- "aio",
- "tokio-comp",
- "tokio-native-tls-comp",
-] }
static_file_service_client = { path = "../static_file_service_client" }
+stream = { path = "../stream" }
strum = { workspace = true }
sync_service_client = { path = "../sync_service_client" }
thiserror = { workspace = true }
@@ -132,9 +132,9 @@ tower = { workspace = true, features = ["util"] }
tower-http = { workspace = true, features = ["limit", "timeout"] }
tracing = { workspace = true }
unfurl_service = { path = "../unfurl_service" }
+url = { workspace = true }
utoipa = { workspace = true, features = ["axum_extras", "chrono"] }
utoipa-swagger-ui = { workspace = true, features = ["axum"] }
-url = { workspace = true }
uuid = { workspace = true }
[dev-dependencies]
diff --git a/rust/cloud-storage/document_cognition_service/src/api/chats/mod.rs b/rust/cloud-storage/document_cognition_service/src/api/chats/mod.rs
index 5210c5e940..a876554cab 100644
--- a/rust/cloud-storage/document_cognition_service/src/api/chats/mod.rs
+++ b/rust/cloud-storage/document_cognition_service/src/api/chats/mod.rs
@@ -22,6 +22,9 @@ pub fn router(state: ApiContext) -> Router<ApiContext> {
chat_repo,
state.all_tools.clone(),
state.tool_service_context.clone(),
+ entity_access_management::domain::service::EntityAccessManagementServiceImpl::new(
+ entity_access_management::outbound::PgRepository::new(state.db.clone()),
+ ),
);
let chat_state = ChatRouterState::new(chat_service, access_service);
diff --git a/rust/cloud-storage/document_cognition_service/src/api/context/test.rs b/rust/cloud-storage/document_cognition_service/src/api/context/test.rs
index cad71853e9..f67e27abf0 100644
--- a/rust/cloud-storage/document_cognition_service/src/api/context/test.rs
+++ b/rust/cloud-storage/document_cognition_service/src/api/context/test.rs
@@ -240,6 +240,9 @@ pub async fn test_api_context(pool: sqlx::Pool<sqlx::Postgres>) -> std::sync::Ar
s3_upload_adapter,
ai_tools::NoOpTaskProperties,
ai_tools::NoOpConnectionService,
+ entity_access_management::domain::service::EntityAccessManagementServiceImpl::new(
+ entity_access_management::outbound::PgRepository::new(pool.clone()),
+ ),
);
let entity_access_service = Arc::new(
entity_access::domain::service::EntityAccessServiceImpl::new(
diff --git a/rust/cloud-storage/document_cognition_service/src/main.rs b/rust/cloud-storage/document_cognition_service/src/main.rs
index e38a96d293..dc22c4a365 100644
--- a/rust/cloud-storage/document_cognition_service/src/main.rs
+++ b/rust/cloud-storage/document_cognition_service/src/main.rs
@@ -233,6 +233,9 @@ async fn main() -> anyhow::Result<()> {
s3_upload_adapter,
NoOpTaskProperties,
NoOpConnectionService,
+ entity_access_management::domain::service::EntityAccessManagementServiceImpl::new(
+ entity_access_management::outbound::PgRepository::new(db.clone()),
+ ),
);
let lexical_client_for_tools = (*lexical_client).clone();
let document_tool_context = DocumentToolContext::new(
diff --git a/rust/cloud-storage/document_storage_service/Cargo.toml b/rust/cloud-storage/document_storage_service/Cargo.toml
index 31e5a3eb3a..e75356f02e 100644
--- a/rust/cloud-storage/document_storage_service/Cargo.toml
+++ b/rust/cloud-storage/document_storage_service/Cargo.toml
@@ -13,10 +13,6 @@ path = "src/main.rs"
name = "backfill_document_search"
path = "src/bin/backfill_search.rs"
-[[bin]]
-name = "backfill_useritemaccess"
-path = "src/bin/backfill_useritemaccess/mod.rs"
-
[[bin]]
name = "document_storage_service_openapi"
path = "src/openapi.rs"
@@ -58,7 +54,8 @@ document_sub_type = { path = "../document_sub_type" }
documents_hex = { path = "../documents", package = "documents" }
dynamodb_client = { path = "../dynamodb_client" }
email = { path = "../email", features = ["outbound", "ports"] }
-entity_access = { path = "../entity_access", features = ["schema", "inbound"] }
+entity_access = { path = "../entity_access", features = ["inbound", "schema"] }
+entity_access_management = { path = "../entity_access_management" }
frecency = { path = "../frecency", features = ["postgres"] }
futures = { workspace = true }
github = { path = "../github", default-features = false, features = [
@@ -87,12 +84,10 @@ macro_middleware = { path = "../macro_middleware", default-features = false, fea
] }
macro_project_utils = { path = "../macro_project_utils" }
macro_sha_count_client = { path = "../macro_sha_count_client" }
-macro_share_permissions = { path = "../macro_share_permissions" }
macro_user_id = { path = "../macro_user_id" }
macro_uuid = { path = "../macro_uuid" }
mockall = { workspace = true }
model = { path = "../model" }
-s3_key = { path = "../s3_key" }
model-entity = { path = "../model-entity" }
model_notifications = { path = "../model_notifications" }
model_user = { path = "../model_user", features = ["axum"] }
@@ -108,6 +103,7 @@ properties = { path = "../properties" }
properties_db_client = { path = "../properties_db_client" }
properties_service = { path = "../properties_service" }
rayon = "1.10.0"
+readonly_pool = { path = "../readonly_pool" }
redis = { workspace = true, features = [
"aio",
"cluster-async",
@@ -115,10 +111,10 @@ redis = { workspace = true, features = [
] }
regex = { workspace = true }
reqwest = { workspace = true }
+s3_key = { path = "../s3_key" }
saved_views = { path = "../saved_views" }
schemars = { workspace = true }
search_service = { path = "../search_service" }
-readonly_pool = { path = "../readonly_pool" }
secretsmanager_client = { path = "../secretsmanager_client" }
serde = { workspace = true }
serde_json = { workspace = true }
diff --git a/rust/cloud-storage/document_storage_service/src/api/context.rs b/rust/cloud-storage/document_storage_service/src/api/context.rs
index da893e7592..e177dcf456 100644
--- a/rust/cloud-storage/document_storage_service/src/api/context.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/context.rs
@@ -152,11 +152,17 @@ impl TaskPropertiesPort for TaskPropertiesAdapter {
}
}
+pub(crate) type EntityAccessManagementService =
+ entity_access_management::domain::service::EntityAccessManagementServiceImpl<
+ entity_access_management::outbound::PgRepository,
+ >;
+
pub(crate) type DocumentService = DocumentServiceImpl<
PgDocumentRepo,
S3UploadUrlAdapter,
TaskPropertiesAdapter,
ConnectionServiceImpl<EntityAccessService, ConnectionGatewayImpl>,
+ EntityAccessManagementService,
>;
/// Type alias for the documents router state.
@@ -231,6 +237,7 @@ pub(crate) struct ApiContext {
pub call_state: DssCallState,
pub call_webhook_state: DssCallWebhookState,
pub call_internal_state: DssCallInternalState,
+ pub entity_access_management_service: EntityAccessManagementService,
}
env_var! {
diff --git a/rust/cloud-storage/document_storage_service/src/api/internal/mod.rs b/rust/cloud-storage/document_storage_service/src/api/internal/mod.rs
index 101bd09972..a1c01f30ce 100644
--- a/rust/cloud-storage/document_storage_service/src/api/internal/mod.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/internal/mod.rs
@@ -2,7 +2,6 @@ use super::{
context::{ApiContext, EntityAccessService},
documents::{export_document, get_document_version},
history::upsert_history,
- permissions,
projects::upload_folder,
};
use super::{documents::get_document_access_level, user::delete_user_items};
@@ -38,10 +37,6 @@ pub fn router(state: ApiContext) -> Router<ApiContext> {
Router::new()
// User routes
- .route(
- "/channel/update_user_channel_permissions",
- post(permissions::update_user_channel_permissions::handler),
- )
.route(
"/users/{user_id}",
delete(delete_user_items::delete_user_items_handler),
diff --git a/rust/cloud-storage/document_storage_service/src/api/mod.rs b/rust/cloud-storage/document_storage_service/src/api/mod.rs
index 81335247b5..301599a1b0 100644
--- a/rust/cloud-storage/document_storage_service/src/api/mod.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/mod.rs
@@ -43,7 +43,6 @@ mod user_document_view_location;
mod entity;
mod items;
-mod permissions;
pub(crate) mod swagger;
mod threads;
diff --git a/rust/cloud-storage/document_storage_service/src/api/permissions/mod.rs b/rust/cloud-storage/document_storage_service/src/api/permissions/mod.rs
deleted file mode 100644
index 6d23263bc8..0000000000
--- a/rust/cloud-storage/document_storage_service/src/api/permissions/mod.rs
+++ /dev/null
@@ -1 +0,0 @@
-pub mod update_user_channel_permissions;
diff --git a/rust/cloud-storage/document_storage_service/src/api/permissions/update_user_channel_permissions.rs b/rust/cloud-storage/document_storage_service/src/api/permissions/update_user_channel_permissions.rs
deleted file mode 100644
index fefb853222..0000000000
--- a/rust/cloud-storage/document_storage_service/src/api/permissions/update_user_channel_permissions.rs
+++ /dev/null
@@ -1,151 +0,0 @@
-use crate::api::context::ApiContext;
-use anyhow::Context;
-use axum::Json;
-use axum::extract::State;
-use axum::http::StatusCode;
-use axum::response::{IntoResponse, Response};
-use model::document_storage_service_internal::UpdateUserChannelPermissionsRequest;
-use model::response::{ErrorResponse, GenericSuccessResponse};
-use models_permissions::share_permission::channel_share_permission::UpdateOperation;
-use models_permissions::user_item_access::UserItemAccess;
-use sqlx::PgPool;
-use uuid::Uuid;
-
-/// Adds or removes permissions for a user for all items in a channel they were just added to/removed from.
-#[tracing::instrument(skip(ctx, req), fields(channel_id=%req.channel_id, user_ids=?req.user_ids))]
-pub async fn handler(
- State(ctx): State<ApiContext>,
- Json(req): Json<UpdateUserChannelPermissionsRequest>,
-) -> Result<Response, Response> {
- let channel_id = macro_uuid::string_to_uuid(&req.channel_id).map_err(|e| {
- tracing::error!(error=?e, "failed to parse channel_id as UUID");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "invalid channel id format".into(),
- }),
- )
- .into_response()
- })?;
-
- // insert
- match req.operation {
- UpdateOperation::Add | UpdateOperation::Replace => {
- add_permissions_for_channel_users(&ctx.db, &req.channel_id, &req.user_ids, channel_id)
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "failed to add permissions for channel users");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "failed to add permissions for channel users".into(),
- }),
- )
- .into_response()
- })?;
- }
- UpdateOperation::Remove => {
- remove_permissions_for_channel_users(&ctx.db, channel_id, &req.user_ids)
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "failed to remove permissions for channel users");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "failed to remove permissions for channel users".into(),
- }),
- )
- .into_response()
- })?;
- }
- }
-
- Ok((StatusCode::OK, Json(GenericSuccessResponse::default())).into_response())
-}
-
-/// Adds permissions for users who have been added to a channel
-#[tracing::instrument(skip(db))]
-async fn add_permissions_for_channel_users(
- db: &PgPool,
- channel_id: &str,
- user_ids: &[String],
- channel_uuid: Uuid,
-) -> anyhow::Result<()> {
- if user_ids.is_empty() {
- return Ok(());
- }
-
- let mut items_to_insert: Vec<UserItemAccess> = Vec::new();
-
- // Get all channel share permissions for the channel
- let csps = macro_db_client::share_permission::channel_permission::get::get_channel_share_permissions_by_channel_id(
- db,
- channel_id,
- )
- .await
- .context("failed to get channel share permissions for channel")?;
-
- let csp_ids = csps
- .iter()
- .map(|csp| csp.share_permission_id.clone())
- .collect::<Vec<_>>();
-
- if csp_ids.is_empty() {
- return Ok(());
- }
-
- // Get all items matching the channel share permission IDs
- let item_type_map =
- macro_db_client::share_permission::get::get_items_by_share_permission_ids(db, &csp_ids)
- .await
- .context("failed to get items for share permission ids")?;
-
- // For each item, add an entry for each user into UserItemAccess
- for csp in csps {
- if let Some((item_id, item_type)) = item_type_map.get(&csp.share_permission_id) {
- for user_id in user_ids.iter() {
- items_to_insert.push(UserItemAccess {
- id: macro_uuid::generate_uuid_v7(),
- user_id: user_id.to_string(),
- item_id: item_id.to_string(),
- item_type: item_type.to_string(),
- access_level: csp.access_level,
- granted_from_channel_id: Some(channel_uuid),
- created_at: chrono::Utc::now(),
- updated_at: chrono::Utc::now(),
- });
- }
- }
- }
-
- if !items_to_insert.is_empty() {
- // Insert into database
- macro_db_client::item_access::insert::insert_user_item_access_batch(db, &items_to_insert)
- .await
- .context("failed to insert user item access records")?;
- }
-
- Ok(())
-}
-
-/// Removes permissions for users who have been removed from a channel
-#[tracing::instrument(skip(db))]
-async fn remove_permissions_for_channel_users(
- db: &PgPool,
- channel_id: Uuid,
- user_ids: &[String],
-) -> anyhow::Result<u64> {
- if user_ids.is_empty() {
- return Ok(0);
- }
-
- // Delete all UserItemAccess records for these users granted from this channel
- let rows_affected =
- macro_db_client::item_access::delete::delete_user_item_access_by_channel_and_users(
- db, channel_id, user_ids,
- )
- .await
- .context("failed to delete user item access records")?;
-
- Ok(rows_affected)
-}
diff --git a/rust/cloud-storage/document_storage_service/src/api/projects/create_project.rs b/rust/cloud-storage/document_storage_service/src/api/projects/create_project.rs
index d3f950a6ee..6952d345a8 100644
--- a/rust/cloud-storage/document_storage_service/src/api/projects/create_project.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/projects/create_project.rs
@@ -6,11 +6,13 @@ use axum::{
response::{IntoResponse, Json, Response},
};
use entity_access::inbound::axum_extractors::ProjectBodyAccessLevelExtractor;
+use entity_access_management::domain::ports::EntityAccessManagementService;
use model::{
project::{Project, request::CreateProjectRequest, response::CreateProjectResponse},
response::{GenericErrorResponse, GenericResponse},
user::axum_extractor::MacroUserExtractor,
};
+use model_entity::EntityType;
use models_permissions::share_permission::SharePermissionV2;
use models_permissions::share_permission::access_level::EditAccessLevel;
use unicode_segmentation::UnicodeSegmentation;
@@ -75,7 +77,7 @@ async fn create_project_v2(
ctx.db.clone(),
user_context.macro_user_id.clone(),
&req.name,
- req.project_parent_id.clone(),
+ req.project_parent_id.map(|p| p.to_string()),
&share_permission,
)
.await
@@ -90,11 +92,22 @@ async fn create_project_v2(
// update project modified if necessary
if let Some(project_id) = req.project_parent_id {
tracing::trace!("updating project modified date");
+ // SAFETY: this is a uuid.
+ let entity_id = macro_uuid::string_to_uuid(&project.id).unwrap();
+
+ let _ = ctx
+ .entity_access_management_service
+ .add_entity_to_project(&entity_id, EntityType::Project, &project_id)
+ .await
+ .inspect_err(
+ |e| tracing::error!(error=?e, entity_id=?entity_id, project_id=?project_id, "unable to update entity access for project"),
+ );
+
macro_project_utils::update_project_modified(
&ctx.db,
macro_project_utils::ProjectModifiedArgs {
- project_id: None,
- old_project_id: Some(project_id.to_string()),
+ project_id: Some(project_id.to_string()),
+ old_project_id: None,
user_id: user_context.user_context.user_id.clone(),
},
)
diff --git a/rust/cloud-storage/document_storage_service/src/api/projects/edit_project.rs b/rust/cloud-storage/document_storage_service/src/api/projects/edit_project.rs
index 3cc4212278..6f6a34a15c 100644
--- a/rust/cloud-storage/document_storage_service/src/api/projects/edit_project.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/projects/edit_project.rs
@@ -11,7 +11,7 @@ use entity_access::domain::models::EntityPermission;
use entity_access::inbound::axum_extractors::{
ProjectAccessLevelExtractor, ProjectBodyAccessLevelExtractor,
};
-use macro_share_permissions::user_item_access::update_user_item_access;
+use entity_access_management::domain::ports::EntityAccessManagementService;
use model::response::{GenericErrorResponse, SuccessResponse};
use model::{project::BasicProject, response::GenericSuccessResponse};
use model::{project::request::PatchProjectRequestV2, response::ErrorResponse, user::UserContext};
@@ -194,6 +194,23 @@ async fn edit_project_v2(
)
.await;
+ let _ = ctx
+ .entity_access_management_service
+ .move_project(
+ &macro_uuid::string_to_uuid(&id).unwrap(),
+ project_context
+ .parent_id
+ .as_ref()
+ .map(|p| macro_uuid::string_to_uuid(p).unwrap())
+ .as_ref(),
+ req.project_parent_id
+ .as_ref()
+ .map(|p| macro_uuid::string_to_uuid(p).unwrap())
+ .as_ref(),
+ )
+ .await
+ .inspect_err(|e| tracing::error!(error=?e, "unable to update entity access for project"));
+
// Update the project you moved from and moved to
macro_project_utils::update_project_modified(
&ctx.db,
@@ -236,19 +253,6 @@ async fn patch_project_transaction(
.await
.context("failed to patch project")?;
- // Update user access if share permissions are provided
- if let Some(share_permission) = share_permission {
- update_user_item_access(
- &mut transaction,
- &user_context.user_id,
- &project_context.id,
- "project",
- share_permission,
- )
- .await
- .context("failed to update user item access")?;
- }
-
transaction
.commit()
.await
diff --git a/rust/cloud-storage/document_storage_service/src/api/swagger.rs b/rust/cloud-storage/document_storage_service/src/api/swagger.rs
index 0cf542a42f..0584927808 100644
--- a/rust/cloud-storage/document_storage_service/src/api/swagger.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/swagger.rs
@@ -196,7 +196,9 @@ use utoipa::OpenApi;
call::inbound::axum_router::check_active_call_handler,
call::inbound::axum_router::leave_or_end_call_handler,
call::inbound::axum_router::get_call_record_handler,
+ call::inbound::axum_router::edit_call_record_handler,
call::inbound::axum_router::delete_call_record_handler,
+ call::inbound::axum_router::toggle_share_with_team_handler,
call::inbound::axum_router::webhook_handler,
call::inbound::axum_router::transcript_handler,
@@ -222,11 +224,11 @@ use utoipa::OpenApi;
projects::get_project::get_project_handler,
projects::revert_delete_project::handler,
+ entity::get_entity_permission::handler,
+
// threads
threads::edit_thread::edit_thread_handler,
- entity::get_entity_permission::handler,
-
// /recents
recents::recently_deleted::handler,
saved_views::create_view_handler,
@@ -345,6 +347,7 @@ use utoipa::OpenApi;
call::domain::models::CallRecord,
call::domain::models::CallRecordParticipant,
call::domain::models::CallRecordTranscriptSegment,
+ call::domain::models::EditCallRecordRequest,
SoupCallRecord,
SoupCallRecordParticipant,
diff --git a/rust/cloud-storage/document_storage_service/src/api/threads/edit_thread.rs b/rust/cloud-storage/document_storage_service/src/api/threads/edit_thread.rs
index 6094442280..84da5b8dc1 100644
--- a/rust/cloud-storage/document_storage_service/src/api/threads/edit_thread.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/threads/edit_thread.rs
@@ -8,12 +8,10 @@ use entity_access::domain::models::EntityPermission;
use entity_access::inbound::axum_extractors::ProjectBodyAccessLevelExtractor;
use entity_access::inbound::axum_extractors::ThreadAccessLevelExtractor;
use macro_db_client::share_permission::edit::edit_thread_permission;
-use macro_share_permissions::user_item_access::update_user_item_access;
use model::response::{
ErrorResponse, GenericErrorResponse, GenericSuccessResponse, SuccessResponse,
};
use model::thread::EmailThreadPermission;
-use model::thread::request::PatchThreadRequestV2;
use model::user::UserContext;
use models_permissions::share_permission::access_level::{
AccessLevel, EditAccessLevel, OwnerAccessLevel,
@@ -24,12 +22,22 @@ pub struct ThreadParams {
pub thread_id: String,
}
+#[derive(serde::Serialize, serde::Deserialize, Debug, utoipa::ToSchema)]
+#[serde(rename_all = "camelCase")]
+pub struct PatchThreadRequestV2 {
+ /// The new project that the thread will belong to.
+ pub project_id: Option<String>,
+ /// The share permissions for the thread.
+ pub share_permission:
+ Option<models_permissions::share_permission::UpdateSharePermissionRequestV2>,
+}
+
/// Edits the share permissions of a thread.
#[utoipa::path(
tag = "threads",
patch,
operation_id="edit_thread_v2",
- path = "/v2/threads/{thread_id}",
+ path = "/threads/{thread_id}",
params(
("thread_id" = String, Path, description = "thread ID")
),
@@ -94,8 +102,9 @@ pub async fn edit_thread_handler(
edit_thread_permission(
&mut tx,
- &share_permission,
+ &macro_uuid::string_to_uuid(&thread_id).unwrap(),
&thread_context.share_permission_id,
+ &share_permission,
)
.await
.map_err(|e| {
@@ -109,25 +118,6 @@ pub async fn edit_thread_handler(
.into_response()
})?;
- update_user_item_access(
- &mut tx,
- &user_context.user_id,
- &thread_id,
- "thread",
- &share_permission,
- )
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "unable to update user item access");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "unable to update user item access".into(),
- }),
- )
- .into_response()
- })?;
-
tx.commit().await.map_err(|e| {
tracing::error!(error=?e, "unable to edit thread");
(
diff --git a/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/chat.rs b/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/chat.rs
deleted file mode 100644
index 2d8391733a..0000000000
--- a/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/chat.rs
+++ /dev/null
@@ -1,184 +0,0 @@
-use crate::{CONCURRENT_PROCESSING_LIMIT, DB_FETCH_SIZE, INSERT_BATCH_SIZE};
-use anyhow::Context;
-use chrono::Utc;
-use futures::future::join_all;
-use models_permissions::share_permission::access_level::AccessLevel;
-use models_permissions::user_item_access::UserItemAccess;
-use sqlx::PgPool;
-
-async fn process_single_chat(
- db: PgPool,
- chat_id: String,
- user_id: String,
-) -> anyhow::Result<Vec<UserItemAccess>> {
- let mut generated_items = Vec::new();
-
- // Add row for the owner of the item
- generated_items.push(UserItemAccess {
- id: macro_uuid::generate_uuid_v7(),
- user_id: user_id.clone(),
- item_id: chat_id.clone(),
- item_type: "chat".to_string(),
- access_level: AccessLevel::Owner,
- granted_from_channel_id: None,
- created_at: Utc::now(),
- updated_at: Utc::now(),
- });
-
- // Get channel share permissions
- let sp = macro_db_client::share_permission::get::get_chat_share_permission(&db, &chat_id)
- .await
- .with_context(|| format!("Failed to get share permission for chat {}", chat_id))?;
-
- // Get participants for each shared channel
- for csp in sp.channel_share_permissions.unwrap_or_default() {
- let channel_id = uuid::Uuid::parse_str(&csp.channel_id)
- .with_context(|| format!("Failed to parse channel UUID: {}", csp.channel_id))?;
-
- let participants =
- comms_db_client::participants::get_participants::get_participants(&db, &channel_id)
- .await
- .with_context(|| {
- format!("Failed to get participants for channel {}", csp.channel_id)
- })?;
-
- // Add an access record for each participant
- for participant in participants {
- if participant.user_id.as_ref() != user_id {
- generated_items.push(UserItemAccess {
- id: macro_uuid::generate_uuid_v7(),
- user_id: participant.user_id.to_string(),
- item_id: chat_id.clone(),
- item_type: "chat".to_string(),
- access_level: csp.access_level,
- granted_from_channel_id: Some(channel_id),
- created_at: Utc::now(),
- updated_at: Utc::now(),
- });
- }
- }
- }
-
- Ok(generated_items)
-}
-
-/// Backfills UserItemAccess records for chats with concurrent processing.
-pub async fn backfill_chats_updated(db: &PgPool, start_offset: Option<i64>) -> anyhow::Result<()> {
- let mut offset = start_offset.unwrap_or(0);
-
- if let Some(so) = start_offset {
- println!("Starting chat backfill from custom offset: {}", so);
- } else {
- println!("Starting chat backfill from the beginning (streaming/concurrent version)");
- }
-
- let mut total_chats_processed = 0;
- let mut total_items_inserted = 0;
- let mut items_to_insert: Vec<UserItemAccess> = Vec::with_capacity(INSERT_BATCH_SIZE);
-
- loop {
- // 1. FETCH a batch of chats from the database
- let chats_batch = macro_db_client::chat::get::get_all_chat_ids_with_users_paginated(
- db,
- DB_FETCH_SIZE,
- offset,
- )
- .await
- .context("failed to get a batch of chats")?;
-
- let num_in_batch = chats_batch.len();
- if num_in_batch == 0 {
- println!(
- "No more chats found at offset {}. Concluding chat backfill.",
- offset
- );
- break;
- }
-
- println!(
- "Fetched batch of {} chats at offset {}. Processing concurrently...",
- num_in_batch, offset
- );
-
- // 2. PROCESS the fetched batch concurrently, in chunks
- for chunk in chats_batch.chunks(CONCURRENT_PROCESSING_LIMIT) {
- let mut tasks = Vec::new();
- for (chat_id, user_id) in chunk {
- // Clone the resources needed for the concurrent task.
- // Cloning PgPool and the client should be cheap.
- let db_clone = db.clone();
- let chat_id_clone = chat_id.clone();
- let user_id_clone = user_id.clone();
-
- tasks.push(tokio::spawn(process_single_chat(
- db_clone,
- chat_id_clone,
- user_id_clone,
- )));
- }
-
- // Wait for all tasks in the current chunk to complete
- let results = join_all(tasks).await;
-
- // Collect the results
- for result in results {
- match result {
- // Task completed successfully
- Ok(Ok(generated_items)) => {
- items_to_insert.extend(generated_items);
- }
- // Task completed but returned an error
- Ok(Err(e)) => {
- eprintln!("ERROR: A chat processing task failed: {:?}", e);
- }
- // Task panicked or was cancelled
- Err(e) => {
- eprintln!("ERROR: A chat processing task panicked: {:?}", e);
- }
- }
- }
- }
-
- total_chats_processed += num_in_batch;
-
- // 3. INSERT the generated items if the batch is full
- if items_to_insert.len() >= INSERT_BATCH_SIZE {
- let items_to_drain = items_to_insert.len();
- let batch: Vec<_> = std::mem::take(&mut items_to_insert);
-
- macro_db_client::item_access::insert::insert_user_item_access_batch(db, &batch)
- .await
- .context("failed to insert user item access batch")?;
-
- total_items_inserted += items_to_drain;
- println!(
- "Inserted batch of {} access records (total inserted this run: {})",
- items_to_drain, total_items_inserted
- );
- }
-
- // 4. PREPARE for the next iteration
- if num_in_batch < DB_FETCH_SIZE as usize {
- break;
- }
- offset += DB_FETCH_SIZE;
- }
-
- // Insert any remaining items
- if !items_to_insert.is_empty() {
- let items_count = items_to_insert.len();
- macro_db_client::item_access::insert::insert_user_item_access_batch(db, &items_to_insert)
- .await
- .context("failed to insert final user item access batch")?;
-
- total_items_inserted += items_count;
- println!("Inserted final batch of {} access records.", items_count);
- }
-
- println!(
- "Chat backfill complete! Processed {} chats and inserted {} access records in this run.",
- total_chats_processed, total_items_inserted
- );
-
- Ok(())
-}
diff --git a/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/document.rs b/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/document.rs
deleted file mode 100644
index 4fafededd2..0000000000
--- a/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/document.rs
+++ /dev/null
@@ -1,179 +0,0 @@
-use crate::{CONCURRENT_PROCESSING_LIMIT, DB_FETCH_SIZE, INSERT_BATCH_SIZE};
-use anyhow::Context;
-use chrono::Utc;
-use futures::future::join_all;
-use model::document::DocumentMetadata;
-use models_permissions::share_permission::access_level::AccessLevel;
-use models_permissions::user_item_access::UserItemAccess;
-use sqlx::PgPool;
-
-/// Processes a single document to generate its corresponding UserItemAccess records.
-async fn process_single_document(
- db: PgPool,
- document: DocumentMetadata, // Assuming DocumentMetadata implements Clone
-) -> anyhow::Result<Vec<UserItemAccess>> {
- let mut generated_items = Vec::new();
- let document_id = document.document_id;
- let user_id = document.owner;
-
- // Add row for the owner
- generated_items.push(UserItemAccess {
- id: macro_uuid::generate_uuid_v7(),
- user_id: user_id.to_string(),
- item_id: document_id.clone(),
- item_type: "document".to_string(),
- access_level: AccessLevel::Owner,
- granted_from_channel_id: None,
- created_at: Utc::now(),
- updated_at: Utc::now(),
- });
-
- // Get share permissions
- let sp =
- macro_db_client::share_permission::get::get_document_share_permission(&db, &document_id)
- .await
- .with_context(|| {
- format!(
- "Failed to get share permission for document {}",
- document_id
- )
- })?;
-
- // Get participants
- for csp in sp.channel_share_permissions.unwrap_or_default() {
- let channel_id = uuid::Uuid::parse_str(&csp.channel_id)
- .with_context(|| format!("Failed to parse channel UUID: {}", csp.channel_id))?;
-
- let participants =
- comms_db_client::participants::get_participants::get_participants(&db, &channel_id)
- .await
- .with_context(|| {
- format!("Failed to get participants for channel {}", csp.channel_id)
- })?;
-
- for participant in participants {
- if participant.user_id != user_id {
- generated_items.push(UserItemAccess {
- id: macro_uuid::generate_uuid_v7(),
- user_id: participant.user_id.to_string(),
- item_id: document_id.clone(),
- item_type: "document".to_string(),
- access_level: csp.access_level,
- granted_from_channel_id: Some(channel_id),
- created_at: Utc::now(),
- updated_at: Utc::now(),
- });
- }
- }
- }
-
- Ok(generated_items)
-}
-
-/// Backfills UserItemAccess records for documents with concurrent processing.
-pub async fn backfill_documents_updated(
- db: &PgPool,
- start_offset: Option<i64>,
-) -> anyhow::Result<()> {
- let mut offset = start_offset.unwrap_or(0);
-
- if let Some(so) = start_offset {
- println!("Starting document backfill from custom offset: {}", so);
- } else {
- println!("Starting document backfill from the beginning (streaming/concurrent version)");
- }
-
- let mut total_docs_processed = 0;
- let mut total_items_inserted = 0;
- let mut items_to_insert: Vec<UserItemAccess> = Vec::with_capacity(INSERT_BATCH_SIZE);
-
- loop {
- // 1. FETCH
- let documents_batch = macro_db_client::document::get_all_documents::get_all_documents(
- db,
- DB_FETCH_SIZE,
- offset,
- )
- .await
- .context("failed to get a batch of documents")?
- .0;
-
- let num_in_batch = documents_batch.len();
- if num_in_batch == 0 {
- println!(
- "No more documents found at offset {}. Concluding document backfill.",
- offset
- );
- break;
- }
-
- println!(
- "Fetched batch of {} documents at offset {}. Processing concurrently...",
- num_in_batch, offset
- );
-
- // 2. PROCESS concurrently in chunks
- for chunk in documents_batch.chunks(CONCURRENT_PROCESSING_LIMIT) {
- let mut tasks = Vec::new();
- for document in chunk {
- let db_clone = db.clone();
- // Assumes DocumentMetadata implements Clone. If not, add `#[derive(Clone)]`.
- let document_clone = document.clone();
-
- tasks.push(tokio::spawn(process_single_document(
- db_clone,
- document_clone,
- )));
- }
-
- for result in join_all(tasks).await {
- match result {
- Ok(Ok(generated_items)) => items_to_insert.extend(generated_items),
- Ok(Err(e)) => eprintln!("ERROR: A document processing task failed: {:?}", e),
- Err(e) => eprintln!("ERROR: A document processing task panicked: {:?}", e),
- }
- }
- }
-
- total_docs_processed += num_in_batch;
-
- // 3. INSERT
- if items_to_insert.len() >= INSERT_BATCH_SIZE {
- let batch: Vec<_> = std::mem::take(&mut items_to_insert);
- macro_db_client::item_access::insert::insert_user_item_access_batch(db, &batch)
- .await
- .context("failed to insert user item access batch")?;
-
- total_items_inserted += batch.len();
- println!(
- "Inserted batch of {} access records (total inserted this run: {})",
- batch.len(),
- total_items_inserted
- );
- }
-
- // 4. PREPARE for next iteration
- if num_in_batch < DB_FETCH_SIZE as usize {
- break;
- }
- offset += DB_FETCH_SIZE;
- }
-
- // Insert any remaining items
- if !items_to_insert.is_empty() {
- let items_count = items_to_insert.len();
- macro_db_client::item_access::insert::insert_user_item_access_batch(db, &items_to_insert)
- .await
- .context("failed to insert final user item access batch")?;
-
- total_items_inserted += items_count;
- println!("Inserted final batch of {} access records.", items_count);
- }
-
- println!(
- "Document backfill complete! Processed {} documents and inserted {} access records in this run.",
- total_docs_processed, total_items_inserted
- );
-
- Ok(())
-}
diff --git a/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/mod.rs b/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/mod.rs
deleted file mode 100644
index af58809849..0000000000
--- a/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/mod.rs
+++ /dev/null
@@ -1,92 +0,0 @@
-//! backfill_useritemaccess.rs is used to trigger a backfill for the UserItemAccess table
-//! - DATABASE_URL
-//! - DOCUMENT_STORAGE_SERVICE_AUTH_KEY
-mod chat;
-mod document;
-mod project;
-
-use anyhow::Context;
-use macro_entrypoint::MacroEntrypoint;
-use sqlx::postgres::PgPoolOptions;
-
-// the number of useritemaccess records we insert at once
-const INSERT_BATCH_SIZE: usize = 10000;
-
-// the number of items we fetch from the db to process at once
-const DB_FETCH_SIZE: i64 = 10000;
-
-// the number of concurrent processes we use for fetching permission info for items
-const CONCURRENT_PROCESSING_LIMIT: usize = 25;
-
-/// Checks if a backfill process is enabled via an environment variable.
-/// The variable must be set to "true" (case-insensitive) to be considered enabled.
-fn is_backfill_enabled(var_name: &str) -> bool {
- match std::env::var(var_name) {
- Ok(val) => val.eq_ignore_ascii_case("true"),
- Err(_) => false, // If not set, it's disabled.
- }
-}
-
-/// Gets a numeric offset from an environment variable.
-/// Returns Some(offset) if the variable is set and is a valid number, otherwise None.
-fn get_offset(var_name: &str) -> Option<i64> {
- match std::env::var(var_name) {
- Ok(val) => match val.parse::<i64>() {
- Ok(offset) => {
- println!("-> Found custom offset for {}: {}", var_name, offset);
- Some(offset)
- }
- Err(_) => {
- eprintln!(
- "WARN: Could not parse value for {} ('{}'). Defaulting to no offset.",
- var_name, val
- );
- None
- }
- },
- Err(_) => None, // Variable is not set, so no offset.
- }
-}
-
-#[tokio::main]
-async fn main() -> anyhow::Result<()> {
- MacroEntrypoint::default().init();
-
- println!("Starting backfill_useritemaccess script");
-
- let database_url = std::env::var("DATABASE_URL").context("DATABASE_URL not set")?;
-
- let db = PgPoolOptions::new()
- .min_connections(10)
- .max_connections(60)
- .connect(&database_url)
- .await
- .context("could not connect to db")?;
-
- // --- Backfill Logic Controlled by Environment Variables ---
-
- if is_backfill_enabled("BACKFILL_CHATS") {
- let offset = get_offset("CHAT_OFFSET");
- chat::backfill_chats_updated(&db, offset).await?;
- } else {
- println!("Skipping chat backfill: BACKFILL_CHATS is not set to 'true'.");
- }
-
- if is_backfill_enabled("BACKFILL_DOCUMENTS") {
- let offset = get_offset("DOCS_OFFSET");
- document::backfill_documents_updated(&db, offset).await?;
- } else {
- println!("Skipping document backfill: BACKFILL_DOCUMENTS is not set to 'true'.");
- }
-
- if is_backfill_enabled("BACKFILL_PROJECTS") {
- let offset = get_offset("PROJECTS_OFFSET");
- project::backfill_projects_updated(&db, offset).await?;
- } else {
- println!("Skipping project backfill: BACKFILL_PROJECTS is not set to 'true'.");
- }
-
- println!("Backfill script finished!");
-
- Ok(())
-}
diff --git a/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/project.rs b/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/project.rs
deleted file mode 100644
index a0d5a39fe4..0000000000
--- a/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/project.rs
+++ /dev/null
@@ -1,170 +0,0 @@
-use crate::{CONCURRENT_PROCESSING_LIMIT, DB_FETCH_SIZE, INSERT_BATCH_SIZE};
-use anyhow::Context;
-use chrono::Utc;
-use futures::future::join_all;
-use models_permissions::share_permission::access_level::AccessLevel;
-use models_permissions::user_item_access::UserItemAccess;
-use sqlx::PgPool;
-
-pub async fn process_single_project(
- db: PgPool,
- project_id: String,
- user_id: String,
-) -> anyhow::Result<Vec<UserItemAccess>> {
- let mut generated_items = Vec::new();
-
- // Add row for the owner
- generated_items.push(UserItemAccess {
- id: macro_uuid::generate_uuid_v7(),
- user_id: user_id.clone(),
- item_id: project_id.clone(),
- item_type: "project".to_string(),
- access_level: AccessLevel::Owner,
- granted_from_channel_id: None,
- created_at: Utc::now(),
- updated_at: Utc::now(),
- });
-
- // Get share permissions
- let sp = macro_db_client::share_permission::get::get_project_share_permission(&db, &project_id)
- .await
- .with_context(|| format!("Failed to get share permission for project {}", project_id))?;
-
- // Get participants
- for csp in sp.channel_share_permissions.unwrap_or_default() {
- let channel_id = uuid::Uuid::parse_str(&csp.channel_id)
- .with_context(|| format!("Failed to parse channel UUID: {}", csp.channel_id))?;
-
- let participants =
- comms_db_client::participants::get_participants::get_participants(&db, &channel_id)
- .await
- .with_context(|| {
- format!("Failed to get participants for channel {}", csp.channel_id)
- })?;
-
- for participant in participants {
- if participant.user_id.as_ref() != user_id {
- generated_items.push(UserItemAccess {
- id: macro_uuid::generate_uuid_v7(),
- user_id: participant.user_id.to_string(),
- item_id: project_id.clone(),
- item_type: "project".to_string(),
- access_level: csp.access_level,
- granted_from_channel_id: Some(channel_id),
- created_at: Utc::now(),
- updated_at: Utc::now(),
- });
- }
- }
- }
-
- Ok(generated_items)
-}
-
-/// Backfills UserItemAccess records for projects with concurrent processing.
-pub async fn backfill_projects_updated(
- db: &PgPool,
- start_offset: Option<i64>,
-) -> anyhow::Result<()> {
- let mut offset = start_offset.unwrap_or(0);
-
- if let Some(so) = start_offset {
- println!("Starting project backfill from custom offset: {}", so);
- } else {
- println!("Starting project backfill from the beginning (streaming/concurrent version)");
- }
-
- let mut total_projects_processed = 0;
- let mut total_items_inserted = 0;
- let mut items_to_insert: Vec<UserItemAccess> = Vec::with_capacity(INSERT_BATCH_SIZE);
-
- loop {
- // 1. FETCH
- let projects_batch = macro_db_client::projects::get_all_project_ids_with_users_paginated(
- db,
- DB_FETCH_SIZE,
- offset,
- )
- .await
- .context("failed to get a batch of projects")?;
-
- let num_in_batch = projects_batch.len();
- if num_in_batch == 0 {
- println!(
- "No more projects found at offset {}. Concluding project backfill.",
- offset
- );
- break;
- }
-
- println!(
- "Fetched batch of {} projects at offset {}. Processing concurrently...",
- num_in_batch, offset
- );
-
- // 2. PROCESS concurrently in chunks
- for chunk in projects_batch.chunks(CONCURRENT_PROCESSING_LIMIT) {
- let mut tasks = Vec::new();
- for (project_id, user_id) in chunk {
- let db_clone = db.clone();
- let project_id_clone = project_id.clone();
- let user_id_clone = user_id.clone();
-
- tasks.push(tokio::spawn(process_single_project(
- db_clone,
- project_id_clone,
- user_id_clone,
- )));
- }
-
- for result in join_all(tasks).await {
- match result {
- Ok(Ok(generated_items)) => items_to_insert.extend(generated_items),
- Ok(Err(e)) => eprintln!("ERROR: A project processing task failed: {:?}", e),
- Err(e) => eprintln!("ERROR: A project processing task panicked: {:?}", e),
- }
- }
- }
-
- total_projects_processed += num_in_batch;
-
- // 3. INSERT
- if items_to_insert.len() >= INSERT_BATCH_SIZE {
- let batch: Vec<_> = std::mem::take(&mut items_to_insert);
- macro_db_client::item_access::insert::insert_user_item_access_batch(db, &batch)
- .await
- .context("failed to insert user item access batch")?;
-
- total_items_inserted += batch.len();
- println!(
- "Inserted batch of {} access records (total inserted this run: {})",
- batch.len(),
- total_items_inserted
- );
- }
-
- // 4. PREPARE for next iteration
- if num_in_batch < DB_FETCH_SIZE as usize {
- break;
- }
- offset += DB_FETCH_SIZE;
- }
-
- // Insert any remaining items
- if !items_to_insert.is_empty() {
- let items_count = items_to_insert.len();
- macro_db_client::item_access::insert::insert_user_item_access_batch(db, &items_to_insert)
- .await
- .context("failed to insert final user item access batch")?;
-
- total_items_inserted += items_count;
- println!("Inserted final batch of {} access records.", items_count);
- }
-
- println!(
- "Project backfill complete! Processed {} projects and inserted {} access records in this run.",
- total_projects_processed, total_items_inserted
- );
-
- Ok(())
-}
diff --git a/rust/cloud-storage/document_storage_service/src/main.rs b/rust/cloud-storage/document_storage_service/src/main.rs
index 18c196e7e2..a507d6bf60 100644
--- a/rust/cloud-storage/document_storage_service/src/main.rs
+++ b/rust/cloud-storage/document_storage_service/src/main.rs
@@ -318,6 +318,11 @@ async fn main() -> anyhow::Result<()> {
let connection_service =
ConnectionServiceImpl::new(entity_access_service.clone(), connection_gateway.clone());
+ let entity_access_management_service =
+ entity_access_management::domain::service::EntityAccessManagementServiceImpl::new(
+ entity_access_management::outbound::PgRepository::new(db.clone()),
+ );
+
let document_service = Arc::new(DocumentServiceImpl::new(
document_repo,
cloudfront_config,
@@ -328,6 +333,7 @@ async fn main() -> anyhow::Result<()> {
properties: properties_service.clone(),
},
connection_service,
+ entity_access_management_service.clone(),
));
let github_webhook_secret = secretsmanager_client
@@ -471,6 +477,7 @@ async fn main() -> anyhow::Result<()> {
call_state,
call_webhook_state,
call_internal_state,
+ entity_access_management_service,
};
// Spawn the delete document worker
diff --git a/rust/cloud-storage/document_storage_service_client/src/lib.rs b/rust/cloud-storage/document_storage_service_client/src/lib.rs
index b57356ad9f..781ec71415 100644
--- a/rust/cloud-storage/document_storage_service_client/src/lib.rs
+++ b/rust/cloud-storage/document_storage_service_client/src/lib.rs
@@ -7,8 +7,6 @@ pub mod error;
pub mod notification;
pub mod project;
pub mod thread;
-pub mod update_channel_share_permission;
-pub mod update_user_channel_permissions;
pub mod upload;
#[derive(Clone)]
diff --git a/rust/cloud-storage/document_storage_service_client/src/update_channel_share_permission.rs b/rust/cloud-storage/document_storage_service_client/src/update_channel_share_permission.rs
deleted file mode 100644
index 5935349eab..0000000000
--- a/rust/cloud-storage/document_storage_service_client/src/update_channel_share_permission.rs
+++ /dev/null
@@ -1,43 +0,0 @@
-use super::DocumentStorageServiceClient;
-use anyhow::Result;
-use model::document_storage_service_internal::UpdateChannelSharePermissionRequest;
-
-impl DocumentStorageServiceClient {
- #[tracing::instrument(skip(self))]
- pub async fn update_channel_share_permission(
- &self,
- req: UpdateChannelSharePermissionRequest,
- ) -> Result<()> {
- let res = self
- .client
- .post(format!(
- "{}/internal/channel/update_share_permission",
- self.url
- ))
- .json(&req)
- .send()
- .await?;
-
- let status_code = res.status();
-
- match status_code {
- reqwest::StatusCode::OK => {
- tracing::trace!("channel share permission updated");
- return Ok(());
- }
- reqwest::StatusCode::NOT_MODIFIED => {
- tracing::trace!("channel share permission not modified");
- return Ok(());
- }
- _ => {
- let body: String = res.text().await?;
- tracing::error!(
- body=%body,
- status=%status_code,
- "unexpected response from document storage service"
- );
- anyhow::bail!(body);
- }
- }
- }
-}
diff --git a/rust/cloud-storage/document_storage_service_client/src/update_user_channel_permissions.rs b/rust/cloud-storage/document_storage_service_client/src/update_user_channel_permissions.rs
deleted file mode 100644
index ec5544311f..0000000000
--- a/rust/cloud-storage/document_storage_service_client/src/update_user_channel_permissions.rs
+++ /dev/null
@@ -1,41 +0,0 @@
-use super::DocumentStorageServiceClient;
-use anyhow::Result;
-use model::document_storage_service_internal::UpdateUserChannelPermissionsRequest;
-
-impl DocumentStorageServiceClient {
- /// Updates permissions for users in a channel by either adding, replacing, or removing
- /// access to all items shared with that channel.
- #[tracing::instrument(skip(self))]
- pub async fn update_user_channel_permissions(
- &self,
- req: UpdateUserChannelPermissionsRequest,
- ) -> Result<()> {
- let res = self
- .client
- .post(format!(
- "{}/internal/channel/update_user_channel_permissions",
- self.url
- ))
- .json(&req)
- .send()
- .await?;
-
- let status_code = res.status();
-
- match status_code {
- reqwest::StatusCode::OK => {
- tracing::trace!("user channel permissions updated successfully");
- Ok(())
- }
- _ => {
- let body: String = res.text().await?;
- tracing::error!(
- body=%body,
- status=%status_code,
- "unexpected response from document storage service"
- );
- Err(anyhow::anyhow!(body))
- }
- }
- }
-}
diff --git a/rust/cloud-storage/documents/.sqlx/query-06a72bfcfbcc5f5bbed6cd093436309607f9375d2ba7b151e9dc1a8493f88e44.json b/rust/cloud-storage/documents/.sqlx/query-06a72bfcfbcc5f5bbed6cd093436309607f9375d2ba7b151e9dc1a8493f88e44.json
new file mode 100644
index 0000000000..4c5afc274a
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-06a72bfcfbcc5f5bbed6cd093436309607f9375d2ba7b151e9dc1a8493f88e44.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM notification_user_device_registration\n WHERE device_endpoint = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "06a72bfcfbcc5f5bbed6cd093436309607f9375d2ba7b151e9dc1a8493f88e44"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d.json b/rust/cloud-storage/documents/.sqlx/query-0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d.json
new file mode 100644
index 0000000000..99a3b6f452
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id FROM (\n -- Direct user grants\n SELECT source_id as user_id FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'user'\n\n UNION ALL\n\n -- Channel Members\n SELECT cp.user_id FROM comms_channel_participants cp\n WHERE cp.left_at IS NULL AND cp.channel_id IN (\n SELECT source_id::uuid FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'channel'\n )\n\n UNION ALL\n\n -- Team Members\n SELECT tu.user_id FROM team_user tu\n WHERE tu.team_id IN (\n SELECT source_id::uuid FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'team'\n )\n )\n \n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6.json b/rust/cloud-storage/documents/.sqlx/query-1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6.json
new file mode 100644
index 0000000000..f97907a55c
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" = $1\n )\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-270cd8ae6b47508cb7e4e920bd76cb0f6177d685bddedb06f1892d0014af6f01.json b/rust/cloud-storage/documents/.sqlx/query-270cd8ae6b47508cb7e4e920bd76cb0f6177d685bddedb06f1892d0014af6f01.json
new file mode 100644
index 0000000000..01cece9642
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-270cd8ae6b47508cb7e4e920bd76cb0f6177d685bddedb06f1892d0014af6f01.json
@@ -0,0 +1,33 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM notification_user_device_registration\n WHERE device_token = $1 AND device_type = $2\n RETURNING device_endpoint\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "device_endpoint",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ {
+ "Custom": {
+ "name": "notification_device_type_option",
+ "kind": {
+ "Enum": [
+ "ios",
+ "android"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "270cd8ae6b47508cb7e4e920bd76cb0f6177d685bddedb06f1892d0014af6f01"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-279926d74db34fd618a6b507e2ec60160ef8399af5cfa11393a2e1e8d9762d65.json b/rust/cloud-storage/documents/.sqlx/query-279926d74db34fd618a6b507e2ec60160ef8399af5cfa11393a2e1e8d9762d65.json
new file mode 100644
index 0000000000..0216da5e97
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-279926d74db34fd618a6b507e2ec60160ef8399af5cfa11393a2e1e8d9762d65.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM entity_access\n WHERE entity_id = ANY($1)\n AND granted_from_project_id = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "UuidArray",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "279926d74db34fd618a6b507e2ec60160ef8399af5cfa11393a2e1e8d9762d65"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-2db739bbaa907ce20364049887168f9a47b0e7d1c06d619df37fe7644418c104.json b/rust/cloud-storage/documents/.sqlx/query-2db739bbaa907ce20364049887168f9a47b0e7d1c06d619df37fe7644418c104.json
deleted file mode 100644
index 2eb400f754..0000000000
--- a/rust/cloud-storage/documents/.sqlx/query-2db739bbaa907ce20364049887168f9a47b0e7d1c06d619df37fe7644418c104.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO \"UserItemAccess\" (\n \"id\",\n \"user_id\",\n \"item_id\",\n \"item_type\",\n \"access_level\",\n \"granted_from_channel_id\",\n \"created_at\",\n \"updated_at\"\n )\n SELECT\n gen_random_uuid(),\n cp.user_id,\n $1,\n 'document',\n 'view'::\"AccessLevel\",\n cp.channel_id,\n NOW(),\n NOW()\n FROM comms_channel_participants cp\n WHERE cp.channel_id = ANY($2::uuid[])\n AND cp.left_at IS NULL\n ON CONFLICT (\"user_id\", \"item_id\", \"item_type\", \"granted_from_channel_id\")\n DO UPDATE SET\n \"access_level\" = EXCLUDED.\"access_level\",\n \"updated_at\" = NOW()\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text",
- "UuidArray"
- ]
- },
- "nullable": []
- },
- "hash": "2db739bbaa907ce20364049887168f9a47b0e7d1c06d619df37fe7644418c104"
-}
diff --git a/rust/cloud-storage/documents/.sqlx/query-317f05707fdc73269f3017a3bb96d55b7327338bf5e52dfaad106b4b492cbb8e.json b/rust/cloud-storage/documents/.sqlx/query-317f05707fdc73269f3017a3bb96d55b7327338bf5e52dfaad106b4b492cbb8e.json
new file mode 100644
index 0000000000..b17b203167
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-317f05707fdc73269f3017a3bb96d55b7327338bf5e52dfaad106b4b492cbb8e.json
@@ -0,0 +1,98 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n un.user_id as owner_id,\n un.notification_id,\n n.event_item_id,\n n.event_item_type,\n un.sent,\n un.done,\n un.created_at::timestamptz as \"created_at!\",\n un.seen_at::timestamptz as viewed_at,\n un.created_at::timestamptz as \"updated_at!\",\n un.deleted_at::timestamptz,\n n.metadata as \"notification_metadata: serde_json::Value\",\n n.notification_event_type as notification_event_type,\n n.sender_id as sender_id\n FROM user_notification un\n JOIN notification n ON n.id = un.notification_id\n WHERE un.user_id = $1\n AND n.event_item_id = ANY($2)\n AND un.deleted_at IS NULL\n AND un.done = false\n AND (($4::timestamptz IS NULL)\n OR (un.created_at, un.notification_id) < ($4, $5))\n ORDER BY un.created_at DESC, un.notification_id DESC\n LIMIT $3\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "owner_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "event_item_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "event_item_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "sent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 5,
+ "name": "done",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "notification_metadata: serde_json::Value",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 11,
+ "name": "notification_event_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 12,
+ "name": "sender_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray",
+ "Int8",
+ "Timestamptz",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ null,
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "317f05707fdc73269f3017a3bb96d55b7327338bf5e52dfaad106b4b492cbb8e"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-3293eab63193f1b3822a59e9a6a9621520f26e6ec8248abed103985281ef7ff1.json b/rust/cloud-storage/documents/.sqlx/query-3293eab63193f1b3822a59e9a6a9621520f26e6ec8248abed103985281ef7ff1.json
new file mode 100644
index 0000000000..e4a18ac5f0
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-3293eab63193f1b3822a59e9a6a9621520f26e6ec8248abed103985281ef7ff1.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET done = $3\n WHERE user_id = $1 AND notification_id = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray",
+ "Bool"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "3293eab63193f1b3822a59e9a6a9621520f26e6ec8248abed103985281ef7ff1"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-3357165799ff1f7bf1de3891174668e0ab16c64bd9dfc905213681e6021474fa.json b/rust/cloud-storage/documents/.sqlx/query-3357165799ff1f7bf1de3891174668e0ab16c64bd9dfc905213681e6021474fa.json
new file mode 100644
index 0000000000..6696253445
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-3357165799ff1f7bf1de3891174668e0ab16c64bd9dfc905213681e6021474fa.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT EXISTS(\n SELECT 1 FROM notification_message_receipt\n WHERE user_id = $1\n AND notification_id = $2\n AND failed = false\n ) as \"exists!\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "exists!",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "3357165799ff1f7bf1de3891174668e0ab16c64bd9dfc905213681e6021474fa"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-36dfcf982834f117d97d1ba332be6784c946f05120c7c228ff258389ceba97a1.json b/rust/cloud-storage/documents/.sqlx/query-36dfcf982834f117d97d1ba332be6784c946f05120c7c228ff258389ceba97a1.json
new file mode 100644
index 0000000000..c07ec0acbe
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-36dfcf982834f117d97d1ba332be6784c946f05120c7c228ff258389ceba97a1.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO user_notification_type_preference (user_id, notification_event_type)\n VALUES ($1, $2)\n ON CONFLICT (user_id, notification_event_type) DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Varchar"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "36dfcf982834f117d97d1ba332be6784c946f05120c7c228ff258389ceba97a1"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08.json b/rust/cloud-storage/documents/.sqlx/query-377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08.json
new file mode 100644
index 0000000000..9348d25315
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"DocumentPermission\" WHERE \"documentId\" = $1\n )\n \n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60.json b/rust/cloud-storage/documents/.sqlx/query-37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60.json
new file mode 100644
index 0000000000..44d3a67e72
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT EXISTS (\n SELECT 1\n FROM public.email_threads t\n JOIN public.email_links l ON l.id = t.link_id\n WHERE t.id = $1::uuid\n AND l.macro_id = $2\n ) AS \"exists!\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "exists!",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json b/rust/cloud-storage/documents/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json
new file mode 100644
index 0000000000..b75a3a2ff5
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json
@@ -0,0 +1,41 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)\n VALUES ($1, $2, $3, $4, $5)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text",
+ {
+ "Custom": {
+ "name": "entity_access_source_type",
+ "kind": {
+ "Enum": [
+ "channel",
+ "team",
+ "user"
+ ]
+ }
+ }
+ },
+ {
+ "Custom": {
+ "name": "\"AccessLevel\"",
+ "kind": {
+ "Enum": [
+ "view",
+ "comment",
+ "edit",
+ "owner"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237.json b/rust/cloud-storage/documents/.sqlx/query-46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237.json
new file mode 100644
index 0000000000..c91a76ff52
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2\n AND source_id = ANY($3) AND source_type = 'channel'\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-48697f17a7121986cc770d6698fbca7bf107ae20dbadbf64a7799ab162b2feb4.json b/rust/cloud-storage/documents/.sqlx/query-48697f17a7121986cc770d6698fbca7bf107ae20dbadbf64a7799ab162b2feb4.json
new file mode 100644
index 0000000000..3fdea7e232
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-48697f17a7121986cc770d6698fbca7bf107ae20dbadbf64a7799ab162b2feb4.json
@@ -0,0 +1,95 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n un.user_id as owner_id,\n un.notification_id,\n n.event_item_id,\n n.event_item_type,\n un.sent,\n un.done,\n un.created_at::timestamptz as \"created_at!\",\n un.seen_at::timestamptz as viewed_at,\n un.created_at::timestamptz as \"updated_at!\",\n un.deleted_at::timestamptz,\n n.metadata as \"notification_metadata: serde_json::Value\",\n n.notification_event_type as notification_event_type,\n n.sender_id as sender_id\n FROM user_notification un\n JOIN notification n ON n.id = un.notification_id\n WHERE un.user_id = $1\n AND un.notification_id = $2\n AND un.deleted_at IS NULL\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "owner_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "event_item_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "event_item_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "sent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 5,
+ "name": "done",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "notification_metadata: serde_json::Value",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 11,
+ "name": "notification_event_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 12,
+ "name": "sender_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ null,
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "48697f17a7121986cc770d6698fbca7bf107ae20dbadbf64a7799ab162b2feb4"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-4e096eb7d3c507e3647685073fba7b3f36ef0e70c887db31f5cc5a8eb8ee1844.json b/rust/cloud-storage/documents/.sqlx/query-4e096eb7d3c507e3647685073fba7b3f36ef0e70c887db31f5cc5a8eb8ee1844.json
new file mode 100644
index 0000000000..55fcda1121
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-4e096eb7d3c507e3647685073fba7b3f36ef0e70c887db31f5cc5a8eb8ee1844.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM user_notification\n WHERE user_id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "4e096eb7d3c507e3647685073fba7b3f36ef0e70c887db31f5cc5a8eb8ee1844"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf.json b/rust/cloud-storage/documents/.sqlx/query-5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf.json
new file mode 100644
index 0000000000..514e8d9770
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ChatPermission\" WHERE \"chatId\" = $1\n )\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-5b17a30f841372cce9989af409baf993e24bfe90d3a3553f6851b3e92c8540eb.json b/rust/cloud-storage/documents/.sqlx/query-5b17a30f841372cce9989af409baf993e24bfe90d3a3553f6851b3e92c8540eb.json
new file mode 100644
index 0000000000..113b9e269a
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-5b17a30f841372cce9989af409baf993e24bfe90d3a3553f6851b3e92c8540eb.json
@@ -0,0 +1,63 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n entity_id,\n source_id,\n source_type as \"source_type:EntityAccessSourceType\",\n access_level as \"access_level:AccessLevel\"\n FROM entity_access\n WHERE entity_id = ANY($1) AND entity_type = 'project' AND granted_from_project_id IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "entity_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "source_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "source_type:EntityAccessSourceType",
+ "type_info": {
+ "Custom": {
+ "name": "entity_access_source_type",
+ "kind": {
+ "Enum": [
+ "channel",
+ "team",
+ "user"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 3,
+ "name": "access_level:AccessLevel",
+ "type_info": {
+ "Custom": {
+ "name": "\"AccessLevel\"",
+ "kind": {
+ "Enum": [
+ "view",
+ "comment",
+ "edit",
+ "owner"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "UuidArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "5b17a30f841372cce9989af409baf993e24bfe90d3a3553f6851b3e92c8540eb"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b.json b/rust/cloud-storage/documents/.sqlx/query-5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b.json
new file mode 100644
index 0000000000..ac050656e7
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b.json
@@ -0,0 +1,29 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)\n SELECT $1, $2, u.user_id, 'user', $3\n FROM UNNEST($4::text[]) as u(user_id)\n ON CONFLICT (entity_id, entity_type, source_id, source_type)\n WHERE granted_from_project_id IS NULL\n AND access_level != 'owner' -- this prevents us from overriding the owner user\n DO UPDATE SET access_level = EXCLUDED.access_level, updated_at = NOW()\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ {
+ "Custom": {
+ "name": "\"AccessLevel\"",
+ "kind": {
+ "Enum": [
+ "view",
+ "comment",
+ "edit",
+ "owner"
+ ]
+ }
+ }
+ },
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-621186dcec072b603a5f3d7b9e987a1638589d539c60d9dc5c2ab0865ff062d6.json b/rust/cloud-storage/documents/.sqlx/query-621186dcec072b603a5f3d7b9e987a1638589d539c60d9dc5c2ab0865ff062d6.json
new file mode 100644
index 0000000000..d0a749ebd2
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-621186dcec072b603a5f3d7b9e987a1638589d539c60d9dc5c2ab0865ff062d6.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id FROM user_mute_notification\n WHERE user_id = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "621186dcec072b603a5f3d7b9e987a1638589d539c60d9dc5c2ab0865ff062d6"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-625ee33d48768e369ee1fe3abe27811ad04313b1aa31f4b51abe5fd3bf569674.json b/rust/cloud-storage/documents/.sqlx/query-625ee33d48768e369ee1fe3abe27811ad04313b1aa31f4b51abe5fd3bf569674.json
new file mode 100644
index 0000000000..d374c2f79f
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-625ee33d48768e369ee1fe3abe27811ad04313b1aa31f4b51abe5fd3bf569674.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM user_notification_type_preference\n WHERE user_id = $1 AND notification_event_type = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "625ee33d48768e369ee1fe3abe27811ad04313b1aa31f4b51abe5fd3bf569674"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json b/rust/cloud-storage/documents/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json
new file mode 100644
index 0000000000..a110bb67c6
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT DISTINCT cp.user_id\n FROM comms_channel_participants cp\n WHERE cp.channel_id = $1 AND cp.left_at IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029.json b/rust/cloud-storage/documents/.sqlx/query-7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029.json
new file mode 100644
index 0000000000..b7e5230b4c
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM entity_access\n WHERE (source_id = ANY($1) AND source_type = 'channel')\n AND (entity_id = ANY($2) OR granted_from_project_id = ANY($3))\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "UuidArray",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-73c67fbf678e1479d528adcc5bea7da3261d0a04e24cc16f96ec9f2dea3b2e98.json b/rust/cloud-storage/documents/.sqlx/query-73c67fbf678e1479d528adcc5bea7da3261d0a04e24cc16f96ec9f2dea3b2e98.json
new file mode 100644
index 0000000000..65459bcefd
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-73c67fbf678e1479d528adcc5bea7da3261d0a04e24cc16f96ec9f2dea3b2e98.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id\n FROM \"User\"\n WHERE email = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "73c67fbf678e1479d528adcc5bea7da3261d0a04e24cc16f96ec9f2dea3b2e98"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-74d33764e454fb9ab4f2775974462d6fdb092bffc720d929de5e7b50ecef5139.json b/rust/cloud-storage/documents/.sqlx/query-74d33764e454fb9ab4f2775974462d6fdb092bffc720d929de5e7b50ecef5139.json
new file mode 100644
index 0000000000..34382e8725
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-74d33764e454fb9ab4f2775974462d6fdb092bffc720d929de5e7b50ecef5139.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id, apns_collapse_key as \"apns_collapse_key!: String\"\n FROM notification\n WHERE id = ANY($1) AND apns_collapse_key IS NOT NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "apns_collapse_key!: String",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "UuidArray"
+ ]
+ },
+ "nullable": [
+ false,
+ true
+ ]
+ },
+ "hash": "74d33764e454fb9ab4f2775974462d6fdb092bffc720d929de5e7b50ecef5139"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a.json b/rust/cloud-storage/documents/.sqlx/query-7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a.json
new file mode 100644
index 0000000000..655495fb29
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT c.id\n FROM comms_channels c\n INNER JOIN comms_channel_participants cp ON cp.channel_id = c.id\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n AND c.id = ANY($2::uuid[])\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-765650cab2b1a1d1abe6ca406438bf48968cebebc7316b87b192d649e096cd67.json b/rust/cloud-storage/documents/.sqlx/query-765650cab2b1a1d1abe6ca406438bf48968cebebc7316b87b192d649e096cd67.json
new file mode 100644
index 0000000000..a8e7326c35
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-765650cab2b1a1d1abe6ca406438bf48968cebebc7316b87b192d649e096cd67.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id FROM user_notification_item_unsubscribe\n WHERE item_id = $1 AND user_id = ANY($2)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "765650cab2b1a1d1abe6ca406438bf48968cebebc7316b87b192d649e096cd67"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-78f1cf9da464937604c1a2d5115c014cab9de72bd88605ff47a316baa2c7acc2.json b/rust/cloud-storage/documents/.sqlx/query-78f1cf9da464937604c1a2d5115c014cab9de72bd88605ff47a316baa2c7acc2.json
new file mode 100644
index 0000000000..9e6f7f8877
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-78f1cf9da464937604c1a2d5115c014cab9de72bd88605ff47a316baa2c7acc2.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT d.device_endpoint\n FROM notification_user_device_registration d\n WHERE d.device_token = $1\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "device_endpoint",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "78f1cf9da464937604c1a2d5115c014cab9de72bd88605ff47a316baa2c7acc2"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-7c0b9d645a85e30577377e4d8c8a8f976e86c6251e12517a2b1e14d525e09198.json b/rust/cloud-storage/documents/.sqlx/query-7c0b9d645a85e30577377e4d8c8a8f976e86c6251e12517a2b1e14d525e09198.json
new file mode 100644
index 0000000000..721b0038f2
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-7c0b9d645a85e30577377e4d8c8a8f976e86c6251e12517a2b1e14d525e09198.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id, notification_event_type\n FROM user_notification_type_preference\n WHERE user_id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_event_type",
+ "type_info": "Varchar"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "7c0b9d645a85e30577377e4d8c8a8f976e86c6251e12517a2b1e14d525e09198"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc.json b/rust/cloud-storage/documents/.sqlx/query-7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc.json
new file mode 100644
index 0000000000..a166680895
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc.json
@@ -0,0 +1,21 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO notification (id, notification_event_type, event_item_id, event_item_type, service_sender, metadata, sender_id, apns_collapse_key)\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8)\n ON CONFLICT (id) DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Varchar",
+ "Text",
+ "Text",
+ "Text",
+ "Jsonb",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-86eee52e30e4168f4a7f319d1dcaa59144a5b3269120df892f161c74b5fe7436.json b/rust/cloud-storage/documents/.sqlx/query-86eee52e30e4168f4a7f319d1dcaa59144a5b3269120df892f161c74b5fe7436.json
new file mode 100644
index 0000000000..eab49b91f7
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-86eee52e30e4168f4a7f319d1dcaa59144a5b3269120df892f161c74b5fe7436.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET sent = true\n WHERE notification_id = $1 AND user_id = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "86eee52e30e4168f4a7f319d1dcaa59144a5b3269120df892f161c74b5fe7436"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-90832c95920a9b40329509f4ee611f765a6c10025c1b519f4a5d76ccfd64fb75.json b/rust/cloud-storage/documents/.sqlx/query-90832c95920a9b40329509f4ee611f765a6c10025c1b519f4a5d76ccfd64fb75.json
new file mode 100644
index 0000000000..696addd983
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-90832c95920a9b40329509f4ee611f765a6c10025c1b519f4a5d76ccfd64fb75.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)\n VALUES ($1, 'document', $2, 'team', $3)\n ON CONFLICT DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ {
+ "Custom": {
+ "name": "\"AccessLevel\"",
+ "kind": {
+ "Enum": [
+ "view",
+ "comment",
+ "edit",
+ "owner"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "90832c95920a9b40329509f4ee611f765a6c10025c1b519f4a5d76ccfd64fb75"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-92edc80110af7b96f7f908989461a4abb11652671a95454969369a0484ed9239.json b/rust/cloud-storage/documents/.sqlx/query-92edc80110af7b96f7f908989461a4abb11652671a95454969369a0484ed9239.json
new file mode 100644
index 0000000000..a8520fdfd0
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-92edc80110af7b96f7f908989461a4abb11652671a95454969369a0484ed9239.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO notification_message_receipt (message_id, user_id, notification_id)\n VALUES ($1, $2, $3)\n ON CONFLICT (message_id) DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "92edc80110af7b96f7f908989461a4abb11652671a95454969369a0484ed9239"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-94c019227741f6c4fe8411454cb7c0a3a97e5594c29f11fa893238656e161ff1.json b/rust/cloud-storage/documents/.sqlx/query-94c019227741f6c4fe8411454cb7c0a3a97e5594c29f11fa893238656e161ff1.json
new file mode 100644
index 0000000000..4035617965
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-94c019227741f6c4fe8411454cb7c0a3a97e5594c29f11fa893238656e161ff1.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET deleted_at = NOW()\n WHERE user_id = $1 AND notification_id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "94c019227741f6c4fe8411454cb7c0a3a97e5594c29f11fa893238656e161ff1"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-a0046a263c572915a8e14a8ac70479f1ba89549f1930f571bf278fcfe259cfd1.json b/rust/cloud-storage/documents/.sqlx/query-a0046a263c572915a8e14a8ac70479f1ba89549f1930f571bf278fcfe259cfd1.json
new file mode 100644
index 0000000000..ad14cfedba
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-a0046a263c572915a8e14a8ac70479f1ba89549f1930f571bf278fcfe259cfd1.json
@@ -0,0 +1,44 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id, device_endpoint, device_type as \"device_type: DbDeviceType\"\n FROM notification_user_device_registration\n WHERE user_id = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "device_endpoint",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "device_type: DbDeviceType",
+ "type_info": {
+ "Custom": {
+ "name": "notification_device_type_option",
+ "kind": {
+ "Enum": [
+ "ios",
+ "android"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "a0046a263c572915a8e14a8ac70479f1ba89549f1930f571bf278fcfe259cfd1"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-a5d9f358b5382c0eaed918f903bc6aa328f527e6e47d649c37dfcf1c9f3a7139.json b/rust/cloud-storage/documents/.sqlx/query-a5d9f358b5382c0eaed918f903bc6aa328f527e6e47d649c37dfcf1c9f3a7139.json
new file mode 100644
index 0000000000..7626c0a06b
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-a5d9f358b5382c0eaed918f903bc6aa328f527e6e47d649c37dfcf1c9f3a7139.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET seen_at = NOW()\n WHERE user_id = $1 AND notification_id = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "a5d9f358b5382c0eaed918f903bc6aa328f527e6e47d649c37dfcf1c9f3a7139"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24.json b/rust/cloud-storage/documents/.sqlx/query-a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24.json
new file mode 100644
index 0000000000..f214362a1f
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'call'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE id in (\n SELECT share_permission_id\n FROM calls\n WHERE id = $1\n UNION ALL\n SELECT share_permission_id\n FROM call_records\n WHERE id = $1\n LIMIT 1\n )\n AND \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10.json b/rust/cloud-storage/documents/.sqlx/query-ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10.json
new file mode 100644
index 0000000000..b0fb258d2d
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT l.macro_id\n FROM email_threads et\n JOIN email_links l ON et.link_id = l.id\n WHERE et.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "macro_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815.json b/rust/cloud-storage/documents/.sqlx/query-b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815.json
new file mode 100644
index 0000000000..aa74e2b98b
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'email_thread'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"EmailThreadPermission\" WHERE \"threadId\" = $3\n )\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-b3f9f3696438bd2ad8754650d87d7bbf32e70d3d173a748a07eacdb4e42841eb.json b/rust/cloud-storage/documents/.sqlx/query-b3f9f3696438bd2ad8754650d87d7bbf32e70d3d173a748a07eacdb4e42841eb.json
new file mode 100644
index 0000000000..e5d913399d
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-b3f9f3696438bd2ad8754650d87d7bbf32e70d3d173a748a07eacdb4e42841eb.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO notification_user_device_registration (id, user_id, device_token, device_endpoint, device_type)\n VALUES ($1, $2, $3, $4, $5)\n ON CONFLICT (device_endpoint) DO UPDATE SET user_id = $2, device_token = $3, device_type = $5, updated_at = NOW()\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text",
+ "Text",
+ {
+ "Custom": {
+ "name": "notification_device_type_option",
+ "kind": {
+ "Enum": [
+ "ios",
+ "android"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "b3f9f3696438bd2ad8754650d87d7bbf32e70d3d173a748a07eacdb4e42841eb"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524.json b/rust/cloud-storage/documents/.sqlx/query-b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524.json
new file mode 100644
index 0000000000..be13d76b25
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'document'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"DocumentPermission\" WHERE \"documentId\" = $3\n ) \n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-b6705d3675950d0bbbd4a0ba10f7716a24694cfd98741fc0508d607684b1c8a9.json b/rust/cloud-storage/documents/.sqlx/query-b6705d3675950d0bbbd4a0ba10f7716a24694cfd98741fc0508d607684b1c8a9.json
new file mode 100644
index 0000000000..1168d26a34
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-b6705d3675950d0bbbd4a0ba10f7716a24694cfd98741fc0508d607684b1c8a9.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE notification_message_receipt\n SET failed = true, failed_at = NOW()\n WHERE message_id = $1\n RETURNING user_id, notification_id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "b6705d3675950d0bbbd4a0ba10f7716a24694cfd98741fc0508d607684b1c8a9"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157.json b/rust/cloud-storage/documents/.sqlx/query-b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157.json
new file mode 100644
index 0000000000..d560cb7eb3
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'chat'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ChatPermission\" WHERE \"chatId\" = $3\n )\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682.json b/rust/cloud-storage/documents/.sqlx/query-bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682.json
new file mode 100644
index 0000000000..3ed3f3db5e
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE id in (SELECT share_permission_id\n FROM calls\n WHERE id = $1\n UNION ALL\n SELECT share_permission_id\n FROM call_records\n WHERE id = $1\n LIMIT 1)\n AND \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476.json b/rust/cloud-storage/documents/.sqlx/query-c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476.json
new file mode 100644
index 0000000000..1216b39a3c
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'project'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" = $3\n )\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580.json b/rust/cloud-storage/documents/.sqlx/query-cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580.json
new file mode 100644
index 0000000000..ddcaf87146
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT cp.channel_id::text FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "channel_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-cd2ae30f38c8fd4467fafbf57d515e303d2c5bed1c53a5c1cf255a172defa46c.json b/rust/cloud-storage/documents/.sqlx/query-cd2ae30f38c8fd4467fafbf57d515e303d2c5bed1c53a5c1cf255a172defa46c.json
new file mode 100644
index 0000000000..a42c11b623
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-cd2ae30f38c8fd4467fafbf57d515e303d2c5bed1c53a5c1cf255a172defa46c.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM entity_access\n WHERE entity_id = $1\n AND entity_type = $2\n AND granted_from_project_id = ANY($3)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "cd2ae30f38c8fd4467fafbf57d515e303d2c5bed1c53a5c1cf255a172defa46c"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-d20bc5b5dfecf0a2ef4b7d77b9090ad28584cd0a1fd24460096b6a5097a870ac.json b/rust/cloud-storage/documents/.sqlx/query-d20bc5b5dfecf0a2ef4b7d77b9090ad28584cd0a1fd24460096b6a5097a870ac.json
new file mode 100644
index 0000000000..f3780614e0
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-d20bc5b5dfecf0a2ef4b7d77b9090ad28584cd0a1fd24460096b6a5097a870ac.json
@@ -0,0 +1,97 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n un.user_id as owner_id,\n un.notification_id,\n n.event_item_id,\n n.event_item_type,\n un.sent,\n un.done,\n un.created_at::timestamptz as \"created_at!\",\n un.seen_at::timestamptz as viewed_at,\n un.created_at::timestamptz as \"updated_at!\",\n un.deleted_at::timestamptz,\n n.metadata as \"notification_metadata: serde_json::Value\",\n n.notification_event_type as notification_event_type,\n n.sender_id as sender_id\n FROM user_notification un\n JOIN notification n ON n.id = un.notification_id\n WHERE un.user_id = $1\n AND un.deleted_at IS NULL\n AND un.done = false\n AND (($3::timestamptz IS NULL)\n OR (un.created_at, un.notification_id) < ($3, $4))\n ORDER BY un.created_at DESC, un.notification_id DESC\n LIMIT $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "owner_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "event_item_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "event_item_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "sent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 5,
+ "name": "done",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "notification_metadata: serde_json::Value",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 11,
+ "name": "notification_event_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 12,
+ "name": "sender_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Int8",
+ "Timestamptz",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ null,
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "d20bc5b5dfecf0a2ef4b7d77b9090ad28584cd0a1fd24460096b6a5097a870ac"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-db297e24e3ed1e94c27121977d81813bbe4cde5e5b7bec42e424c72db0e27e73.json b/rust/cloud-storage/documents/.sqlx/query-db297e24e3ed1e94c27121977d81813bbe4cde5e5b7bec42e424c72db0e27e73.json
new file mode 100644
index 0000000000..d197caf563
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-db297e24e3ed1e94c27121977d81813bbe4cde5e5b7bec42e424c72db0e27e73.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id FROM user_notification_type_preference\n WHERE notification_event_type = $1 AND user_id = ANY($2)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "db297e24e3ed1e94c27121977d81813bbe4cde5e5b7bec42e424c72db0e27e73"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-db69e5ddf8fbee090a57d3cfd0b2910bdf3bcaa2de68e51d43425b56b68f1e8b.json b/rust/cloud-storage/documents/.sqlx/query-db69e5ddf8fbee090a57d3cfd0b2910bdf3bcaa2de68e51d43425b56b68f1e8b.json
deleted file mode 100644
index fdd501e89e..0000000000
--- a/rust/cloud-storage/documents/.sqlx/query-db69e5ddf8fbee090a57d3cfd0b2910bdf3bcaa2de68e51d43425b56b68f1e8b.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO \"UserItemAccess\" (\n \"id\", \"user_id\", \"item_id\", \"item_type\", \"access_level\",\n \"granted_from_channel_id\", \"granted_from_team_id\",\n \"created_at\", \"updated_at\"\n )\n SELECT\n u.id,\n u.user_id,\n $1 AS item_id,\n 'document' AS item_type,\n 'comment' AS access_level,\n NULL AS granted_from_channel_id,\n $4 AS granted_from_team_id,\n NOW() AS created_at,\n NOW() AS updated_at\n FROM UNNEST($2::uuid[], $3::text[]) AS u(id, user_id)\n WHERE NOT EXISTS (\n SELECT 1 FROM \"UserItemAccess\" uia\n WHERE uia.\"user_id\" = u.user_id\n AND uia.\"item_id\" = $1\n AND uia.\"item_type\" = 'document'\n AND uia.\"granted_from_channel_id\" IS NULL\n )\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text",
- "UuidArray",
- "TextArray",
- "Uuid"
- ]
- },
- "nullable": []
- },
- "hash": "db69e5ddf8fbee090a57d3cfd0b2910bdf3bcaa2de68e51d43425b56b68f1e8b"
-}
diff --git a/rust/cloud-storage/documents/.sqlx/query-e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2.json b/rust/cloud-storage/documents/.sqlx/query-e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2.json
new file mode 100644
index 0000000000..f47413e3dc
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH RECURSIVE parent_projects AS (\n -- Base case: the project itself\n SELECT id, name, \"parentId\"\n FROM \"Project\"\n WHERE id = $1\n\n UNION ALL\n\n -- Recursive case: walk up to the parent\n SELECT p.id, p.name, p.\"parentId\"\n FROM \"Project\" p\n INNER JOIN parent_projects pp ON p.id = pp.\"parentId\"\n )\n SELECT id as \"id!\"\n FROM parent_projects\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437.json b/rust/cloud-storage/documents/.sqlx/query-e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437.json
new file mode 100644
index 0000000000..3ac1b029f6
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"EmailThreadPermission\" WHERE \"threadId\" = $1\n )\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-efc740cd935fb67ef5c2a75b3c37cf16bf09d6e52e5f6e5c5b107ef8244a141d.json b/rust/cloud-storage/documents/.sqlx/query-efc740cd935fb67ef5c2a75b3c37cf16bf09d6e52e5f6e5c5b107ef8244a141d.json
new file mode 100644
index 0000000000..1cbb49a96b
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-efc740cd935fb67ef5c2a75b3c37cf16bf09d6e52e5f6e5c5b107ef8244a141d.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO user_notification (notification_id, user_id)\n SELECT $1, user_id\n FROM UNNEST($2::text[]) as user_id\n RETURNING created_at::timestamptz as \"created_at!\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "efc740cd935fb67ef5c2a75b3c37cf16bf09d6e52e5f6e5c5b107ef8244a141d"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-f3e53dd531be738b881df199783a2beded3bd378038cbd6f012080ac77c5291b.json b/rust/cloud-storage/documents/.sqlx/query-f3e53dd531be738b881df199783a2beded3bd378038cbd6f012080ac77c5291b.json
new file mode 100644
index 0000000000..39180b3b0f
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-f3e53dd531be738b881df199783a2beded3bd378038cbd6f012080ac77c5291b.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET deleted_at = NOW()\n WHERE user_id = $1 AND notification_id = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "f3e53dd531be738b881df199783a2beded3bd378038cbd6f012080ac77c5291b"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f.json b/rust/cloud-storage/documents/.sqlx/query-f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f.json
new file mode 100644
index 0000000000..c718076a09
--- /dev/null
+++ b/rust/cloud-storage/documents/.sqlx/query-f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH RECURSIVE child_projects AS (\n SELECT id FROM \"Project\" WHERE id = $1\n\n UNION ALL\n\n SELECT p.id FROM \"Project\" p\n INNER JOIN child_projects cp ON p.\"parentId\" = cp.id\n )\n SELECT id as \"entity_id!\", 'project' as \"entity_type!\" FROM child_projects\n\n UNION ALL\n\n SELECT d.id as \"entity_id!\", 'document' as \"entity_type!\" FROM \"Document\" d\n WHERE d.\"projectId\" IN (SELECT id FROM child_projects)\n\n UNION ALL\n\n SELECT c.id as \"entity_id!\", 'chat' as \"entity_type!\" FROM \"Chat\" c\n WHERE c.\"projectId\" IN (SELECT id FROM child_projects)\n\n UNION ALL\n\n SELECT et.id::text as \"entity_id!\", 'email_thread' as \"entity_type!\" FROM email_threads et\n WHERE et.project_id IN (SELECT id FROM child_projects)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "entity_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "entity_type!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null,
+ null
+ ]
+ },
+ "hash": "f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f"
+}
diff --git a/rust/cloud-storage/documents/.sqlx/query-fc034d46b4247730fc6f69c8dc5070f2c9776b5c6dca78b7927a0e2d2d8306ed.json b/rust/cloud-storage/documents/.sqlx/query-fc034d46b4247730fc6f69c8dc5070f2c9776b5c6dca78b7927a0e2d2d8306ed.json
deleted file mode 100644
index ebd34825d8..0000000000
--- a/rust/cloud-storage/documents/.sqlx/query-fc034d46b4247730fc6f69c8dc5070f2c9776b5c6dca78b7927a0e2d2d8306ed.json
+++ /dev/null
@@ -1,31 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO \"UserItemAccess\" (\n \"id\", \"user_id\", \"item_id\", \"item_type\", \"access_level\",\n \"granted_from_channel_id\", \"created_at\", \"updated_at\"\n )\n VALUES ($1, $2, $3, $4, $5, $6, NOW(), NOW())\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Uuid",
- "Text",
- "Text",
- "Text",
- {
- "Custom": {
- "name": "\"AccessLevel\"",
- "kind": {
- "Enum": [
- "view",
- "comment",
- "edit",
- "owner"
- ]
- }
- }
- },
- "Uuid"
- ]
- },
- "nullable": []
- },
- "hash": "fc034d46b4247730fc6f69c8dc5070f2c9776b5c6dca78b7927a0e2d2d8306ed"
-}
diff --git a/rust/cloud-storage/documents/Cargo.toml b/rust/cloud-storage/documents/Cargo.toml
index 51c508a636..8085d6b9fa 100644
--- a/rust/cloud-storage/documents/Cargo.toml
+++ b/rust/cloud-storage/documents/Cargo.toml
@@ -26,8 +26,15 @@ axum = [
]
default = ["ai_tools", "axum", "inbound", "outbound", "ports"]
inbound = ["axum", "ports"]
-outbound = ["dep:aws-sdk-s3", "dep:base64", "dep:hex", "dep:sqlx", "ports"]
-ports = ["dep:tokio"]
+outbound = [
+ "dep:aws-sdk-s3",
+ "dep:base64",
+ "dep:entity_access_db_utils",
+ "dep:hex",
+ "dep:sqlx",
+ "ports",
+]
+ports = ["dep:entity_access_management", "dep:tokio"]
[dependencies]
# Core
@@ -46,13 +53,18 @@ connection = { path = "../connection", default-features = false, features = [
] }
document_sub_type = { path = "../document_sub_type" }
entity_access = { path = "../entity_access" }
+entity_access_management = { path = "../entity_access_management", default-features = false, features = [
+ "outbound",
+ "ports",
+], optional = true }
macro_aws_config = { path = "../macro_aws_config", features = ["s3"] }
macro_user_id = { path = "../macro_user_id" }
macro_uuid = { path = "../macro_uuid" }
model = { path = "../model" }
-s3_key = { path = "../s3_key" }
+model-entity = { path = "../model-entity" }
models_permissions = { path = "../models_permissions" }
models_properties = { path = "../models_properties" }
+s3_key = { path = "../s3_key" }
# Async runtime (for ports)
tokio = { workspace = true, optional = true }
@@ -68,6 +80,7 @@ utoipa = { workspace = true, optional = true }
aws-sdk-s3 = { workspace = true, optional = true }
base64 = { workspace = true, optional = true }
cloudfront_sign = { workspace = true }
+entity_access_db_utils = { path = "../entity_access_db_utils", optional = true }
futures = { workspace = true }
hex = { workspace = true, optional = true }
sqlx = { workspace = true, optional = true }
diff --git a/rust/cloud-storage/documents/examples/documents_toolset.rs b/rust/cloud-storage/documents/examples/documents_toolset.rs
index 1ba24de8e2..6420af5169 100644
--- a/rust/cloud-storage/documents/examples/documents_toolset.rs
+++ b/rust/cloud-storage/documents/examples/documents_toolset.rs
@@ -90,6 +90,41 @@ impl TaskPropertiesPort for NoOpTaskProperties {
}
}
+/// No-op entity access management service (not needed for toolset example).
+#[derive(Clone)]
+struct NoOpEntityAccessManagementService;
+
+impl entity_access_management::domain::ports::EntityAccessManagementService
+ for NoOpEntityAccessManagementService
+{
+ async fn add_entity_to_project(
+ &self,
+ _entity_id: &uuid::Uuid,
+ _entity_type: model_entity::EntityType,
+ _project_id: &uuid::Uuid,
+ ) -> Result<(), entity_access_management::domain::models::EntityAccessManagementError> {
+ Ok(())
+ }
+
+ async fn remove_entity_from_project(
+ &self,
+ _entity_id: &uuid::Uuid,
+ _entity_type: model_entity::EntityType,
+ _old_project_id: &uuid::Uuid,
+ ) -> Result<(), entity_access_management::domain::models::EntityAccessManagementError> {
+ Ok(())
+ }
+
+ async fn move_project(
+ &self,
+ _project_id: &uuid::Uuid,
+ _old_project_id: Option<&uuid::Uuid>,
+ _new_project_id: Option<&uuid::Uuid>,
+ ) -> Result<(), entity_access_management::domain::models::EntityAccessManagementError> {
+ Ok(())
+ }
+}
+
/// The prompt to use in the example.
const PROMPT: &str = "You are an assistant that helps users explore, create and manage their documents. Use the available tools to create and read documents.";
@@ -153,6 +188,7 @@ async fn main() {
s3_upload_adapter,
NoOpTaskProperties,
NoOpConnectionService,
+ NoOpEntityAccessManagementService,
);
let lexical_client = LexicalClient::new(sync_service_auth_key, lexical_service_url);
diff --git a/rust/cloud-storage/documents/fixtures/documents_test_data.sql b/rust/cloud-storage/documents/fixtures/documents_test_data.sql
index edf687f4d9..ac8064c316 100644
--- a/rust/cloud-storage/documents/fixtures/documents_test_data.sql
+++ b/rust/cloud-storage/documents/fixtures/documents_test_data.sql
@@ -29,7 +29,7 @@ INSERT INTO
INSERT INTO
public."Document" ("id", "name", "fileType", "owner") (
SELECT
- 'document-one',
+ 'd0000000-0000-0000-0000-000000000001',
'test_document_name',
'txt',
@@ -39,7 +39,7 @@ INSERT INTO
public."DocumentInstance" ("revisionName", "documentId", "sha") (
SELECT
'test_document_name',
- 'document-one',
+ 'd0000000-0000-0000-0000-000000000001',
'sha-one'
);
@@ -53,7 +53,7 @@ INSERT INTO
INSERT INTO
public."Document" ("id", "name", "fileType", "owner") (
SELECT
- 'document-two',
+ 'd0000000-0000-0000-0000-000000000002',
'test_document_name',
'pdf',
@@ -63,13 +63,13 @@ INSERT INTO
public."DocumentBom" ("revisionName", "documentId") (
SELECT
'test_document_name',
- 'document-two'
+ 'd0000000-0000-0000-0000-000000000002'
);
INSERT INTO
public."Project" ("id", "name", "userId") (
SELECT
- 'new-project',
+ 'd0000000-0000-0000-0000-100000000001',
'test_project_name',
);
@@ -95,15 +95,15 @@ INSERT INTO public."team_user" ("user_id", "team_id", "team_role")
VALUES ('macro|[email protected]', 'a0000000-0000-0000-0000-000000000001', 'member');
-- Owner access for document-one (used in share_with_team tests)
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level", "created_at", "updated_at")
- VALUES ('b0000000-0000-0000-0000-000000000001', 'macro|[email protected]', 'document-one', 'document', 'owner', NOW(), NOW());
+INSERT INTO public.entity_access (entity_id, entity_type, source_id, source_type, access_level)
+ VALUES ('d0000000-0000-0000-0000-000000000001', 'document', 'macro|[email protected]', 'user', 'owner');
-- Share permissions for document-one
INSERT INTO public."SharePermission" ("id", "isPublic", "publicAccessLevel", "createdAt", "updatedAt")
(SELECT 'sp-doc-one', true, 'read', NOW(), NOW());
INSERT INTO public."DocumentPermission" ("documentId", "sharePermissionId")
- (SELECT 'document-one', 'sp-doc-one');
+ (SELECT 'd0000000-0000-0000-0000-000000000001', 'sp-doc-one');
-- Channel and participants for channel share permission tests
INSERT INTO comms_channels (id, name, channel_type, owner_id) VALUES
@@ -119,4 +119,4 @@ INSERT INTO public."SharePermission" ("id", "isPublic", "createdAt", "updatedAt"
(SELECT 'sp-doc-two', false, NOW(), NOW());
INSERT INTO public."DocumentPermission" ("documentId", "sharePermissionId")
- (SELECT 'document-two', 'sp-doc-two');
+ (SELECT 'd0000000-0000-0000-0000-000000000002', 'sp-doc-two');
diff --git a/rust/cloud-storage/documents/src/domain/service.rs b/rust/cloud-storage/documents/src/domain/service.rs
index 4ea8d26248..97cf541bb4 100644
--- a/rust/cloud-storage/documents/src/domain/service.rs
+++ b/rust/cloud-storage/documents/src/domain/service.rs
@@ -3,6 +3,8 @@
#[cfg(test)]
mod tests;
+use entity_access_management::domain::ports::EntityAccessManagementService;
+use model_entity::EntityType;
use std::borrow::Cow;
use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};
@@ -42,6 +44,7 @@ pub struct DocumentServiceImpl<
U: PresignedUploadUrlPort,
T: TaskPropertiesPort,
C: ConnectionService,
+ Eam: EntityAccessManagementService,
> {
repo: R,
cloudfront_config: CloudFrontConfig,
@@ -49,10 +52,17 @@ pub struct DocumentServiceImpl<
upload_url_service: U,
task_properties_service: T,
connection_service: C,
+ #[allow(dead_code)]
+ entity_access_management_service: Eam,
}
-impl<R: DocumentRepo, U: PresignedUploadUrlPort, T: TaskPropertiesPort, C: ConnectionService>
- DocumentServiceImpl<R, U, T, C>
+impl<
+ R: DocumentRepo,
+ U: PresignedUploadUrlPort,
+ T: TaskPropertiesPort,
+ C: ConnectionService,
+ Eam: EntityAccessManagementService,
+> DocumentServiceImpl<R, U, T, C, Eam>
{
/// Create a new document service.
pub fn new(
@@ -62,6 +72,7 @@ impl<R: DocumentRepo, U: PresignedUploadUrlPort, T: TaskPropertiesPort, C: Conne
upload_url_service: U,
task_properties_service: T,
connection_service: C,
+ entity_access_management_service: Eam,
) -> Self {
Self {
repo,
@@ -70,6 +81,7 @@ impl<R: DocumentRepo, U: PresignedUploadUrlPort, T: TaskPropertiesPort, C: Conne
upload_url_service,
task_properties_service,
connection_service,
+ entity_access_management_service,
}
}
@@ -277,8 +289,13 @@ impl<R: DocumentRepo, U: PresignedUploadUrlPort, T: TaskPropertiesPort, C: Conne
}
}
-impl<R: DocumentRepo, U: PresignedUploadUrlPort, T: TaskPropertiesPort, C: ConnectionService>
- DocumentService for DocumentServiceImpl<R, U, T, C>
+impl<
+ R: DocumentRepo,
+ U: PresignedUploadUrlPort,
+ T: TaskPropertiesPort,
+ C: ConnectionService,
+ Eam: EntityAccessManagementService,
+> DocumentService for DocumentServiceImpl<R, U, T, C, Eam>
{
#[tracing::instrument(err, skip(self))]
async fn get_document(
@@ -552,6 +569,13 @@ impl<R: DocumentRepo, U: PresignedUploadUrlPort, T: TaskPropertiesPort, C: Conne
// Update project modified timestamp
if let Some(project_id) = &project_id {
let project_id_str = project_id.to_string();
+ let document_uuid =
+ uuid::Uuid::parse_str(&document_response_metadata.document_id).unwrap();
+ let _ = self
+ .entity_access_management_service
+ .add_entity_to_project(&document_uuid, EntityType::Document, project_id)
+ .await.inspect_err(|e| tracing::error!(error=?e, project_id=?project_id, "unable to update entity access for project"));
+ // Update project
let _ = self.repo.update_project_modified(&project_id_str).await.inspect_err(
|e| tracing::error!(error=?e, project_id=?project_id, "unable to update project modified date"),
);
@@ -661,14 +685,26 @@ impl<R: DocumentRepo, U: PresignedUploadUrlPort, T: TaskPropertiesPort, C: Conne
if let Some(old_project_id) = &document_context.project_id
&& !old_project_id.is_empty()
{
- let _ = self.repo.update_project_modified(old_project_id).await.inspect_err(
+ let old_project_id = uuid::Uuid::parse_str(old_project_id).unwrap();
+ let document_uuid = uuid::Uuid::parse_str(&document_context.document_id).unwrap();
+ let _ = self
+ .entity_access_management_service
+ .add_entity_to_project(&document_uuid, EntityType::Document, &old_project_id)
+ .await.inspect_err(|e| tracing::error!(error=?e, project_id=?old_project_id, "unable to update entity access for project"));
+ let _ = self.repo.update_project_modified(&old_project_id.to_string()).await.inspect_err(
|e| tracing::error!(error=?e, project_id=?old_project_id, "unable to update project modified date"),
);
}
if let Some(project_id) = &args.project_id
&& !project_id.is_empty()
{
- let _ = self.repo.update_project_modified(project_id).await.inspect_err(
+ let project_id = uuid::Uuid::parse_str(project_id).unwrap();
+ let document_uuid = uuid::Uuid::parse_str(&document_context.document_id).unwrap();
+ let _ = self
+ .entity_access_management_service
+ .add_entity_to_project(&document_uuid, EntityType::Document, &project_id)
+ .await.inspect_err(|e| tracing::error!(error=?e, project_id=?project_id, "unable to update entity access for project"));
+ let _ = self.repo.update_project_modified(&project_id.to_string()).await.inspect_err(
|e| tracing::error!(error=?e, project_id=?project_id, "unable to update project modified date"),
);
}
diff --git a/rust/cloud-storage/documents/src/outbound/pg_document_repo.rs b/rust/cloud-storage/documents/src/outbound/pg_document_repo.rs
index 64823beec3..07311bed60 100644
--- a/rust/cloud-storage/documents/src/outbound/pg_document_repo.rs
+++ b/rust/cloud-storage/documents/src/outbound/pg_document_repo.rs
@@ -445,8 +445,16 @@ impl DocumentRepo for PgDocumentRepo {
create::insert_history(&mut transaction, &document_id, &user_id, created_at).await?;
}
- // Insert user item access (Owner level)
- create::insert_item_access(&mut transaction, &document_id, &user_id).await?;
+ // Insert user entity access (Owner level)
+ entity_access_db_utils::insert_entity_access_row(
+ &mut transaction,
+ &document_id,
+ entity_access_db_utils::EntityType::Document,
+ user_id.as_ref(),
+ entity_access_db_utils::EntityAccessSourceType::User,
+ entity_access_db_utils::AccessLevel::Owner,
+ )
+ .await?;
// Link to email attachment if provided
if let Some(attachment_id) = email_attachment_id {
@@ -727,8 +735,18 @@ impl DocumentRepo for PgDocumentRepo {
// Create share permission
create::set_share_permission(&mut transaction, &document_id, file_type).await?;
- // Insert user item access (Owner level)
- create::insert_item_access(&mut transaction, &document_id, &user_id).await?;
+ // Insert user entity access (Owner level)
+
+ // Insert user entity access (Owner level)
+ entity_access_db_utils::insert_entity_access_row(
+ &mut transaction,
+ &document_id,
+ entity_access_db_utils::EntityType::Document,
+ user_id.as_ref(),
+ entity_access_db_utils::EntityAccessSourceType::User,
+ entity_access_db_utils::AccessLevel::Owner,
+ )
+ .await?;
// Insert user history
let now = chrono::Utc::now();
diff --git a/rust/cloud-storage/documents/src/outbound/pg_document_repo/create.rs b/rust/cloud-storage/documents/src/outbound/pg_document_repo/create.rs
index 84dad7592c..de7b21b7ba 100644
--- a/rust/cloud-storage/documents/src/outbound/pg_document_repo/create.rs
+++ b/rust/cloud-storage/documents/src/outbound/pg_document_repo/create.rs
@@ -1,5 +1,4 @@
use document_sub_type::DocumentSubType;
-use entity_access::domain::models::AccessLevel;
use macro_user_id::user_id::MacroUserIdStr;
use model::document::VersionIDWithTimeStamps;
use model_file_type::FileType;
@@ -197,32 +196,3 @@ pub async fn insert_history<'a>(
Ok(())
}
-
-/// Inserts user item access
-#[tracing::instrument(skip(transaction), err)]
-pub async fn insert_item_access<'a>(
- transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
- document_id: &uuid::Uuid,
- user_id: &MacroUserIdStr<'a>,
-) -> Result<(), sqlx::Error> {
- let access_id = macro_uuid::generate_uuid_v7();
- sqlx::query!(
- r#"
- INSERT INTO "UserItemAccess" (
- "id", "user_id", "item_id", "item_type", "access_level",
- "granted_from_channel_id", "created_at", "updated_at"
- )
- VALUES ($1, $2, $3, $4, $5, $6, NOW(), NOW())
- "#,
- access_id,
- user_id.as_ref(),
- &document_id.to_string(),
- "document",
- AccessLevel::Owner as _,
- None::<uuid::Uuid>,
- )
- .execute(transaction.as_mut())
- .await?;
-
- Ok(())
-}
diff --git a/rust/cloud-storage/documents/src/outbound/pg_document_repo/edit.rs b/rust/cloud-storage/documents/src/outbound/pg_document_repo/edit.rs
index a01aeedcbc..93d8cf6910 100644
--- a/rust/cloud-storage/documents/src/outbound/pg_document_repo/edit.rs
+++ b/rust/cloud-storage/documents/src/outbound/pg_document_repo/edit.rs
@@ -1,5 +1,6 @@
//! SQL operations for editing document metadata and share permissions.
+use model_entity::EntityType;
use models_permissions::share_permission::UpdateSharePermissionRequestV2;
use models_permissions::share_permission::channel_share_permission::UpdateOperation;
use sqlx::{Postgres, Transaction};
@@ -82,10 +83,12 @@ pub(super) async fn update_share_permission(
// Handle channel share permission changes
if let Some(channel_perms) = &share_permission.channel_share_permissions {
- update_channel_share_permissions(
+ update_channel_share_permissions(transaction, &share_permission_id, channel_perms).await?;
+
+ entity_access_db_utils::update_entity_access_channel_share_permissions(
transaction,
- document_id,
- &share_permission_id,
+ &macro_uuid::string_to_uuid(document_id).unwrap(),
+ EntityType::Document,
channel_perms,
)
.await?;
@@ -174,11 +177,9 @@ async fn update_share_permission_row(
Ok(())
}
-/// Update channel share permissions (add/replace/remove) and ensure UserItemAccess rows
-/// are created for all active channel participants.
+/// Update channel share permissions (add/replace/remove)
async fn update_channel_share_permissions(
transaction: &mut Transaction<'_, Postgres>,
- document_id: &str,
share_permission_id: &str,
channel_perms: &[models_permissions::share_permission::channel_share_permission::UpdateChannelSharePermission],
) -> Result<(), sqlx::Error> {
@@ -236,51 +237,6 @@ async fn update_channel_share_permissions(
)
.execute(transaction.as_mut())
.await?;
-
- // Upsert UserItemAccess rows for all active participants of the upserted channels.
- // This ensures that even if the comms_service's update_channel_share_permission sees
- // the CSP already exists and returns early, the UserItemAccess rows still get created.
- let channel_uuids: Vec<uuid::Uuid> = upsert_channel_ids
- .iter()
- .filter_map(|id| uuid::Uuid::parse_str(id).ok())
- .collect();
-
- if !channel_uuids.is_empty() {
- sqlx::query!(
- r#"
- INSERT INTO "UserItemAccess" (
- "id",
- "user_id",
- "item_id",
- "item_type",
- "access_level",
- "granted_from_channel_id",
- "created_at",
- "updated_at"
- )
- SELECT
- gen_random_uuid(),
- cp.user_id,
- $1,
- 'document',
- 'view'::"AccessLevel",
- cp.channel_id,
- NOW(),
- NOW()
- FROM comms_channel_participants cp
- WHERE cp.channel_id = ANY($2::uuid[])
- AND cp.left_at IS NULL
- ON CONFLICT ("user_id", "item_id", "item_type", "granted_from_channel_id")
- DO UPDATE SET
- "access_level" = EXCLUDED."access_level",
- "updated_at" = NOW()
- "#,
- document_id,
- &channel_uuids,
- )
- .execute(transaction.as_mut())
- .await?;
- }
}
Ok(())
diff --git a/rust/cloud-storage/documents/src/outbound/pg_document_repo/share.rs b/rust/cloud-storage/documents/src/outbound/pg_document_repo/share.rs
index f60c7251eb..fb44fe5aea 100644
--- a/rust/cloud-storage/documents/src/outbound/pg_document_repo/share.rs
+++ b/rust/cloud-storage/documents/src/outbound/pg_document_repo/share.rs
@@ -1,15 +1,8 @@
+use entity_access_db_utils::AccessLevel;
use sqlx::PgPool;
use uuid::Uuid;
/// Share a document with all members of the given user's team.
-///
-/// Finds team members via the `team_user` join table, then bulk-inserts
-/// `UserItemAccess` rows with `comment` access, a NULL
-/// `granted_from_channel_id`, and the originating `granted_from_team_id`.
-/// Skips users who already have a direct
-/// (non-channel) access row so existing permissions (e.g. the owner's
-/// `owner` row) are never downgraded. Channel-granted rows are left
-/// untouched and may coexist.
#[tracing::instrument(err, skip(pool))]
pub async fn share_with_team(
pool: &PgPool,
@@ -33,61 +26,18 @@ pub async fn share_with_team(
return Ok(());
};
- // Find all users on the same team.
- let team_members: Vec<String> = sqlx::query_scalar!(
- r#"
- SELECT user_id
- FROM team_user
- WHERE team_id = $1
- "#,
- team_id,
- )
- .fetch_all(pool)
- .await?;
-
- if team_members.is_empty() {
- return Ok(());
- }
-
- let ids: Vec<Uuid> = team_members
- .iter()
- .map(|_| macro_uuid::generate_uuid_v7())
- .collect();
+ let document_uuid = macro_uuid::string_to_uuid(document_id)
+ .map_err(|e| sqlx::Error::Protocol(e.to_string()))?;
- // Insert comment access for team members who don't already have access.
- // Uses WHERE NOT EXISTS instead of ON CONFLICT because the unique index
- // includes granted_from_channel_id which can be NULL, and PostgreSQL
- // treats NULLs as distinct in unique indexes.
sqlx::query!(
r#"
- INSERT INTO "UserItemAccess" (
- "id", "user_id", "item_id", "item_type", "access_level",
- "granted_from_channel_id", "granted_from_team_id",
- "created_at", "updated_at"
- )
- SELECT
- u.id,
- u.user_id,
- $1 AS item_id,
- 'document' AS item_type,
- 'comment' AS access_level,
- NULL AS granted_from_channel_id,
- $4 AS granted_from_team_id,
- NOW() AS created_at,
- NOW() AS updated_at
- FROM UNNEST($2::uuid[], $3::text[]) AS u(id, user_id)
- WHERE NOT EXISTS (
- SELECT 1 FROM "UserItemAccess" uia
- WHERE uia."user_id" = u.user_id
- AND uia."item_id" = $1
- AND uia."item_type" = 'document'
- AND uia."granted_from_channel_id" IS NULL
- )
+ INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)
+ VALUES ($1, 'document', $2, 'team', $3)
+ ON CONFLICT DO NOTHING
"#,
- document_id,
- &ids,
- &team_members,
- team_id,
+ &document_uuid,
+ &team_id.to_string(),
+ AccessLevel::Comment as _,
)
.execute(pool)
.await?;
diff --git a/rust/cloud-storage/documents/src/outbound/pg_document_repo/tests.rs b/rust/cloud-storage/documents/src/outbound/pg_document_repo/tests.rs
index ae0e06abcc..dc9910a055 100644
--- a/rust/cloud-storage/documents/src/outbound/pg_document_repo/tests.rs
+++ b/rust/cloud-storage/documents/src/outbound/pg_document_repo/tests.rs
@@ -18,8 +18,11 @@ async fn test_get_document_metadata(pool: Pool<Postgres>) {
let repo = PgDocumentRepo::new(pool);
// Document exists
- let metadata = repo.get_document_metadata("document-one").await.unwrap();
- assert_eq!(metadata.document_id, "document-one");
+ let metadata = repo
+ .get_document_metadata("d0000000-0000-0000-0000-000000000001")
+ .await
+ .unwrap();
+ assert_eq!(metadata.document_id, "d0000000-0000-0000-0000-000000000001");
assert_eq!(metadata.document_name, "test_document_name");
assert_eq!(metadata.owner.as_ref(), "macro|[email protected]");
assert_eq!(metadata.document_version_id, 1);
@@ -37,8 +40,11 @@ async fn test_get_document_metadata(pool: Pool<Postgres>) {
async fn test_get_basic_document(pool: Pool<Postgres>) {
let repo = PgDocumentRepo::new(pool);
- let basic = repo.get_basic_document("document-one").await.unwrap();
- assert_eq!(basic.document_id, "document-one");
+ let basic = repo
+ .get_basic_document("d0000000-0000-0000-0000-000000000001")
+ .await
+ .unwrap();
+ assert_eq!(basic.document_id, "d0000000-0000-0000-0000-000000000001");
assert_eq!(basic.document_name, "test_document_name");
assert_eq!(basic.owner.as_ref(), "macro|[email protected]");
assert_eq!(basic.file_type, Some("txt".to_string()));
@@ -55,12 +61,14 @@ async fn test_get_basic_document(pool: Pool<Postgres>) {
async fn test_soft_delete_document(pool: Pool<Postgres>) {
let repo = PgDocumentRepo::new(pool.clone());
- repo.soft_delete_document("document-one").await.unwrap();
+ repo.soft_delete_document("d0000000-0000-0000-0000-000000000001")
+ .await
+ .unwrap();
// Verify deleted_at is set
let row = sqlx::query!(
r#"SELECT "deletedAt"::timestamptz as deleted_at FROM "Document" WHERE id = $1"#,
- "document-one"
+ "d0000000-0000-0000-0000-000000000001"
)
.fetch_one(&pool)
.await
@@ -76,7 +84,7 @@ async fn test_get_latest_document_version_id(pool: Pool<Postgres>) {
let repo = PgDocumentRepo::new(pool);
let (version_id, _uploaded) = repo
- .get_latest_document_version_id("document-one")
+ .get_latest_document_version_id("d0000000-0000-0000-0000-000000000001")
.await
.unwrap();
assert_eq!(version_id, 1);
@@ -89,7 +97,10 @@ async fn test_get_latest_document_version_id(pool: Pool<Postgres>) {
async fn test_get_document_version_id(pool: Pool<Postgres>) {
let repo = PgDocumentRepo::new(pool);
- let (version_id, _uploaded) = repo.get_document_version_id("document-one").await.unwrap();
+ let (version_id, _uploaded) = repo
+ .get_document_version_id("d0000000-0000-0000-0000-000000000001")
+ .await
+ .unwrap();
assert_eq!(version_id, 1);
}
@@ -102,7 +113,10 @@ async fn test_get_user_view_location(pool: Pool<Postgres>) {
// No view location exists
let location = repo
- .get_user_view_location("macro|[email protected]", "document-one")
+ .get_user_view_location(
+ "d0000000-0000-0000-0000-000000000001",
+ )
.await
.unwrap();
assert!(location.is_none());
@@ -116,7 +130,7 @@ async fn test_edit_document_name(pool: Pool<Postgres>) {
let repo = PgDocumentRepo::new(pool.clone());
repo.edit_document(EditDocumentRepoArgs {
- document_id: "document-one".to_string(),
+ document_id: "d0000000-0000-0000-0000-000000000001".to_string(),
document_name: Some("new-name".to_string()),
project_id: None,
share_permission: None,
@@ -125,7 +139,10 @@ async fn test_edit_document_name(pool: Pool<Postgres>) {
.await
.unwrap();
- let doc = repo.get_basic_document("document-one").await.unwrap();
+ let doc = repo
+ .get_basic_document("d0000000-0000-0000-0000-000000000001")
+ .await
+ .unwrap();
assert_eq!(doc.document_name, "new-name");
}
@@ -137,7 +154,7 @@ async fn test_edit_document_set_file_type(pool: Pool<Postgres>) {
let repo = PgDocumentRepo::new(pool.clone());
repo.edit_document(EditDocumentRepoArgs {
- document_id: "document-one".to_string(),
+ document_id: "d0000000-0000-0000-0000-000000000001".to_string(),
document_name: None,
project_id: None,
share_permission: None,
@@ -146,7 +163,10 @@ async fn test_edit_document_set_file_type(pool: Pool<Postgres>) {
.await
.unwrap();
- let doc = repo.get_basic_document("document-one").await.unwrap();
+ let doc = repo
+ .get_basic_document("d0000000-0000-0000-0000-000000000001")
+ .await
+ .unwrap();
assert_eq!(doc.file_type, Some("rs".to_string()));
}
@@ -158,7 +178,7 @@ async fn test_edit_document_clear_file_type(pool: Pool<Postgres>) {
let repo = PgDocumentRepo::new(pool.clone());
repo.edit_document(EditDocumentRepoArgs {
- document_id: "document-one".to_string(),
+ document_id: "d0000000-0000-0000-0000-000000000001".to_string(),
document_name: None,
project_id: None,
share_permission: None,
@@ -167,7 +187,10 @@ async fn test_edit_document_clear_file_type(pool: Pool<Postgres>) {
.await
.unwrap();
- let doc = repo.get_basic_document("document-one").await.unwrap();
+ let doc = repo
+ .get_basic_document("d0000000-0000-0000-0000-000000000001")
+ .await
+ .unwrap();
assert_eq!(doc.file_type, None);
}
@@ -179,17 +202,23 @@ async fn test_edit_document_project(pool: Pool<Postgres>) {
let repo = PgDocumentRepo::new(pool.clone());
repo.edit_document(EditDocumentRepoArgs {
- document_id: "document-one".to_string(),
+ document_id: "d0000000-0000-0000-0000-000000000001".to_string(),
document_name: None,
- project_id: Some("new-project".to_string()),
+ project_id: Some("d0000000-0000-0000-0000-100000000001".to_string()),
share_permission: None,
file_type: None,
})
.await
.unwrap();
- let doc = repo.get_basic_document("document-one").await.unwrap();
- assert_eq!(doc.project_id, Some("new-project".to_string()));
+ let doc = repo
+ .get_basic_document("d0000000-0000-0000-0000-000000000001")
+ .await
+ .unwrap();
+ assert_eq!(
+ doc.project_id,
+ Some("d0000000-0000-0000-0000-100000000001".to_string())
+ );
}
#[sqlx::test(
@@ -201,21 +230,27 @@ async fn test_edit_document_remove_project(pool: Pool<Postgres>) {
// First set a project
repo.edit_document(EditDocumentRepoArgs {
- document_id: "document-one".to_string(),
+ document_id: "d0000000-0000-0000-0000-000000000001".to_string(),
document_name: None,
- project_id: Some("new-project".to_string()),
+ project_id: Some("d0000000-0000-0000-0000-100000000001".to_string()),
share_permission: None,
file_type: None,
})
.await
.unwrap();
- let doc = repo.get_basic_document("document-one").await.unwrap();
- assert_eq!(doc.project_id, Some("new-project".to_string()));
+ let doc = repo
+ .get_basic_document("d0000000-0000-0000-0000-000000000001")
+ .await
+ .unwrap();
+ assert_eq!(
+ doc.project_id,
+ Some("d0000000-0000-0000-0000-100000000001".to_string())
+ );
// Then remove it by passing empty string
repo.edit_document(EditDocumentRepoArgs {
- document_id: "document-one".to_string(),
+ document_id: "d0000000-0000-0000-0000-000000000001".to_string(),
document_name: None,
project_id: Some("".to_string()),
share_permission: None,
@@ -224,7 +259,10 @@ async fn test_edit_document_remove_project(pool: Pool<Postgres>) {
.await
.unwrap();
- let doc = repo.get_basic_document("document-one").await.unwrap();
+ let doc = repo
+ .get_basic_document("d0000000-0000-0000-0000-000000000001")
+ .await
+ .unwrap();
assert_eq!(doc.project_id, None);
}
@@ -236,7 +274,7 @@ async fn test_edit_document_share_permission(pool: Pool<Postgres>) {
let repo = PgDocumentRepo::new(pool.clone());
repo.edit_document(EditDocumentRepoArgs {
- document_id: "document-one".to_string(),
+ document_id: "d0000000-0000-0000-0000-000000000001".to_string(),
document_name: None,
project_id: None,
share_permission: Some(UpdateSharePermissionRequestV2 {
@@ -257,7 +295,7 @@ async fn test_edit_document_share_permission(pool: Pool<Postgres>) {
JOIN "DocumentPermission" dp ON dp."sharePermissionId" = sp.id
WHERE dp."documentId" = $1
"#,
- "document-one"
+ "d0000000-0000-0000-0000-000000000001"
)
.fetch_one(&pool)
.await
@@ -275,7 +313,7 @@ async fn test_edit_document_set_public_access_level(pool: Pool<Postgres>) {
let repo = PgDocumentRepo::new(pool.clone());
repo.edit_document(EditDocumentRepoArgs {
- document_id: "document-one".to_string(),
+ document_id: "d0000000-0000-0000-0000-000000000001".to_string(),
document_name: None,
project_id: None,
share_permission: Some(UpdateSharePermissionRequestV2 {
@@ -295,7 +333,7 @@ async fn test_edit_document_set_public_access_level(pool: Pool<Postgres>) {
JOIN "DocumentPermission" dp ON dp."sharePermissionId" = sp.id
WHERE dp."documentId" = $1
"#,
- "document-one"
+ "d0000000-0000-0000-0000-000000000001"
)
.fetch_one(&pool)
.await
@@ -312,9 +350,9 @@ async fn test_edit_document_name_and_project(pool: Pool<Postgres>) {
let repo = PgDocumentRepo::new(pool.clone());
repo.edit_document(EditDocumentRepoArgs {
- document_id: "document-one".to_string(),
+ document_id: "d0000000-0000-0000-0000-000000000001".to_string(),
document_name: Some("renamed".to_string()),
- project_id: Some("new-project".to_string()),
+ project_id: Some("d0000000-0000-0000-0000-100000000001".to_string()),
share_permission: Some(UpdateSharePermissionRequestV2 {
is_public: Some(true),
public_access_level: Some(AccessLevel::Edit),
@@ -325,9 +363,15 @@ async fn test_edit_document_name_and_project(pool: Pool<Postgres>) {
.await
.unwrap();
- let doc = repo.get_basic_document("document-one").await.unwrap();
+ let doc = repo
+ .get_basic_document("d0000000-0000-0000-0000-000000000001")
+ .await
+ .unwrap();
assert_eq!(doc.document_name, "renamed");
- assert_eq!(doc.project_id, Some("new-project".to_string()));
+ assert_eq!(
+ doc.project_id,
+ Some("d0000000-0000-0000-0000-100000000001".to_string())
+ );
let result = sqlx::query!(
r#"
@@ -336,7 +380,7 @@ async fn test_edit_document_name_and_project(pool: Pool<Postgres>) {
JOIN "DocumentPermission" dp ON dp."sharePermissionId" = sp.id
WHERE dp."documentId" = $1
"#,
- "document-one"
+ "d0000000-0000-0000-0000-000000000001"
)
.fetch_one(&pool)
.await
@@ -353,49 +397,43 @@ async fn test_edit_document_name_and_project(pool: Pool<Postgres>) {
async fn test_share_with_team_creates_access_for_team_members(pool: Pool<Postgres>) {
let repo = PgDocumentRepo::new(pool.clone());
- repo.share_with_team("macro|[email protected]", "document-one")
- .await
- .unwrap();
-
- let team_id = uuid::Uuid::parse_str("a0000000-0000-0000-0000-000000000001").unwrap();
+ repo.share_with_team(
+ "d0000000-0000-0000-0000-000000000001",
+ )
+ .await
+ .unwrap();
// All 3 team members should have access rows
+ let doc_uuid = macro_uuid::string_to_uuid("d0000000-0000-0000-0000-000000000001").unwrap();
let rows = sqlx::query!(
r#"
- SELECT "user_id", "access_level"::text as "access_level", "granted_from_team_id"
- FROM "UserItemAccess"
- WHERE "item_id" = 'document-one' AND "item_type" = 'document'
- ORDER BY "user_id"
+ SELECT source_id, access_level::text as "access_level"
+ FROM entity_access
+ WHERE entity_id = $1 AND entity_type = 'document'
+ ORDER BY source_id
"#,
+ doc_uuid,
)
.fetch_all(&pool)
.await
.unwrap();
- assert_eq!(rows.len(), 3);
+ assert_eq!(rows.len(), 2); // 1 owner and 1 team
- // Owner row should still be 'owner' (not downgraded) and have no team grant
+ // Owner row should still be 'owner' (not downgraded)
let owner_row = rows
.iter()
- .find(|r| r.user_id == "macro|[email protected]")
+ .find(|r| r.source_id == "macro|[email protected]")
.unwrap();
assert_eq!(owner_row.access_level, Some("owner".to_string()));
- assert_eq!(owner_row.granted_from_team_id, None);
- // Teammates should have 'comment' access with granted_from_team_id set
+ // Teammates should have 'comment' access
let t1 = rows
.iter()
- .find(|r| r.user_id == "macro|[email protected]")
+ .find(|r| r.source_id == "a0000000-0000-0000-0000-000000000001")
.unwrap();
assert_eq!(t1.access_level, Some("comment".to_string()));
- assert_eq!(t1.granted_from_team_id, Some(team_id));
-
- let t2 = rows
- .iter()
- .find(|r| r.user_id == "macro|[email protected]")
- .unwrap();
- assert_eq!(t2.access_level, Some("comment".to_string()));
- assert_eq!(t2.granted_from_team_id, Some(team_id));
}
#[sqlx::test(
@@ -407,17 +445,22 @@ async fn test_share_with_team_no_op_when_user_not_on_team(pool: Pool<Postgres>)
// teammate1 is on a team, but let's use a user that isn't on any team
// We'll use a non-existent user id to simulate no team membership
- repo.share_with_team("macro|[email protected]", "document-one")
- .await
- .unwrap();
+ repo.share_with_team(
+ "d0000000-0000-0000-0000-000000000001",
+ )
+ .await
+ .unwrap();
// Only the pre-existing owner row should exist
+ let doc_uuid = macro_uuid::string_to_uuid("d0000000-0000-0000-0000-000000000001").unwrap();
let count = sqlx::query_scalar!(
r#"
SELECT COUNT(*) as "count!"
- FROM "UserItemAccess"
- WHERE "item_id" = 'document-one' AND "item_type" = 'document'
+ FROM entity_access
+ WHERE entity_id = $1 AND entity_type = 'document'
"#,
+ doc_uuid,
)
.fetch_one(&pool)
.await
@@ -434,74 +477,33 @@ async fn test_share_with_team_idempotent(pool: Pool<Postgres>) {
let repo = PgDocumentRepo::new(pool.clone());
// Call twice — second call should be a no-op
- repo.share_with_team("macro|[email protected]", "document-one")
- .await
- .unwrap();
- repo.share_with_team("macro|[email protected]", "document-one")
- .await
- .unwrap();
-
- let count = sqlx::query_scalar!(
- r#"
- SELECT COUNT(*) as "count!"
- FROM "UserItemAccess"
- WHERE "item_id" = 'document-one' AND "item_type" = 'document'
- "#,
+ repo.share_with_team(
+ "d0000000-0000-0000-0000-000000000001",
)
- .fetch_one(&pool)
.await
.unwrap();
-
- assert_eq!(count, 3); // owner + 2 teammates, no duplicates
-}
-
-#[sqlx::test(
- migrator = "MACRO_DB_MIGRATIONS",
- fixtures(path = "../../../fixtures", scripts("documents_test_data"))
-)]
-async fn test_share_with_team_preserves_channel_granted_access(pool: Pool<Postgres>) {
- let repo = PgDocumentRepo::new(pool.clone());
-
- // Give teammate1 access via a channel before team sharing
- let channel_id = uuid::Uuid::now_v7();
- sqlx::query!(
- r#"
- INSERT INTO "UserItemAccess"
- ("id", "user_id", "item_id", "item_type", "access_level",
- "granted_from_channel_id", "created_at", "updated_at")
- VALUES ($1, $2, 'document-one', 'document', 'edit', $3, NOW(), NOW())
- "#,
- uuid::Uuid::now_v7(),
- channel_id,
+ repo.share_with_team(
+ "d0000000-0000-0000-0000-000000000001",
)
- .execute(&pool)
.await
.unwrap();
- repo.share_with_team("macro|[email protected]", "document-one")
- .await
- .unwrap();
-
- // teammate1 should have both: channel-granted edit + team-shared comment
- let rows = sqlx::query!(
+ let doc_uuid = macro_uuid::string_to_uuid("d0000000-0000-0000-0000-000000000001").unwrap();
+ let count = sqlx::query_scalar!(
r#"
- SELECT "access_level"::text as "access_level", "granted_from_channel_id"
- FROM "UserItemAccess"
- WHERE "item_id" = 'document-one' AND "item_type" = 'document'
- AND "user_id" = 'macro|[email protected]'
- ORDER BY "granted_from_channel_id" NULLS LAST
+ SELECT COUNT(*) as "count!"
+ FROM entity_access
+ WHERE entity_id = $1 AND entity_type = 'document'
"#,
+ doc_uuid,
)
- .fetch_all(&pool)
+ .fetch_one(&pool)
.await
.unwrap();
- assert_eq!(rows.len(), 2);
- assert_eq!(rows[0].access_level, Some("edit".to_string()));
- assert_eq!(rows[0].granted_from_channel_id, Some(channel_id));
- assert_eq!(rows[1].access_level, Some("comment".to_string()));
- assert!(rows[1].granted_from_channel_id.is_none());
+ assert_eq!(count, 2); // owner + 1 team, no duplicates
}
#[sqlx::test(
@@ -511,33 +513,37 @@ async fn test_share_with_team_preserves_channel_granted_access(pool: Pool<Postgr
async fn test_share_with_team_skips_user_with_existing_direct_access(pool: Pool<Postgres>) {
let repo = PgDocumentRepo::new(pool.clone());
- // Give teammate1 direct (non-channel) edit access before team sharing
+ let doc_uuid = macro_uuid::string_to_uuid("d0000000-0000-0000-0000-000000000001").unwrap();
+
+ // Give teammate1 direct user-sourced edit access before team sharing
sqlx::query!(
r#"
- INSERT INTO "UserItemAccess"
- ("id", "user_id", "item_id", "item_type", "access_level",
- "granted_from_channel_id", "created_at", "updated_at")
- VALUES ($1, $2, 'document-one', 'document', 'edit', NULL, NOW(), NOW())
+ INSERT INTO entity_access
+ (entity_id, entity_type, source_id, source_type, access_level)
+ VALUES ($1, 'document', 'macro|[email protected]', 'user', 'edit')
"#,
- uuid::Uuid::now_v7(),
+ doc_uuid,
)
.execute(&pool)
.await
.unwrap();
- repo.share_with_team("macro|[email protected]", "document-one")
- .await
- .unwrap();
+ repo.share_with_team(
+ "d0000000-0000-0000-0000-000000000001",
+ )
+ .await
+ .unwrap();
// teammate1 should still have just their original edit row, not a second comment row
let rows = sqlx::query!(
r#"
- SELECT "access_level"::text as "access_level"
- FROM "UserItemAccess"
- WHERE "item_id" = 'document-one' AND "item_type" = 'document'
- AND "user_id" = 'macro|[email protected]'
+ SELECT access_level::text as "access_level"
+ FROM entity_access
+ WHERE entity_id = $1 AND entity_type = 'document'
+ AND source_id = 'macro|[email protected]' AND source_type = 'user'
"#,
+ doc_uuid,
)
.fetch_all(&pool)
.await
@@ -554,48 +560,43 @@ async fn test_share_with_team_skips_user_with_existing_direct_access(pool: Pool<
async fn test_share_with_team_called_by_teammate(pool: Pool<Postgres>) {
let repo = PgDocumentRepo::new(pool.clone());
- let team_id = uuid::Uuid::parse_str("a0000000-0000-0000-0000-000000000001").unwrap();
-
// A teammate (not the owner) triggers the share — should still find the
// same team and share with all members including the owner.
- repo.share_with_team("macro|[email protected]", "document-one")
- .await
- .unwrap();
+ repo.share_with_team(
+ "d0000000-0000-0000-0000-000000000001",
+ )
+ .await
+ .unwrap();
+ let doc_uuid = macro_uuid::string_to_uuid("d0000000-0000-0000-0000-000000000001").unwrap();
let rows = sqlx::query!(
r#"
- SELECT "user_id", "access_level"::text as "access_level", "granted_from_team_id"
- FROM "UserItemAccess"
- WHERE "item_id" = 'document-one' AND "item_type" = 'document'
- ORDER BY "user_id"
+ SELECT source_id, access_level::text as "access_level"
+ FROM entity_access
+ WHERE entity_id = $1 AND entity_type = 'document'
+ ORDER BY source_id
"#,
+ doc_uuid,
)
.fetch_all(&pool)
.await
.unwrap();
// Owner keeps their original owner row (no duplicate), teammates get comment
- assert_eq!(rows.len(), 3);
+ assert_eq!(rows.len(), 2);
let owner = rows
.iter()
- .find(|r| r.user_id == "macro|[email protected]")
+ .find(|r| r.source_id == "macro|[email protected]")
.unwrap();
assert_eq!(owner.access_level, Some("owner".to_string()));
let t1 = rows
.iter()
- .find(|r| r.user_id == "macro|[email protected]")
+ .find(|r| r.source_id == "a0000000-0000-0000-0000-000000000001")
.unwrap();
assert_eq!(t1.access_level, Some("comment".to_string()));
- assert_eq!(t1.granted_from_team_id, Some(team_id));
-
- let t2 = rows
- .iter()
- .find(|r| r.user_id == "macro|[email protected]")
- .unwrap();
- assert_eq!(t2.access_level, Some("comment".to_string()));
- assert_eq!(t2.granted_from_team_id, Some(team_id));
}
#[sqlx::test(
@@ -607,7 +608,7 @@ async fn test_edit_document_channel_share_creates_user_item_access(pool: Pool<Po
let channel_id = "c0000000-0000-0000-0000-000000000001";
repo.edit_document(EditDocumentRepoArgs {
- document_id: "document-one".to_string(),
+ document_id: "d0000000-0000-0000-0000-000000000001".to_string(),
document_name: None,
project_id: None,
share_permission: Some(UpdateSharePermissionRequestV2 {
@@ -641,19 +642,20 @@ async fn test_edit_document_channel_share_creates_user_item_access(pool: Pool<Po
"Should have created one ChannelSharePermission"
);
- // Verify UserItemAccess rows were created for all 3 active channel participants
- let channel_uuid = uuid::Uuid::parse_str(channel_id).unwrap();
+ // Verify entity_access rows were created for the channel
+ let doc_uuid = macro_uuid::string_to_uuid("d0000000-0000-0000-0000-000000000001").unwrap();
let access_rows = sqlx::query!(
r#"
- SELECT "user_id", "access_level"::text as "access_level", "granted_from_channel_id"
- FROM "UserItemAccess"
- WHERE "item_id" = 'document-one'
- AND "item_type" = 'document'
- AND "granted_from_channel_id" = $1
- ORDER BY "user_id"
+ SELECT source_id, access_level::text as "access_level", source_type::text as "source_type"
+ FROM entity_access
+ WHERE entity_id = $1
+ AND entity_type = 'document'
+ AND source_id = $2
+ AND source_type = 'channel'
"#,
- channel_uuid,
+ doc_uuid,
+ channel_id,
)
.fetch_all(&pool)
.await
@@ -661,19 +663,12 @@ async fn test_edit_document_channel_share_creates_user_item_access(pool: Pool<Po
assert_eq!(
access_rows.len(),
- 3,
- "All 3 channel participants should have UserItemAccess rows"
+ 1,
+ "Channel should have one entity_access row"
);
- for row in &access_rows {
- assert_eq!(row.access_level, Some("view".to_string()));
- assert_eq!(row.granted_from_channel_id, Some(channel_uuid));
- }
-
- let user_ids: Vec<&str> = access_rows.iter().map(|r| r.user_id.as_str()).collect();
- assert!(user_ids.contains(&"macro|[email protected]"));
- assert!(user_ids.contains(&"macro|[email protected]"));
- assert!(user_ids.contains(&"macro|[email protected]"));
+ assert_eq!(access_rows[0].access_level, Some("view".to_string()));
+ assert_eq!(access_rows[0].source_id, channel_id);
}
#[sqlx::test(
@@ -683,10 +678,9 @@ async fn test_edit_document_channel_share_creates_user_item_access(pool: Pool<Po
async fn test_edit_document_channel_share_idempotent(pool: Pool<Postgres>) {
let repo = PgDocumentRepo::new(pool.clone());
let channel_id = "c0000000-0000-0000-0000-000000000001";
- let channel_uuid = uuid::Uuid::parse_str(channel_id).unwrap();
let make_args = || EditDocumentRepoArgs {
- document_id: "document-one".to_string(),
+ document_id: "d0000000-0000-0000-0000-000000000001".to_string(),
document_name: None,
project_id: None,
share_permission: Some(UpdateSharePermissionRequestV2 {
@@ -705,22 +699,25 @@ async fn test_edit_document_channel_share_idempotent(pool: Pool<Postgres>) {
repo.edit_document(make_args()).await.unwrap();
repo.edit_document(make_args()).await.unwrap();
+ let doc_uuid = macro_uuid::string_to_uuid("d0000000-0000-0000-0000-000000000001").unwrap();
let count = sqlx::query_scalar!(
r#"
SELECT COUNT(*) as "count!"
- FROM "UserItemAccess"
- WHERE "item_id" = 'document-one'
- AND "item_type" = 'document'
- AND "granted_from_channel_id" = $1
+ FROM entity_access
+ WHERE entity_id = $1
+ AND entity_type = 'document'
+ AND source_id = $2
+ AND source_type = 'channel'
"#,
- channel_uuid,
+ doc_uuid,
+ channel_id,
)
.fetch_one(&pool)
.await
.unwrap();
assert_eq!(
- count, 3,
- "Should still have exactly 3 rows after idempotent upsert"
+ count, 1,
+ "Should still have exactly 1 channel row after idempotent upsert"
);
}
diff --git a/rust/cloud-storage/email/.sqlx/query-0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d.json b/rust/cloud-storage/email/.sqlx/query-0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d.json
new file mode 100644
index 0000000000..99a3b6f452
--- /dev/null
+++ b/rust/cloud-storage/email/.sqlx/query-0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id FROM (\n -- Direct user grants\n SELECT source_id as user_id FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'user'\n\n UNION ALL\n\n -- Channel Members\n SELECT cp.user_id FROM comms_channel_participants cp\n WHERE cp.left_at IS NULL AND cp.channel_id IN (\n SELECT source_id::uuid FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'channel'\n )\n\n UNION ALL\n\n -- Team Members\n SELECT tu.user_id FROM team_user tu\n WHERE tu.team_id IN (\n SELECT source_id::uuid FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'team'\n )\n )\n \n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d"
+}
diff --git a/rust/cloud-storage/email/.sqlx/query-1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6.json b/rust/cloud-storage/email/.sqlx/query-1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6.json
new file mode 100644
index 0000000000..f97907a55c
--- /dev/null
+++ b/rust/cloud-storage/email/.sqlx/query-1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" = $1\n )\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6"
+}
diff --git a/rust/cloud-storage/email/.sqlx/query-377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08.json b/rust/cloud-storage/email/.sqlx/query-377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08.json
new file mode 100644
index 0000000000..9348d25315
--- /dev/null
+++ b/rust/cloud-storage/email/.sqlx/query-377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"DocumentPermission\" WHERE \"documentId\" = $1\n )\n \n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08"
+}
diff --git a/rust/cloud-storage/email/.sqlx/query-37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60.json b/rust/cloud-storage/email/.sqlx/query-37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60.json
new file mode 100644
index 0000000000..44d3a67e72
--- /dev/null
+++ b/rust/cloud-storage/email/.sqlx/query-37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT EXISTS (\n SELECT 1\n FROM public.email_threads t\n JOIN public.email_links l ON l.id = t.link_id\n WHERE t.id = $1::uuid\n AND l.macro_id = $2\n ) AS \"exists!\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "exists!",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60"
+}
diff --git a/rust/cloud-storage/email/.sqlx/query-5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf.json b/rust/cloud-storage/email/.sqlx/query-5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf.json
new file mode 100644
index 0000000000..514e8d9770
--- /dev/null
+++ b/rust/cloud-storage/email/.sqlx/query-5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ChatPermission\" WHERE \"chatId\" = $1\n )\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf"
+}
diff --git a/rust/cloud-storage/email/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json b/rust/cloud-storage/email/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json
new file mode 100644
index 0000000000..a110bb67c6
--- /dev/null
+++ b/rust/cloud-storage/email/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT DISTINCT cp.user_id\n FROM comms_channel_participants cp\n WHERE cp.channel_id = $1 AND cp.left_at IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8"
+}
diff --git a/rust/cloud-storage/email/.sqlx/query-7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a.json b/rust/cloud-storage/email/.sqlx/query-7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a.json
new file mode 100644
index 0000000000..655495fb29
--- /dev/null
+++ b/rust/cloud-storage/email/.sqlx/query-7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT c.id\n FROM comms_channels c\n INNER JOIN comms_channel_participants cp ON cp.channel_id = c.id\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n AND c.id = ANY($2::uuid[])\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a"
+}
diff --git a/rust/cloud-storage/email/.sqlx/query-a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24.json b/rust/cloud-storage/email/.sqlx/query-a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24.json
new file mode 100644
index 0000000000..f214362a1f
--- /dev/null
+++ b/rust/cloud-storage/email/.sqlx/query-a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'call'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE id in (\n SELECT share_permission_id\n FROM calls\n WHERE id = $1\n UNION ALL\n SELECT share_permission_id\n FROM call_records\n WHERE id = $1\n LIMIT 1\n )\n AND \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24"
+}
diff --git a/rust/cloud-storage/email/.sqlx/query-ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10.json b/rust/cloud-storage/email/.sqlx/query-ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10.json
new file mode 100644
index 0000000000..b0fb258d2d
--- /dev/null
+++ b/rust/cloud-storage/email/.sqlx/query-ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT l.macro_id\n FROM email_threads et\n JOIN email_links l ON et.link_id = l.id\n WHERE et.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "macro_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10"
+}
diff --git a/rust/cloud-storage/email/.sqlx/query-b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815.json b/rust/cloud-storage/email/.sqlx/query-b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815.json
new file mode 100644
index 0000000000..aa74e2b98b
--- /dev/null
+++ b/rust/cloud-storage/email/.sqlx/query-b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'email_thread'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"EmailThreadPermission\" WHERE \"threadId\" = $3\n )\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815"
+}
diff --git a/rust/cloud-storage/email/.sqlx/query-b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524.json b/rust/cloud-storage/email/.sqlx/query-b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524.json
new file mode 100644
index 0000000000..be13d76b25
--- /dev/null
+++ b/rust/cloud-storage/email/.sqlx/query-b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'document'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"DocumentPermission\" WHERE \"documentId\" = $3\n ) \n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524"
+}
diff --git a/rust/cloud-storage/email/.sqlx/query-b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157.json b/rust/cloud-storage/email/.sqlx/query-b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157.json
new file mode 100644
index 0000000000..d560cb7eb3
--- /dev/null
+++ b/rust/cloud-storage/email/.sqlx/query-b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'chat'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ChatPermission\" WHERE \"chatId\" = $3\n )\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157"
+}
diff --git a/rust/cloud-storage/email/.sqlx/query-bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682.json b/rust/cloud-storage/email/.sqlx/query-bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682.json
new file mode 100644
index 0000000000..3ed3f3db5e
--- /dev/null
+++ b/rust/cloud-storage/email/.sqlx/query-bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE id in (SELECT share_permission_id\n FROM calls\n WHERE id = $1\n UNION ALL\n SELECT share_permission_id\n FROM call_records\n WHERE id = $1\n LIMIT 1)\n AND \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682"
+}
diff --git a/rust/cloud-storage/email/.sqlx/query-c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476.json b/rust/cloud-storage/email/.sqlx/query-c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476.json
new file mode 100644
index 0000000000..1216b39a3c
--- /dev/null
+++ b/rust/cloud-storage/email/.sqlx/query-c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'project'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" = $3\n )\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476"
+}
diff --git a/rust/cloud-storage/email/.sqlx/query-cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580.json b/rust/cloud-storage/email/.sqlx/query-cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580.json
new file mode 100644
index 0000000000..ddcaf87146
--- /dev/null
+++ b/rust/cloud-storage/email/.sqlx/query-cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT cp.channel_id::text FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "channel_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580"
+}
diff --git a/rust/cloud-storage/email/.sqlx/query-e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437.json b/rust/cloud-storage/email/.sqlx/query-e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437.json
new file mode 100644
index 0000000000..3ac1b029f6
--- /dev/null
+++ b/rust/cloud-storage/email/.sqlx/query-e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"EmailThreadPermission\" WHERE \"threadId\" = $1\n )\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437"
+}
diff --git a/rust/cloud-storage/email/fixtures/email_shared_threads.sql b/rust/cloud-storage/email/fixtures/email_shared_threads.sql
index 955b80e3c2..521addcf18 100644
--- a/rust/cloud-storage/email/fixtures/email_shared_threads.sql
+++ b/rust/cloud-storage/email/fixtures/email_shared_threads.sql
@@ -1,6 +1,6 @@
-- Fixture for testing shared email thread filtering.
-- Builds on email_dynamic_query fixture by adding a second user with their own
--- email threads, some of which are shared with user1 via UserItemAccess or project membership.
+-- email threads, some of which are shared with user1 via entity_access or project membership.
-- == Second user ==
INSERT INTO "macro_user" (id, username, email, stripe_customer_id)
@@ -27,15 +27,15 @@ VALUES
-- == Shared project: user1 has access to this project owned by user2 ==
INSERT INTO "Project" (id, name, "userId", "createdAt", "updatedAt")
-VALUES ('proj-cccc-cccc-cccc-cccccccccccc', 'Shared Project', 'macro|[email protected]', NOW(), NOW());
+VALUES ('cccccccc-cccc-cccc-cccc-cccccccccccc', 'Shared Project', 'macro|[email protected]', NOW(), NOW());
-- Grant user1 access to the shared project
-INSERT INTO "UserItemAccess" (id, user_id, item_id, item_type, access_level, created_at, updated_at)
-VALUES ('acc00000-0000-0000-0000-000000000001', 'macro|[email protected]', 'proj-cccc-cccc-cccc-cccccccccccc', 'project', 'view', NOW(), NOW());
+INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)
+VALUES ('cccccccc-cccc-cccc-cccc-cccccccccccc'::uuid, 'project', 'macro|[email protected]', 'user', 'view');
-- == User2's email threads ==
--- Thread 101: Directly shared with user1 via UserItemAccess (not in any shared project)
+-- Thread 101: Directly shared with user1 via entity_access (not in any shared project)
INSERT INTO email_threads (
id, provider_id, link_id, inbox_visible, is_read,
latest_inbound_message_ts, latest_outbound_message_ts, latest_non_spam_message_ts,
@@ -54,7 +54,7 @@ INSERT INTO email_threads (
VALUES
('20000102-0000-0000-0000-000000000102', 'shared_thread2', 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
true, false, '2024-02-02 10:00:00+00', NULL, '2024-02-02 10:00:00+00', NOW(), NOW(),
- 'proj-cccc-cccc-cccc-cccccccccccc');
+ 'cccccccc-cccc-cccc-cccc-cccccccccccc');
-- Thread 103: User2's thread NOT shared with user1 (should never appear)
INSERT INTO email_threads (
@@ -67,8 +67,12 @@ VALUES
true, false, '2024-02-03 10:00:00+00', NULL, '2024-02-03 10:00:00+00', NOW(), NOW());
-- Direct share: thread 101 shared with user1
-INSERT INTO "UserItemAccess" (id, user_id, item_id, item_type, access_level, created_at, updated_at)
-VALUES ('acc00000-0000-0000-0000-000000000002', 'macro|[email protected]', '20000101-0000-0000-0000-000000000101', 'thread', 'view', NOW(), NOW());
+INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)
+VALUES ('20000101-0000-0000-0000-000000000101'::uuid, 'thread', 'macro|[email protected]', 'user', 'view');
+
+-- Denormalized row: thread 102 inherits access from the shared project
+INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level, granted_from_project_id)
+VALUES ('20000102-0000-0000-0000-000000000102'::uuid, 'thread', 'macro|[email protected]', 'user', 'view', 'cccccccc-cccc-cccc-cccc-cccccccccccc');
-- == Messages for user2's threads ==
INSERT INTO email_messages (
diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/query.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/query.rs
index 10926efc21..2f631e1b7b 100644
--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/query.rs
+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/dynamic/query.rs
@@ -136,35 +136,32 @@ fn build_query(
let mut builder = if needs_shared_cte {
let mut b = sqlx::QueryBuilder::new(
r#"
- WITH RECURSIVE ProjectHierarchy AS (
- SELECT p.id, uia.access_level
- FROM "Project" p
- JOIN "UserItemAccess" uia ON p.id = uia.item_id AND uia.item_type = 'project'
- WHERE uia.user_id = "#,
+ WITH user_source_ids AS (
+ SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp
+ WHERE cp.user_id = "#,
);
b.push_bind(params.user_id.clone());
b.push(
- r#" AND p."deletedAt" IS NULL
+ r#" AND cp.left_at IS NULL
UNION ALL
- SELECT p.id, ph.access_level
- FROM "Project" p
- JOIN ProjectHierarchy ph ON p."parentId" = ph.id
- WHERE p."deletedAt" IS NULL
- ),
- SharedEmailThreads AS (
- SELECT item_id::uuid AS thread_id
- FROM "UserItemAccess"
- WHERE user_id = "#,
+ SELECT t.team_id::text FROM team_user t
+ WHERE t.user_id = "#,
+ );
+ b.push_bind(params.user_id.clone());
+ b.push(
+ r#"
+ UNION ALL
+ SELECT "#,
);
b.push_bind(params.user_id.clone());
b.push(
- r#" AND item_type = 'thread'
- UNION
- -- Find threads living in accessible projects.
- -- project_id is text, ProjectHierarchy.id is uuid, so cast to text for comparison.
- SELECT t.id AS thread_id
- FROM email_threads t
- WHERE t.project_id = ANY(ARRAY(SELECT id::text FROM ProjectHierarchy))
+ r#"
+ ),
+ SharedEmailThreads AS (
+ SELECT entity_id AS thread_id
+ FROM entity_access
+ WHERE source_id = ANY(SELECT source_id FROM user_source_ids)
+ AND entity_type = 'thread'
)
"#,
);
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-03a323aefdba22727c6789b28d90d7200e795a4591812dab4c4e7718c5512055.json b/rust/cloud-storage/entity_access/.sqlx/query-03a323aefdba22727c6789b28d90d7200e795a4591812dab4c4e7718c5512055.json
deleted file mode 100644
index 83caec4173..0000000000
--- a/rust/cloud-storage/entity_access/.sqlx/query-03a323aefdba22727c6789b28d90d7200e795a4591812dab4c4e7718c5512055.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE project_hierarchy AS (\n SELECT p.id as project_id\n FROM email_threads t\n JOIN \"Project\" p ON t.project_id = p.id AND p.\"deletedAt\" IS NULL\n WHERE t.id = $1\n UNION ALL\n SELECT parent.id as project_id\n FROM project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n SELECT DISTINCT user_id FROM \"UserItemAccess\"\n WHERE item_id IN (\n SELECT $2\n UNION\n SELECT project_id FROM project_hierarchy\n )\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "user_id",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Uuid",
- "Text"
- ]
- },
- "nullable": [
- false
- ]
- },
- "hash": "03a323aefdba22727c6789b28d90d7200e795a4591812dab4c4e7718c5512055"
-}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d.json b/rust/cloud-storage/entity_access/.sqlx/query-0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d.json
new file mode 100644
index 0000000000..99a3b6f452
--- /dev/null
+++ b/rust/cloud-storage/entity_access/.sqlx/query-0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id FROM (\n -- Direct user grants\n SELECT source_id as user_id FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'user'\n\n UNION ALL\n\n -- Channel Members\n SELECT cp.user_id FROM comms_channel_participants cp\n WHERE cp.left_at IS NULL AND cp.channel_id IN (\n SELECT source_id::uuid FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'channel'\n )\n\n UNION ALL\n\n -- Team Members\n SELECT tu.user_id FROM team_user tu\n WHERE tu.team_id IN (\n SELECT source_id::uuid FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'team'\n )\n )\n \n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d"
+}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6.json b/rust/cloud-storage/entity_access/.sqlx/query-1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6.json
new file mode 100644
index 0000000000..f97907a55c
--- /dev/null
+++ b/rust/cloud-storage/entity_access/.sqlx/query-1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" = $1\n )\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6"
+}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08.json b/rust/cloud-storage/entity_access/.sqlx/query-377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08.json
new file mode 100644
index 0000000000..9348d25315
--- /dev/null
+++ b/rust/cloud-storage/entity_access/.sqlx/query-377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"DocumentPermission\" WHERE \"documentId\" = $1\n )\n \n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08"
+}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-3a7be99469ed150e0506efa786b672198a6d3419c6bd5548418520cd3e6a8e95.json b/rust/cloud-storage/entity_access/.sqlx/query-3a7be99469ed150e0506efa786b672198a6d3419c6bd5548418520cd3e6a8e95.json
deleted file mode 100644
index 60bfee0647..0000000000
--- a/rust/cloud-storage/entity_access/.sqlx/query-3a7be99469ed150e0506efa786b672198a6d3419c6bd5548418520cd3e6a8e95.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE project_hierarchy AS (\n SELECT p.id as project_id\n FROM \"Document\" d\n JOIN \"Project\" p ON d.\"projectId\" = p.id AND p.\"deletedAt\" IS NULL\n WHERE d.id = $1 AND d.\"deletedAt\" IS NULL\n UNION ALL\n SELECT parent.id as project_id\n FROM project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n SELECT access_level FROM (\n -- Source 1: Cast the AccessLevel enum to text.\n SELECT access_level::text FROM \"UserItemAccess\"\n WHERE user_id = $2 AND item_id IN (\n SELECT $1\n UNION\n SELECT project_id FROM project_hierarchy\n )\n UNION ALL\n -- Source 2: Select the publicAccessLevel (which is already text).\n SELECT \"publicAccessLevel\" as access_level\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true AND \"publicAccessLevel\" IS NOT NULL AND id IN (\n SELECT \"sharePermissionId\" FROM \"DocumentPermission\" WHERE \"documentId\" = $1\n UNION\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" IN (SELECT project_id FROM project_hierarchy)\n )\n ) as all_levels\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "access_level",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text"
- ]
- },
- "nullable": [
- null
- ]
- },
- "hash": "3a7be99469ed150e0506efa786b672198a6d3419c6bd5548418520cd3e6a8e95"
-}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-4afa79ca95bdbcebe9d3de7ebb204636419e6cf89e650a8716c40ab2e588aa5b.json b/rust/cloud-storage/entity_access/.sqlx/query-4afa79ca95bdbcebe9d3de7ebb204636419e6cf89e650a8716c40ab2e588aa5b.json
deleted file mode 100644
index 58618b2697..0000000000
--- a/rust/cloud-storage/entity_access/.sqlx/query-4afa79ca95bdbcebe9d3de7ebb204636419e6cf89e650a8716c40ab2e588aa5b.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n -- CTE to recursively find all parent projects, starting from the given project.\n WITH RECURSIVE project_hierarchy AS (\n -- Base case: Start with the project ID provided.\n SELECT id as project_id\n FROM \"Project\"\n WHERE id = $1 AND \"deletedAt\" IS NULL\n UNION ALL\n -- Recursive case: Find the parent of the project from the previous step.\n SELECT parent.id as project_id\n FROM project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n -- The subquery now gathers all levels as plain text.\n SELECT access_level FROM (\n -- Source 1: Cast the AccessLevel enum to text.\n SELECT access_level::text FROM \"UserItemAccess\"\n WHERE user_id = $2 AND item_id IN (\n -- The hierarchy CTE includes the starting project, so this is all we need.\n SELECT project_id FROM project_hierarchy\n )\n UNION ALL\n -- Source 2: Select the publicAccessLevel (which is already text).\n SELECT \"publicAccessLevel\" as access_level\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true AND \"publicAccessLevel\" IS NOT NULL AND id IN (\n -- We only need to check ProjectPermission for the items in the hierarchy.\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\"\n WHERE \"projectId\" IN (SELECT project_id FROM project_hierarchy)\n )\n ) as all_levels\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "access_level",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text"
- ]
- },
- "nullable": [
- null
- ]
- },
- "hash": "4afa79ca95bdbcebe9d3de7ebb204636419e6cf89e650a8716c40ab2e588aa5b"
-}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-4c695b011d49ba7d5fce4b309875ed952dc386ac760444d7883c5a76718f15be.json b/rust/cloud-storage/entity_access/.sqlx/query-4c695b011d49ba7d5fce4b309875ed952dc386ac760444d7883c5a76718f15be.json
deleted file mode 100644
index 524cc25ec7..0000000000
--- a/rust/cloud-storage/entity_access/.sqlx/query-4c695b011d49ba7d5fce4b309875ed952dc386ac760444d7883c5a76718f15be.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE project_hierarchy AS (\n SELECT p.id as project_id\n FROM \"Chat\" c\n JOIN \"Project\" p ON c.\"projectId\" = p.id AND p.\"deletedAt\" IS NULL\n WHERE c.id = $1 AND c.\"deletedAt\" IS NULL\n UNION ALL\n SELECT parent.id as project_id\n FROM project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n SELECT access_level FROM (\n -- Source 1: Cast the AccessLevel enum to text.\n SELECT access_level::text FROM \"UserItemAccess\"\n WHERE user_id = $2 AND item_id IN (\n SELECT $1 -- The chat itself\n UNION\n SELECT project_id FROM project_hierarchy -- All parent projects\n )\n UNION ALL\n -- Source 2: Select the publicAccessLevel (which is already text).\n SELECT \"publicAccessLevel\" as access_level\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true AND \"publicAccessLevel\" IS NOT NULL AND id IN (\n SELECT \"sharePermissionId\" FROM \"ChatPermission\" WHERE \"chatId\" = $1\n UNION\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" IN (SELECT project_id FROM project_hierarchy)\n )\n ) as all_levels\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "access_level",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text"
- ]
- },
- "nullable": [
- null
- ]
- },
- "hash": "4c695b011d49ba7d5fce4b309875ed952dc386ac760444d7883c5a76718f15be"
-}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-54e3755d63a676a7fa70da77321e618032f0130c73eb6b0ae985f07c5c6c448b.json b/rust/cloud-storage/entity_access/.sqlx/query-54e3755d63a676a7fa70da77321e618032f0130c73eb6b0ae985f07c5c6c448b.json
deleted file mode 100644
index 03a8dbf6bb..0000000000
--- a/rust/cloud-storage/entity_access/.sqlx/query-54e3755d63a676a7fa70da77321e618032f0130c73eb6b0ae985f07c5c6c448b.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE project_hierarchy AS (\n SELECT p.id as project_id\n FROM \"Chat\" c\n JOIN \"Project\" p ON c.\"projectId\" = p.id AND p.\"deletedAt\" IS NULL\n WHERE c.id = $1 AND c.\"deletedAt\" IS NULL\n UNION ALL\n SELECT parent.id as project_id\n FROM project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n SELECT DISTINCT user_id FROM \"UserItemAccess\"\n WHERE item_id IN (\n SELECT $1\n UNION\n SELECT project_id FROM project_hierarchy\n )\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "user_id",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false
- ]
- },
- "hash": "54e3755d63a676a7fa70da77321e618032f0130c73eb6b0ae985f07c5c6c448b"
-}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf.json b/rust/cloud-storage/entity_access/.sqlx/query-5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf.json
new file mode 100644
index 0000000000..514e8d9770
--- /dev/null
+++ b/rust/cloud-storage/entity_access/.sqlx/query-5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ChatPermission\" WHERE \"chatId\" = $1\n )\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf"
+}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-79d3bc72e6f424765706f7deea426379ae49cbd70dd122daedd95343618b9ac6.json b/rust/cloud-storage/entity_access/.sqlx/query-79d3bc72e6f424765706f7deea426379ae49cbd70dd122daedd95343618b9ac6.json
deleted file mode 100644
index 2bde15938f..0000000000
--- a/rust/cloud-storage/entity_access/.sqlx/query-79d3bc72e6f424765706f7deea426379ae49cbd70dd122daedd95343618b9ac6.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE project_hierarchy AS (\n SELECT id as project_id\n FROM \"Project\"\n WHERE id = $1 AND \"deletedAt\" IS NULL\n UNION ALL\n SELECT parent.id as project_id\n FROM project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n SELECT DISTINCT user_id FROM \"UserItemAccess\"\n WHERE item_id IN (\n SELECT project_id FROM project_hierarchy\n )\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "user_id",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false
- ]
- },
- "hash": "79d3bc72e6f424765706f7deea426379ae49cbd70dd122daedd95343618b9ac6"
-}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-96d853b887f2e6d7aac6b15ddd2b71a8d8900d2ef30047da7ca1a5940503b6d0.json b/rust/cloud-storage/entity_access/.sqlx/query-96d853b887f2e6d7aac6b15ddd2b71a8d8900d2ef30047da7ca1a5940503b6d0.json
deleted file mode 100644
index e42c9f2009..0000000000
--- a/rust/cloud-storage/entity_access/.sqlx/query-96d853b887f2e6d7aac6b15ddd2b71a8d8900d2ef30047da7ca1a5940503b6d0.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE project_hierarchy AS (\n SELECT p.id as project_id\n FROM \"Document\" d\n JOIN \"Project\" p ON d.\"projectId\" = p.id AND p.\"deletedAt\" IS NULL\n WHERE d.id = $1 AND d.\"deletedAt\" IS NULL\n UNION ALL\n SELECT parent.id as project_id\n FROM project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n SELECT DISTINCT user_id FROM \"UserItemAccess\"\n WHERE item_id IN (\n SELECT $1\n UNION\n SELECT project_id FROM project_hierarchy\n )\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "user_id",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- false
- ]
- },
- "hash": "96d853b887f2e6d7aac6b15ddd2b71a8d8900d2ef30047da7ca1a5940503b6d0"
-}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24.json b/rust/cloud-storage/entity_access/.sqlx/query-a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24.json
new file mode 100644
index 0000000000..f214362a1f
--- /dev/null
+++ b/rust/cloud-storage/entity_access/.sqlx/query-a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'call'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE id in (\n SELECT share_permission_id\n FROM calls\n WHERE id = $1\n UNION ALL\n SELECT share_permission_id\n FROM call_records\n WHERE id = $1\n LIMIT 1\n )\n AND \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24"
+}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10.json b/rust/cloud-storage/entity_access/.sqlx/query-ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10.json
new file mode 100644
index 0000000000..b0fb258d2d
--- /dev/null
+++ b/rust/cloud-storage/entity_access/.sqlx/query-ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT l.macro_id\n FROM email_threads et\n JOIN email_links l ON et.link_id = l.id\n WHERE et.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "macro_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10"
+}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815.json b/rust/cloud-storage/entity_access/.sqlx/query-b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815.json
new file mode 100644
index 0000000000..aa74e2b98b
--- /dev/null
+++ b/rust/cloud-storage/entity_access/.sqlx/query-b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'email_thread'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"EmailThreadPermission\" WHERE \"threadId\" = $3\n )\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815"
+}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524.json b/rust/cloud-storage/entity_access/.sqlx/query-b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524.json
new file mode 100644
index 0000000000..be13d76b25
--- /dev/null
+++ b/rust/cloud-storage/entity_access/.sqlx/query-b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'document'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"DocumentPermission\" WHERE \"documentId\" = $3\n ) \n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524"
+}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157.json b/rust/cloud-storage/entity_access/.sqlx/query-b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157.json
new file mode 100644
index 0000000000..d560cb7eb3
--- /dev/null
+++ b/rust/cloud-storage/entity_access/.sqlx/query-b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'chat'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ChatPermission\" WHERE \"chatId\" = $3\n )\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157"
+}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682.json b/rust/cloud-storage/entity_access/.sqlx/query-bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682.json
new file mode 100644
index 0000000000..3ed3f3db5e
--- /dev/null
+++ b/rust/cloud-storage/entity_access/.sqlx/query-bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE id in (SELECT share_permission_id\n FROM calls\n WHERE id = $1\n UNION ALL\n SELECT share_permission_id\n FROM call_records\n WHERE id = $1\n LIMIT 1)\n AND \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682"
+}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476.json b/rust/cloud-storage/entity_access/.sqlx/query-c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476.json
new file mode 100644
index 0000000000..1216b39a3c
--- /dev/null
+++ b/rust/cloud-storage/entity_access/.sqlx/query-c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'project'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" = $3\n )\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476"
+}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580.json b/rust/cloud-storage/entity_access/.sqlx/query-cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580.json
new file mode 100644
index 0000000000..ddcaf87146
--- /dev/null
+++ b/rust/cloud-storage/entity_access/.sqlx/query-cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT cp.channel_id::text FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "channel_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580"
+}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-d536db3ccfb32aee9a48227e2b15d2404023ea24b62c159466c95899d76e29ed.json b/rust/cloud-storage/entity_access/.sqlx/query-d536db3ccfb32aee9a48227e2b15d2404023ea24b62c159466c95899d76e29ed.json
deleted file mode 100644
index 6ef8856744..0000000000
--- a/rust/cloud-storage/entity_access/.sqlx/query-d536db3ccfb32aee9a48227e2b15d2404023ea24b62c159466c95899d76e29ed.json
+++ /dev/null
@@ -1,24 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE project_hierarchy AS (\n SELECT p.id as project_id\n FROM email_threads t\n JOIN \"Project\" p ON t.project_id = p.id AND p.\"deletedAt\" IS NULL\n WHERE t.id = $1\n UNION ALL\n SELECT parent.id as project_id\n FROM project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n SELECT access_level FROM (\n -- Source 1: Cast the AccessLevel enum to text.\n SELECT access_level::text FROM \"UserItemAccess\"\n WHERE user_id = $3 AND item_id IN (\n SELECT $2 -- The thread ID as text\n UNION\n SELECT project_id FROM project_hierarchy -- All parent projects\n )\n UNION ALL\n -- Source 2: Select the publicAccessLevel (which is already text).\n SELECT \"publicAccessLevel\" as access_level\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true AND \"publicAccessLevel\" IS NOT NULL AND id IN (\n SELECT \"sharePermissionId\" FROM \"EmailThreadPermission\" WHERE \"threadId\" = $2\n UNION\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" IN (SELECT project_id FROM project_hierarchy)\n )\n ) as all_levels\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "access_level",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Uuid",
- "Text",
- "Text"
- ]
- },
- "nullable": [
- null
- ]
- },
- "hash": "d536db3ccfb32aee9a48227e2b15d2404023ea24b62c159466c95899d76e29ed"
-}
diff --git a/rust/cloud-storage/entity_access/.sqlx/query-e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437.json b/rust/cloud-storage/entity_access/.sqlx/query-e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437.json
new file mode 100644
index 0000000000..3ac1b029f6
--- /dev/null
+++ b/rust/cloud-storage/entity_access/.sqlx/query-e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"EmailThreadPermission\" WHERE \"threadId\" = $1\n )\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437"
+}
diff --git a/rust/cloud-storage/entity_access/Cargo.toml b/rust/cloud-storage/entity_access/Cargo.toml
index 0f3305e8f5..3f40af3e22 100644
--- a/rust/cloud-storage/entity_access/Cargo.toml
+++ b/rust/cloud-storage/entity_access/Cargo.toml
@@ -1,36 +1,36 @@
[package]
-name = "entity_access"
-version = "0.1.0"
edition = "2024"
+name = "entity_access"
publish = false
+version = "0.1.0"
[features]
-default = ["ports", "inbound", "outbound", "axum"]
-ports = ["dep:tokio"]
-inbound = ["axum", "ports"]
-outbound = ["ports"]
-schema = ["dep:utoipa"]
axum = [
- "dep:axum",
- "dep:axum-extra",
- "dep:model",
- "dep:model_user",
- "dep:model-error-response",
+ "dep:axum",
+ "dep:axum-extra",
+ "dep:model",
+ "dep:model-error-response",
+ "dep:model_user",
]
+default = ["axum", "inbound", "outbound", "ports"]
+inbound = ["axum", "ports"]
+outbound = ["dep:cached", "ports"]
+ports = ["dep:tokio"]
+schema = ["dep:utoipa"]
[dependencies]
# Core
anyhow = { workspace = true }
+serde = { workspace = true }
+serde_json = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
uuid = { workspace = true }
-serde = { workspace = true }
-serde_json = { workspace = true }
# Domain models (always included)
-models_permissions = { path = "../models_permissions" }
macro_user_id = { path = "../macro_user_id" }
-model-entity = { path = "../model-entity"}
+model-entity = { path = "../model-entity" }
+models_permissions = { path = "../models_permissions" }
# Async runtime (for ports)
tokio = { workspace = true, optional = true }
@@ -39,17 +39,19 @@ tokio = { workspace = true, optional = true }
axum = { workspace = true, optional = true }
axum-extra = { workspace = true, optional = true }
model = { path = "../model", optional = true }
-model_user = { path = "../model_user", optional = true, features = ["axum"] }
model-error-response = { path = "../model-error-response", optional = true }
+model_user = { path = "../model_user", optional = true, features = ["axum"] }
# OpenAPI schema (optional)
utoipa = { workspace = true, optional = true }
# Database
+cached = { workspace = true, optional = true }
sqlx = { workspace = true }
[dev-dependencies]
+cool_asserts = "2"
+macro_db_migrator = { path = "../macro_db_migrator" }
mockall = { workspace = true }
+sqlx = { workspace = true, features = ["postgres", "runtime-tokio-rustls"] }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
-cool_asserts = "2"
-sqlx = { workspace = true, features = ["runtime-tokio-rustls", "postgres"] }
diff --git a/rust/cloud-storage/entity_access/src/domain/ports.rs b/rust/cloud-storage/entity_access/src/domain/ports.rs
index f7d939abaa..ec05fbc55b 100644
--- a/rust/cloud-storage/entity_access/src/domain/ports.rs
+++ b/rust/cloud-storage/entity_access/src/domain/ports.rs
@@ -17,9 +17,6 @@ use uuid::Uuid;
/// All methods query the database directly - no HTTP calls to external services.
pub trait AccessRepository: Clone + Send + Sync + 'static {
/// Get the highest access level a user has for a document.
- ///
- /// Considers both explicit grants (UserItemAccess) and public access
- /// (SharePermission) inherited through the project hierarchy.
fn get_document_access(
&self,
document_id: &str,
@@ -27,9 +24,6 @@ pub trait AccessRepository: Clone + Send + Sync + 'static {
) -> impl Future<Output = Result<Option<AccessLevel>, AccessError>> + Send;
/// Get the highest access level a user has for a chat.
- ///
- /// Considers both explicit grants (UserItemAccess) and public access
- /// (SharePermission) inherited through the project hierarchy.
fn get_chat_access(
&self,
chat_id: &str,
@@ -37,9 +31,6 @@ pub trait AccessRepository: Clone + Send + Sync + 'static {
) -> impl Future<Output = Result<Option<AccessLevel>, AccessError>> + Send;
/// Get the highest access level a user has for a project.
- ///
- /// Considers both explicit grants (UserItemAccess) and public access
- /// (SharePermission) inherited through the project hierarchy.
fn get_project_access(
&self,
project_id: &str,
@@ -47,15 +38,19 @@ pub trait AccessRepository: Clone + Send + Sync + 'static {
) -> impl Future<Output = Result<Option<AccessLevel>, AccessError>> + Send;
/// Get the highest access level a user has for an email thread.
- ///
- /// Considers both explicit grants (UserItemAccess) and public access
- /// (SharePermission) inherited through the project hierarchy.
fn get_thread_access(
&self,
thread_id: &str,
user_id: Option<&MacroUserId<Lowercase<'_>>>,
) -> impl Future<Output = Result<Option<AccessLevel>, AccessError>> + Send;
+ /// Get the highest access level a user has for a call.
+ fn get_call_access(
+ &self,
+ call_id: &str,
+ user_id: Option<&MacroUserId<Lowercase<'_>>>,
+ ) -> impl Future<Output = Result<Option<AccessLevel>, AccessError>> + Send;
+
/// Check if a user is a member of the specified channels.
///
/// Returns the subset of channel_ids that the user is a participant of.
@@ -78,36 +73,11 @@ pub trait AccessRepository: Clone + Send + Sync + 'static {
user_org_id: Option<i64>,
) -> impl Future<Output = Result<ChannelRoleResult, AccessError>> + Send;
- /// Get all user IDs with access to a document via `UserItemAccess`.
- ///
- /// Includes users with direct access and users with access through the project hierarchy.
- fn get_document_users(
- &self,
- document_id: &str,
- ) -> impl Future<Output = Result<Vec<MacroUserIdStr<'static>>, AccessError>> + Send;
-
- /// Get all user IDs with access to a chat via `UserItemAccess`.
- ///
- /// Includes users with direct access and users with access through the project hierarchy.
- fn get_chat_users(
+ /// Gets all the user's that have access to a given entity.
+ fn get_entity_users(
&self,
- chat_id: &str,
- ) -> impl Future<Output = Result<Vec<MacroUserIdStr<'static>>, AccessError>> + Send;
-
- /// Get all user IDs with access to a project via `UserItemAccess`.
- ///
- /// Includes users with direct access and users with access through the project hierarchy.
- fn get_project_users(
- &self,
- project_id: &str,
- ) -> impl Future<Output = Result<Vec<MacroUserIdStr<'static>>, AccessError>> + Send;
-
- /// Get all user IDs with access to an email thread via `UserItemAccess`.
- ///
- /// Includes users with direct access and users with access through the project hierarchy.
- fn get_thread_users(
- &self,
- thread_id: &str,
+ entity_id: &uuid::Uuid,
+ entity_type: EntityType,
) -> impl Future<Output = Result<Vec<MacroUserIdStr<'static>>, AccessError>> + Send;
/// Get all active participant user IDs in a channel.
@@ -201,7 +171,7 @@ pub trait EntityAccessService: Clone + Send + Sync + 'static {
/// Get all user IDs that have access to a given entity.
///
/// For Document, Chat, Project, and EmailThread: returns user IDs with direct
- /// access or inherited access through the project hierarchy via `UserItemAccess`.
+ /// access or inherited access through the project hierarchy via `entity_access`.
/// For Channel: returns active channel participants.
/// Returns `AccessError::BadRequest` for unsupported types (Team, User).
fn get_users_by_entity(
diff --git a/rust/cloud-storage/entity_access/src/domain/service.rs b/rust/cloud-storage/entity_access/src/domain/service.rs
index 4f8c7da221..fafaf0ba2b 100644
--- a/rust/cloud-storage/entity_access/src/domain/service.rs
+++ b/rust/cloud-storage/entity_access/src/domain/service.rs
@@ -35,8 +35,6 @@ where
}
/// Get access level for optimized entity types (document, chat, project, thread).
- ///
- /// These use the UserItemAccess table for efficient lookups.
async fn get_optimized_access(
&self,
entity_id: &str,
@@ -48,6 +46,7 @@ where
EntityType::Chat => self.repo.get_chat_access(entity_id, user_id).await,
EntityType::Project => self.repo.get_project_access(entity_id, user_id).await,
EntityType::EmailThread => self.repo.get_thread_access(entity_id, user_id).await,
+ EntityType::Call => self.repo.get_call_access(entity_id, user_id).await,
_ => unreachable!("Only optimized types should call this method"),
}
}
@@ -134,17 +133,12 @@ where
EntityType::Document
| EntityType::Chat
| EntityType::Project
- | EntityType::EmailThread => {
+ | EntityType::EmailThread
+ | EntityType::Call => {
self.get_optimized_access(entity_id, user_id, entity_type)
.await
}
EntityType::Channel => self.get_channel_access(entity_id, user_id).await,
- // Call access is inherited from the call's channel.
- EntityType::Call => {
- let channel_uuid = self.resolve_call_channel_id(entity_id).await?;
- self.get_channel_access(&channel_uuid.to_string(), user_id)
- .await
- }
// These entity types don't have access checks implemented yet.
EntityType::Team | EntityType::User => Ok(None),
}
@@ -196,7 +190,8 @@ where
EntityType::Document
| EntityType::Chat
| EntityType::Project
- | EntityType::EmailThread => {
+ | EntityType::EmailThread
+ | EntityType::Call => {
let access = self
.get_optimized_access(entity_id, user_id, entity_type)
.await?;
@@ -221,19 +216,6 @@ where
ChannelRoleResult::NotFound => Err(AccessError::NotFound("Channel not found")),
}
}
- EntityType::Call => {
- // Call permission is the caller's role on the call's channel.
- let channel_uuid = self.resolve_call_channel_id(entity_id).await?;
- match self
- .repo
- .get_channel_role(&channel_uuid, user_id, user_org_id)
- .await?
- {
- ChannelRoleResult::Role(role) => Ok(EntityPermission::ChannelRole { role }),
- ChannelRoleResult::NoAccess => Err(AccessError::Unauthorized),
- ChannelRoleResult::NotFound => Err(AccessError::NotFound("Channel not found")),
- }
- }
_ => Err(AccessError::BadRequest("Unsupported entity type")),
}
}
@@ -245,10 +227,16 @@ where
entity_type: EntityType,
) -> Result<Vec<MacroUserIdStr<'static>>, AccessError> {
match entity_type {
- EntityType::Document => self.repo.get_document_users(entity_id).await,
- EntityType::Chat => self.repo.get_chat_users(entity_id).await,
- EntityType::Project => self.repo.get_project_users(entity_id).await,
- EntityType::EmailThread => self.repo.get_thread_users(entity_id).await,
+ EntityType::Document
+ | EntityType::Chat
+ | EntityType::Project
+ | EntityType::EmailThread => {
+ let entity_id = Uuid::parse_str(entity_id).map_err(|_| {
+ AccessError::BadRequest("invalid entity_id for get_users_by_entity")
+ })?;
+
+ self.repo.get_entity_users(&entity_id, entity_type).await
+ }
EntityType::Channel => {
let channel_id = Uuid::parse_str(entity_id).map_err(|_| {
AccessError::BadRequest("invalid channel_id for get_users_by_entity")
diff --git a/rust/cloud-storage/entity_access/src/domain/service/test.rs b/rust/cloud-storage/entity_access/src/domain/service/test.rs
index 74644b5464..1d57f6bbc1 100644
--- a/rust/cloud-storage/entity_access/src/domain/service/test.rs
+++ b/rust/cloud-storage/entity_access/src/domain/service/test.rs
@@ -17,6 +17,7 @@ struct MockRepo {
chat_access: Arc<Mutex<Option<AccessLevel>>>,
project_access: Arc<Mutex<Option<AccessLevel>>>,
thread_access: Arc<Mutex<Option<AccessLevel>>>,
+ call_access: Arc<Mutex<Option<AccessLevel>>>,
channel_membership: Arc<Mutex<Vec<Uuid>>>,
channel_role: Arc<Mutex<ChannelRoleResult>>,
document_users: Arc<Mutex<Vec<MacroUserIdStr<'static>>>>,
@@ -34,6 +35,7 @@ impl MockRepo {
chat_access: Arc::new(Mutex::new(None)),
project_access: Arc::new(Mutex::new(None)),
thread_access: Arc::new(Mutex::new(None)),
+ call_access: Arc::new(Mutex::new(None)),
channel_membership: Arc::new(Mutex::new(vec![])),
channel_role: Arc::new(Mutex::new(ChannelRoleResult::NotFound)),
document_users: Arc::new(Mutex::new(vec![])),
@@ -65,6 +67,11 @@ impl MockRepo {
self
}
+ fn with_call_access(mut self, level: AccessLevel) -> Self {
+ self.call_access = Arc::new(Mutex::new(Some(level)));
+ self
+ }
+
fn with_channel_membership(mut self, channels: Vec<Uuid>) -> Self {
self.channel_membership = Arc::new(Mutex::new(channels));
self
@@ -146,32 +153,26 @@ impl AccessRepository for MockRepo {
Ok(*self.channel_role.lock().await)
}
- async fn get_document_users(
+ async fn get_call_access(
&self,
- _document_id: &str,
- ) -> Result<Vec<MacroUserIdStr<'static>>, AccessError> {
- Ok(self.document_users.lock().await.clone())
- }
-
- async fn get_chat_users(
- &self,
- _chat_id: &str,
- ) -> Result<Vec<MacroUserIdStr<'static>>, AccessError> {
- Ok(self.chat_users.lock().await.clone())
- }
-
- async fn get_project_users(
- &self,
- _project_id: &str,
- ) -> Result<Vec<MacroUserIdStr<'static>>, AccessError> {
- Ok(self.project_users.lock().await.clone())
+ _call_id: &str,
+ _user_id: Option<&MacroUserId<Lowercase<'_>>>,
+ ) -> Result<Option<AccessLevel>, AccessError> {
+ Ok(*self.call_access.lock().await)
}
- async fn get_thread_users(
+ async fn get_entity_users(
&self,
- _thread_id: &str,
+ _entity_id: &uuid::Uuid,
+ entity_type: EntityType,
) -> Result<Vec<MacroUserIdStr<'static>>, AccessError> {
- Ok(self.thread_users.lock().await.clone())
+ match entity_type {
+ EntityType::Document => Ok(self.document_users.lock().await.clone()),
+ EntityType::Chat => Ok(self.chat_users.lock().await.clone()),
+ EntityType::Project => Ok(self.project_users.lock().await.clone()),
+ EntityType::EmailThread => Ok(self.thread_users.lock().await.clone()),
+ _ => Err(AccessError::BadRequest("unsupported entity type")),
+ }
}
async fn get_channel_users(
@@ -924,7 +925,7 @@ async fn test_get_users_by_entity_document_returns_users() {
let service = EntityAccessServiceImpl::new(repo);
let result = service
- .get_users_by_entity("doc-1", EntityType::Document)
+ .get_users_by_entity("00000000-0000-0000-0000-000000000001", EntityType::Document)
.await
.unwrap();
@@ -939,7 +940,7 @@ async fn test_get_users_by_entity_document_returns_empty_when_no_users() {
let service = EntityAccessServiceImpl::new(repo);
let result = service
- .get_users_by_entity("doc-1", EntityType::Document)
+ .get_users_by_entity("00000000-0000-0000-0000-000000000001", EntityType::Document)
.await
.unwrap();
@@ -953,7 +954,7 @@ async fn test_get_users_by_entity_chat_returns_users() {
let service = EntityAccessServiceImpl::new(repo);
let result = service
- .get_users_by_entity("chat-1", EntityType::Chat)
+ .get_users_by_entity("00000000-0000-0000-0000-000000000002", EntityType::Chat)
.await
.unwrap();
@@ -967,7 +968,7 @@ async fn test_get_users_by_entity_chat_returns_empty_when_no_users() {
let service = EntityAccessServiceImpl::new(repo);
let result = service
- .get_users_by_entity("chat-1", EntityType::Chat)
+ .get_users_by_entity("00000000-0000-0000-0000-000000000002", EntityType::Chat)
.await
.unwrap();
@@ -985,7 +986,7 @@ async fn test_get_users_by_entity_project_returns_users() {
let service = EntityAccessServiceImpl::new(repo);
let result = service
- .get_users_by_entity("proj-1", EntityType::Project)
+ .get_users_by_entity("00000000-0000-0000-0000-000000000003", EntityType::Project)
.await
.unwrap();
@@ -1001,7 +1002,7 @@ async fn test_get_users_by_entity_project_returns_empty_when_no_users() {
let service = EntityAccessServiceImpl::new(repo);
let result = service
- .get_users_by_entity("proj-1", EntityType::Project)
+ .get_users_by_entity("00000000-0000-0000-0000-000000000003", EntityType::Project)
.await
.unwrap();
@@ -1018,7 +1019,10 @@ async fn test_get_users_by_entity_thread_returns_users() {
let service = EntityAccessServiceImpl::new(repo);
let result = service
- .get_users_by_entity("thread-1", EntityType::EmailThread)
+ .get_users_by_entity(
+ "00000000-0000-0000-0000-000000000004",
+ EntityType::EmailThread,
+ )
.await
.unwrap();
@@ -1033,7 +1037,10 @@ async fn test_get_users_by_entity_thread_returns_empty_when_no_users() {
let service = EntityAccessServiceImpl::new(repo);
let result = service
- .get_users_by_entity("thread-1", EntityType::EmailThread)
+ .get_users_by_entity(
+ "00000000-0000-0000-0000-000000000004",
+ EntityType::EmailThread,
+ )
.await
.unwrap();
@@ -1084,7 +1091,7 @@ async fn test_get_users_by_entity_document_with_single_user() {
let service = EntityAccessServiceImpl::new(repo);
let result = service
- .get_users_by_entity("doc-1", EntityType::Document)
+ .get_users_by_entity("00000000-0000-0000-0000-000000000001", EntityType::Document)
.await
.unwrap();
@@ -1101,7 +1108,7 @@ async fn test_get_users_by_entity_project_with_many_users() {
let service = EntityAccessServiceImpl::new(repo);
let result = service
- .get_users_by_entity("proj-1", EntityType::Project)
+ .get_users_by_entity("00000000-0000-0000-0000-000000000003", EntityType::Project)
.await
.unwrap();
diff --git a/rust/cloud-storage/entity_access/src/inbound/axum_extractors/call.rs b/rust/cloud-storage/entity_access/src/inbound/axum_extractors/call.rs
index 188f69f984..bf91b340e3 100644
--- a/rust/cloud-storage/entity_access/src/inbound/axum_extractors/call.rs
+++ b/rust/cloud-storage/entity_access/src/inbound/axum_extractors/call.rs
@@ -65,11 +65,7 @@ where
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
let service = <Arc<Svc>>::from_ref(state);
- let OptionalMacroUserExtractor {
- macro_user_id,
- user_context,
- ..
- } = parts
+ let OptionalMacroUserExtractor { macro_user_id, .. } = parts
.extract()
.await
.map_err(|_| ExtractorError::Internal)?;
@@ -120,16 +116,8 @@ where
return Err(ExtractorError::Unauthorized);
};
- let user_org_id = user_context.organization_id.map(i64::from);
- let channel_id_str = call_info.channel_id.to_string();
-
let permission = service
- .get_entity_permission(
- Some(&macro_user_id),
- &channel_id_str,
- EntityType::Channel,
- user_org_id,
- )
+ .get_entity_permission(Some(&macro_user_id), &call_id, EntityType::Call, None)
.await
.map_err(ExtractorError::from)?;
diff --git a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/mod.rs b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/mod.rs
index 2813ee71b8..6c19ec2fe2 100644
--- a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/mod.rs
+++ b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/mod.rs
@@ -3,23 +3,13 @@
mod queries;
use crate::domain::{
- models::{AccessError, AccessLevel, CallChannelInfo, ChannelRoleResult},
+ models::{AccessError, AccessLevel, CallChannelInfo, ChannelRoleResult, EntityType},
ports::AccessRepository,
};
use macro_user_id::{lowercased::Lowercase, user_id::MacroUserId, user_id::MacroUserIdStr};
use sqlx::PgPool;
use uuid::Uuid;
-/// Convert a list of user ID strings from the database into typed [`MacroUserIdStr`] values.
-///
-/// Invalid user IDs are silently filtered out to avoid failing the entire query
-/// due to a single malformed row.
-fn parse_user_ids(raw: Vec<String>) -> Vec<MacroUserIdStr<'static>> {
- raw.into_iter()
- .filter_map(|s| MacroUserIdStr::try_from(s).ok())
- .collect()
-}
-
/// PostgreSQL-backed implementation of [`AccessRepository`].
///
/// Contains all SQL queries directly - no external crate dependencies.
@@ -42,7 +32,16 @@ impl AccessRepository for PgAccessRepository {
document_id: &str,
user_id: Option<&MacroUserId<Lowercase<'_>>>,
) -> Result<Option<AccessLevel>, AccessError> {
- Ok(queries::document_access::get_document_access(&self.pool, document_id, user_id).await?)
+ let document_uuid = document_id
+ .parse::<Uuid>()
+ .map_err(|_| AccessError::BadRequest("Invalid document ID format"))?;
+ let source_ids = queries::get_user_source_ids(&self.pool, user_id)
+ .await
+ .map_err(|_| AccessError::Internal)?;
+ Ok(
+ queries::document_access::get_document_access(&self.pool, &document_uuid, &source_ids)
+ .await?,
+ )
}
#[tracing::instrument(err, skip(self))]
@@ -51,7 +50,13 @@ impl AccessRepository for PgAccessRepository {
chat_id: &str,
user_id: Option<&MacroUserId<Lowercase<'_>>>,
) -> Result<Option<AccessLevel>, AccessError> {
- Ok(queries::chat_access::get_chat_access(&self.pool, chat_id, user_id).await?)
+ let chat_uuid = chat_id
+ .parse::<Uuid>()
+ .map_err(|_| AccessError::BadRequest("Invalid chat ID format"))?;
+ let source_ids = queries::get_user_source_ids(&self.pool, user_id)
+ .await
+ .map_err(|_| AccessError::Internal)?;
+ Ok(queries::chat_access::get_chat_access(&self.pool, &chat_uuid, &source_ids).await?)
}
#[tracing::instrument(err, skip(self))]
@@ -60,7 +65,16 @@ impl AccessRepository for PgAccessRepository {
project_id: &str,
user_id: Option<&MacroUserId<Lowercase<'_>>>,
) -> Result<Option<AccessLevel>, AccessError> {
- Ok(queries::project_access::get_project_access(&self.pool, project_id, user_id).await?)
+ let project_uuid = project_id
+ .parse::<Uuid>()
+ .map_err(|_| AccessError::BadRequest("Invalid project ID format"))?;
+ let source_ids = queries::get_user_source_ids(&self.pool, user_id)
+ .await
+ .map_err(|_| AccessError::Internal)?;
+ Ok(
+ queries::project_access::get_project_access(&self.pool, &project_uuid, &source_ids)
+ .await?,
+ )
}
#[tracing::instrument(err, skip(self))]
@@ -69,7 +83,34 @@ impl AccessRepository for PgAccessRepository {
thread_id: &str,
user_id: Option<&MacroUserId<Lowercase<'_>>>,
) -> Result<Option<AccessLevel>, AccessError> {
- Ok(queries::thread_access::get_thread_access(&self.pool, thread_id, user_id).await?)
+ let thread_uuid = thread_id
+ .parse::<Uuid>()
+ .map_err(|_| AccessError::BadRequest("Invalid thread ID format"))?;
+ let source_ids = queries::get_user_source_ids(&self.pool, user_id)
+ .await
+ .map_err(|_| AccessError::Internal)?;
+ Ok(queries::thread_access::get_thread_access(
+ &self.pool,
+ &thread_uuid,
+ &source_ids,
+ user_id,
+ )
+ .await?)
+ }
+
+ #[tracing::instrument(err, skip(self))]
+ async fn get_call_access(
+ &self,
+ call_id: &str,
+ user_id: Option<&MacroUserId<Lowercase<'_>>>,
+ ) -> Result<Option<AccessLevel>, AccessError> {
+ let call_uuid = call_id
+ .parse::<Uuid>()
+ .map_err(|_| AccessError::BadRequest("Invalid call ID format"))?;
+ let source_ids = queries::get_user_source_ids(&self.pool, user_id)
+ .await
+ .map_err(|_| AccessError::Internal)?;
+ Ok(queries::call_access::get_call_access(&self.pool, &call_uuid, &source_ids).await?)
}
#[tracing::instrument(err, skip(self))]
@@ -103,39 +144,14 @@ impl AccessRepository for PgAccessRepository {
}
#[tracing::instrument(err, skip(self))]
- async fn get_document_users(
- &self,
- document_id: &str,
- ) -> Result<Vec<MacroUserIdStr<'static>>, AccessError> {
- let raw = queries::document_users::get_document_users(&self.pool, document_id).await?;
- Ok(parse_user_ids(raw))
- }
-
- #[tracing::instrument(err, skip(self))]
- async fn get_chat_users(
+ async fn get_entity_users(
&self,
- chat_id: &str,
- ) -> Result<Vec<MacroUserIdStr<'static>>, AccessError> {
- let raw = queries::chat_users::get_chat_users(&self.pool, chat_id).await?;
- Ok(parse_user_ids(raw))
- }
-
- #[tracing::instrument(err, skip(self))]
- async fn get_project_users(
- &self,
- project_id: &str,
- ) -> Result<Vec<MacroUserIdStr<'static>>, AccessError> {
- let raw = queries::project_users::get_project_users(&self.pool, project_id).await?;
- Ok(parse_user_ids(raw))
- }
-
- #[tracing::instrument(err, skip(self))]
- async fn get_thread_users(
- &self,
- thread_id: &str,
+ entity_id: &uuid::Uuid,
+ entity_type: EntityType,
) -> Result<Vec<MacroUserIdStr<'static>>, AccessError> {
- let raw = queries::thread_users::get_thread_users(&self.pool, thread_id).await?;
- Ok(parse_user_ids(raw))
+ queries::get_entity_users(&self.pool, entity_id, entity_type)
+ .await
+ .map_err(|_| AccessError::Internal)
}
#[tracing::instrument(err, skip(self))]
@@ -143,8 +159,9 @@ impl AccessRepository for PgAccessRepository {
&self,
channel_id: &Uuid,
) -> Result<Vec<MacroUserIdStr<'static>>, AccessError> {
- let raw = queries::channel_users::get_channel_users(&self.pool, channel_id).await?;
- Ok(parse_user_ids(raw))
+ queries::channel_users::get_channel_users(&self.pool, channel_id)
+ .await
+ .map_err(|_| AccessError::Internal)
}
#[tracing::instrument(err, skip(self))]
diff --git a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/call_access/mod.rs b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/call_access/mod.rs
new file mode 100644
index 0000000000..938f90b034
--- /dev/null
+++ b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/call_access/mod.rs
@@ -0,0 +1,84 @@
+//! Query for call access level.
+
+#[cfg(test)]
+mod test;
+
+use crate::{domain::models::AccessLevel, outbound::pg_access_repo::queries::SourceIds};
+use sqlx::PgPool;
+use std::str::FromStr;
+
+/// Get the highest access level a user has for a call.
+#[tracing::instrument(err, skip(pool, source_ids))]
+pub async fn get_call_access(
+ pool: &PgPool,
+ call_id: &uuid::Uuid,
+ source_ids: &SourceIds,
+) -> Result<Option<AccessLevel>, sqlx::Error> {
+ // Check share permission access only
+ if source_ids.0.is_empty() {
+ let access_level = sqlx::query_scalar!(
+ r#"
+ SELECT
+ "publicAccessLevel" as "access_level!"
+ FROM "SharePermission"
+ WHERE id in (SELECT share_permission_id
+ FROM calls
+ WHERE id = $1
+ UNION ALL
+ SELECT share_permission_id
+ FROM call_records
+ WHERE id = $1
+ LIMIT 1)
+ AND "isPublic" = true
+ AND "publicAccessLevel" IS NOT NULL
+ "#,
+ &call_id
+ )
+ .fetch_optional(pool)
+ .await?;
+
+ return Ok(access_level.and_then(|level| AccessLevel::from_str(&level).ok()));
+ }
+
+ let all_level_strings: Vec<Option<String>> = sqlx::query_scalar!(
+ r#"
+ SELECT access_level FROM (
+ -- Source 1: entity_access source_id match
+ SELECT
+ access_level::text FROM entity_access
+ WHERE entity_id = $1
+ AND entity_type = 'call'
+ AND source_id = ANY($2)
+
+ UNION ALL
+ -- Source 2: items share permission
+ SELECT
+ "publicAccessLevel" as "access_level!"
+ FROM "SharePermission"
+ WHERE id in (
+ SELECT share_permission_id
+ FROM calls
+ WHERE id = $1
+ UNION ALL
+ SELECT share_permission_id
+ FROM call_records
+ WHERE id = $1
+ LIMIT 1
+ )
+ AND "isPublic" = true
+ AND "publicAccessLevel" IS NOT NULL
+ )
+ "#,
+ call_id,
+ &source_ids.0,
+ )
+ .fetch_all(pool)
+ .await?;
+
+ let highest_level = all_level_strings
+ .iter()
+ .filter_map(|opt| opt.as_ref().and_then(|s| AccessLevel::from_str(s).ok()))
+ .max();
+
+ Ok(highest_level)
+}
diff --git a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/call_access/test.rs b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/call_access/test.rs
new file mode 100644
index 0000000000..9f63d7a0b0
--- /dev/null
+++ b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/call_access/test.rs
@@ -0,0 +1,257 @@
+use super::*;
+use crate::domain::models::AccessLevel;
+use macro_db_migrator::MACRO_DB_MIGRATIONS;
+use sqlx::PgPool;
+use uuid::Uuid;
+
+async fn insert_channel(pool: &PgPool, channel_id: Uuid) {
+ sqlx::query!(
+ r#"
+ INSERT INTO comms_channels (id, name, channel_type, org_id, owner_id)
+ VALUES ($1, 'test', 'public', NULL, 'owner')
+ "#,
+ channel_id
+ )
+ .execute(pool)
+ .await
+ .unwrap();
+}
+
+async fn insert_share_permission(
+ pool: &PgPool,
+ id: &str,
+ is_public: bool,
+ access_level: Option<&str>,
+) {
+ sqlx::query!(
+ r#"
+ INSERT INTO "SharePermission" (id, "isPublic", "publicAccessLevel")
+ VALUES ($1, $2, $3)
+ "#,
+ id,
+ is_public,
+ access_level,
+ )
+ .execute(pool)
+ .await
+ .unwrap();
+}
+
+async fn insert_call(pool: &PgPool, call_id: Uuid, channel_id: Uuid, share_permission_id: &str) {
+ sqlx::query!(
+ r#"
+ INSERT INTO calls (id, channel_id, room_name, created_by, share_permission_id)
+ VALUES ($1, $2, 'room', 'creator', $3)
+ "#,
+ call_id,
+ channel_id,
+ share_permission_id,
+ )
+ .execute(pool)
+ .await
+ .unwrap();
+}
+
+async fn insert_call_record(
+ pool: &PgPool,
+ call_id: Uuid,
+ channel_id: Uuid,
+ share_permission_id: &str,
+) {
+ sqlx::query!(
+ r#"
+ INSERT INTO call_records (id, channel_id, room_name, created_by, started_at, ended_at, duration_ms, share_permission_id)
+ VALUES ($1, $2, 'room', 'creator', NOW() - INTERVAL '1 hour', NOW(), 3600000, $3)
+ "#,
+ call_id,
+ channel_id,
+ share_permission_id,
+ )
+ .execute(pool)
+ .await
+ .unwrap();
+}
+
+async fn insert_entity_access(
+ pool: &PgPool,
+ entity_id: Uuid,
+ source_id: &str,
+ access_level: AccessLevel,
+) {
+ let level_str = access_level.to_string();
+ sqlx::query!(
+ r#"
+ INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)
+ VALUES ($1, 'call', $2, 'user', $3::text::"AccessLevel")
+ "#,
+ entity_id,
+ source_id,
+ level_str,
+ )
+ .execute(pool)
+ .await
+ .unwrap();
+}
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn returns_none_when_call_does_not_exist(pool: PgPool) -> anyhow::Result<()> {
+ let call_id = Uuid::new_v4();
+ let source_ids = SourceIds(vec!["macro|[email protected]".to_string()]);
+
+ let result = get_call_access(&pool, &call_id, &source_ids).await?;
+
+ assert_eq!(result, None);
+ Ok(())
+}
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn returns_none_when_no_source_ids_and_not_public(pool: PgPool) -> anyhow::Result<()> {
+ let call_id = Uuid::new_v4();
+ let channel_id = Uuid::new_v4();
+ let sp_id = Uuid::new_v4().to_string();
+
+ insert_channel(&pool, channel_id).await;
+ insert_share_permission(&pool, &sp_id, false, None).await;
+ insert_call(&pool, call_id, channel_id, &sp_id).await;
+
+ let source_ids = SourceIds(vec![]);
+
+ let result = get_call_access(&pool, &call_id, &source_ids).await?;
+
+ assert_eq!(result, None);
+ Ok(())
+}
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn returns_public_access_when_no_source_ids_and_public(pool: PgPool) -> anyhow::Result<()> {
+ let call_id = Uuid::new_v4();
+ let channel_id = Uuid::new_v4();
+ let sp_id = Uuid::new_v4().to_string();
+
+ insert_channel(&pool, channel_id).await;
+ insert_share_permission(&pool, &sp_id, true, Some("view")).await;
+ insert_call(&pool, call_id, channel_id, &sp_id).await;
+
+ let source_ids = SourceIds(vec![]);
+
+ let result = get_call_access(&pool, &call_id, &source_ids).await?;
+
+ assert_eq!(result, Some(AccessLevel::View));
+ Ok(())
+}
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn returns_direct_user_access_from_entity_access(pool: PgPool) -> anyhow::Result<()> {
+ let call_id = Uuid::new_v4();
+ let channel_id = Uuid::new_v4();
+ let sp_id = Uuid::new_v4().to_string();
+ let user_id = "macro|[email protected]";
+
+ insert_channel(&pool, channel_id).await;
+ insert_share_permission(&pool, &sp_id, false, None).await;
+ insert_call(&pool, call_id, channel_id, &sp_id).await;
+ insert_entity_access(&pool, call_id, user_id, AccessLevel::Edit).await;
+
+ let source_ids = SourceIds(vec![user_id.to_string()]);
+
+ let result = get_call_access(&pool, &call_id, &source_ids).await?;
+
+ assert_eq!(result, Some(AccessLevel::Edit));
+ Ok(())
+}
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn returns_highest_of_direct_and_public_access(pool: PgPool) -> anyhow::Result<()> {
+ let call_id = Uuid::new_v4();
+ let channel_id = Uuid::new_v4();
+ let sp_id = Uuid::new_v4().to_string();
+ let user_id = "macro|[email protected]";
+
+ insert_channel(&pool, channel_id).await;
+ insert_share_permission(&pool, &sp_id, true, Some("view")).await;
+ insert_call(&pool, call_id, channel_id, &sp_id).await;
+ insert_entity_access(&pool, call_id, user_id, AccessLevel::Edit).await;
+
+ let source_ids = SourceIds(vec![user_id.to_string()]);
+
+ let result = get_call_access(&pool, &call_id, &source_ids).await?;
+
+ assert_eq!(result, Some(AccessLevel::Edit));
+ Ok(())
+}
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn public_access_wins_when_higher_than_direct(pool: PgPool) -> anyhow::Result<()> {
+ let call_id = Uuid::new_v4();
+ let channel_id = Uuid::new_v4();
+ let sp_id = Uuid::new_v4().to_string();
+ let user_id = "macro|[email protected]";
+
+ insert_channel(&pool, channel_id).await;
+ insert_share_permission(&pool, &sp_id, true, Some("edit")).await;
+ insert_call(&pool, call_id, channel_id, &sp_id).await;
+ insert_entity_access(&pool, call_id, user_id, AccessLevel::View).await;
+
+ let source_ids = SourceIds(vec![user_id.to_string()]);
+
+ let result = get_call_access(&pool, &call_id, &source_ids).await?;
+
+ assert_eq!(result, Some(AccessLevel::Edit));
+ Ok(())
+}
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn returns_none_when_user_has_no_access(pool: PgPool) -> anyhow::Result<()> {
+ let call_id = Uuid::new_v4();
+ let channel_id = Uuid::new_v4();
+ let sp_id = Uuid::new_v4().to_string();
+
+ insert_channel(&pool, channel_id).await;
+ insert_share_permission(&pool, &sp_id, false, None).await;
+ insert_call(&pool, call_id, channel_id, &sp_id).await;
+
+ let source_ids = SourceIds(vec!["macro|[email protected]".to_string()]);
+
+ let result = get_call_access(&pool, &call_id, &source_ids).await?;
+
+ assert_eq!(result, None);
+ Ok(())
+}
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn resolves_access_from_call_records(pool: PgPool) -> anyhow::Result<()> {
+ let call_id = Uuid::new_v4();
+ let channel_id = Uuid::new_v4();
+ let sp_id = Uuid::new_v4().to_string();
+
+ insert_channel(&pool, channel_id).await;
+ insert_share_permission(&pool, &sp_id, true, Some("view")).await;
+ insert_call_record(&pool, call_id, channel_id, &sp_id).await;
+
+ let source_ids = SourceIds(vec![]);
+
+ let result = get_call_access(&pool, &call_id, &source_ids).await?;
+
+ assert_eq!(result, Some(AccessLevel::View));
+ Ok(())
+}
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn returns_owner_access_from_entity_access(pool: PgPool) -> anyhow::Result<()> {
+ let call_id = Uuid::new_v4();
+ let channel_id = Uuid::new_v4();
+ let sp_id = Uuid::new_v4().to_string();
+ let user_id = "macro|[email protected]";
+
+ insert_channel(&pool, channel_id).await;
+ insert_share_permission(&pool, &sp_id, false, None).await;
+ insert_call(&pool, call_id, channel_id, &sp_id).await;
+ insert_entity_access(&pool, call_id, user_id, AccessLevel::Owner).await;
+
+ let source_ids = SourceIds(vec![user_id.to_string()]);
+
+ let result = get_call_access(&pool, &call_id, &source_ids).await?;
+
+ assert_eq!(result, Some(AccessLevel::Owner));
+ Ok(())
+}
diff --git a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/channel_users.rs b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/channel_users.rs
index 88fad7b790..6d32af7629 100644
--- a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/channel_users.rs
+++ b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/channel_users.rs
@@ -1,5 +1,6 @@
//! Query for users in a channel via comms_channel_participants.
+use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};
use sqlx::PgPool;
use uuid::Uuid;
@@ -8,8 +9,8 @@ use uuid::Uuid;
pub async fn get_channel_users(
pool: &PgPool,
channel_id: &Uuid,
-) -> Result<Vec<String>, sqlx::Error> {
- let users: Vec<String> = sqlx::query_scalar!(
+) -> Result<Vec<MacroUserIdStr<'static>>, sqlx::Error> {
+ let users = sqlx::query_scalar!(
r#"
SELECT DISTINCT cp.user_id
FROM comms_channel_participants cp
@@ -18,7 +19,14 @@ pub async fn get_channel_users(
channel_id
)
.fetch_all(pool)
- .await?;
+ .await?
+ .into_iter()
+ .filter_map(|u| {
+ MacroUserIdStr::parse_from_str(u.as_str())
+ .ok()
+ .map(|u| u.into_owned())
+ })
+ .collect();
Ok(users)
}
diff --git a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/chat_access.rs b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/chat_access.rs
index 141cec0b33..60d07747cc 100644
--- a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/chat_access.rs
+++ b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/chat_access.rs
@@ -1,56 +1,63 @@
//! Query for chat access level.
-use crate::domain::models::AccessLevel;
-use macro_user_id::{lowercased::Lowercase, user_id::MacroUserId};
+use crate::{domain::models::AccessLevel, outbound::pg_access_repo::queries::SourceIds};
use sqlx::PgPool;
use std::str::FromStr;
/// Get the highest access level a user has for a chat.
-///
-/// Considers both explicit grants (UserItemAccess) and public access
-/// (SharePermission) inherited through the project hierarchy.
-#[tracing::instrument(err, skip(pool))]
+#[tracing::instrument(err, skip(pool, source_ids))]
pub async fn get_chat_access(
pool: &PgPool,
- chat_id: &str,
- user_id: Option<&MacroUserId<Lowercase<'_>>>,
+ chat_id: &uuid::Uuid,
+ source_ids: &SourceIds,
) -> Result<Option<AccessLevel>, sqlx::Error> {
- let user_id = user_id.map(AsRef::as_ref).unwrap_or("");
- let all_level_strings: Vec<Option<String>> = sqlx::query_scalar!(
- r#"
- WITH RECURSIVE project_hierarchy AS (
- SELECT p.id as project_id
- FROM "Chat" c
- JOIN "Project" p ON c."projectId" = p.id AND p."deletedAt" IS NULL
- WHERE c.id = $1 AND c."deletedAt" IS NULL
- UNION ALL
- SELECT parent.id as project_id
- FROM project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
+ // Check share permission access only
+ if source_ids.0.is_empty() {
+ let access_level = sqlx::query_scalar!(
+ r#"
+ SELECT
+ "publicAccessLevel" as "access_level!"
+ FROM "SharePermission"
+ WHERE "isPublic" = true
+ AND "publicAccessLevel" IS NOT NULL
+ AND id IN (
+ SELECT "sharePermissionId" FROM "ChatPermission" WHERE "chatId" = $1
)
+
+ "#,
+ &chat_id.to_string()
)
+ .fetch_optional(pool)
+ .await?;
+
+ return Ok(access_level.and_then(|level| AccessLevel::from_str(&level).ok()));
+ }
+
+ let all_level_strings: Vec<Option<String>> = sqlx::query_scalar!(
+ r#"
SELECT access_level FROM (
- -- Source 1: Cast the AccessLevel enum to text.
- SELECT access_level::text FROM "UserItemAccess"
- WHERE user_id = $2 AND item_id IN (
- SELECT $1 -- The chat itself
- UNION
- SELECT project_id FROM project_hierarchy -- All parent projects
- )
+ -- Source 1: entity_access source_id match
+ SELECT
+ access_level::text FROM entity_access
+ WHERE entity_id = $1
+ AND entity_type = 'chat'
+ AND source_id = ANY($2)
+
UNION ALL
- -- Source 2: Select the publicAccessLevel (which is already text).
- SELECT "publicAccessLevel" as access_level
+ -- Source 2: items share permission
+ SELECT
+ "publicAccessLevel" as "access_level!"
FROM "SharePermission"
- WHERE "isPublic" = true AND "publicAccessLevel" IS NOT NULL AND id IN (
- SELECT "sharePermissionId" FROM "ChatPermission" WHERE "chatId" = $1
- UNION
- SELECT "sharePermissionId" FROM "ProjectPermission" WHERE "projectId" IN (SELECT project_id FROM project_hierarchy)
+ WHERE "isPublic" = true
+ AND "publicAccessLevel" IS NOT NULL
+ AND id IN (
+ SELECT "sharePermissionId" FROM "ChatPermission" WHERE "chatId" = $3
)
- ) as all_levels
+ )
"#,
chat_id,
- user_id
+ &source_ids.0,
+ &chat_id.to_string()
)
.fetch_all(pool)
.await?;
diff --git a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/chat_users.rs b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/chat_users.rs
deleted file mode 100644
index 343359121e..0000000000
--- a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/chat_users.rs
+++ /dev/null
@@ -1,38 +0,0 @@
-//! Query for users with access to a chat via UserItemAccess.
-
-use sqlx::PgPool;
-
-/// Get all user IDs that have access to a chat via `UserItemAccess`.
-///
-/// Includes users with direct access to the chat and users with access
-/// to any parent project in the hierarchy.
-#[tracing::instrument(err, skip(pool))]
-pub async fn get_chat_users(pool: &PgPool, chat_id: &str) -> Result<Vec<String>, sqlx::Error> {
- let users: Vec<String> = sqlx::query_scalar!(
- r#"
- WITH RECURSIVE project_hierarchy AS (
- SELECT p.id as project_id
- FROM "Chat" c
- JOIN "Project" p ON c."projectId" = p.id AND p."deletedAt" IS NULL
- WHERE c.id = $1 AND c."deletedAt" IS NULL
- UNION ALL
- SELECT parent.id as project_id
- FROM project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
- )
- )
- SELECT DISTINCT user_id FROM "UserItemAccess"
- WHERE item_id IN (
- SELECT $1
- UNION
- SELECT project_id FROM project_hierarchy
- )
- "#,
- chat_id
- )
- .fetch_all(pool)
- .await?;
-
- Ok(users)
-}
diff --git a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/document_access.rs b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/document_access.rs
index 7c8fdd40fb..9be23bcac0 100644
--- a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/document_access.rs
+++ b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/document_access.rs
@@ -1,56 +1,63 @@
//! Query for document access level.
-use crate::domain::models::AccessLevel;
-use macro_user_id::{lowercased::Lowercase, user_id::MacroUserId};
+use crate::{domain::models::AccessLevel, outbound::pg_access_repo::queries::SourceIds};
use sqlx::PgPool;
use std::str::FromStr;
/// Get the highest access level a user has for a document.
-///
-/// Considers both explicit grants (UserItemAccess) and public access
-/// (SharePermission) inherited through the project hierarchy.
-#[tracing::instrument(err, skip(pool))]
+#[tracing::instrument(err, skip(pool, source_ids))]
pub async fn get_document_access(
pool: &PgPool,
- document_id: &str,
- user_id: Option<&MacroUserId<Lowercase<'_>>>,
+ document_id: &uuid::Uuid,
+ source_ids: &SourceIds,
) -> Result<Option<AccessLevel>, sqlx::Error> {
- let user_id = user_id.map(AsRef::as_ref).unwrap_or("");
- let all_level_strings: Vec<Option<String>> = sqlx::query_scalar!(
- r#"
- WITH RECURSIVE project_hierarchy AS (
- SELECT p.id as project_id
- FROM "Document" d
- JOIN "Project" p ON d."projectId" = p.id AND p."deletedAt" IS NULL
- WHERE d.id = $1 AND d."deletedAt" IS NULL
- UNION ALL
- SELECT parent.id as project_id
- FROM project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
+ // Check share permission access only
+ if source_ids.0.is_empty() {
+ let access_level = sqlx::query_scalar!(
+ r#"
+ SELECT
+ "publicAccessLevel" as "access_level!"
+ FROM "SharePermission"
+ WHERE "isPublic" = true
+ AND "publicAccessLevel" IS NOT NULL
+ AND id IN (
+ SELECT "sharePermissionId" FROM "DocumentPermission" WHERE "documentId" = $1
)
+
+ "#,
+ &document_id.to_string()
)
+ .fetch_optional(pool)
+ .await?;
+
+ return Ok(access_level.and_then(|level| AccessLevel::from_str(&level).ok()));
+ }
+
+ let all_level_strings: Vec<Option<String>> = sqlx::query_scalar!(
+ r#"
SELECT access_level FROM (
- -- Source 1: Cast the AccessLevel enum to text.
- SELECT access_level::text FROM "UserItemAccess"
- WHERE user_id = $2 AND item_id IN (
- SELECT $1
- UNION
- SELECT project_id FROM project_hierarchy
- )
+ -- Source 1: entity_access source_id match
+ SELECT
+ access_level::text FROM entity_access
+ WHERE entity_id = $1
+ AND entity_type = 'document'
+ AND source_id = ANY($2)
+
UNION ALL
- -- Source 2: Select the publicAccessLevel (which is already text).
- SELECT "publicAccessLevel" as access_level
+ -- Source 2: items share permission
+ SELECT
+ "publicAccessLevel" as "access_level!"
FROM "SharePermission"
- WHERE "isPublic" = true AND "publicAccessLevel" IS NOT NULL AND id IN (
- SELECT "sharePermissionId" FROM "DocumentPermission" WHERE "documentId" = $1
- UNION
- SELECT "sharePermissionId" FROM "ProjectPermission" WHERE "projectId" IN (SELECT project_id FROM project_hierarchy)
- )
- ) as all_levels
+ WHERE "isPublic" = true
+ AND "publicAccessLevel" IS NOT NULL
+ AND id IN (
+ SELECT "sharePermissionId" FROM "DocumentPermission" WHERE "documentId" = $3
+ )
+ )
"#,
document_id,
- user_id
+ &source_ids.0,
+ &document_id.to_string()
)
.fetch_all(pool)
.await?;
diff --git a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/document_users.rs b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/document_users.rs
deleted file mode 100644
index 6658b9e99a..0000000000
--- a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/document_users.rs
+++ /dev/null
@@ -1,41 +0,0 @@
-//! Query for users with access to a document via UserItemAccess.
-
-use sqlx::PgPool;
-
-/// Get all user IDs that have access to a document via `UserItemAccess`.
-///
-/// Includes users with direct access to the document and users with access
-/// to any parent project in the hierarchy.
-#[tracing::instrument(err, skip(pool))]
-pub async fn get_document_users(
- pool: &PgPool,
- document_id: &str,
-) -> Result<Vec<String>, sqlx::Error> {
- let users: Vec<String> = sqlx::query_scalar!(
- r#"
- WITH RECURSIVE project_hierarchy AS (
- SELECT p.id as project_id
- FROM "Document" d
- JOIN "Project" p ON d."projectId" = p.id AND p."deletedAt" IS NULL
- WHERE d.id = $1 AND d."deletedAt" IS NULL
- UNION ALL
- SELECT parent.id as project_id
- FROM project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
- )
- )
- SELECT DISTINCT user_id FROM "UserItemAccess"
- WHERE item_id IN (
- SELECT $1
- UNION
- SELECT project_id FROM project_hierarchy
- )
- "#,
- document_id
- )
- .fetch_all(pool)
- .await?;
-
- Ok(users)
-}
diff --git a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/mod.rs b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/mod.rs
index caa2cf31fd..fd0b17b288 100644
--- a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/mod.rs
+++ b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/mod.rs
@@ -2,15 +2,161 @@
//!
//! Each module contains a single query function for checking access to a specific entity type.
+#[cfg(not(test))]
+use cached::proc_macro::cached;
+
+use anyhow::Context;
+
+use macro_user_id::{
+ cowlike::CowLike,
+ lowercased::Lowercase,
+ user_id::{MacroUserId, MacroUserIdStr},
+};
+use model_entity::EntityType;
+use sqlx::{Pool, Postgres};
+
+pub mod call_access;
pub mod call_channel;
pub mod channel_membership;
pub mod channel_role;
pub mod channel_users;
pub mod chat_access;
-pub mod chat_users;
pub mod document_access;
-pub mod document_users;
pub mod project_access;
-pub mod project_users;
pub mod thread_access;
-pub mod thread_users;
+
+/// Type safety for source ids for entity_access table
+#[derive(Debug, Clone)]
+pub(in crate::outbound::pg_access_repo) struct SourceIds(pub Vec<String>);
+
+/// Grabs the users source ids for the entity access table
+/// NOTE: This could return an empty list in the event the user is not logged in and attempting to review a resource
+#[tracing::instrument(skip(pool), err)]
+#[cfg_attr(
+ not(test),
+ cached(
+ time = 30,
+ result = true,
+ key = "String",
+ convert = r#"{format!("{}", user_id.map(AsRef::as_ref).unwrap_or(""))}"#,
+ )
+)]
+pub(in crate::outbound::pg_access_repo) async fn get_user_source_ids(
+ pool: &Pool<Postgres>,
+ user_id: Option<&MacroUserId<Lowercase<'_>>>,
+) -> anyhow::Result<SourceIds> {
+ if let Some(user_id) = user_id {
+ // Fetch source IDs first
+ let source_ids = sqlx::query_scalar!(
+ r#"
+ SELECT cp.channel_id::text FROM comms_channel_participants cp
+ WHERE cp.user_id = $1 AND cp.left_at IS NULL
+ UNION ALL
+ SELECT t.team_id::text FROM team_user t
+ WHERE t.user_id = $1
+ UNION ALL
+ SELECT $1
+ "#,
+ user_id.as_ref()
+ )
+ .fetch_all(pool)
+ .await?;
+
+ let source_ids: Vec<String> = source_ids.into_iter().flatten().collect();
+
+ Ok(SourceIds(source_ids))
+ } else {
+ Ok(SourceIds(vec![]))
+ }
+}
+
+/// Grabs all user IDs with access to an entity via the entity_access table.
+#[tracing::instrument(skip(pool), err)]
+#[cfg_attr(
+ not(test),
+ cached(
+ time = 30,
+ result = true,
+ key = "String",
+ convert = r#"{format!("{}:{}", entity_type.as_ref(), entity_id)}"#
+ )
+)]
+pub(in crate::outbound::pg_access_repo) async fn get_entity_users(
+ pool: &Pool<Postgres>,
+ entity_id: &uuid::Uuid,
+ entity_type: EntityType,
+) -> anyhow::Result<Vec<MacroUserIdStr<'static>>> {
+ // because we don't store entity_access per email we need to also grab the owner of the email to append to the list
+ let mut email_owner: Vec<MacroUserIdStr> = if let EntityType::EmailThread = entity_type {
+ let owner = sqlx::query_scalar!(
+ r#"
+ SELECT l.macro_id
+ FROM email_threads et
+ JOIN email_links l ON et.link_id = l.id
+ WHERE et.id = $1
+ "#,
+ entity_id
+ )
+ .fetch_one(pool)
+ .await?;
+
+ vec![
+ MacroUserIdStr::parse_from_str(owner.as_str())
+ .context("macro user id should be valid")?
+ .into_owned(),
+ ]
+ } else {
+ vec![]
+ };
+
+ let mut users: Vec<MacroUserIdStr<'static>> = sqlx::query_scalar!(
+ r#"
+ SELECT user_id FROM (
+ -- Direct user grants
+ SELECT source_id as user_id FROM entity_access
+ WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'user'
+
+ UNION ALL
+
+ -- Channel Members
+ SELECT cp.user_id FROM comms_channel_participants cp
+ WHERE cp.left_at IS NULL AND cp.channel_id IN (
+ SELECT source_id::uuid FROM entity_access
+ WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'channel'
+ )
+
+ UNION ALL
+
+ -- Team Members
+ SELECT tu.user_id FROM team_user tu
+ WHERE tu.team_id IN (
+ SELECT source_id::uuid FROM entity_access
+ WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'team'
+ )
+ )
+
+ "#,
+ entity_id,
+ entity_type.as_ref(),
+ )
+ .fetch_all(pool)
+ .await?
+ .into_iter()
+ .filter_map(|u| {
+ u.and_then(|u| {
+ MacroUserIdStr::parse_from_str(u.as_str())
+ .ok()
+ .map(|u| u.into_owned())
+ })
+ })
+ .collect::<Vec<MacroUserIdStr<'static>>>();
+
+ // add in email owner (if applicable)
+ users.append(&mut email_owner);
+
+ Ok(users
+ .into_iter()
+ .collect::<std::collections::HashSet<_>>()
+ .into_iter()
+ .collect())
+}
diff --git a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/project_access.rs b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/project_access.rs
index 8393c38e7d..7c8a0ecaa9 100644
--- a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/project_access.rs
+++ b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/project_access.rs
@@ -1,58 +1,63 @@
//! Query for project access level.
-use crate::domain::models::AccessLevel;
-use macro_user_id::{lowercased::Lowercase, user_id::MacroUserId};
+use crate::{domain::models::AccessLevel, outbound::pg_access_repo::queries::SourceIds};
use sqlx::PgPool;
use std::str::FromStr;
/// Get the highest access level a user has for a project.
-///
-/// Considers both explicit grants (UserItemAccess) and public access
-/// (SharePermission) inherited through the project hierarchy.
-#[tracing::instrument(err, skip(pool))]
+#[tracing::instrument(err, skip(pool, source_ids))]
pub async fn get_project_access(
pool: &PgPool,
- project_id: &str,
- user_id: Option<&MacroUserId<Lowercase<'_>>>,
+ project_id: &uuid::Uuid,
+ source_ids: &SourceIds,
) -> Result<Option<AccessLevel>, sqlx::Error> {
- let user_id = user_id.map(AsRef::as_ref).unwrap_or("");
- let all_level_strings: Vec<Option<String>> = sqlx::query_scalar!(
- r#"
- -- CTE to recursively find all parent projects, starting from the given project.
- WITH RECURSIVE project_hierarchy AS (
- -- Base case: Start with the project ID provided.
- SELECT id as project_id
- FROM "Project"
- WHERE id = $1 AND "deletedAt" IS NULL
- UNION ALL
- -- Recursive case: Find the parent of the project from the previous step.
- SELECT parent.id as project_id
- FROM project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
+ // Check share permission access only
+ if source_ids.0.is_empty() {
+ let access_level = sqlx::query_scalar!(
+ r#"
+ SELECT
+ "publicAccessLevel" as "access_level!"
+ FROM "SharePermission"
+ WHERE "isPublic" = true
+ AND "publicAccessLevel" IS NOT NULL
+ AND id IN (
+ SELECT "sharePermissionId" FROM "ProjectPermission" WHERE "projectId" = $1
)
+
+ "#,
+ &project_id.to_string()
)
- -- The subquery now gathers all levels as plain text.
+ .fetch_optional(pool)
+ .await?;
+
+ return Ok(access_level.and_then(|level| AccessLevel::from_str(&level).ok()));
+ }
+
+ let all_level_strings: Vec<Option<String>> = sqlx::query_scalar!(
+ r#"
SELECT access_level FROM (
- -- Source 1: Cast the AccessLevel enum to text.
- SELECT access_level::text FROM "UserItemAccess"
- WHERE user_id = $2 AND item_id IN (
- -- The hierarchy CTE includes the starting project, so this is all we need.
- SELECT project_id FROM project_hierarchy
- )
+ -- Source 1: entity_access source_id match
+ SELECT
+ access_level::text FROM entity_access
+ WHERE entity_id = $1
+ AND entity_type = 'project'
+ AND source_id = ANY($2)
+
UNION ALL
- -- Source 2: Select the publicAccessLevel (which is already text).
- SELECT "publicAccessLevel" as access_level
+ -- Source 2: items share permission
+ SELECT
+ "publicAccessLevel" as "access_level!"
FROM "SharePermission"
- WHERE "isPublic" = true AND "publicAccessLevel" IS NOT NULL AND id IN (
- -- We only need to check ProjectPermission for the items in the hierarchy.
- SELECT "sharePermissionId" FROM "ProjectPermission"
- WHERE "projectId" IN (SELECT project_id FROM project_hierarchy)
+ WHERE "isPublic" = true
+ AND "publicAccessLevel" IS NOT NULL
+ AND id IN (
+ SELECT "sharePermissionId" FROM "ProjectPermission" WHERE "projectId" = $3
)
- ) as all_levels
+ )
"#,
project_id,
- user_id
+ &source_ids.0,
+ &project_id.to_string()
)
.fetch_all(pool)
.await?;
diff --git a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/project_users.rs b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/project_users.rs
deleted file mode 100644
index aa7df82a3c..0000000000
--- a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/project_users.rs
+++ /dev/null
@@ -1,38 +0,0 @@
-//! Query for users with access to a project via UserItemAccess.
-
-use sqlx::PgPool;
-
-/// Get all user IDs that have access to a project via `UserItemAccess`.
-///
-/// Includes users with direct access to the project and users with access
-/// to any parent project in the hierarchy.
-#[tracing::instrument(err, skip(pool))]
-pub async fn get_project_users(
- pool: &PgPool,
- project_id: &str,
-) -> Result<Vec<String>, sqlx::Error> {
- let users: Vec<String> = sqlx::query_scalar!(
- r#"
- WITH RECURSIVE project_hierarchy AS (
- SELECT id as project_id
- FROM "Project"
- WHERE id = $1 AND "deletedAt" IS NULL
- UNION ALL
- SELECT parent.id as project_id
- FROM project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
- )
- )
- SELECT DISTINCT user_id FROM "UserItemAccess"
- WHERE item_id IN (
- SELECT project_id FROM project_hierarchy
- )
- "#,
- project_id
- )
- .fetch_all(pool)
- .await?;
-
- Ok(users)
-}
diff --git a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/thread_access.rs b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/thread_access.rs
index 7a90ba98a3..796eae3d1b 100644
--- a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/thread_access.rs
+++ b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/thread_access.rs
@@ -1,25 +1,22 @@
//! Query for email thread access level.
-use crate::domain::models::AccessLevel;
+use crate::{domain::models::AccessLevel, outbound::pg_access_repo::queries::SourceIds};
use macro_user_id::{lowercased::Lowercase, user_id::MacroUserId};
use sqlx::PgPool;
use std::str::FromStr;
use uuid::Uuid;
/// Get the highest access level a user has for an email thread.
-///
-/// Considers both explicit grants (UserItemAccess) and public access
-/// (SharePermission) inherited through the project hierarchy.
-#[tracing::instrument(err, skip(pool))]
+#[tracing::instrument(err, skip(pool, source_ids))]
pub async fn get_thread_access(
pool: &PgPool,
- thread_id: &str,
+ thread_id: &Uuid,
+ source_ids: &SourceIds,
user_id: Option<&MacroUserId<Lowercase<'_>>>,
) -> Result<Option<AccessLevel>, sqlx::Error> {
- let user_id = user_id.map(AsRef::as_ref).unwrap_or("");
-
- let thread_uuid = Uuid::parse_str(thread_id).map_err(|e| sqlx::Error::Decode(Box::new(e)))?;
+ let user_id_str = user_id.map(AsRef::as_ref).unwrap_or("");
+ // Thread-specific: check if user is the thread owner via email_links
let is_owner = sqlx::query_scalar!(
r#"
SELECT EXISTS (
@@ -30,8 +27,8 @@ pub async fn get_thread_access(
AND l.macro_id = $2
) AS "exists!"
"#,
- thread_uuid,
- user_id
+ thread_id,
+ user_id_str
)
.fetch_one(pool)
.await?;
@@ -40,42 +37,53 @@ pub async fn get_thread_access(
return Ok(Some(AccessLevel::Owner));
}
- let all_level_strings: Vec<Option<String>> = sqlx::query_scalar!(
- r#"
- WITH RECURSIVE project_hierarchy AS (
- SELECT p.id as project_id
- FROM email_threads t
- JOIN "Project" p ON t.project_id = p.id AND p."deletedAt" IS NULL
- WHERE t.id = $1
- UNION ALL
- SELECT parent.id as project_id
- FROM project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
+ // Check share permission access only
+ if source_ids.0.is_empty() {
+ let access_level = sqlx::query_scalar!(
+ r#"
+ SELECT
+ "publicAccessLevel" as "access_level!"
+ FROM "SharePermission"
+ WHERE "isPublic" = true
+ AND "publicAccessLevel" IS NOT NULL
+ AND id IN (
+ SELECT "sharePermissionId" FROM "EmailThreadPermission" WHERE "threadId" = $1
)
+
+ "#,
+ &thread_id.to_string()
)
+ .fetch_optional(pool)
+ .await?;
+
+ return Ok(access_level.and_then(|level| AccessLevel::from_str(&level).ok()));
+ }
+
+ let all_level_strings: Vec<Option<String>> = sqlx::query_scalar!(
+ r#"
SELECT access_level FROM (
- -- Source 1: Cast the AccessLevel enum to text.
- SELECT access_level::text FROM "UserItemAccess"
- WHERE user_id = $3 AND item_id IN (
- SELECT $2 -- The thread ID as text
- UNION
- SELECT project_id FROM project_hierarchy -- All parent projects
- )
+ -- Source 1: entity_access source_id match
+ SELECT
+ access_level::text FROM entity_access
+ WHERE entity_id = $1
+ AND entity_type = 'email_thread'
+ AND source_id = ANY($2)
+
UNION ALL
- -- Source 2: Select the publicAccessLevel (which is already text).
- SELECT "publicAccessLevel" as access_level
+ -- Source 2: items share permission
+ SELECT
+ "publicAccessLevel" as "access_level!"
FROM "SharePermission"
- WHERE "isPublic" = true AND "publicAccessLevel" IS NOT NULL AND id IN (
- SELECT "sharePermissionId" FROM "EmailThreadPermission" WHERE "threadId" = $2
- UNION
- SELECT "sharePermissionId" FROM "ProjectPermission" WHERE "projectId" IN (SELECT project_id FROM project_hierarchy)
+ WHERE "isPublic" = true
+ AND "publicAccessLevel" IS NOT NULL
+ AND id IN (
+ SELECT "sharePermissionId" FROM "EmailThreadPermission" WHERE "threadId" = $3
)
- ) as all_levels
+ )
"#,
- thread_uuid,
thread_id,
- user_id
+ &source_ids.0,
+ &thread_id.to_string()
)
.fetch_all(pool)
.await?;
diff --git a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/thread_users.rs b/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/thread_users.rs
deleted file mode 100644
index b87f34f9e6..0000000000
--- a/rust/cloud-storage/entity_access/src/outbound/pg_access_repo/queries/thread_users.rs
+++ /dev/null
@@ -1,42 +0,0 @@
-//! Query for users with access to an email thread via UserItemAccess.
-
-use sqlx::PgPool;
-use uuid::Uuid;
-
-/// Get all user IDs that have access to an email thread via `UserItemAccess`.
-///
-/// Includes users with direct access to the thread and users with access
-/// to any parent project in the hierarchy.
-#[tracing::instrument(err, skip(pool))]
-pub async fn get_thread_users(pool: &PgPool, thread_id: &str) -> Result<Vec<String>, sqlx::Error> {
- let thread_uuid = Uuid::parse_str(thread_id).map_err(|e| sqlx::Error::Decode(Box::new(e)))?;
-
- let users: Vec<String> = sqlx::query_scalar!(
- r#"
- WITH RECURSIVE project_hierarchy AS (
- SELECT p.id as project_id
- FROM email_threads t
- JOIN "Project" p ON t.project_id = p.id AND p."deletedAt" IS NULL
- WHERE t.id = $1
- UNION ALL
- SELECT parent.id as project_id
- FROM project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
- )
- )
- SELECT DISTINCT user_id FROM "UserItemAccess"
- WHERE item_id IN (
- SELECT $2
- UNION
- SELECT project_id FROM project_hierarchy
- )
- "#,
- thread_uuid,
- thread_id
- )
- .fetch_all(pool)
- .await?;
-
- Ok(users)
-}
diff --git a/rust/cloud-storage/entity_access_db_utils/.sqlx/query-34a70ab661c087eb2c6b97d57099ac2c7ff263b9340003c319475fcafdf0356b.json b/rust/cloud-storage/entity_access_db_utils/.sqlx/query-34a70ab661c087eb2c6b97d57099ac2c7ff263b9340003c319475fcafdf0356b.json
new file mode 100644
index 0000000000..c92d9c45fc
--- /dev/null
+++ b/rust/cloud-storage/entity_access_db_utils/.sqlx/query-34a70ab661c087eb2c6b97d57099ac2c7ff263b9340003c319475fcafdf0356b.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "34a70ab661c087eb2c6b97d57099ac2c7ff263b9340003c319475fcafdf0356b"
+}
diff --git a/rust/cloud-storage/entity_access_db_utils/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json b/rust/cloud-storage/entity_access_db_utils/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json
new file mode 100644
index 0000000000..b75a3a2ff5
--- /dev/null
+++ b/rust/cloud-storage/entity_access_db_utils/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json
@@ -0,0 +1,41 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)\n VALUES ($1, $2, $3, $4, $5)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text",
+ {
+ "Custom": {
+ "name": "entity_access_source_type",
+ "kind": {
+ "Enum": [
+ "channel",
+ "team",
+ "user"
+ ]
+ }
+ }
+ },
+ {
+ "Custom": {
+ "name": "\"AccessLevel\"",
+ "kind": {
+ "Enum": [
+ "view",
+ "comment",
+ "edit",
+ "owner"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132"
+}
diff --git a/rust/cloud-storage/entity_access_db_utils/.sqlx/query-46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237.json b/rust/cloud-storage/entity_access_db_utils/.sqlx/query-46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237.json
new file mode 100644
index 0000000000..c91a76ff52
--- /dev/null
+++ b/rust/cloud-storage/entity_access_db_utils/.sqlx/query-46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2\n AND source_id = ANY($3) AND source_type = 'channel'\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237"
+}
diff --git a/rust/cloud-storage/entity_access_db_utils/.sqlx/query-5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b.json b/rust/cloud-storage/entity_access_db_utils/.sqlx/query-5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b.json
new file mode 100644
index 0000000000..ac050656e7
--- /dev/null
+++ b/rust/cloud-storage/entity_access_db_utils/.sqlx/query-5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b.json
@@ -0,0 +1,29 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)\n SELECT $1, $2, u.user_id, 'user', $3\n FROM UNNEST($4::text[]) as u(user_id)\n ON CONFLICT (entity_id, entity_type, source_id, source_type)\n WHERE granted_from_project_id IS NULL\n AND access_level != 'owner' -- this prevents us from overriding the owner user\n DO UPDATE SET access_level = EXCLUDED.access_level, updated_at = NOW()\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ {
+ "Custom": {
+ "name": "\"AccessLevel\"",
+ "kind": {
+ "Enum": [
+ "view",
+ "comment",
+ "edit",
+ "owner"
+ ]
+ }
+ }
+ },
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b"
+}
diff --git a/rust/cloud-storage/entity_access_db_utils/.sqlx/query-7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029.json b/rust/cloud-storage/entity_access_db_utils/.sqlx/query-7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029.json
new file mode 100644
index 0000000000..b7e5230b4c
--- /dev/null
+++ b/rust/cloud-storage/entity_access_db_utils/.sqlx/query-7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM entity_access\n WHERE (source_id = ANY($1) AND source_type = 'channel')\n AND (entity_id = ANY($2) OR granted_from_project_id = ANY($3))\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "UuidArray",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029"
+}
diff --git a/rust/cloud-storage/entity_access_db_utils/.sqlx/query-e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2.json b/rust/cloud-storage/entity_access_db_utils/.sqlx/query-e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2.json
new file mode 100644
index 0000000000..f47413e3dc
--- /dev/null
+++ b/rust/cloud-storage/entity_access_db_utils/.sqlx/query-e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH RECURSIVE parent_projects AS (\n -- Base case: the project itself\n SELECT id, name, \"parentId\"\n FROM \"Project\"\n WHERE id = $1\n\n UNION ALL\n\n -- Recursive case: walk up to the parent\n SELECT p.id, p.name, p.\"parentId\"\n FROM \"Project\" p\n INNER JOIN parent_projects pp ON p.id = pp.\"parentId\"\n )\n SELECT id as \"id!\"\n FROM parent_projects\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2"
+}
diff --git a/rust/cloud-storage/entity_access_db_utils/.sqlx/query-f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f.json b/rust/cloud-storage/entity_access_db_utils/.sqlx/query-f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f.json
new file mode 100644
index 0000000000..c718076a09
--- /dev/null
+++ b/rust/cloud-storage/entity_access_db_utils/.sqlx/query-f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH RECURSIVE child_projects AS (\n SELECT id FROM \"Project\" WHERE id = $1\n\n UNION ALL\n\n SELECT p.id FROM \"Project\" p\n INNER JOIN child_projects cp ON p.\"parentId\" = cp.id\n )\n SELECT id as \"entity_id!\", 'project' as \"entity_type!\" FROM child_projects\n\n UNION ALL\n\n SELECT d.id as \"entity_id!\", 'document' as \"entity_type!\" FROM \"Document\" d\n WHERE d.\"projectId\" IN (SELECT id FROM child_projects)\n\n UNION ALL\n\n SELECT c.id as \"entity_id!\", 'chat' as \"entity_type!\" FROM \"Chat\" c\n WHERE c.\"projectId\" IN (SELECT id FROM child_projects)\n\n UNION ALL\n\n SELECT et.id::text as \"entity_id!\", 'email_thread' as \"entity_type!\" FROM email_threads et\n WHERE et.project_id IN (SELECT id FROM child_projects)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "entity_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "entity_type!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null,
+ null
+ ]
+ },
+ "hash": "f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f"
+}
diff --git a/rust/cloud-storage/macro_share_permissions/Cargo.toml b/rust/cloud-storage/entity_access_db_utils/Cargo.toml
similarity index 50%
rename from rust/cloud-storage/macro_share_permissions/Cargo.toml
rename to rust/cloud-storage/entity_access_db_utils/Cargo.toml
index 62ff1f860c..edb700faec 100644
--- a/rust/cloud-storage/macro_share_permissions/Cargo.toml
+++ b/rust/cloud-storage/entity_access_db_utils/Cargo.toml
@@ -1,20 +1,24 @@
[package]
edition = "2024"
-exclude = ["examples/"]
-name = "macro_share_permissions"
+name = "entity_access_db_utils"
publish = false
version = "0.1.0"
[dependencies]
+# Core
anyhow = { workspace = true }
-macro_db_client = { path = "../macro_db_client" }
-comms_db_client = { path = "../comms_db_client" }
-macro_user_id = { path = "../macro_user_id" }
-model = { path = "../model" }
-model-entity = { path = "../model-entity" }
-model_notifications = { path = "../model_notifications" }
-models_permissions = { path = "../models_permissions" }
+macro_uuid = { path = "../macro_uuid" }
serde = { workspace = true }
-serde_json = { workspace = true }
sqlx = { workspace = true }
tracing = { workspace = true }
+
+macro_user_id = { path = "../macro_user_id" }
+model-entity = { path = "../model-entity" }
+models_entity_access_management = { path = "../models_entity_access_management", features = [
+ "db",
+] }
+models_permissions = { path = "../models_permissions" }
+
+[dev-dependencies]
+macro_db_migrator = { path = "../macro_db_migrator" }
+tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
diff --git a/rust/cloud-storage/entity_access_db_utils/fixtures/upsert_test_data.sql b/rust/cloud-storage/entity_access_db_utils/fixtures/upsert_test_data.sql
new file mode 100644
index 0000000000..facac97adc
--- /dev/null
+++ b/rust/cloud-storage/entity_access_db_utils/fixtures/upsert_test_data.sql
@@ -0,0 +1,36 @@
+INSERT INTO public."Organization" ("id", "name")
+ VALUES (1, 'test-org');
+
+INSERT INTO public."macro_user" ("id", "username", "email", "stripe_customer_id")
+ VALUES ('a1111111-1111-1111-1111-111111111111', 'testuser', '[email protected]', 'stripe_test');
+
+INSERT INTO public."User" ("id", "email", "stripeCustomerId", "organizationId", "macro_user_id")
+ VALUES ('macro|[email protected]', '[email protected]', 'stripe_test', 1, 'a1111111-1111-1111-1111-111111111111');
+
+-- Root project (no parent)
+INSERT INTO public."Project" ("id", "name", "userId")
+ VALUES ('11111111-1111-1111-1111-111111111111', 'root-project', 'macro|[email protected]');
+
+-- Child project (parent = root)
+INSERT INTO public."Project" ("id", "name", "userId", "parentId")
+ VALUES ('22222222-2222-2222-2222-222222222222', 'child-project', 'macro|[email protected]', '11111111-1111-1111-1111-111111111111');
+
+-- Empty project (no children, used to test the no-children edge case)
+INSERT INTO public."Project" ("id", "name", "userId")
+ VALUES ('33333333-3333-3333-3333-333333333333', 'empty-project', 'macro|[email protected]');
+
+-- Document under root
+INSERT INTO public."Document" ("id", "name", "owner", "projectId")
+ VALUES ('44444444-4444-4444-4444-444444444444', 'doc-root', 'macro|[email protected]', '11111111-1111-1111-1111-111111111111');
+
+-- Document under child
+INSERT INTO public."Document" ("id", "name", "owner", "projectId")
+ VALUES ('55555555-5555-5555-5555-555555555555', 'doc-child', 'macro|[email protected]', '22222222-2222-2222-2222-222222222222');
+
+-- Chat under child
+INSERT INTO public."Chat" ("id", "name", "userId", "projectId")
+ VALUES ('66666666-6666-6666-6666-666666666666', 'chat-child', 'macro|[email protected]', '22222222-2222-2222-2222-222222222222');
+
+-- Standalone chat under root (used for single-entity upsert tests)
+INSERT INTO public."Chat" ("id", "name", "userId", "projectId")
+ VALUES ('77777777-7777-7777-7777-777777777777', 'chat-root', 'macro|[email protected]', '11111111-1111-1111-1111-111111111111');
diff --git a/rust/cloud-storage/entity_access_db_utils/justfile b/rust/cloud-storage/entity_access_db_utils/justfile
new file mode 100644
index 0000000000..d5a52bc432
--- /dev/null
+++ b/rust/cloud-storage/entity_access_db_utils/justfile
@@ -0,0 +1,6 @@
+DATABASE_URL := "postgres://user:password@localhost:5432/macrodb"
+
+mod sqlx '../sqlx.just'
+
+prepare_db:
+ just sqlx::prepare_db {{ DATABASE_URL }}
diff --git a/rust/cloud-storage/entity_access_db_utils/src/lib.rs b/rust/cloud-storage/entity_access_db_utils/src/lib.rs
new file mode 100644
index 0000000000..d63587dd43
--- /dev/null
+++ b/rust/cloud-storage/entity_access_db_utils/src/lib.rs
@@ -0,0 +1,379 @@
+#![deny(missing_docs)]
+
+//! entity_access_db_utils crate contains common db queries that are required when manipulating entity_access table.
+
+#[cfg(test)]
+mod test;
+
+use macro_user_id::user_id::MacroUserIdStr;
+pub use model_entity::EntityType;
+pub use models_entity_access_management::EntityAccessSourceType;
+pub use models_permissions::share_permission::access_level::AccessLevel;
+use models_permissions::share_permission::channel_share_permission::{
+ UpdateChannelSharePermission, UpdateOperation,
+};
+use sqlx::{Executor, Postgres, QueryBuilder, Transaction};
+
+/// Inserts a row into the entity access table
+/// *NOTE*: The transaction does not get committed automatically
+#[tracing::instrument(skip(transaction), err)]
+pub async fn insert_entity_access_row(
+ transaction: &mut Transaction<'_, Postgres>,
+ entity_id: &macro_uuid::Uuid,
+ entity_type: EntityType,
+ source_id: &str,
+ source_type: EntityAccessSourceType,
+ access_level: AccessLevel,
+) -> Result<(), sqlx::Error> {
+ sqlx::query!(
+ r#"
+ INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)
+ VALUES ($1, $2, $3, $4, $5)
+ "#,
+ entity_id,
+ entity_type.as_ref(),
+ source_id,
+ source_type as _,
+ access_level as _,
+ )
+ .execute(transaction.as_mut())
+ .await?;
+
+ Ok(())
+}
+
+/// Deletes all entity_access rows for a given (entity_id, entity_type).
+/// *NOTE*: The transaction does not get committed automatically.
+#[tracing::instrument(skip(transaction), err)]
+pub async fn delete_entity_access_rows(
+ transaction: &mut Transaction<'_, Postgres>,
+ entity_id: &macro_uuid::Uuid,
+ entity_type: EntityType,
+) -> Result<(), sqlx::Error> {
+ sqlx::query!(
+ r#"
+ DELETE FROM entity_access
+ WHERE entity_id = $1 AND entity_type = $2
+ "#,
+ entity_id,
+ entity_type.as_ref(),
+ )
+ .execute(transaction.as_mut())
+ .await?;
+
+ Ok(())
+}
+
+/// Bulk upserts entity access for users
+#[tracing::instrument(skip(executor), err)]
+pub async fn upsert_user_entity_access_bulk<'e, E>(
+ executor: E,
+ user_ids: &[MacroUserIdStr<'_>],
+ entity_id: &macro_uuid::Uuid,
+ entity_type: EntityType,
+ access_level: AccessLevel,
+) -> anyhow::Result<()>
+where
+ E: Executor<'e, Database = Postgres>,
+{
+ if user_ids.is_empty() {
+ return Ok(());
+ }
+
+ let macro_ids: Vec<String> = user_ids.iter().map(|s| s.to_string()).collect();
+
+ sqlx::query!(
+ r#"
+ INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)
+ SELECT $1, $2, u.user_id, 'user', $3
+ FROM UNNEST($4::text[]) as u(user_id)
+ ON CONFLICT (entity_id, entity_type, source_id, source_type)
+ WHERE granted_from_project_id IS NULL
+ AND access_level != 'owner' -- this prevents us from overriding the owner user
+ DO UPDATE SET access_level = EXCLUDED.access_level, updated_at = NOW()
+ "#,
+ entity_id,
+ entity_type.as_ref(),
+ access_level as _,
+ macro_ids.as_slice(),
+ )
+ .execute(executor)
+ .await?;
+
+ Ok(())
+}
+
+/// Simple entity wrapper
+#[derive(Clone, Debug)]
+pub struct SimpleEntity {
+ /// The entity id
+ pub entity_id: String,
+ /// The entity type
+ pub entity_type: String,
+}
+
+/// Gets all nested entities for a given project
+/// Includes the project itself
+#[tracing::instrument(skip(transaction), err)]
+pub async fn get_nested_project_entities(
+ transaction: &mut Transaction<'_, Postgres>,
+ project_id: &macro_uuid::Uuid,
+) -> Result<Vec<SimpleEntity>, sqlx::Error> {
+ let results = sqlx::query!(
+ r#"
+ WITH RECURSIVE child_projects AS (
+ SELECT id FROM "Project" WHERE id = $1
+
+ UNION ALL
+
+ SELECT p.id FROM "Project" p
+ INNER JOIN child_projects cp ON p."parentId" = cp.id
+ )
+ SELECT id as "entity_id!", 'project' as "entity_type!" FROM child_projects
+
+ UNION ALL
+
+ SELECT d.id as "entity_id!", 'document' as "entity_type!" FROM "Document" d
+ WHERE d."projectId" IN (SELECT id FROM child_projects)
+
+ UNION ALL
+
+ SELECT c.id as "entity_id!", 'chat' as "entity_type!" FROM "Chat" c
+ WHERE c."projectId" IN (SELECT id FROM child_projects)
+
+ UNION ALL
+
+ SELECT et.id::text as "entity_id!", 'email_thread' as "entity_type!" FROM email_threads et
+ WHERE et.project_id IN (SELECT id FROM child_projects)
+ "#,
+ &project_id.to_string()
+ )
+ .map(|r| SimpleEntity {
+ entity_id: r.entity_id,
+ entity_type: r.entity_type,
+ })
+ .fetch_all(transaction.as_mut())
+ .await?;
+
+ Ok(results)
+}
+
+/// Walks up the project tree and grabs all projects including the project provided id
+#[tracing::instrument(skip(transaction), err)]
+pub async fn walk_up_project_tree(
+ transaction: &mut Transaction<'_, Postgres>,
+ project_id: &macro_uuid::Uuid,
+) -> Result<Vec<macro_uuid::Uuid>, sqlx::Error> {
+ let results = sqlx::query!(
+ r#"
+ WITH RECURSIVE parent_projects AS (
+ -- Base case: the project itself
+ SELECT id, name, "parentId"
+ FROM "Project"
+ WHERE id = $1
+
+ UNION ALL
+
+ -- Recursive case: walk up to the parent
+ SELECT p.id, p.name, p."parentId"
+ FROM "Project" p
+ INNER JOIN parent_projects pp ON p.id = pp."parentId"
+ )
+ SELECT id as "id!"
+ FROM parent_projects
+ "#,
+ &project_id.to_string()
+ )
+ .map(|p| macro_uuid::string_to_uuid(&p.id).unwrap()) // SAFETY: the project_id is always a uuid, we just haven't migrated the type to be that in the db schema
+ .fetch_all(transaction.as_mut())
+ .await?;
+
+ Ok(results)
+}
+
+/// Updates the entity_access table according to the UpdateChannelSharePermission request.
+/// *NOTE*: This strictly updates `entity_access` table. It does not update any other tables.
+#[tracing::instrument(skip(transaction), err)]
+pub async fn update_entity_access_channel_share_permissions(
+ transaction: &mut Transaction<'_, Postgres>,
+ entity_id: &macro_uuid::Uuid,
+ entity_type: EntityType,
+ channel_perms: &[UpdateChannelSharePermission],
+) -> Result<(), sqlx::Error> {
+ let mut upsert_channel_ids = Vec::new();
+ let mut remove_channel_ids = Vec::new();
+
+ for perm in channel_perms {
+ match perm.operation {
+ UpdateOperation::Add | UpdateOperation::Replace => {
+ upsert_channel_ids.push((
+ perm.channel_id.clone(),
+ perm.access_level.unwrap_or(AccessLevel::View),
+ ));
+ }
+ UpdateOperation::Remove => {
+ remove_channel_ids.push(perm.channel_id.clone());
+ }
+ }
+ }
+
+ // We need to remove all required items from entity_access for the given entity id for all channels
+ if !remove_channel_ids.is_empty() {
+ match entity_type {
+ EntityType::User | EntityType::Team | EntityType::Channel => {
+ unreachable!()
+ }
+ EntityType::Project => {
+ // Get all items in project
+ let project_items = get_nested_project_entities(transaction, entity_id).await?;
+
+ sqlx::query!(
+ r#"
+ DELETE FROM entity_access
+ WHERE (source_id = ANY($1) AND source_type = 'channel')
+ AND (entity_id = ANY($2) OR granted_from_project_id = ANY($3))
+ "#,
+ &remove_channel_ids,
+ &project_items
+ .iter()
+ .map(|p| macro_uuid::string_to_uuid(&p.entity_id).unwrap())
+ .collect::<Vec<macro_uuid::Uuid>>(),
+ &project_items
+ .iter()
+ .filter_map(|p| {
+ if p.entity_type == "project" {
+ Some(p.entity_id.clone())
+ } else {
+ None
+ }
+ })
+ .collect::<Vec<String>>(),
+ )
+ .execute(transaction.as_mut())
+ .await?;
+ }
+ EntityType::Chat
+ | EntityType::Document
+ | EntityType::EmailThread
+ | EntityType::Call => {
+ sqlx::query!(
+ r#"
+ DELETE FROM entity_access
+ WHERE entity_id = $1 AND entity_type = $2
+ AND source_id = ANY($3) AND source_type = 'channel'
+ "#,
+ entity_id,
+ entity_type.as_ref(),
+ &remove_channel_ids,
+ )
+ .execute(transaction.as_mut())
+ .await?;
+ }
+ }
+ }
+
+ // We need to upsert all required items into entity_access for all channels with the desired access level
+ if !upsert_channel_ids.is_empty() {
+ match entity_type {
+ EntityType::User | EntityType::Team | EntityType::Channel => {
+ unreachable!()
+ }
+ EntityType::Project => {
+ // (a) Direct grant on the project itself (granted_from_project_id IS NULL)
+ let mut qb: QueryBuilder<Postgres> = QueryBuilder::new(
+ "INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level) ",
+ );
+ qb.push_values(&upsert_channel_ids, |mut b, (channel_id, access_level)| {
+ b.push_bind(entity_id)
+ .push_bind("project")
+ .push_bind(channel_id)
+ .push_bind(EntityAccessSourceType::Channel)
+ .push_bind(*access_level);
+ });
+ qb.push(
+ " ON CONFLICT (entity_id, entity_type, source_id, source_type) \
+ WHERE granted_from_project_id IS NULL \
+ DO UPDATE SET access_level = EXCLUDED.access_level, updated_at = NOW()",
+ );
+ qb.build().execute(transaction.as_mut()).await?;
+
+ // (b) Inherited grants on every nested entity (granted_from_project_id = project_id)
+ let project_items = get_nested_project_entities(transaction, entity_id).await?;
+ let granted_from = entity_id.to_string();
+
+ // Cross-join nested entities × upsert channel perms, excluding the
+ // project itself (already covered by step (a) under a different
+ // partial unique index).
+ let rows: Vec<_> = project_items
+ .iter()
+ .filter(|e| !(e.entity_type == "project" && e.entity_id == granted_from))
+ .filter_map(|e| {
+ macro_uuid::string_to_uuid(&e.entity_id)
+ .ok()
+ .map(|id| (id, e.entity_type.clone()))
+ })
+ .flat_map(|(nested_id, nested_type)| {
+ upsert_channel_ids
+ .iter()
+ .map(move |(channel_id, access_level)| {
+ (
+ nested_id,
+ nested_type.clone(),
+ channel_id.clone(),
+ *access_level,
+ )
+ })
+ })
+ .collect();
+
+ if !rows.is_empty() {
+ let mut qb: QueryBuilder<Postgres> = QueryBuilder::new(
+ "INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level, granted_from_project_id) ",
+ );
+ qb.push_values(
+ &rows,
+ |mut b, (nested_id, nested_type, channel_id, access_level)| {
+ b.push_bind(nested_id)
+ .push_bind(nested_type)
+ .push_bind(channel_id)
+ .push_bind(EntityAccessSourceType::Channel)
+ .push_bind(*access_level)
+ .push_bind(&granted_from);
+ },
+ );
+ qb.push(
+ " ON CONFLICT (entity_id, entity_type, source_id, source_type, granted_from_project_id) \
+ WHERE granted_from_project_id IS NOT NULL \
+ DO UPDATE SET access_level = EXCLUDED.access_level, updated_at = NOW()",
+ );
+ qb.build().execute(transaction.as_mut()).await?;
+ }
+ }
+ EntityType::Chat
+ | EntityType::Document
+ | EntityType::EmailThread
+ | EntityType::Call => {
+ let entity_type_str = entity_type.as_ref();
+
+ let mut qb: QueryBuilder<Postgres> = QueryBuilder::new(
+ "INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level) ",
+ );
+ qb.push_values(&upsert_channel_ids, |mut b, (channel_id, access_level)| {
+ b.push_bind(entity_id)
+ .push_bind(entity_type_str)
+ .push_bind(channel_id)
+ .push_bind(EntityAccessSourceType::Channel)
+ .push_bind(*access_level);
+ });
+ qb.push(
+ " ON CONFLICT (entity_id, entity_type, source_id, source_type) \
+ WHERE granted_from_project_id IS NULL \
+ DO UPDATE SET access_level = EXCLUDED.access_level, updated_at = NOW()",
+ );
+ qb.build().execute(transaction.as_mut()).await?;
+ }
+ }
+ }
+
+ Ok(())
+}
diff --git a/rust/cloud-storage/entity_access_db_utils/src/test.rs b/rust/cloud-storage/entity_access_db_utils/src/test.rs
new file mode 100644
index 0000000000..c5e29371a8
--- /dev/null
+++ b/rust/cloud-storage/entity_access_db_utils/src/test.rs
@@ -0,0 +1,356 @@
+use macro_db_migrator::MACRO_DB_MIGRATIONS;
+use macro_uuid::Uuid;
+use model_entity::EntityType;
+use models_permissions::share_permission::access_level::AccessLevel;
+use models_permissions::share_permission::channel_share_permission::{
+ UpdateChannelSharePermission, UpdateOperation,
+};
+use sqlx::Row as _;
+use sqlx::{Pool, Postgres};
+
+use super::*;
+
+const ROOT_PROJECT_ID: Uuid = Uuid::from_u128(0x11111111_1111_1111_1111_111111111111);
+const CHILD_PROJECT_ID: Uuid = Uuid::from_u128(0x22222222_2222_2222_2222_222222222222);
+const EMPTY_PROJECT_ID: Uuid = Uuid::from_u128(0x33333333_3333_3333_3333_333333333333);
+const DOC_ROOT_ID: Uuid = Uuid::from_u128(0x44444444_4444_4444_4444_444444444444);
+const DOC_CHILD_ID: Uuid = Uuid::from_u128(0x55555555_5555_5555_5555_555555555555);
+const CHAT_CHILD_ID: Uuid = Uuid::from_u128(0x66666666_6666_6666_6666_666666666666);
+const CHAT_ROOT_ID: Uuid = Uuid::from_u128(0x77777777_7777_7777_7777_777777777777);
+
+#[derive(Debug)]
+struct Row {
+ entity_id: Uuid,
+ entity_type: String,
+ source_id: String,
+ access_level: AccessLevel,
+ granted_from_project_id: Option<String>,
+}
+
+async fn fetch_channel_rows(pool: &Pool<Postgres>, channel_id: &str) -> Vec<Row> {
+ // Runtime query (not the compile-time macro) so this test file does not
+ // require a `.sqlx` cache entry to build.
+ sqlx::query(
+ r#"
+ SELECT
+ entity_id,
+ entity_type,
+ source_id,
+ access_level,
+ granted_from_project_id
+ FROM entity_access
+ WHERE source_id = $1 AND source_type = 'channel'
+ ORDER BY entity_type, entity_id, granted_from_project_id NULLS FIRST
+ "#,
+ )
+ .bind(channel_id)
+ .map(|r: sqlx::postgres::PgRow| Row {
+ entity_id: r.get("entity_id"),
+ entity_type: r.get("entity_type"),
+ source_id: r.get("source_id"),
+ access_level: r.get("access_level"),
+ granted_from_project_id: r.get("granted_from_project_id"),
+ })
+ .fetch_all(pool)
+ .await
+ .unwrap()
+}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../fixtures", scripts("upsert_test_data"))
+)]
+async fn upsert_single_channel_to_chat(pool: Pool<Postgres>) {
+ let mut tx = pool.begin().await.unwrap();
+
+ let perms = vec![UpdateChannelSharePermission {
+ operation: UpdateOperation::Add,
+ channel_id: "channel-1".to_string(),
+ access_level: Some(AccessLevel::Edit),
+ }];
+
+ update_entity_access_channel_share_permissions(
+ &mut tx,
+ &CHAT_ROOT_ID,
+ EntityType::Chat,
+ &perms,
+ )
+ .await
+ .unwrap();
+ tx.commit().await.unwrap();
+
+ let rows = fetch_channel_rows(&pool, "channel-1").await;
+ assert_eq!(rows.len(), 1);
+ assert_eq!(rows[0].entity_id, CHAT_ROOT_ID);
+ assert_eq!(rows[0].entity_type, "chat");
+ assert_eq!(rows[0].source_id, "channel-1");
+ assert_eq!(rows[0].access_level, AccessLevel::Edit);
+ assert!(rows[0].granted_from_project_id.is_none());
+}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../fixtures", scripts("upsert_test_data"))
+)]
+async fn upsert_multiple_channels_to_document(pool: Pool<Postgres>) {
+ let mut tx = pool.begin().await.unwrap();
+
+ let perms = vec![
+ UpdateChannelSharePermission {
+ operation: UpdateOperation::Add,
+ channel_id: "channel-a".to_string(),
+ access_level: Some(AccessLevel::View),
+ },
+ UpdateChannelSharePermission {
+ operation: UpdateOperation::Add,
+ channel_id: "channel-b".to_string(),
+ access_level: Some(AccessLevel::Comment),
+ },
+ UpdateChannelSharePermission {
+ operation: UpdateOperation::Add,
+ channel_id: "channel-c".to_string(),
+ access_level: None, // defaults to View
+ },
+ ];
+
+ update_entity_access_channel_share_permissions(
+ &mut tx,
+ &DOC_ROOT_ID,
+ EntityType::Document,
+ &perms,
+ )
+ .await
+ .unwrap();
+ tx.commit().await.unwrap();
+
+ let mut all_rows = Vec::new();
+ for ch in ["channel-a", "channel-b", "channel-c"] {
+ all_rows.extend(fetch_channel_rows(&pool, ch).await);
+ }
+
+ assert_eq!(all_rows.len(), 3);
+ let by_ch: std::collections::HashMap<_, _> =
+ all_rows.iter().map(|r| (r.source_id.as_str(), r)).collect();
+
+ assert_eq!(by_ch["channel-a"].access_level, AccessLevel::View);
+ assert_eq!(by_ch["channel-b"].access_level, AccessLevel::Comment);
+ assert_eq!(by_ch["channel-c"].access_level, AccessLevel::View);
+ assert!(
+ all_rows
+ .iter()
+ .all(|r| r.entity_id == DOC_ROOT_ID && r.entity_type == "document")
+ );
+ assert!(all_rows.iter().all(|r| r.granted_from_project_id.is_none()));
+}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../fixtures", scripts("upsert_test_data"))
+)]
+async fn upsert_to_project_inserts_direct_grant_and_inherited_rows(pool: Pool<Postgres>) {
+ let mut tx = pool.begin().await.unwrap();
+
+ let perms = vec![UpdateChannelSharePermission {
+ operation: UpdateOperation::Add,
+ channel_id: "channel-1".to_string(),
+ access_level: Some(AccessLevel::Comment),
+ }];
+
+ update_entity_access_channel_share_permissions(
+ &mut tx,
+ &ROOT_PROJECT_ID,
+ EntityType::Project,
+ &perms,
+ )
+ .await
+ .unwrap();
+ tx.commit().await.unwrap();
+
+ let rows = fetch_channel_rows(&pool, "channel-1").await;
+ // root project (direct), child project (inherited), doc-root (inherited),
+ // doc-child (inherited), chat-child (inherited), chat-root (inherited) = 6
+ assert_eq!(rows.len(), 6);
+
+ // All rows are for channel-1 with Comment access.
+ assert!(rows.iter().all(|r| r.access_level == AccessLevel::Comment));
+
+ // The project itself: direct grant (NULL granted_from)
+ let project_row = rows
+ .iter()
+ .find(|r| r.entity_id == ROOT_PROJECT_ID && r.entity_type == "project")
+ .unwrap();
+ assert!(project_row.granted_from_project_id.is_none());
+
+ // Every other row: inherited from ROOT_PROJECT_ID
+ let inherited: Vec<_> = rows
+ .iter()
+ .filter(|r| !(r.entity_id == ROOT_PROJECT_ID && r.entity_type == "project"))
+ .collect();
+ assert_eq!(inherited.len(), 5);
+ let root_str = ROOT_PROJECT_ID.to_string();
+ assert!(
+ inherited
+ .iter()
+ .all(|r| r.granted_from_project_id.as_deref() == Some(root_str.as_str()))
+ );
+
+ // Spot-check each expected nested entity is present.
+ assert!(
+ inherited
+ .iter()
+ .any(|r| r.entity_id == CHILD_PROJECT_ID && r.entity_type == "project")
+ );
+ assert!(
+ inherited
+ .iter()
+ .any(|r| r.entity_id == DOC_ROOT_ID && r.entity_type == "document")
+ );
+ assert!(
+ inherited
+ .iter()
+ .any(|r| r.entity_id == DOC_CHILD_ID && r.entity_type == "document")
+ );
+ assert!(
+ inherited
+ .iter()
+ .any(|r| r.entity_id == CHAT_CHILD_ID && r.entity_type == "chat")
+ );
+ assert!(
+ inherited
+ .iter()
+ .any(|r| r.entity_id == CHAT_ROOT_ID && r.entity_type == "chat")
+ );
+}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../fixtures", scripts("upsert_test_data"))
+)]
+async fn replace_updates_access_level_on_existing_row(pool: Pool<Postgres>) {
+ // First: insert a row with View
+ let mut tx = pool.begin().await.unwrap();
+ let perms = vec![UpdateChannelSharePermission {
+ operation: UpdateOperation::Add,
+ channel_id: "channel-1".to_string(),
+ access_level: Some(AccessLevel::View),
+ }];
+ update_entity_access_channel_share_permissions(
+ &mut tx,
+ &DOC_ROOT_ID,
+ EntityType::Document,
+ &perms,
+ )
+ .await
+ .unwrap();
+ tx.commit().await.unwrap();
+
+ let initial = fetch_channel_rows(&pool, "channel-1").await;
+ assert_eq!(initial.len(), 1);
+ assert_eq!(initial[0].access_level, AccessLevel::View);
+
+ // Second: replace with Edit
+ let mut tx = pool.begin().await.unwrap();
+ let perms = vec![UpdateChannelSharePermission {
+ operation: UpdateOperation::Replace,
+ channel_id: "channel-1".to_string(),
+ access_level: Some(AccessLevel::Edit),
+ }];
+ update_entity_access_channel_share_permissions(
+ &mut tx,
+ &DOC_ROOT_ID,
+ EntityType::Document,
+ &perms,
+ )
+ .await
+ .unwrap();
+ tx.commit().await.unwrap();
+
+ let after = fetch_channel_rows(&pool, "channel-1").await;
+ // Still exactly one row — the existing row was updated, not duplicated.
+ assert_eq!(after.len(), 1);
+ assert_eq!(after[0].entity_id, DOC_ROOT_ID);
+ assert_eq!(after[0].access_level, AccessLevel::Edit);
+}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../fixtures", scripts("upsert_test_data"))
+)]
+async fn remove_then_upsert_in_same_call_yields_upserted_state(pool: Pool<Postgres>) {
+ // Pre-populate: View access on chat-root for channel-1
+ let mut tx = pool.begin().await.unwrap();
+ update_entity_access_channel_share_permissions(
+ &mut tx,
+ &CHAT_ROOT_ID,
+ EntityType::Chat,
+ &[UpdateChannelSharePermission {
+ operation: UpdateOperation::Add,
+ channel_id: "channel-1".to_string(),
+ access_level: Some(AccessLevel::View),
+ }],
+ )
+ .await
+ .unwrap();
+ tx.commit().await.unwrap();
+
+ // Now: remove + upsert the same channel in a single call. Final state
+ // should be the upsert (Edit), since remove runs first, then upsert.
+ let mut tx = pool.begin().await.unwrap();
+ let perms = vec![
+ UpdateChannelSharePermission {
+ operation: UpdateOperation::Remove,
+ channel_id: "channel-1".to_string(),
+ access_level: None,
+ },
+ UpdateChannelSharePermission {
+ operation: UpdateOperation::Add,
+ channel_id: "channel-1".to_string(),
+ access_level: Some(AccessLevel::Edit),
+ },
+ ];
+ update_entity_access_channel_share_permissions(
+ &mut tx,
+ &CHAT_ROOT_ID,
+ EntityType::Chat,
+ &perms,
+ )
+ .await
+ .unwrap();
+ tx.commit().await.unwrap();
+
+ let rows = fetch_channel_rows(&pool, "channel-1").await;
+ assert_eq!(rows.len(), 1);
+ assert_eq!(rows[0].entity_id, CHAT_ROOT_ID);
+ assert_eq!(rows[0].access_level, AccessLevel::Edit);
+}
+
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../fixtures", scripts("upsert_test_data"))
+)]
+async fn upsert_to_project_with_no_children_inserts_only_project_row(pool: Pool<Postgres>) {
+ let mut tx = pool.begin().await.unwrap();
+
+ let perms = vec![UpdateChannelSharePermission {
+ operation: UpdateOperation::Add,
+ channel_id: "channel-1".to_string(),
+ access_level: Some(AccessLevel::View),
+ }];
+
+ update_entity_access_channel_share_permissions(
+ &mut tx,
+ &EMPTY_PROJECT_ID,
+ EntityType::Project,
+ &perms,
+ )
+ .await
+ .unwrap();
+ tx.commit().await.unwrap();
+
+ let rows = fetch_channel_rows(&pool, "channel-1").await;
+ assert_eq!(rows.len(), 1);
+ assert_eq!(rows[0].entity_id, EMPTY_PROJECT_ID);
+ assert_eq!(rows[0].entity_type, "project");
+ assert!(rows[0].granted_from_project_id.is_none());
+ assert_eq!(rows[0].access_level, AccessLevel::View);
+}
diff --git a/rust/cloud-storage/entity_access_management/Cargo.toml b/rust/cloud-storage/entity_access_management/Cargo.toml
index 9a41d279fe..83e4758143 100644
--- a/rust/cloud-storage/entity_access_management/Cargo.toml
+++ b/rust/cloud-storage/entity_access_management/Cargo.toml
@@ -6,8 +6,13 @@ version = "0.1.0"
[features]
default = ["outbound", "ports"]
-outbound = ["dep:sqlx", "ports"]
-ports = ["dep:tokio"]
+outbound = [
+ "dep:entity_access_db_utils",
+ "dep:sqlx",
+ "models_entity_access_management/db",
+ "ports",
+]
+ports = []
[dependencies]
# Core
@@ -21,12 +26,11 @@ uuid = { workspace = true }
# Domain models (always included)
macro_user_id = { path = "../macro_user_id" }
model-entity = { path = "../model-entity" }
+models_entity_access_management = { path = "../models_entity_access_management", default-features = false }
models_permissions = { path = "../models_permissions" }
-# Async runtime (for ports)
-tokio = { workspace = true, optional = true }
-
# Database
+entity_access_db_utils = { path = "../entity_access_db_utils", optional = true }
sqlx = { workspace = true, optional = true }
[dev-dependencies]
diff --git a/rust/cloud-storage/entity_access_management/src/domain/models.rs b/rust/cloud-storage/entity_access_management/src/domain/models.rs
index 2ecbbcedc6..a8ca96c168 100644
--- a/rust/cloud-storage/entity_access_management/src/domain/models.rs
+++ b/rust/cloud-storage/entity_access_management/src/domain/models.rs
@@ -2,6 +2,8 @@
use model_entity::EntityType;
+pub use models_entity_access_management::EntityAccessSourceType;
+
/// Errors that can occur in entity_access_management crate.
#[derive(Debug, thiserror::Error)]
pub enum EntityAccessManagementError {
@@ -15,19 +17,3 @@ pub enum EntityAccessManagementError {
#[error("invalid project move configuration")]
InvalidProjectMove,
}
-
-/// Entity access source type
-#[derive(Debug, Clone, Copy)]
-#[cfg_attr(feature = "outbound", derive(sqlx::Type))]
-#[cfg_attr(
- feature = "outbound",
- sqlx(type_name = "entity_access_source_type", rename_all = "lowercase")
-)]
-pub enum EntityAccessSourceType {
- /// Channel source
- Channel,
- /// Team source
- Team,
- /// User source
- User,
-}
diff --git a/rust/cloud-storage/entity_access_management/src/outbound/pg_repo.rs b/rust/cloud-storage/entity_access_management/src/outbound/pg_repo.rs
index 3d1275f5d4..44531bdae1 100644
--- a/rust/cloud-storage/entity_access_management/src/outbound/pg_repo.rs
+++ b/rust/cloud-storage/entity_access_management/src/outbound/pg_repo.rs
@@ -3,6 +3,7 @@
#[cfg(test)]
mod test;
+use entity_access_db_utils::SimpleEntity;
use model_entity::EntityType;
use models_permissions::share_permission::access_level::AccessLevel;
use sqlx::{PgPool, Postgres, QueryBuilder, Transaction};
@@ -23,15 +24,6 @@ struct ProjectSourceEntity {
pub access_level: AccessLevel,
}
-/// Simple entity wrapper
-#[derive(Clone, Debug)]
-struct SimpleEntity {
- /// The entity id
- pub entity_id: String,
- /// The entity type
- pub entity_type: String,
-}
-
/// PostgreSQL-backed implementation of [`EntityAccessManagementRepository`]
#[derive(Clone)]
pub struct PgRepository {
@@ -54,43 +46,7 @@ impl PgRepository {
transaction: &mut Transaction<'_, Postgres>,
project_id: &uuid::Uuid,
) -> Result<Vec<SimpleEntity>, sqlx::Error> {
- let results = sqlx::query!(
- r#"
- WITH RECURSIVE child_projects AS (
- SELECT id FROM "Project" WHERE id = $1
-
- UNION ALL
-
- SELECT p.id FROM "Project" p
- INNER JOIN child_projects cp ON p."parentId" = cp.id
- )
- SELECT id as "entity_id!", 'project' as "entity_type!" FROM child_projects
-
- UNION ALL
-
- SELECT d.id as "entity_id!", 'document' as "entity_type!" FROM "Document" d
- WHERE d."projectId" IN (SELECT id FROM child_projects)
-
- UNION ALL
-
- SELECT c.id as "entity_id!", 'chat' as "entity_type!" FROM "Chat" c
- WHERE c."projectId" IN (SELECT id FROM child_projects)
-
- UNION ALL
-
- SELECT et.id::text as "entity_id!", 'email_thread' as "entity_type!" FROM email_threads et
- WHERE et.project_id IN (SELECT id FROM child_projects)
- "#,
- &project_id.to_string()
- )
- .map(|r| SimpleEntity {
- entity_id: r.entity_id,
- entity_type: r.entity_type,
- })
- .fetch_all(transaction.as_mut())
- .await?;
-
- Ok(results)
+ entity_access_db_utils::get_nested_project_entities(transaction, project_id).await
}
/// Walks up the project tree and grabs all projects including the project provided id
@@ -100,31 +56,7 @@ impl PgRepository {
transaction: &mut Transaction<'_, Postgres>,
project_id: &uuid::Uuid,
) -> Result<Vec<uuid::Uuid>, sqlx::Error> {
- let results = sqlx::query!(
- r#"
- WITH RECURSIVE parent_projects AS (
- -- Base case: the project itself
- SELECT id, name, "parentId"
- FROM "Project"
- WHERE id = $1
-
- UNION ALL
-
- -- Recursive case: walk up to the parent
- SELECT p.id, p.name, p."parentId"
- FROM "Project" p
- INNER JOIN parent_projects pp ON p.id = pp."parentId"
- )
- SELECT id as "id!"
- FROM parent_projects
- "#,
- &project_id.to_string()
- )
- .map(|p| Uuid::parse_str(&p.id).unwrap()) // SAFETY: the project_id is always a uuid, we just haven't migrated the type to be that in the db schema
- .fetch_all(transaction.as_mut())
- .await?;
-
- Ok(results)
+ entity_access_db_utils::walk_up_project_tree(transaction, project_id).await
}
/// Given a list of project ids, this will return a list of all source entities (source_id/source_type/access_level) entries that we need to insert rows for the new entity
diff --git a/rust/cloud-storage/justfile b/rust/cloud-storage/justfile
index c0d82e90fd..d0da8a2805 100644
--- a/rust/cloud-storage/justfile
+++ b/rust/cloud-storage/justfile
@@ -91,6 +91,7 @@ setup_test_envs:
echo "DATABASE_URL={{ MACRODB }}" >> ./backfill_entity_access/.env
echo "DATABASE_URL={{ MACRODB }}" >> ./entity_access_management/.env
echo "DATABASE_URL={{ MACRODB }}" >> ./mobile_welcome_email_db_client/.env
+ echo "DATABASE_URL={{ MACRODB }}" >> ./entity_access_db_utils/.env
setup_macrodb:
just macro_db_client/create_db
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d.json b/rust/cloud-storage/macro_db_client/.sqlx/query-0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d.json
new file mode 100644
index 0000000000..99a3b6f452
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id FROM (\n -- Direct user grants\n SELECT source_id as user_id FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'user'\n\n UNION ALL\n\n -- Channel Members\n SELECT cp.user_id FROM comms_channel_participants cp\n WHERE cp.left_at IS NULL AND cp.channel_id IN (\n SELECT source_id::uuid FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'channel'\n )\n\n UNION ALL\n\n -- Team Members\n SELECT tu.user_id FROM team_user tu\n WHERE tu.team_id IN (\n SELECT source_id::uuid FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'team'\n )\n )\n \n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-0e124775055015b822196bac04d7421635befe41752d32bceaf5ab66e9215cc8.json b/rust/cloud-storage/macro_db_client/.sqlx/query-0e124775055015b822196bac04d7421635befe41752d32bceaf5ab66e9215cc8.json
deleted file mode 100644
index a1c4c0d402..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-0e124775055015b822196bac04d7421635befe41752d32bceaf5ab66e9215cc8.json
+++ /dev/null
@@ -1,77 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n -- recursively finds all parent projects for the given document.\n WITH RECURSIVE project_hierarchy AS (\n -- Base case: Start with the project directly associated with the document.\n SELECT\n p.id as project_id\n FROM\n \"Document\" d\n JOIN \"Project\" p ON d.\"projectId\" = p.id AND p.\"deletedAt\" IS NULL\n WHERE\n d.id = $1 AND d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Recursive case: Find the parent of the project from the previous step.\n SELECT\n parent.id as project_id\n FROM\n project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n -- The main query to select from UserItemAccess\n SELECT\n id,\n user_id,\n item_id,\n item_type,\n granted_from_channel_id,\n -- The `access_level` column is mapped directly to the `AccessLevel` Rust enum\n -- thanks to `#[derive(sqlx::Type)]`.\n access_level as \"access_level!: AccessLevel\",\n created_at as \"created_at!: DateTime<Utc>\",\n updated_at as \"updated_at!: DateTime<Utc>\"\n FROM \"UserItemAccess\"\n WHERE\n -- Filter for the specific user we are interested in.\n user_id = $2\n AND item_id IN (\n -- The document ID itself\n SELECT $1\n UNION\n -- All project IDs from the recursive CTE\n SELECT project_id FROM project_hierarchy\n )\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "item_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "item_type",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "granted_from_channel_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 5,
- "name": "access_level!: AccessLevel",
- "type_info": {
- "Custom": {
- "name": "\"AccessLevel\"",
- "kind": {
- "Enum": [
- "view",
- "comment",
- "edit",
- "owner"
- ]
- }
- }
- }
- },
- {
- "ordinal": 6,
- "name": "created_at!: DateTime<Utc>",
- "type_info": "Timestamp"
- },
- {
- "ordinal": 7,
- "name": "updated_at!: DateTime<Utc>",
- "type_info": "Timestamp"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- true,
- false,
- false,
- false
- ]
- },
- "hash": "0e124775055015b822196bac04d7421635befe41752d32bceaf5ab66e9215cc8"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75.json b/rust/cloud-storage/macro_db_client/.sqlx/query-1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75.json
new file mode 100644
index 0000000000..d2b084cf10
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-1435acbba365796ddcb6ddbef86f4ebf664cffc44082996f6b60a60373c28f75.json
@@ -0,0 +1,17 @@
+{
+ "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-18134bc97487fbf6b88e8afdb94dc601bf0d997ad5b6974ef5866dd6262b8618.json b/rust/cloud-storage/macro_db_client/.sqlx/query-18134bc97487fbf6b88e8afdb94dc601bf0d997ad5b6974ef5866dd6262b8618.json
new file mode 100644
index 0000000000..cbb754459e
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-18134bc97487fbf6b88e8afdb94dc601bf0d997ad5b6974ef5866dd6262b8618.json
@@ -0,0 +1,31 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n -- Get all entities the user has access to via entity_access, filtered to requested items\n AllAccessGrants AS (\n -- Documents the user has access to\n SELECT ea.entity_id::text as item_id, ea.entity_type as item_type\n FROM entity_access ea\n LEFT JOIN \"Document\" d ON ea.entity_type = 'document' AND ea.entity_id::text = d.id\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n AND ea.entity_type = 'document'\n AND ea.entity_id::text = ANY($2)\n AND d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Chats the user has access to\n SELECT ea.entity_id::text as item_id, ea.entity_type as item_type\n FROM entity_access ea\n LEFT JOIN \"Chat\" c ON ea.entity_type = 'chat' AND ea.entity_id::text = c.id\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n AND ea.entity_type = 'chat'\n AND ea.entity_id::text = ANY($3)\n AND c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Projects the user has access to\n SELECT ea.entity_id::text as item_id, ea.entity_type as item_type\n FROM entity_access ea\n LEFT JOIN \"Project\" p ON ea.entity_type = 'project' AND ea.entity_id::text = p.id\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n AND ea.entity_type = 'project'\n AND ea.entity_id::text = ANY($4)\n AND p.\"deletedAt\" IS NULL\n ),\n UserAccessibleItems AS (\n SELECT\n item_id,\n item_type\n FROM AllAccessGrants\n GROUP BY item_id, item_type\n )\n SELECT item_id as \"item_id!\", item_type as \"item_type!\" FROM UserAccessibleItems\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "item_type!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray",
+ "TextArray",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ null,
+ null
+ ]
+ },
+ "hash": "18134bc97487fbf6b88e8afdb94dc601bf0d997ad5b6974ef5866dd6262b8618"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6.json b/rust/cloud-storage/macro_db_client/.sqlx/query-1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6.json
new file mode 100644
index 0000000000..f97907a55c
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" = $1\n )\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-1cecf9cebdb427d5d13f9e5f59b0404f319568148636a1b14e41963036473dbd.json b/rust/cloud-storage/macro_db_client/.sqlx/query-1cecf9cebdb427d5d13f9e5f59b0404f319568148636a1b14e41963036473dbd.json
deleted file mode 100644
index e0b59444ca..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-1cecf9cebdb427d5d13f9e5f59b0404f319568148636a1b14e41963036473dbd.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n DELETE FROM \"UserItemAccess\"\n WHERE \"user_id\" = $1 AND \"item_id\" = $2 AND \"item_type\" = $3\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text",
- "Text",
- "Text"
- ]
- },
- "nullable": []
- },
- "hash": "1cecf9cebdb427d5d13f9e5f59b0404f319568148636a1b14e41963036473dbd"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-1e5254d3d30a9a118b8943d43b0b319df33d60f490569ee26385b0ae134db9bb.json b/rust/cloud-storage/macro_db_client/.sqlx/query-1e5254d3d30a9a118b8943d43b0b319df33d60f490569ee26385b0ae134db9bb.json
deleted file mode 100644
index b0ff11c695..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-1e5254d3d30a9a118b8943d43b0b319df33d60f490569ee26385b0ae134db9bb.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n DELETE FROM \"UserItemAccess\"\n WHERE \"item_id\" = ANY($1) AND \"item_type\" = $2\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "TextArray",
- "Text"
- ]
- },
- "nullable": []
- },
- "hash": "1e5254d3d30a9a118b8943d43b0b319df33d60f490569ee26385b0ae134db9bb"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-1ec329c4c6cd6397c372e3dc59834a3828c3a08c4088dd60535416ad3c0aca3e.json b/rust/cloud-storage/macro_db_client/.sqlx/query-1ec329c4c6cd6397c372e3dc59834a3828c3a08c4088dd60535416ad3c0aca3e.json
deleted file mode 100644
index e13247b9d2..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-1ec329c4c6cd6397c372e3dc59834a3828c3a08c4088dd60535416ad3c0aca3e.json
+++ /dev/null
@@ -1,31 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE ProjectHierarchy AS (\n -- Find direct user access to ALL projects (not filtered) as starting point\n SELECT\n p.id,\n uia.access_level\n FROM \"Project\" p\n JOIN \"UserItemAccess\" uia ON p.id = uia.item_id AND uia.item_type = 'project'\n WHERE uia.user_id = $1 AND p.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Then walk down the project tree and grab child projects, keeping parent's access\n SELECT\n p.id,\n ph.access_level\n FROM \"Project\" p\n JOIN ProjectHierarchy ph ON p.\"parentId\" = ph.id\n WHERE p.\"deletedAt\" IS NULL\n ),\n -- Now build up all the ways a user can have access to stuff\n AllAccessGrants AS (\n -- Explicit access to documents via UserItemAccess table\n SELECT uia.item_id, uia.item_type, uia.access_level\n FROM \"UserItemAccess\" uia\n LEFT JOIN \"Document\" d ON uia.item_type = 'document' AND uia.item_id = d.id\n WHERE uia.user_id = $1\n AND uia.item_type = 'document'\n AND uia.item_id = ANY($2)\n AND d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Explicit access to chats via UserItemAccess table\n SELECT uia.item_id, uia.item_type, uia.access_level\n FROM \"UserItemAccess\" uia\n LEFT JOIN \"Chat\" c ON uia.item_type = 'chat' AND uia.item_id = c.id\n WHERE uia.user_id = $1\n AND uia.item_type = 'chat'\n AND uia.item_id = ANY($3)\n AND c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Explicit access to projects via UserItemAccess table\n SELECT uia.item_id, uia.item_type, uia.access_level\n FROM \"UserItemAccess\" uia\n LEFT JOIN \"Project\" p ON uia.item_type = 'project' AND uia.item_id = p.id\n WHERE uia.user_id = $1\n AND uia.item_type = 'project'\n AND uia.item_id = ANY($4)\n AND p.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Access to docs in visible projects (only filter by requested doc IDs)\n SELECT\n d.id AS item_id,\n 'document' AS item_type,\n ph.access_level\n FROM \"Document\" d\n JOIN ProjectHierarchy ph ON d.\"projectId\" = ph.id\n WHERE d.id = ANY($2)\n AND d.\"projectId\" IS NOT NULL \n AND d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Access to chats in visible projects (only filter by requested chat IDs)\n SELECT\n c.id AS item_id,\n 'chat' AS item_type,\n ph.access_level\n FROM \"Chat\" c\n JOIN ProjectHierarchy ph ON c.\"projectId\" = ph.id\n WHERE c.id = ANY($3)\n AND c.\"projectId\" IS NOT NULL \n AND c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Include the projects we found earlier (only filter by requested project IDs)\n SELECT\n ph.id AS item_id,\n 'project' AS item_type,\n ph.access_level\n FROM ProjectHierarchy ph\n WHERE ph.id = ANY($4)\n ),\n UserAccessibleItems AS (\n SELECT\n item_id,\n item_type\n FROM AllAccessGrants\n GROUP BY item_id, item_type\n )\n SELECT item_id as \"item_id!\", item_type as \"item_type!\" FROM UserAccessibleItems\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "item_id!",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "item_type!",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "TextArray",
- "TextArray",
- "TextArray"
- ]
- },
- "nullable": [
- null,
- null
- ]
- },
- "hash": "1ec329c4c6cd6397c372e3dc59834a3828c3a08c4088dd60535416ad3c0aca3e"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-270c1f7ab00df1095282625b0766522d883948bc3589eb9a70fffa7787710bbf.json b/rust/cloud-storage/macro_db_client/.sqlx/query-270c1f7ab00df1095282625b0766522d883948bc3589eb9a70fffa7787710bbf.json
deleted file mode 100644
index 602ce4228d..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-270c1f7ab00df1095282625b0766522d883948bc3589eb9a70fffa7787710bbf.json
+++ /dev/null
@@ -1,31 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO \"UserItemAccess\" (\n \"id\",\n \"user_id\",\n \"item_id\",\n \"item_type\",\n \"access_level\",\n \"granted_from_channel_id\",\n \"created_at\",\n \"updated_at\"\n )\n VALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6,\n NOW(),\n NOW()\n )\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Uuid",
- "Text",
- "Text",
- "Text",
- {
- "Custom": {
- "name": "\"AccessLevel\"",
- "kind": {
- "Enum": [
- "view",
- "comment",
- "edit",
- "owner"
- ]
- }
- }
- },
- "Uuid"
- ]
- },
- "nullable": []
- },
- "hash": "270c1f7ab00df1095282625b0766522d883948bc3589eb9a70fffa7787710bbf"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08.json b/rust/cloud-storage/macro_db_client/.sqlx/query-377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08.json
new file mode 100644
index 0000000000..9348d25315
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"DocumentPermission\" WHERE \"documentId\" = $1\n )\n \n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60.json b/rust/cloud-storage/macro_db_client/.sqlx/query-37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60.json
new file mode 100644
index 0000000000..44d3a67e72
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT EXISTS (\n SELECT 1\n FROM public.email_threads t\n JOIN public.email_links l ON l.id = t.link_id\n WHERE t.id = $1::uuid\n AND l.macro_id = $2\n ) AS \"exists!\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "exists!",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "37b5168f739c490a3373c65eab35f247a34af0a8e659cbad61cb99e3094e5a60"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-3a7be99469ed150e0506efa786b672198a6d3419c6bd5548418520cd3e6a8e95.json b/rust/cloud-storage/macro_db_client/.sqlx/query-3a7be99469ed150e0506efa786b672198a6d3419c6bd5548418520cd3e6a8e95.json
deleted file mode 100644
index 60bfee0647..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-3a7be99469ed150e0506efa786b672198a6d3419c6bd5548418520cd3e6a8e95.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE project_hierarchy AS (\n SELECT p.id as project_id\n FROM \"Document\" d\n JOIN \"Project\" p ON d.\"projectId\" = p.id AND p.\"deletedAt\" IS NULL\n WHERE d.id = $1 AND d.\"deletedAt\" IS NULL\n UNION ALL\n SELECT parent.id as project_id\n FROM project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n SELECT access_level FROM (\n -- Source 1: Cast the AccessLevel enum to text.\n SELECT access_level::text FROM \"UserItemAccess\"\n WHERE user_id = $2 AND item_id IN (\n SELECT $1\n UNION\n SELECT project_id FROM project_hierarchy\n )\n UNION ALL\n -- Source 2: Select the publicAccessLevel (which is already text).\n SELECT \"publicAccessLevel\" as access_level\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true AND \"publicAccessLevel\" IS NOT NULL AND id IN (\n SELECT \"sharePermissionId\" FROM \"DocumentPermission\" WHERE \"documentId\" = $1\n UNION\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" IN (SELECT project_id FROM project_hierarchy)\n )\n ) as all_levels\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "access_level",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text"
- ]
- },
- "nullable": [
- null
- ]
- },
- "hash": "3a7be99469ed150e0506efa786b672198a6d3419c6bd5548418520cd3e6a8e95"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json b/rust/cloud-storage/macro_db_client/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json
new file mode 100644
index 0000000000..b75a3a2ff5
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json
@@ -0,0 +1,41 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)\n VALUES ($1, $2, $3, $4, $5)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text",
+ {
+ "Custom": {
+ "name": "entity_access_source_type",
+ "kind": {
+ "Enum": [
+ "channel",
+ "team",
+ "user"
+ ]
+ }
+ }
+ },
+ {
+ "Custom": {
+ "name": "\"AccessLevel\"",
+ "kind": {
+ "Enum": [
+ "view",
+ "comment",
+ "edit",
+ "owner"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237.json b/rust/cloud-storage/macro_db_client/.sqlx/query-46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237.json
new file mode 100644
index 0000000000..c91a76ff52
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2\n AND source_id = ANY($3) AND source_type = 'channel'\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-47527ceedb84aa81cf48fd3529718a5303e9f456e3db0ac35840627b086d3995.json b/rust/cloud-storage/macro_db_client/.sqlx/query-47527ceedb84aa81cf48fd3529718a5303e9f456e3db0ac35840627b086d3995.json
new file mode 100644
index 0000000000..76fa7f167e
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-47527ceedb84aa81cf48fd3529718a5303e9f456e3db0ac35840627b086d3995.json
@@ -0,0 +1,74 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n UserAccessibleDocuments AS (\n SELECT DISTINCT ON (entity_id) entity_id, access_level\n FROM entity_access\n WHERE source_id = ANY(SELECT source_id FROM user_source_ids)\n AND entity_type = 'document'\n ORDER BY entity_id,\n CASE access_level::text\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3\n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END DESC\n )\n SELECT\n d.id as \"document_id!\",\n d.name as \"document_name!\",\n d.owner as \"owner!\",\n d.\"fileType\" as \"file_type\",\n d.\"projectId\" as \"project_id\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\",\n uad.access_level::text as \"access_level!\"\n FROM \"Document\" d\n INNER JOIN UserAccessibleDocuments uad ON uad.entity_id = d.id::uuid\n WHERE d.\"deletedAt\" IS NULL\n AND ($2::text[] IS NULL OR d.\"fileType\" = ANY($2))\n AND (\n CASE uad.access_level::text\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3\n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END >=\n CASE $3\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3\n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END\n )\n ORDER BY d.\"updatedAt\" DESC\n LIMIT $4 OFFSET $5\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "document_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "document_name!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "owner!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 6,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray",
+ "Text",
+ "Int8",
+ "Int8"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ true,
+ true,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "47527ceedb84aa81cf48fd3529718a5303e9f456e3db0ac35840627b086d3995"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-4825133a0ea4f2d839f5976681269e6ad7a517fd29a3d2a7634cc655bf7f2bfb.json b/rust/cloud-storage/macro_db_client/.sqlx/query-4825133a0ea4f2d839f5976681269e6ad7a517fd29a3d2a7634cc655bf7f2bfb.json
new file mode 100644
index 0000000000..e9ccf34748
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-4825133a0ea4f2d839f5976681269e6ad7a517fd29a3d2a7634cc655bf7f2bfb.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"entity_access\"\n WHERE entity_id = ANY($1) AND entity_type = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "UuidArray",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "4825133a0ea4f2d839f5976681269e6ad7a517fd29a3d2a7634cc655bf7f2bfb"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-4afa79ca95bdbcebe9d3de7ebb204636419e6cf89e650a8716c40ab2e588aa5b.json b/rust/cloud-storage/macro_db_client/.sqlx/query-4afa79ca95bdbcebe9d3de7ebb204636419e6cf89e650a8716c40ab2e588aa5b.json
deleted file mode 100644
index 58618b2697..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-4afa79ca95bdbcebe9d3de7ebb204636419e6cf89e650a8716c40ab2e588aa5b.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n -- CTE to recursively find all parent projects, starting from the given project.\n WITH RECURSIVE project_hierarchy AS (\n -- Base case: Start with the project ID provided.\n SELECT id as project_id\n FROM \"Project\"\n WHERE id = $1 AND \"deletedAt\" IS NULL\n UNION ALL\n -- Recursive case: Find the parent of the project from the previous step.\n SELECT parent.id as project_id\n FROM project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n -- The subquery now gathers all levels as plain text.\n SELECT access_level FROM (\n -- Source 1: Cast the AccessLevel enum to text.\n SELECT access_level::text FROM \"UserItemAccess\"\n WHERE user_id = $2 AND item_id IN (\n -- The hierarchy CTE includes the starting project, so this is all we need.\n SELECT project_id FROM project_hierarchy\n )\n UNION ALL\n -- Source 2: Select the publicAccessLevel (which is already text).\n SELECT \"publicAccessLevel\" as access_level\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true AND \"publicAccessLevel\" IS NOT NULL AND id IN (\n -- We only need to check ProjectPermission for the items in the hierarchy.\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\"\n WHERE \"projectId\" IN (SELECT project_id FROM project_hierarchy)\n )\n ) as all_levels\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "access_level",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text"
- ]
- },
- "nullable": [
- null
- ]
- },
- "hash": "4afa79ca95bdbcebe9d3de7ebb204636419e6cf89e650a8716c40ab2e588aa5b"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-4c695b011d49ba7d5fce4b309875ed952dc386ac760444d7883c5a76718f15be.json b/rust/cloud-storage/macro_db_client/.sqlx/query-4c695b011d49ba7d5fce4b309875ed952dc386ac760444d7883c5a76718f15be.json
deleted file mode 100644
index 524cc25ec7..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-4c695b011d49ba7d5fce4b309875ed952dc386ac760444d7883c5a76718f15be.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE project_hierarchy AS (\n SELECT p.id as project_id\n FROM \"Chat\" c\n JOIN \"Project\" p ON c.\"projectId\" = p.id AND p.\"deletedAt\" IS NULL\n WHERE c.id = $1 AND c.\"deletedAt\" IS NULL\n UNION ALL\n SELECT parent.id as project_id\n FROM project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n SELECT access_level FROM (\n -- Source 1: Cast the AccessLevel enum to text.\n SELECT access_level::text FROM \"UserItemAccess\"\n WHERE user_id = $2 AND item_id IN (\n SELECT $1 -- The chat itself\n UNION\n SELECT project_id FROM project_hierarchy -- All parent projects\n )\n UNION ALL\n -- Source 2: Select the publicAccessLevel (which is already text).\n SELECT \"publicAccessLevel\" as access_level\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true AND \"publicAccessLevel\" IS NOT NULL AND id IN (\n SELECT \"sharePermissionId\" FROM \"ChatPermission\" WHERE \"chatId\" = $1\n UNION\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" IN (SELECT project_id FROM project_hierarchy)\n )\n ) as all_levels\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "access_level",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text"
- ]
- },
- "nullable": [
- null
- ]
- },
- "hash": "4c695b011d49ba7d5fce4b309875ed952dc386ac760444d7883c5a76718f15be"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-4d769c5d33741ec4fffebbbe6aa655e807a7d52f0cbde4e5e958375ce73b699f.json b/rust/cloud-storage/macro_db_client/.sqlx/query-4d769c5d33741ec4fffebbbe6aa655e807a7d52f0cbde4e5e958375ce73b699f.json
deleted file mode 100644
index 8f833ed2f6..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-4d769c5d33741ec4fffebbbe6aa655e807a7d52f0cbde4e5e958375ce73b699f.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n DELETE FROM \"UserItemAccess\"\n WHERE \"user_id\" = ANY($1) \n AND \"item_id\" = $2 \n AND \"item_type\" = $3\n AND \"granted_from_channel_id\" = $4\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "TextArray",
- "Text",
- "Text",
- "Uuid"
- ]
- },
- "nullable": []
- },
- "hash": "4d769c5d33741ec4fffebbbe6aa655e807a7d52f0cbde4e5e958375ce73b699f"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-530ba9c14f6f9e857023f66fa06cf632d4f2122183631ee8ae15902cd870cac3.json b/rust/cloud-storage/macro_db_client/.sqlx/query-530ba9c14f6f9e857023f66fa06cf632d4f2122183631ee8ae15902cd870cac3.json
deleted file mode 100644
index 51a42b64cb..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-530ba9c14f6f9e857023f66fa06cf632d4f2122183631ee8ae15902cd870cac3.json
+++ /dev/null
@@ -1,77 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n -- recursively finds all parent projects for the given email thread.\n WITH RECURSIVE project_hierarchy AS (\n -- Base case: Start with the project directly associated with the thread.\n SELECT\n p.id as project_id\n FROM\n \"EmailThreadPermission\" etp\n JOIN \"Project\" p ON etp.\"projectId\" = p.id AND p.\"deletedAt\" IS NULL\n WHERE\n etp.\"threadId\" = $1\n\n UNION ALL\n\n -- Recursive case: Find the parent of the project from the previous step.\n SELECT\n parent.id as project_id\n FROM\n project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n -- The main query to select from UserItemAccess\n SELECT\n id,\n user_id,\n item_id,\n item_type,\n granted_from_channel_id,\n access_level as \"access_level!: AccessLevel\",\n created_at as \"created_at!: DateTime<Utc>\",\n updated_at as \"updated_at!: DateTime<Utc>\"\n FROM \"UserItemAccess\"\n WHERE\n -- Filter for the specific user we are interested in.\n user_id = $2\n AND item_id IN (\n -- The thread ID itself\n SELECT $1\n UNION\n -- All project IDs from the recursive CTE\n SELECT project_id FROM project_hierarchy\n )\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "item_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "item_type",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "granted_from_channel_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 5,
- "name": "access_level!: AccessLevel",
- "type_info": {
- "Custom": {
- "name": "\"AccessLevel\"",
- "kind": {
- "Enum": [
- "view",
- "comment",
- "edit",
- "owner"
- ]
- }
- }
- }
- },
- {
- "ordinal": 6,
- "name": "created_at!: DateTime<Utc>",
- "type_info": "Timestamp"
- },
- {
- "ordinal": 7,
- "name": "updated_at!: DateTime<Utc>",
- "type_info": "Timestamp"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- true,
- false,
- false,
- false
- ]
- },
- "hash": "530ba9c14f6f9e857023f66fa06cf632d4f2122183631ee8ae15902cd870cac3"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-53915ada0ceed09122ca151e1b75f23839345912f19de026d0713574d8bfb76f.json b/rust/cloud-storage/macro_db_client/.sqlx/query-53915ada0ceed09122ca151e1b75f23839345912f19de026d0713574d8bfb76f.json
deleted file mode 100644
index 3e63b7caa5..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-53915ada0ceed09122ca151e1b75f23839345912f19de026d0713574d8bfb76f.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n DELETE FROM \"UserItemAccess\"\n WHERE \"granted_from_channel_id\" = $1\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Uuid"
- ]
- },
- "nullable": []
- },
- "hash": "53915ada0ceed09122ca151e1b75f23839345912f19de026d0713574d8bfb76f"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-5897743acce966af5da46adca4a2b7648bfef1b07e8bc77e533ce3554b9f0e0a.json b/rust/cloud-storage/macro_db_client/.sqlx/query-5897743acce966af5da46adca4a2b7648bfef1b07e8bc77e533ce3554b9f0e0a.json
deleted file mode 100644
index 33c09f5dd9..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-5897743acce966af5da46adca4a2b7648bfef1b07e8bc77e533ce3554b9f0e0a.json
+++ /dev/null
@@ -1,29 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE project_hierarchy AS (\n SELECT c.id as chat_id, p.id as project_id\n FROM \"Chat\" c\n JOIN \"Project\" p ON c.\"projectId\" = p.id AND p.\"deletedAt\" IS NULL\n WHERE c.id = ANY($1) AND c.\"deletedAt\" IS NULL\n UNION ALL\n SELECT ph.chat_id, parent.id as project_id\n FROM project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n SELECT \n chat_id,\n access_level\n FROM (\n -- Source 1: Cast the AccessLevel enum to text.\n SELECT \n ph.chat_id,\n uia.access_level::text as access_level\n FROM project_hierarchy ph\n JOIN \"UserItemAccess\" uia ON uia.user_id = $2 AND (\n uia.item_id = ph.chat_id OR uia.item_id = ph.project_id\n )\n UNION ALL\n -- Source 2: Select the publicAccessLevel (which is already text).\n SELECT \n ph.chat_id,\n sp.\"publicAccessLevel\" as access_level\n FROM project_hierarchy ph\n JOIN \"ProjectPermission\" pp ON pp.\"projectId\" = ph.project_id\n JOIN \"SharePermission\" sp ON sp.id = pp.\"sharePermissionId\" \n AND sp.\"isPublic\" = true \n AND sp.\"publicAccessLevel\" IS NOT NULL\n UNION ALL\n -- Source 3: Direct chat permissions\n SELECT \n c.id as chat_id,\n uia.access_level::text as access_level\n FROM \"Chat\" c\n JOIN \"UserItemAccess\" uia ON uia.user_id = $2 AND uia.item_id = c.id\n WHERE c.id = ANY($1) AND c.\"deletedAt\" IS NULL\n UNION ALL\n -- Source 4: Direct chat public permissions\n SELECT \n c.id as chat_id,\n sp.\"publicAccessLevel\" as access_level\n FROM \"Chat\" c\n JOIN \"ChatPermission\" cp ON cp.\"chatId\" = c.id\n JOIN \"SharePermission\" sp ON sp.id = cp.\"sharePermissionId\"\n AND sp.\"isPublic\" = true \n AND sp.\"publicAccessLevel\" IS NOT NULL\n WHERE c.id = ANY($1) AND c.\"deletedAt\" IS NULL\n ) as all_levels\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "chat_id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "access_level",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "TextArray",
- "Text"
- ]
- },
- "nullable": [
- null,
- null
- ]
- },
- "hash": "5897743acce966af5da46adca4a2b7648bfef1b07e8bc77e533ce3554b9f0e0a"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf.json b/rust/cloud-storage/macro_db_client/.sqlx/query-5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf.json
new file mode 100644
index 0000000000..514e8d9770
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ChatPermission\" WHERE \"chatId\" = $1\n )\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-5c110b698a00004a548556064f3ec7f96170613378e2fc37f78f2585a26f91f0.json b/rust/cloud-storage/macro_db_client/.sqlx/query-5c110b698a00004a548556064f3ec7f96170613378e2fc37f78f2585a26f91f0.json
new file mode 100644
index 0000000000..ab05ec9386
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-5c110b698a00004a548556064f3ec7f96170613378e2fc37f78f2585a26f91f0.json
@@ -0,0 +1,30 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n -- Get all entities the user has access to via entity_access\n UserAccessibleEntities AS (\n SELECT DISTINCT\n ea.entity_id,\n ea.entity_type\n FROM entity_access ea\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n AND ($2::text IS NULL OR ea.entity_type = $2)\n ),\n -- Filter out deleted items and optionally exclude owned\n FilteredItems AS (\n SELECT uae.entity_id::text as item_id, uae.entity_type as item_type\n FROM UserAccessibleEntities uae\n LEFT JOIN \"Document\" d ON uae.entity_type = 'document' AND uae.entity_id::text = d.id\n LEFT JOIN \"Chat\" c ON uae.entity_type = 'chat' AND uae.entity_id::text = c.id\n LEFT JOIN \"Project\" p ON uae.entity_type = 'project' AND uae.entity_id::text = p.id\n WHERE\n (uae.entity_type = 'document' AND d.\"deletedAt\" IS NULL\n AND ($3 = false OR d.owner != $1)) OR\n (uae.entity_type = 'chat' AND c.\"deletedAt\" IS NULL\n AND ($3 = false OR c.\"userId\" != $1)) OR\n (uae.entity_type = 'project' AND p.\"deletedAt\" IS NULL\n AND ($3 = false OR p.\"userId\" != $1))\n )\n SELECT item_id as \"item_id!\", item_type as \"item_type!\" FROM FilteredItems\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "item_type!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Bool"
+ ]
+ },
+ "nullable": [
+ null,
+ false
+ ]
+ },
+ "hash": "5c110b698a00004a548556064f3ec7f96170613378e2fc37f78f2585a26f91f0"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b.json b/rust/cloud-storage/macro_db_client/.sqlx/query-5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b.json
new file mode 100644
index 0000000000..ac050656e7
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b.json
@@ -0,0 +1,29 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)\n SELECT $1, $2, u.user_id, 'user', $3\n FROM UNNEST($4::text[]) as u(user_id)\n ON CONFLICT (entity_id, entity_type, source_id, source_type)\n WHERE granted_from_project_id IS NULL\n AND access_level != 'owner' -- this prevents us from overriding the owner user\n DO UPDATE SET access_level = EXCLUDED.access_level, updated_at = NOW()\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ {
+ "Custom": {
+ "name": "\"AccessLevel\"",
+ "kind": {
+ "Enum": [
+ "view",
+ "comment",
+ "edit",
+ "owner"
+ ]
+ }
+ }
+ },
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-62c7dd4cfaf7bf7d6bb8c408a314fcf517efb8b1a9639df99261d44a7218922f.json b/rust/cloud-storage/macro_db_client/.sqlx/query-62c7dd4cfaf7bf7d6bb8c408a314fcf517efb8b1a9639df99261d44a7218922f.json
deleted file mode 100644
index 2115b935c8..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-62c7dd4cfaf7bf7d6bb8c408a314fcf517efb8b1a9639df99261d44a7218922f.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n UPDATE \"Document\"\n SET \"deletedAt\" = NOW()\n WHERE id = $1",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": []
- },
- "hash": "62c7dd4cfaf7bf7d6bb8c408a314fcf517efb8b1a9639df99261d44a7218922f"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c.json b/rust/cloud-storage/macro_db_client/.sqlx/query-63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c.json
new file mode 100644
index 0000000000..6d97183829
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-63492b018803ce26db5891964a0f52f37d2f54bd8243265c6561f4423af8617c.json
@@ -0,0 +1,16 @@
+{
+ "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-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json b/rust/cloud-storage/macro_db_client/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json
new file mode 100644
index 0000000000..a110bb67c6
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT DISTINCT cp.user_id\n FROM comms_channel_participants cp\n WHERE cp.channel_id = $1 AND cp.left_at IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "63ca13cc79c27b5267ebbf53491b657ca7671e1ab9d1a4691372693a9f9a4ff8"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-662c88166785d82c5262c1f7ea4def14934b7f43ee43b2a023d6ffe7abfe15c1.json b/rust/cloud-storage/macro_db_client/.sqlx/query-662c88166785d82c5262c1f7ea4def14934b7f43ee43b2a023d6ffe7abfe15c1.json
deleted file mode 100644
index 8974d475c7..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-662c88166785d82c5262c1f7ea4def14934b7f43ee43b2a023d6ffe7abfe15c1.json
+++ /dev/null
@@ -1,19 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO \"UserItemAccess\" (\n \"id\",\n \"user_id\",\n \"item_id\",\n \"item_type\",\n \"access_level\",\n \"granted_from_channel_id\",\n \"created_at\",\n \"updated_at\"\n )\n SELECT \n u.id, \n u.user_id, \n u.item_id, \n u.item_type, \n u.access_level::\"AccessLevel\", \n u.granted_from_channel_id,\n NOW() as created_at,\n NOW() as updated_at\n FROM UNNEST(\n $1::uuid[], \n $2::text[], \n $3::text[], \n $4::text[], \n $5::text[],\n $6::uuid[]\n ) as u(\n id, \n user_id, \n item_id, \n item_type, \n access_level, \n granted_from_channel_id\n )\n ON CONFLICT (\"user_id\", \"item_id\", \"item_type\", \"granted_from_channel_id\") \n DO NOTHING\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "UuidArray",
- "TextArray",
- "TextArray",
- "TextArray",
- "TextArray",
- "UuidArray"
- ]
- },
- "nullable": []
- },
- "hash": "662c88166785d82c5262c1f7ea4def14934b7f43ee43b2a023d6ffe7abfe15c1"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029.json b/rust/cloud-storage/macro_db_client/.sqlx/query-7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029.json
new file mode 100644
index 0000000000..b7e5230b4c
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM entity_access\n WHERE (source_id = ANY($1) AND source_type = 'channel')\n AND (entity_id = ANY($2) OR granted_from_project_id = ANY($3))\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "UuidArray",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-70f3f6473707a73d0e1c10cb0b7056614d0bd6c6002ba433b4d1865d308c5629.json b/rust/cloud-storage/macro_db_client/.sqlx/query-70f3f6473707a73d0e1c10cb0b7056614d0bd6c6002ba433b4d1865d308c5629.json
deleted file mode 100644
index 9ee4cefa7c..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-70f3f6473707a73d0e1c10cb0b7056614d0bd6c6002ba433b4d1865d308c5629.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n DELETE FROM \"UserItemAccess\"\n WHERE \"granted_from_channel_id\" = $1 AND \"user_id\" = ANY($2)\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Uuid",
- "TextArray"
- ]
- },
- "nullable": []
- },
- "hash": "70f3f6473707a73d0e1c10cb0b7056614d0bd6c6002ba433b4d1865d308c5629"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a.json b/rust/cloud-storage/macro_db_client/.sqlx/query-7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a.json
new file mode 100644
index 0000000000..655495fb29
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT c.id\n FROM comms_channels c\n INNER JOIN comms_channel_participants cp ON cp.channel_id = c.id\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n AND c.id = ANY($2::uuid[])\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "7617f808df94ffe77c8195a911ee6b230a21fe9935e099d1310d244248ca253a"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-833f7916c7445825f248eac09769afd4b4971b517b12e578ec2f534038609572.json b/rust/cloud-storage/macro_db_client/.sqlx/query-833f7916c7445825f248eac09769afd4b4971b517b12e578ec2f534038609572.json
new file mode 100644
index 0000000000..8b6519505d
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-833f7916c7445825f248eac09769afd4b4971b517b12e578ec2f534038609572.json
@@ -0,0 +1,29 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $2 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $2\n UNION ALL\n SELECT $2\n )\n SELECT\n chat_id,\n access_level\n FROM (\n -- Source 1: entity_access for chats\n SELECT\n ea.entity_id::text as chat_id,\n ea.access_level::text as access_level\n FROM entity_access ea\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n AND ea.entity_id = ANY(SELECT id::uuid FROM \"Chat\" WHERE id = ANY($1) AND \"deletedAt\" IS NULL)\n AND ea.entity_type = 'chat'\n UNION ALL\n -- Source 2: Direct chat public permissions\n SELECT\n c.id as chat_id,\n sp.\"publicAccessLevel\" as access_level\n FROM \"Chat\" c\n JOIN \"ChatPermission\" cp ON cp.\"chatId\" = c.id\n JOIN \"SharePermission\" sp ON sp.id = cp.\"sharePermissionId\"\n AND sp.\"isPublic\" = true\n AND sp.\"publicAccessLevel\" IS NOT NULL\n WHERE c.id = ANY($1) AND c.\"deletedAt\" IS NULL\n ) as all_levels\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "chat_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null,
+ null
+ ]
+ },
+ "hash": "833f7916c7445825f248eac09769afd4b4971b517b12e578ec2f534038609572"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-8d21bf0aa4c20589a55cf5777aa9c658fdacea4d0d0c7070aded12cccd373911.json b/rust/cloud-storage/macro_db_client/.sqlx/query-8d21bf0aa4c20589a55cf5777aa9c658fdacea4d0d0c7070aded12cccd373911.json
new file mode 100644
index 0000000000..505a2bd912
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-8d21bf0aa4c20589a55cf5777aa9c658fdacea4d0d0c7070aded12cccd373911.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE entity_properties\n SET values = $2\n WHERE entity_id = $1\n AND property_definition_id = $3\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Jsonb",
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "8d21bf0aa4c20589a55cf5777aa9c658fdacea4d0d0c7070aded12cccd373911"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-94a1d6338c8e2da84429da7a79f7dcf0a962feb7832aab9fc4bd50613f742b59.json b/rust/cloud-storage/macro_db_client/.sqlx/query-94a1d6338c8e2da84429da7a79f7dcf0a962feb7832aab9fc4bd50613f742b59.json
new file mode 100644
index 0000000000..f6156312ba
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-94a1d6338c8e2da84429da7a79f7dcf0a962feb7832aab9fc4bd50613f742b59.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT share_permission_id as \"share_permission_id!\"\n FROM (\n SELECT share_permission_id FROM calls WHERE id = $1\n UNION ALL\n SELECT share_permission_id FROM call_records WHERE id = $1\n ) t\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "share_permission_id!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "94a1d6338c8e2da84429da7a79f7dcf0a962feb7832aab9fc4bd50613f742b59"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-9cd17d2d44969a4c8812e94980b0b5c438569bd6d3ef57e23fb5393dee4c3780.json b/rust/cloud-storage/macro_db_client/.sqlx/query-9cd17d2d44969a4c8812e94980b0b5c438569bd6d3ef57e23fb5393dee4c3780.json
deleted file mode 100644
index dd0c6a4fb4..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-9cd17d2d44969a4c8812e94980b0b5c438569bd6d3ef57e23fb5393dee4c3780.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n DELETE FROM \"UserItemAccess\"\n WHERE \"item_id\" = $1 AND \"item_type\" = $2\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text",
- "Text"
- ]
- },
- "nullable": []
- },
- "hash": "9cd17d2d44969a4c8812e94980b0b5c438569bd6d3ef57e23fb5393dee4c3780"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4.json b/rust/cloud-storage/macro_db_client/.sqlx/query-9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4.json
new file mode 100644
index 0000000000..9d717fa5f9
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-9cd40fbb1ade51e9e0d49792839d1a363cada017252a6f653c2272608189bcc4.json
@@ -0,0 +1,28 @@
+{
+ "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-9f4c2d6fee38058e51a275281cb14565e4b7733df9a86e2b88b04cea6fc6566a.json b/rust/cloud-storage/macro_db_client/.sqlx/query-9f4c2d6fee38058e51a275281cb14565e4b7733df9a86e2b88b04cea6fc6566a.json
deleted file mode 100644
index 9558f7623c..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-9f4c2d6fee38058e51a275281cb14565e4b7733df9a86e2b88b04cea6fc6566a.json
+++ /dev/null
@@ -1,74 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE ProjectHierarchy AS (\n SELECT p.id, uia.access_level \n FROM \"Project\" p\n JOIN \"UserItemAccess\" uia ON p.id = uia.item_id AND uia.item_type = 'project'\n WHERE uia.user_id = $1 AND p.\"deletedAt\" IS NULL\n UNION ALL\n SELECT p.id, ph.access_level\n FROM \"Project\" p \n JOIN ProjectHierarchy ph ON p.\"parentId\" = ph.id\n WHERE p.\"deletedAt\" IS NULL\n ),\n AllAccessGrants AS (\n SELECT item_id, item_type, access_level \n FROM \"UserItemAccess\" \n WHERE user_id = $1 AND item_type = 'document'\n UNION ALL\n SELECT d.id AS item_id, 'document' AS item_type, ph.access_level\n FROM \"Document\" d \n JOIN ProjectHierarchy ph ON d.\"projectId\" = ph.id\n WHERE d.\"projectId\" IS NOT NULL AND d.\"deletedAt\" IS NULL\n ),\n UserAccessibleDocuments AS (\n SELECT DISTINCT ON (item_id) item_id, access_level\n FROM AllAccessGrants\n ORDER BY item_id, \n CASE access_level\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3 \n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END DESC\n )\n SELECT\n d.id as \"document_id!\",\n d.name as \"document_name!\",\n d.owner as \"owner!\",\n d.\"fileType\" as \"file_type\",\n d.\"projectId\" as \"project_id\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\",\n uad.access_level::text as \"access_level!\"\n FROM \"Document\" d\n INNER JOIN UserAccessibleDocuments uad ON uad.item_id = d.id\n WHERE d.\"deletedAt\" IS NULL\n AND ($2::text[] IS NULL OR d.\"fileType\" = ANY($2))\n AND (\n CASE uad.access_level::text\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3\n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END >= \n CASE $3\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3\n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END\n )\n ORDER BY d.\"updatedAt\" DESC\n LIMIT $4 OFFSET $5\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "document_id!",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "document_name!",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "owner!",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "file_type",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "project_id",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 6,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 7,
- "name": "deleted_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 8,
- "name": "access_level!",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "TextArray",
- "Text",
- "Int8",
- "Int8"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- true,
- true,
- null,
- null,
- null,
- null
- ]
- },
- "hash": "9f4c2d6fee38058e51a275281cb14565e4b7733df9a86e2b88b04cea6fc6566a"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24.json b/rust/cloud-storage/macro_db_client/.sqlx/query-a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24.json
new file mode 100644
index 0000000000..f214362a1f
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'call'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE id in (\n SELECT share_permission_id\n FROM calls\n WHERE id = $1\n UNION ALL\n SELECT share_permission_id\n FROM call_records\n WHERE id = $1\n LIMIT 1\n )\n AND \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10.json b/rust/cloud-storage/macro_db_client/.sqlx/query-ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10.json
new file mode 100644
index 0000000000..b0fb258d2d
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT l.macro_id\n FROM email_threads et\n JOIN email_links l ON et.link_id = l.id\n WHERE et.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "macro_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-ac52ec341d9ff2b334df144dfcba1195b845609b557d278290359a0e6170c10d.json b/rust/cloud-storage/macro_db_client/.sqlx/query-ac52ec341d9ff2b334df144dfcba1195b845609b557d278290359a0e6170c10d.json
new file mode 100644
index 0000000000..19f6ad325a
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-ac52ec341d9ff2b334df144dfcba1195b845609b557d278290359a0e6170c10d.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"entity_access\"\n WHERE \"entity_id\" = $1 AND \"entity_type\" = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "ac52ec341d9ff2b334df144dfcba1195b845609b557d278290359a0e6170c10d"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815.json b/rust/cloud-storage/macro_db_client/.sqlx/query-b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815.json
new file mode 100644
index 0000000000..aa74e2b98b
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'email_thread'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"EmailThreadPermission\" WHERE \"threadId\" = $3\n )\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-b3aeddd507e0efee0e0cecef6eae7503820f0f3302e95a459790c5cb78e5dfb0.json b/rust/cloud-storage/macro_db_client/.sqlx/query-b3aeddd507e0efee0e0cecef6eae7503820f0f3302e95a459790c5cb78e5dfb0.json
deleted file mode 100644
index 2b67c5606d..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-b3aeddd507e0efee0e0cecef6eae7503820f0f3302e95a459790c5cb78e5dfb0.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n -- CTE to recursively find all parent projects for the given email thread.\n WITH RECURSIVE project_hierarchy AS (\n -- Base case: Start with the project directly associated with the thread.\n SELECT\n p.id as project_id\n FROM\n \"EmailThreadPermission\" etp\n JOIN \"Project\" p ON etp.\"projectId\" = p.id AND p.\"deletedAt\" IS NULL\n WHERE\n etp.\"threadId\" = $1\n UNION ALL\n -- Recursive case: Find the parent of the project from the previous step.\n SELECT\n parent.id as project_id\n FROM\n project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n -- The subquery now gathers all levels as plain text.\n SELECT access_level FROM (\n -- Source 1: Cast the AccessLevel enum to text.\n SELECT access_level::text FROM \"UserItemAccess\"\n WHERE user_id = $2 AND item_id IN (\n SELECT $1 -- The thread ID itself\n UNION\n SELECT project_id FROM project_hierarchy -- All parent projects\n )\n UNION ALL\n -- Source 2: Select the publicAccessLevel (which is already text).\n SELECT \"publicAccessLevel\" as access_level\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true AND \"publicAccessLevel\" IS NOT NULL AND id IN (\n SELECT \"sharePermissionId\" FROM \"EmailThreadPermission\" WHERE \"threadId\" = $1\n UNION\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" IN (SELECT project_id FROM project_hierarchy)\n )\n ) as all_levels\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "access_level",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text"
- ]
- },
- "nullable": [
- null
- ]
- },
- "hash": "b3aeddd507e0efee0e0cecef6eae7503820f0f3302e95a459790c5cb78e5dfb0"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-b4edf0877afce79c1811f30b172520e11c357ef671da3ae1a651be27d01984a3.json b/rust/cloud-storage/macro_db_client/.sqlx/query-b4edf0877afce79c1811f30b172520e11c357ef671da3ae1a651be27d01984a3.json
deleted file mode 100644
index 4235a97747..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-b4edf0877afce79c1811f30b172520e11c357ef671da3ae1a651be27d01984a3.json
+++ /dev/null
@@ -1,77 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n -- recursively finds all parent projects for the given project.\n WITH RECURSIVE project_hierarchy AS (\n -- Base case: Start with the provided project itself.\n SELECT\n p.id as project_id\n FROM\n \"Project\" p\n WHERE\n p.id = $1 AND p.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Recursive case: Find the parent of the project from the previous step.\n SELECT\n parent.id as project_id\n FROM\n project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n -- The main query to select from UserItemAccess\n SELECT\n id,\n user_id,\n item_id,\n item_type,\n granted_from_channel_id,\n access_level as \"access_level!: AccessLevel\",\n created_at as \"created_at!: DateTime<Utc>\",\n updated_at as \"updated_at!: DateTime<Utc>\"\n FROM \"UserItemAccess\"\n WHERE\n -- Filter for the specific user we are interested in.\n user_id = $2\n -- Filter for items that are either the project itself or one of the projects in its hierarchy.\n AND item_id IN (\n SELECT project_id FROM project_hierarchy\n )\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "item_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "item_type",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "granted_from_channel_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 5,
- "name": "access_level!: AccessLevel",
- "type_info": {
- "Custom": {
- "name": "\"AccessLevel\"",
- "kind": {
- "Enum": [
- "view",
- "comment",
- "edit",
- "owner"
- ]
- }
- }
- }
- },
- {
- "ordinal": 6,
- "name": "created_at!: DateTime<Utc>",
- "type_info": "Timestamp"
- },
- {
- "ordinal": 7,
- "name": "updated_at!: DateTime<Utc>",
- "type_info": "Timestamp"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- true,
- false,
- false,
- false
- ]
- },
- "hash": "b4edf0877afce79c1811f30b172520e11c357ef671da3ae1a651be27d01984a3"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524.json b/rust/cloud-storage/macro_db_client/.sqlx/query-b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524.json
new file mode 100644
index 0000000000..be13d76b25
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'document'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"DocumentPermission\" WHERE \"documentId\" = $3\n ) \n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157.json b/rust/cloud-storage/macro_db_client/.sqlx/query-b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157.json
new file mode 100644
index 0000000000..d560cb7eb3
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'chat'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ChatPermission\" WHERE \"chatId\" = $3\n )\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682.json b/rust/cloud-storage/macro_db_client/.sqlx/query-bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682.json
new file mode 100644
index 0000000000..3ed3f3db5e
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE id in (SELECT share_permission_id\n FROM calls\n WHERE id = $1\n UNION ALL\n SELECT share_permission_id\n FROM call_records\n WHERE id = $1\n LIMIT 1)\n AND \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476.json b/rust/cloud-storage/macro_db_client/.sqlx/query-c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476.json
new file mode 100644
index 0000000000..1216b39a3c
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'project'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" = $3\n )\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580.json b/rust/cloud-storage/macro_db_client/.sqlx/query-cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580.json
new file mode 100644
index 0000000000..ddcaf87146
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT cp.channel_id::text FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "channel_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2.json b/rust/cloud-storage/macro_db_client/.sqlx/query-e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2.json
new file mode 100644
index 0000000000..f47413e3dc
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH RECURSIVE parent_projects AS (\n -- Base case: the project itself\n SELECT id, name, \"parentId\"\n FROM \"Project\"\n WHERE id = $1\n\n UNION ALL\n\n -- Recursive case: walk up to the parent\n SELECT p.id, p.name, p.\"parentId\"\n FROM \"Project\" p\n INNER JOIN parent_projects pp ON p.id = pp.\"parentId\"\n )\n SELECT id as \"id!\"\n FROM parent_projects\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437.json b/rust/cloud-storage/macro_db_client/.sqlx/query-e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437.json
new file mode 100644
index 0000000000..3ac1b029f6
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"EmailThreadPermission\" WHERE \"threadId\" = $1\n )\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069.json b/rust/cloud-storage/macro_db_client/.sqlx/query-f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069.json
new file mode 100644
index 0000000000..182e0858ba
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-f2d5d7aea9918978cd69c14f8afe24156c2fa387e001ee8eaf57e4a70a106069.json
@@ -0,0 +1,18 @@
+{
+ "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-f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f.json b/rust/cloud-storage/macro_db_client/.sqlx/query-f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f.json
new file mode 100644
index 0000000000..c718076a09
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH RECURSIVE child_projects AS (\n SELECT id FROM \"Project\" WHERE id = $1\n\n UNION ALL\n\n SELECT p.id FROM \"Project\" p\n INNER JOIN child_projects cp ON p.\"parentId\" = cp.id\n )\n SELECT id as \"entity_id!\", 'project' as \"entity_type!\" FROM child_projects\n\n UNION ALL\n\n SELECT d.id as \"entity_id!\", 'document' as \"entity_type!\" FROM \"Document\" d\n WHERE d.\"projectId\" IN (SELECT id FROM child_projects)\n\n UNION ALL\n\n SELECT c.id as \"entity_id!\", 'chat' as \"entity_type!\" FROM \"Chat\" c\n WHERE c.\"projectId\" IN (SELECT id FROM child_projects)\n\n UNION ALL\n\n SELECT et.id::text as \"entity_id!\", 'email_thread' as \"entity_type!\" FROM email_threads et\n WHERE et.project_id IN (SELECT id FROM child_projects)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "entity_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "entity_type!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null,
+ null
+ ]
+ },
+ "hash": "f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-fa45517848b9271711830a6b7e51d95d88ff70260d844e563a25a916cd9a9791.json b/rust/cloud-storage/macro_db_client/.sqlx/query-fa45517848b9271711830a6b7e51d95d88ff70260d844e563a25a916cd9a9791.json
deleted file mode 100644
index fedcaff044..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-fa45517848b9271711830a6b7e51d95d88ff70260d844e563a25a916cd9a9791.json
+++ /dev/null
@@ -1,30 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE ProjectHierarchy AS (\n -- Find direct user access to projects first as starting point\n SELECT\n p.id,\n uia.access_level\n FROM \"Project\" p\n JOIN \"UserItemAccess\" uia ON p.id = uia.item_id AND uia.item_type = 'project'\n WHERE uia.user_id = $1 AND p.\"deletedAt\" IS NULL\n AND ($3 = false OR p.\"userId\" != $1) -- Exclude owned projects if exclude_owned = true\n\n UNION ALL\n\n -- Then walk down the project tree and grab child projects, keeping parent's access\n SELECT\n p.id,\n ph.access_level\n FROM \"Project\" p\n JOIN ProjectHierarchy ph ON p.\"parentId\" = ph.id\n WHERE p.\"deletedAt\" IS NULL\n AND ($3 = false OR p.\"userId\" != $1) -- Exclude owned projects if exclude_owned = true\n ),\n -- Now build up all the ways a user can have access to stuff\n AllAccessGrants AS (\n -- Explicit access to items via UserItemAccess table\n SELECT uia.item_id, uia.item_type, uia.access_level\n FROM \"UserItemAccess\" uia\n -- We join to each table to check its \"deletedAt\" status.\n -- This is more explicit and robust than using subqueries.\n LEFT JOIN \"Document\" d ON uia.item_type = 'document' AND uia.item_id = d.id\n LEFT JOIN \"Chat\" c ON uia.item_type = 'chat' AND uia.item_id = c.id\n LEFT JOIN \"Project\" p ON uia.item_type = 'project' AND uia.item_id = p.id\n WHERE uia.user_id = $1\n AND ($2::text IS NULL OR uia.item_type = $2)\n -- Rule: The item must not be deleted.\n AND (\n (uia.item_type = 'document' AND d.\"deletedAt\" IS NULL) OR\n (uia.item_type = 'chat' AND c.\"deletedAt\" IS NULL) OR\n (uia.item_type = 'project' AND p.\"deletedAt\" IS NULL)\n )\n -- Rule: If exclude_owned is true, the user must not be the creator of the item.\n AND ($3 = false OR (\n (uia.item_type = 'document' AND d.owner != $1) OR\n (uia.item_type = 'chat' AND c.\"userId\" != $1) OR\n (uia.item_type = 'project' AND p.\"userId\" != $1)\n ))\n\n -- The rest of the unions are to get implicit access to items via project access\n UNION ALL\n\n -- Access to docs in visible projects \n SELECT\n d.id AS item_id,\n 'document' AS item_type,\n ph.access_level\n FROM \"Document\" d\n JOIN ProjectHierarchy ph ON d.\"projectId\" = ph.id\n WHERE ($2::text IS NULL OR 'document' = $2)\n AND d.\"projectId\" IS NOT NULL AND d.\"deletedAt\" IS NULL\n AND ($3 = false OR d.owner != $1)\n\n UNION ALL\n\n -- Access to chats in visible projects\n SELECT\n c.id AS item_id,\n 'chat' AS item_type,\n ph.access_level\n FROM \"Chat\" c\n JOIN ProjectHierarchy ph ON c.\"projectId\" = ph.id\n WHERE ($2::text IS NULL OR 'chat' = $2)\n AND c.\"projectId\" IS NOT NULL AND c.\"deletedAt\" IS NULL\n AND ($3 = false OR c.\"userId\" != $1)\n\n UNION ALL\n\n -- Include the projects we found earlier\n SELECT\n ph.id AS item_id,\n 'project' AS item_type,\n ph.access_level\n FROM ProjectHierarchy ph\n WHERE ($2::text IS NULL OR 'project' = $2)\n ),\n UserAccessibleItems AS (\n SELECT\n item_id,\n item_type\n FROM AllAccessGrants\n GROUP BY item_id, item_type\n )\n SELECT item_id as \"item_id!\", item_type as \"item_type!\" FROM UserAccessibleItems\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "item_id!",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "item_type!",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text",
- "Bool"
- ]
- },
- "nullable": [
- null,
- null
- ]
- },
- "hash": "fa45517848b9271711830a6b7e51d95d88ff70260d844e563a25a916cd9a9791"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-fab2fcdcfa7c81426ffddfb934b7c5eade3811d3ec8b5ab962c3dc9fd7886e9b.json b/rust/cloud-storage/macro_db_client/.sqlx/query-fab2fcdcfa7c81426ffddfb934b7c5eade3811d3ec8b5ab962c3dc9fd7886e9b.json
deleted file mode 100644
index 02598512d9..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-fab2fcdcfa7c81426ffddfb934b7c5eade3811d3ec8b5ab962c3dc9fd7886e9b.json
+++ /dev/null
@@ -1,77 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n -- recursively finds all parent projects for the given chat.\n WITH RECURSIVE project_hierarchy AS (\n -- Base case: Start with the project directly associated with the chat.\n SELECT\n p.id as project_id\n FROM\n \"Chat\" c\n JOIN \"Project\" p ON c.\"projectId\" = p.id AND p.\"deletedAt\" IS NULL\n WHERE\n c.id = $1 AND c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Recursive case: Find the parent of the project from the previous step.\n SELECT\n parent.id as project_id\n FROM\n project_hierarchy ph\n JOIN \"Project\" parent ON parent.id = (\n SELECT \"parentId\" FROM \"Project\" WHERE id = ph.project_id AND \"parentId\" IS NOT NULL AND \"deletedAt\" IS NULL\n )\n )\n -- The main query to select from UserItemAccess\n SELECT\n id,\n user_id,\n item_id,\n item_type,\n granted_from_channel_id,\n access_level as \"access_level!: AccessLevel\",\n created_at as \"created_at!: DateTime<Utc>\",\n updated_at as \"updated_at!: DateTime<Utc>\"\n FROM \"UserItemAccess\"\n WHERE\n -- Filter for the specific user we are interested in.\n user_id = $2\n AND item_id IN (\n -- The chat ID itself\n SELECT $1\n UNION\n -- All project IDs from the recursive CTE\n SELECT project_id FROM project_hierarchy\n )\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "item_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "item_type",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "granted_from_channel_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 5,
- "name": "access_level!: AccessLevel",
- "type_info": {
- "Custom": {
- "name": "\"AccessLevel\"",
- "kind": {
- "Enum": [
- "view",
- "comment",
- "edit",
- "owner"
- ]
- }
- }
- }
- },
- {
- "ordinal": 6,
- "name": "created_at!: DateTime<Utc>",
- "type_info": "Timestamp"
- },
- {
- "ordinal": 7,
- "name": "updated_at!: DateTime<Utc>",
- "type_info": "Timestamp"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- true,
- false,
- false,
- false
- ]
- },
- "hash": "fab2fcdcfa7c81426ffddfb934b7c5eade3811d3ec8b5ab962c3dc9fd7886e9b"
-}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-fd65e80e68a17871a3a3ef4bd1bab20faaf6ba24f55172486a74aaec3da480f4.json b/rust/cloud-storage/macro_db_client/.sqlx/query-fd65e80e68a17871a3a3ef4bd1bab20faaf6ba24f55172486a74aaec3da480f4.json
new file mode 100644
index 0000000000..6819822606
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-fd65e80e68a17871a3a3ef4bd1bab20faaf6ba24f55172486a74aaec3da480f4.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM \"entity_access\"\n WHERE (entity_id = ANY($1) AND entity_type = $2)\n OR granted_from_project_id = ANY($3)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "UuidArray",
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "fd65e80e68a17871a3a3ef4bd1bab20faaf6ba24f55172486a74aaec3da480f4"
+}
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-fef80a0b809980ea8efbf49087aff2dd8c12edd081ad759855474fd9a4d1916d.json b/rust/cloud-storage/macro_db_client/.sqlx/query-fef80a0b809980ea8efbf49087aff2dd8c12edd081ad759855474fd9a4d1916d.json
deleted file mode 100644
index 055f08f556..0000000000
--- a/rust/cloud-storage/macro_db_client/.sqlx/query-fef80a0b809980ea8efbf49087aff2dd8c12edd081ad759855474fd9a4d1916d.json
+++ /dev/null
@@ -1,31 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO \"UserItemAccess\" (\n \"id\",\n \"user_id\",\n \"item_id\",\n \"item_type\",\n \"access_level\",\n \"granted_from_channel_id\",\n \"created_at\",\n \"updated_at\"\n )\n SELECT \n u.id, \n u.user_id, \n $1 as item_id, \n $2 as item_type, \n $3 as access_level,\n $4 as granted_from_channel_id,\n NOW() as created_at,\n NOW() as updated_at\n FROM UNNEST($5::uuid[], $6::text[]) as u(id, user_id)\n ON CONFLICT (\"user_id\", \"item_id\", \"item_type\", \"granted_from_channel_id\") DO UPDATE \n SET \n \"access_level\" = EXCLUDED.\"access_level\",\n \"updated_at\" = NOW()\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text",
- "Text",
- {
- "Custom": {
- "name": "\"AccessLevel\"",
- "kind": {
- "Enum": [
- "view",
- "comment",
- "edit",
- "owner"
- ]
- }
- }
- },
- "Uuid",
- "UuidArray",
- "TextArray"
- ]
- },
- "nullable": []
- },
- "hash": "fef80a0b809980ea8efbf49087aff2dd8c12edd081ad759855474fd9a4d1916d"
-}
diff --git a/rust/cloud-storage/macro_db_client/Cargo.toml b/rust/cloud-storage/macro_db_client/Cargo.toml
index cf03ca2ffa..34f39f6a68 100644
--- a/rust/cloud-storage/macro_db_client/Cargo.toml
+++ b/rust/cloud-storage/macro_db_client/Cargo.toml
@@ -16,14 +16,19 @@ async-recursion = "1.1.1"
async-trait = { workspace = true }
cached = { workspace = true }
chrono = { workspace = true }
+document_sub_type = { path = "../document_sub_type" }
+entity_access_db_utils = { path = "../entity_access_db_utils" }
futures = { workspace = true }
macro_user_id = { path = "../macro_user_id" }
macro_uuid = { path = "../macro_uuid" }
mockall = { workspace = true }
model = { path = "../model" }
-model_file_type = { path = "../model_file_type" }
model-entity = { path = "../model-entity" }
+model_file_type = { path = "../model_file_type" }
models_dcs = { path = "../models_dcs" }
+models_entity_access_management = { path = "../models_entity_access_management", features = [
+ "db",
+] }
models_opensearch = { path = "../models_opensearch" }
models_pagination = { path = "../models_pagination" }
models_permissions = { path = "../models_permissions" }
@@ -34,10 +39,9 @@ rand = { workspace = true, optional = true }
serde = { workspace = true }
serde_json = { workspace = true }
sqlx = { workspace = true }
+system_properties = { path = "../system_properties" }
thiserror = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
user_quota = { path = "../user_quota" }
uuid = { workspace = true }
-document_sub_type = { path = "../document_sub_type" }
-system_properties = { path = "../system_properties" }
diff --git a/rust/cloud-storage/macro_db_client/fixtures/basic_user_with_lots_of_documents.sql b/rust/cloud-storage/macro_db_client/fixtures/basic_user_with_lots_of_documents.sql
index 5f7fd131e6..1f409a0648 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/basic_user_with_lots_of_documents.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/basic_user_with_lots_of_documents.sql
@@ -128,14 +128,7 @@ INSERT INTO public."Pin" ("userId", "pinnedItemId", "pinnedItemType", "pinIndex"
INSERT INTO public."Pin" ("userId", "pinnedItemId", "pinnedItemType", "pinIndex", "createdAt", "updatedAt")
(SELECT 'macro|[email protected]', 'project-one', 'project', 0, '2019-10-16 01:00:00', '2019-10-16 01:00:00');
--- Add UserItemAccess entries for documents owned by the user
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES
- ('10000000-0000-0000-0000-000000000001', 'macro|[email protected]', 'document-one', 'document', 'owner'),
- ('10000000-0000-0000-0000-000000000002', 'macro|[email protected]', 'document-two', 'document', 'owner'),
- ('10000000-0000-0000-0000-000000000003', 'macro|[email protected]', 'document-three', 'document', 'owner'),
- ('10000000-0000-0000-0000-000000000004', 'macro|[email protected]', 'document-four', 'document', 'owner'),
- ('10000000-0000-0000-0000-000000000005', 'macro|[email protected]', 'document-five', 'document', 'owner'),
- ('10000000-0000-0000-0000-000000000006', 'macro|[email protected]', 'document-six', 'document', 'owner'),
- ('10000000-0000-0000-0000-000000000007', 'macro|[email protected]', 'document-seven', 'document', 'owner'),
- ('10000000-0000-0000-0000-000000000008', 'macro|[email protected]', 'project-one', 'project', 'owner');
+-- Access entries were previously here but have been removed.
+-- This fixture uses non-UUID text document IDs which cannot be stored in
+-- the entity_access.entity_id UUID column.
+-- Tests that need entity_access should use the list_documents_with_access fixture instead.
diff --git a/rust/cloud-storage/macro_db_client/fixtures/document_access_via_email_thread.sql b/rust/cloud-storage/macro_db_client/fixtures/document_access_via_email_thread.sql
index 2e50228967..d1953315be 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/document_access_via_email_thread.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/document_access_via_email_thread.sql
@@ -4,7 +4,7 @@
TRUNCATE TABLE public."User", public."Project", public."Document", public."SharePermission",
public."DocumentPermission", public."ProjectPermission", public."EmailThreadPermission",
- public."UserItemAccess", public.email_links, public.email_threads, public.email_messages,
+ public.entity_access, public.email_links, public.email_threads, public.email_messages,
public.email_attachments, public.document_email RESTART IDENTITY CASCADE;
------------------------------------------------------------
@@ -48,14 +48,14 @@ VALUES ('a0000000-0000-0000-0000-000000001000', 'a0000000-0000-0000-0000-0000000
-- d-attachment-with-direct: linked to thread 2 via email attachment, also has direct access
-- d-not-attachment: regular document, not linked to any email
INSERT INTO public."Document" ("id", "name", "owner")
-VALUES ('d-attachment', 'Email Attachment Doc', 'user-thread-access'),
- ('d-attachment-with-direct', 'Email Attachment With Direct Access', 'user-both-access'),
- ('d-not-attachment', 'Regular Document', 'user-no-access');
+VALUES ('dddddddd-dddd-dddd-dddd-100000000001', 'Email Attachment Doc', 'user-thread-access'),
+ ('dddddddd-dddd-dddd-dddd-100000000002', 'Email Attachment With Direct Access', 'user-both-access'),
+ ('dddddddd-dddd-dddd-dddd-100000000003', 'Regular Document', 'user-no-access');
-- Link documents to email attachments
INSERT INTO document_email (document_id, email_attachment_id)
-VALUES ('d-attachment', 'a0000000-0000-0000-0000-000000001000'),
- ('d-attachment-with-direct', 'a0000000-0000-0000-0000-000000002000');
+VALUES ('dddddddd-dddd-dddd-dddd-100000000001', 'a0000000-0000-0000-0000-000000001000'),
+ ('dddddddd-dddd-dddd-dddd-100000000002', 'a0000000-0000-0000-0000-000000002000');
------------------------------------------------------------
-- Thread permissions (via EmailThreadPermission + SharePermission)
@@ -70,9 +70,9 @@ VALUES ('a0000000-0000-0000-0000-000000000010', 'sp-thread-1', 'user-thread-acce
-- user-thread-access has view on thread 1 (so should get view on d-attachment)
-- user-both-access has edit on thread 2
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level")
VALUES
- ('b0000000-0000-0000-0000-000000000001', 'user-thread-access', 'a0000000-0000-0000-0000-000000000010', 'thread', 'view'),
- ('b0000000-0000-0000-0000-000000000002', 'user-both-access', 'a0000000-0000-0000-0000-000000000020', 'thread', 'edit'),
+ ('a0000000-0000-0000-0000-000000000010', 'thread', 'user-thread-access', 'user', 'view'),
+ ('a0000000-0000-0000-0000-000000000020', 'thread', 'user-both-access', 'user', 'edit'),
-- user-both-access also has direct view on d-attachment-with-direct (thread gives edit, so edit should win)
- ('b0000000-0000-0000-0000-000000000003', 'user-both-access', 'd-attachment-with-direct', 'document', 'view');
+ ('dddddddd-dddd-dddd-dddd-100000000002', 'document', 'user-both-access', 'user', 'view');
diff --git a/rust/cloud-storage/macro_db_client/fixtures/dynamic_query_exhaustive.sql b/rust/cloud-storage/macro_db_client/fixtures/dynamic_query_exhaustive.sql
index 87ab3817c6..c5ee5948d7 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/dynamic_query_exhaustive.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/dynamic_query_exhaustive.sql
@@ -200,15 +200,32 @@ VALUES
-- USER ACCESS PERMISSIONS
---------------------------------
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level", "granted_from_project_id")
VALUES
- -- user-1: owner on project-root (inherits to mid, deep, and all items therein)
- (gen_random_uuid(), 'macro|[email protected]', 'aa000001-ffff-ffff-ffff-ffffffffffff', 'project', 'owner'),
+ -- user-1: owner on project-root
+ ('aa000001-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'owner', NULL),
+ -- user-1: inherited access to project-mid and project-deep
+ ('aa000002-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('aa000003-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ -- user-1: inherited access to all docs/chats in root project hierarchy
+ ('bb000001-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('bb000002-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('bb000003-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('bb000005-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('bb000006-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('bb000007-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('bb000008-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('bb000010-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('cc000001-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'chat', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('cc000003-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'chat', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('cc000005-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'chat', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
-- user-1: direct access to standalone items
- (gen_random_uuid(), 'macro|[email protected]', 'bb000004-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', 'cc000002-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'chat', 'owner'),
- -- user-2: owner on isolated project
- (gen_random_uuid(), 'macro|[email protected]', 'aa000004-ffff-ffff-ffff-ffffffffffff', 'project', 'owner');
+ ('bb000004-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', NULL),
+ ('cc000002-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'chat', 'macro|[email protected]', 'user', 'owner', NULL),
+ -- user-2: owner on isolated project and its items
+ ('aa000004-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'owner', NULL),
+ ('bb000009-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', 'aa000004-ffff-ffff-ffff-ffffffffffff'),
+ ('cc000004-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'chat', 'macro|[email protected]', 'user', 'owner', 'aa000004-ffff-ffff-ffff-ffffffffffff');
---------------------------------
-- USER HISTORY
diff --git a/rust/cloud-storage/macro_db_client/fixtures/entity_filter_tests.sql b/rust/cloud-storage/macro_db_client/fixtures/entity_filter_tests.sql
index f192d09127..36720d3bc4 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/entity_filter_tests.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/entity_filter_tests.sql
@@ -73,23 +73,35 @@ VALUES
('e5e5e5e5-e5e5-e5e5-e5e5-e5e5e5e5e5e5', 'Isolated Chat', 'macro|[email protected]', '55555555-5555-5555-5555-555555555555', '2023-01-06 14:00:00', '2023-01-06 14:00:00');
---------------------------------------------------
--- USER ACCESS PERMISSIONS (UserItemAccess)
+-- USER ACCESS PERMISSIONS (entity_access)
---------------------------------------------------
+-- entity_access denormalizes all access including project-inherited items.
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level", "granted_from_project_id")
VALUES
--- User gets 'view' on project-A (gives access to A, B, C and their contents)
-(gen_random_uuid(), 'macro|[email protected]', '11111111-1111-1111-1111-111111111111', 'project', 'view'),
-
--- Direct 'edit' on doc-in-B
-(gen_random_uuid(), 'macro|[email protected]', 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', 'edit'),
-
--- User gets 'owner' on project-D
-(gen_random_uuid(), 'macro|[email protected]', '44444444-4444-4444-4444-444444444444', 'project', 'owner'),
+-- Direct access to project-A (view)
+('11111111-1111-1111-1111-111111111111', 'project', 'macro|[email protected]', 'user', 'view', NULL),
+-- Inherited access to project-B and project-C from project-A
+('22222222-2222-2222-2222-222222222222', 'project', 'macro|[email protected]', 'user', 'view', '11111111-1111-1111-1111-111111111111'),
+('33333333-3333-3333-3333-333333333333', 'project', 'macro|[email protected]', 'user', 'view', '11111111-1111-1111-1111-111111111111'),
+-- Inherited access to documents and chats in A, B, C
+('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'view', '11111111-1111-1111-1111-111111111111'),
+('a1a1a1a1-a1a1-a1a1-a1a1-a1a1a1a1a1a1', 'chat', 'macro|[email protected]', 'user', 'view', '11111111-1111-1111-1111-111111111111'),
+('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', 'macro|[email protected]', 'user', 'view', '11111111-1111-1111-1111-111111111111'),
+('b2b2b2b2-b2b2-b2b2-b2b2-b2b2b2b2b2b2', 'chat', 'macro|[email protected]', 'user', 'view', '11111111-1111-1111-1111-111111111111'),
+('cccccccc-cccc-cccc-cccc-cccccccccccc', 'document', 'macro|[email protected]', 'user', 'view', '11111111-1111-1111-1111-111111111111'),
+('c3c3c3c3-c3c3-c3c3-c3c3-c3c3c3c3c3c3', 'chat', 'macro|[email protected]', 'user', 'view', '11111111-1111-1111-1111-111111111111'),
+
+-- Direct 'edit' on doc-in-B (higher than inherited 'view')
+('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', 'macro|[email protected]', 'user', 'edit', NULL),
+
+-- Direct access to project-D (owner) and its document
+('44444444-4444-4444-4444-444444444444', 'project', 'macro|[email protected]', 'user', 'owner', NULL),
+('dddddddd-dddd-dddd-dddd-dddddddddddd', 'document', 'macro|[email protected]', 'user', 'owner', '44444444-4444-4444-4444-444444444444'),
-- Direct access to standalone items
-(gen_random_uuid(), 'macro|[email protected]', 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'document', 'owner'),
-(gen_random_uuid(), 'macro|[email protected]', 'd4d4d4d4-d4d4-d4d4-d4d4-d4d4d4d4d4d4', 'chat', 'owner');
+('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'document', 'macro|[email protected]', 'user', 'owner', NULL),
+('d4d4d4d4-d4d4-d4d4-d4d4-d4d4d4d4d4d4', 'chat', 'macro|[email protected]', 'user', 'owner', NULL);
-- User history
INSERT INTO public."UserHistory" ("userId", "itemId", "itemType", "createdAt", "updatedAt")
diff --git a/rust/cloud-storage/macro_db_client/fixtures/expanded_cursor_soup_exhaustive.sql b/rust/cloud-storage/macro_db_client/fixtures/expanded_cursor_soup_exhaustive.sql
index b796eed6b5..909d714ec6 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/expanded_cursor_soup_exhaustive.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/expanded_cursor_soup_exhaustive.sql
@@ -168,15 +168,30 @@ VALUES
-- USER ACCESS PERMISSIONS
---------------------------------
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level", "granted_from_project_id")
VALUES
- -- user-1: owner on project-root (inherits to mid and deep)
- (gen_random_uuid(), 'macro|[email protected]', 'aa000001-ffff-ffff-ffff-ffffffffffff', 'project', 'owner'),
+ -- user-1: owner on project-root
+ ('aa000001-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'owner', NULL),
+ -- user-1: inherited access to project-mid and project-deep
+ ('aa000002-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('aa000003-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ -- user-1: inherited access to all docs/chats in root project hierarchy
+ ('bb000001-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('bb000002-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('bb000003-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('bb000005-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('bb000006-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('bb000007-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('bb000008-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('cc000001-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'chat', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
+ ('cc000003-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'chat', 'macro|[email protected]', 'user', 'owner', 'aa000001-ffff-ffff-ffff-ffffffffffff'),
-- user-1: direct access to standalone items
- (gen_random_uuid(), 'macro|[email protected]', 'bb000004-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', 'cc000002-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'chat', 'owner'),
- -- user-2: owner on isolated project
- (gen_random_uuid(), 'macro|[email protected]', 'aa000004-ffff-ffff-ffff-ffffffffffff', 'project', 'owner');
+ ('bb000004-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', NULL),
+ ('cc000002-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'chat', 'macro|[email protected]', 'user', 'owner', NULL),
+ -- user-2: owner on isolated project and its items
+ ('aa000004-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'owner', NULL),
+ ('bb000009-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', 'aa000004-ffff-ffff-ffff-ffffffffffff'),
+ ('cc000004-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'chat', 'macro|[email protected]', 'user', 'owner', 'aa000004-ffff-ffff-ffff-ffffffffffff');
---------------------------------
-- USER HISTORY
diff --git a/rust/cloud-storage/macro_db_client/fixtures/get_user_accessible_items_explicit.sql b/rust/cloud-storage/macro_db_client/fixtures/get_user_accessible_items_explicit.sql
index c70ea87c02..ff26ffeb21 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/get_user_accessible_items_explicit.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/get_user_accessible_items_explicit.sql
@@ -15,47 +15,47 @@ INSERT INTO public."User" ("id", "email", "stripeCustomerId", "organizationId",
VALUES ('user-1', '[email protected]', 'stripe_1', 1, 'a1111111-1111-1111-1111-111111111111'),
('user-2', '[email protected]', 'stripe_2', 1, 'a2222222-2222-2222-2222-222222222222');
--- === Items Owned by user-1 ===
+-- === Items Owned by user-1 (using UUID IDs) ===
INSERT INTO public."Project" ("id", "name", "userId")
-VALUES ('project-owned', 'My Project', 'user-1');
+VALUES ('a0000000-0000-0000-0000-0000000e0001', 'My Project', 'user-1');
INSERT INTO public."Chat" ("id", "name", "userId")
-VALUES ('chat-owned', 'My Chat', 'user-1');
+VALUES ('a0000000-0000-0000-0000-0000000e0002', 'My Chat', 'user-1');
INSERT INTO public."Document" ("id", "name", "owner")
-VALUES ('doc-owned', 'My Document', 'user-1');
+VALUES ('a0000000-0000-0000-0000-0000000e0003', 'My Document', 'user-1');
-- === Items Owned by user-2 (and shared with user-1) ===
INSERT INTO public."Project" ("id", "name", "userId")
-VALUES ('project-shared', 'Shared Project', 'user-2');
+VALUES ('a0000000-0000-0000-0000-0000000e0004', 'Shared Project', 'user-2');
INSERT INTO public."Chat" ("id", "name", "userId")
-VALUES ('chat-shared', 'Shared Chat', 'user-2');
+VALUES ('a0000000-0000-0000-0000-0000000e0005', 'Shared Chat', 'user-2');
INSERT INTO public."Document" ("id", "name", "owner")
-VALUES ('doc-shared', 'Shared Document', 'user-2');
+VALUES ('a0000000-0000-0000-0000-0000000e0006', 'Shared Document', 'user-2');
-- An item user-1 should NEVER see
INSERT INTO public."Document" ("id", "name", "owner")
-VALUES ('doc-unrelated', 'Unrelated Document', 'user-2');
+VALUES ('a0000000-0000-0000-0000-0000000e0007', 'Unrelated Document', 'user-2');
-- Dependencies
INSERT INTO public."DocumentFamily" ("id", "rootDocumentId")
-VALUES (1, 'doc-owned'),
- (2, 'doc-shared'),
- (3, 'doc-unrelated');
+VALUES (1, 'a0000000-0000-0000-0000-0000000e0003'),
+ (2, 'a0000000-0000-0000-0000-0000000e0006'),
+ (3, 'a0000000-0000-0000-0000-0000000e0007');
INSERT INTO public."DocumentInstance" ("id", "documentId", "sha")
-VALUES (1, 'doc-owned', 'sha-o'),
- (2, 'doc-shared', 'sha-s'),
- (3, 'doc-unrelated', 'sha-u');
+VALUES (1, 'a0000000-0000-0000-0000-0000000e0003', 'sha-o'),
+ (2, 'a0000000-0000-0000-0000-0000000e0006', 'sha-s'),
+ (3, 'a0000000-0000-0000-0000-0000000e0007', 'sha-u');
--- === Grant Access ===
+-- === Grant Access via entity_access ===
-- user-1 has access to their own items
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES (gen_random_uuid(), 'user-1', 'project-owned', 'project', 'owner'),
- (gen_random_uuid(), 'user-1', 'chat-owned', 'chat', 'owner'),
- (gen_random_uuid(), 'user-1', 'doc-owned', 'document', 'owner');
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level")
+VALUES ('a0000000-0000-0000-0000-0000000e0001'::uuid, 'project', 'user-1', 'user', 'owner'),
+ ('a0000000-0000-0000-0000-0000000e0002'::uuid, 'chat', 'user-1', 'user', 'owner'),
+ ('a0000000-0000-0000-0000-0000000e0003'::uuid, 'document', 'user-1', 'user', 'owner');
-- user-1 is granted access to user-2's items
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES (gen_random_uuid(), 'user-1', 'project-shared', 'project', 'view'),
- (gen_random_uuid(), 'user-1', 'chat-shared', 'chat', 'view'),
- (gen_random_uuid(), 'user-1', 'doc-shared', 'document', 'view');
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level")
+VALUES ('a0000000-0000-0000-0000-0000000e0004'::uuid, 'project', 'user-1', 'user', 'view'),
+ ('a0000000-0000-0000-0000-0000000e0005'::uuid, 'chat', 'user-1', 'user', 'view'),
+ ('a0000000-0000-0000-0000-0000000e0006'::uuid, 'document', 'user-1', 'user', 'view');
-SET session_replication_role = 'origin';
\ No newline at end of file
+SET session_replication_role = 'origin';
diff --git a/rust/cloud-storage/macro_db_client/fixtures/get_user_accessible_items_implicit.sql b/rust/cloud-storage/macro_db_client/fixtures/get_user_accessible_items_implicit.sql
index 0bcf65c914..3fe2f9c8a4 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/get_user_accessible_items_implicit.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/get_user_accessible_items_implicit.sql
@@ -1,7 +1,7 @@
-- This fixture tests implicit (hierarchical) permissions.
-- user-2 owns a project structure: Project A contains Project B, Document A, and Chat A.
--- user-1 is ONLY given explicit 'view' access to the top-level Project A.
--- The tests will verify that user-1 correctly gains implicit access to the nested items.
+-- user-1 has access via entity_access to all entities (entity_access has rows for items
+-- inside projects via granted_from_project_id).
SET session_replication_role = 'replica';
@@ -19,25 +19,28 @@ VALUES ('user-1', '[email protected]', 'stripe_1', 1, 'a1111111-1111-1111-1111-1111
-- === Project Hierarchy (owned by user-2) ===
INSERT INTO public."Project" ("id", "name", "userId", "parentId")
-VALUES ('project-A', 'Top Level Project', 'user-2', NULL),
- ('project-B', 'Nested Project', 'user-2', 'project-A');
+VALUES ('b0000000-0000-0000-0000-0000000e0001', 'Top Level Project', 'user-2', NULL),
+ ('b0000000-0000-0000-0000-0000000e0002', 'Nested Project', 'user-2', 'b0000000-0000-0000-0000-0000000e0001');
-- === Items inside Project A (owned by user-2) ===
INSERT INTO public."Chat" ("id", "name", "userId", "projectId")
-VALUES ('chat-A', 'Nested Chat', 'user-2', 'project-A');
+VALUES ('b0000000-0000-0000-0000-0000000e0003', 'Nested Chat', 'user-2', 'b0000000-0000-0000-0000-0000000e0001');
INSERT INTO public."Document" ("id", "name", "owner", "projectId")
-VALUES ('doc-A', 'Nested Document', 'user-2', 'project-A');
+VALUES ('b0000000-0000-0000-0000-0000000e0004', 'Nested Document', 'user-2', 'b0000000-0000-0000-0000-0000000e0001');
-- Dependencies
INSERT INTO public."DocumentFamily" ("id", "rootDocumentId")
-VALUES (1, 'doc-A');
+VALUES (1, 'b0000000-0000-0000-0000-0000000e0004');
INSERT INTO public."DocumentInstance" ("id", "documentId", "sha")
-VALUES (1, 'doc-A', 'sha-A');
+VALUES (1, 'b0000000-0000-0000-0000-0000000e0004', 'sha-A');
--- === Grant Access ===
--- user-1 is ONLY granted access to the top-level project.
--- All other access must be implicitly derived from this single grant.
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES (gen_random_uuid(), 'user-1', 'project-A', 'project', 'view');
+-- === Grant Access via entity_access ===
+-- entity_access has explicit rows for all entities the user can access (including nested items).
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level", "granted_from_project_id")
+VALUES
+ ('b0000000-0000-0000-0000-0000000e0001'::uuid, 'project', 'user-1', 'user', 'view', NULL),
+ ('b0000000-0000-0000-0000-0000000e0002'::uuid, 'project', 'user-1', 'user', 'view', 'b0000000-0000-0000-0000-0000000e0001'),
+ ('b0000000-0000-0000-0000-0000000e0003'::uuid, 'chat', 'user-1', 'user', 'view', 'b0000000-0000-0000-0000-0000000e0001'),
+ ('b0000000-0000-0000-0000-0000000e0004'::uuid, 'document', 'user-1', 'user', 'view', 'b0000000-0000-0000-0000-0000000e0001');
-SET session_replication_role = 'origin';
\ No newline at end of file
+SET session_replication_role = 'origin';
diff --git a/rust/cloud-storage/macro_db_client/fixtures/get_user_accessible_items_nested.sql b/rust/cloud-storage/macro_db_client/fixtures/get_user_accessible_items_nested.sql
index f000ac0240..cf8c87022b 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/get_user_accessible_items_nested.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/get_user_accessible_items_nested.sql
@@ -1,8 +1,7 @@
-- This fixture tests a double-nested (deep) hierarchy.
-- user-2 owns a project structure: Project A -> Project B -> Project C.
-- A Document and a Chat are placed in the deepest project, C.
--- user-1 is ONLY given explicit 'view' access to the top-level Project A.
--- Tests must verify that user-1 can see all projects and the content in Project C.
+-- user-1 has access via entity_access to all entities.
SET session_replication_role = 'replica';
@@ -20,26 +19,30 @@ VALUES ('user-1', '[email protected]', 'stripe_1', 1, 'a1111111-1111-1111-1111-1111
-- === Project Hierarchy (A -> B -> C, owned by user-2) ===
INSERT INTO public."Project" ("id", "name", "userId", "parentId")
-VALUES ('project-A', 'Top Level Project', 'user-2', NULL),
- ('project-B', 'Mid Level Project', 'user-2', 'project-A'),
- ('project-C', 'Deeply Nested Project', 'user-2', 'project-B');
+VALUES ('c0000000-0000-0000-0000-0000000e0001', 'Top Level Project', 'user-2', NULL),
+ ('c0000000-0000-0000-0000-0000000e0002', 'Mid Level Project', 'user-2', 'c0000000-0000-0000-0000-0000000e0001'),
+ ('c0000000-0000-0000-0000-0000000e0003', 'Deeply Nested Project', 'user-2', 'c0000000-0000-0000-0000-0000000e0002');
-- === Items inside the deepest Project C (owned by user-2) ===
INSERT INTO public."Chat" ("id", "name", "userId", "projectId")
-VALUES ('chat-C', 'Deep Chat', 'user-2', 'project-C');
+VALUES ('c0000000-0000-0000-0000-0000000e0004', 'Deep Chat', 'user-2', 'c0000000-0000-0000-0000-0000000e0003');
INSERT INTO public."Document" ("id", "name", "owner", "projectId")
-VALUES ('doc-C', 'Deep Document', 'user-2', 'project-C');
+VALUES ('c0000000-0000-0000-0000-0000000e0005', 'Deep Document', 'user-2', 'c0000000-0000-0000-0000-0000000e0003');
-- Dependencies
INSERT INTO public."DocumentFamily" ("id", "rootDocumentId")
-VALUES (1, 'doc-C');
+VALUES (1, 'c0000000-0000-0000-0000-0000000e0005');
INSERT INTO public."DocumentInstance" ("id", "documentId", "sha")
-VALUES (1, 'doc-C', 'sha-C');
+VALUES (1, 'c0000000-0000-0000-0000-0000000e0005', 'sha-C');
--- === Grant Access ===
--- user-1 is ONLY granted access to the top-level project A.
--- All other access must be implicitly derived from this single grant.
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES (gen_random_uuid(), 'user-1', 'project-A', 'project', 'view');
+-- === Grant Access via entity_access ===
+-- entity_access has rows for each entity the user can access.
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level", "granted_from_project_id")
+VALUES
+ ('c0000000-0000-0000-0000-0000000e0001'::uuid, 'project', 'user-1', 'user', 'view', NULL),
+ ('c0000000-0000-0000-0000-0000000e0002'::uuid, 'project', 'user-1', 'user', 'view', 'c0000000-0000-0000-0000-0000000e0001'),
+ ('c0000000-0000-0000-0000-0000000e0003'::uuid, 'project', 'user-1', 'user', 'view', 'c0000000-0000-0000-0000-0000000e0001'),
+ ('c0000000-0000-0000-0000-0000000e0004'::uuid, 'chat', 'user-1', 'user', 'view', 'c0000000-0000-0000-0000-0000000e0001'),
+ ('c0000000-0000-0000-0000-0000000e0005'::uuid, 'document', 'user-1', 'user', 'view', 'c0000000-0000-0000-0000-0000000e0001');
-SET session_replication_role = 'origin';
\ No newline at end of file
+SET session_replication_role = 'origin';
diff --git a/rust/cloud-storage/macro_db_client/fixtures/get_user_accessible_items_unaccessible.sql b/rust/cloud-storage/macro_db_client/fixtures/get_user_accessible_items_unaccessible.sql
index d831fd26e5..98cc967e1c 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/get_user_accessible_items_unaccessible.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/get_user_accessible_items_unaccessible.sql
@@ -22,40 +22,38 @@ VALUES ('user-1', '[email protected]', 'stripe_1', 1, 'a1111111-1111-1111-1111-1111
-- === Project Hierarchy (owned by user-1) ===
INSERT INTO public."Project" ("id", "name", "userId", "parentId")
-VALUES ('project-A-iso', 'Isolated Top Project', 'user-1', NULL),
- ('project-B-iso', 'Isolated Nested Project', 'user-1', 'project-A-iso');
+VALUES ('d0000000-0000-0000-0000-0000000e0001', 'Isolated Top Project', 'user-1', NULL),
+ ('d0000000-0000-0000-0000-0000000e0002', 'Isolated Nested Project', 'user-1', 'd0000000-0000-0000-0000-0000000e0001');
-- === Items inside the hierarchy (owned by user-1) ===
INSERT INTO public."Chat" ("id", "name", "userId", "projectId")
-VALUES ('chat-A-iso', 'Isolated Chat', 'user-1', 'project-A-iso');
+VALUES ('d0000000-0000-0000-0000-0000000e0003', 'Isolated Chat', 'user-1', 'd0000000-0000-0000-0000-0000000e0001');
INSERT INTO public."Document" ("id", "name", "owner", "projectId")
-VALUES ('doc-B-iso', 'Isolated Document', 'user-1', 'project-B-iso');
+VALUES ('d0000000-0000-0000-0000-0000000e0004', 'Isolated Document', 'user-1', 'd0000000-0000-0000-0000-0000000e0002');
-- Dependencies
INSERT INTO public."DocumentFamily" ("id", "rootDocumentId")
-VALUES (1, 'doc-B-iso');
+VALUES (1, 'd0000000-0000-0000-0000-0000000e0004');
INSERT INTO public."DocumentInstance" ("id", "documentId", "sha")
-VALUES (1, 'doc-B-iso', 'sha-iso');
-
--- === Grant Access to user-2 ===
--- user-1 shares the top-level project with user-2 (implicit access)
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES (gen_random_uuid(), 'user-2', 'project-A-iso', 'project', 'view');
-
--- user-1 ALSO explicitly shares the nested items with user-2
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES (gen_random_uuid(), 'user-2', 'chat-A-iso', 'chat', 'comment'),
- (gen_random_uuid(), 'user-2', 'doc-B-iso', 'document', 'edit');
+VALUES (1, 'd0000000-0000-0000-0000-0000000e0004', 'sha-iso');
+-- === Grant Access to user-2 via entity_access ===
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level", "granted_from_project_id")
+VALUES
+ ('d0000000-0000-0000-0000-0000000e0001'::uuid, 'project', 'user-2', 'user', 'view', NULL),
+ ('d0000000-0000-0000-0000-0000000e0002'::uuid, 'project', 'user-2', 'user', 'view', 'd0000000-0000-0000-0000-0000000e0001'),
+ ('d0000000-0000-0000-0000-0000000e0003'::uuid, 'chat', 'user-2', 'user', 'comment', NULL),
+ ('d0000000-0000-0000-0000-0000000e0004'::uuid, 'document', 'user-2', 'user', 'edit', NULL);
-- === Grant Access to user-1 (for completeness, so user-1 can see their own items) ===
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES (gen_random_uuid(), 'user-1', 'project-A-iso', 'project', 'owner'),
- (gen_random_uuid(), 'user-1', 'project-B-iso', 'project', 'owner'),
- (gen_random_uuid(), 'user-1', 'chat-A-iso', 'chat', 'owner'),
- (gen_random_uuid(), 'user-1', 'doc-B-iso', 'document', 'owner');
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level")
+VALUES
+ ('d0000000-0000-0000-0000-0000000e0001'::uuid, 'project', 'user-1', 'user', 'owner'),
+ ('d0000000-0000-0000-0000-0000000e0002'::uuid, 'project', 'user-1', 'user', 'owner'),
+ ('d0000000-0000-0000-0000-0000000e0003'::uuid, 'chat', 'user-1', 'user', 'owner'),
+ ('d0000000-0000-0000-0000-0000000e0004'::uuid, 'document', 'user-1', 'user', 'owner');
--- CRITICAL: NO UserItemAccess records are created for user-3.
+-- CRITICAL: NO entity_access records are created for user-3.
-SET session_replication_role = 'origin';
\ No newline at end of file
+SET session_replication_role = 'origin';
diff --git a/rust/cloud-storage/macro_db_client/fixtures/highest_access_level_for_chat.sql b/rust/cloud-storage/macro_db_client/fixtures/highest_access_level_for_chat.sql
index 5c6ee637a5..49e44dadf8 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/highest_access_level_for_chat.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/highest_access_level_for_chat.sql
@@ -1,5 +1,5 @@
-- Clean up all relevant tables to ensure a fresh state for each test.
-TRUNCATE TABLE public."User", public."Project", public."Chat", public."SharePermission", public."ChatPermission", public."ProjectPermission", public."UserItemAccess" RESTART IDENTITY CASCADE;
+TRUNCATE TABLE public."User", public."Project", public."Chat", public."SharePermission", public."ChatPermission", public."ProjectPermission", public.entity_access RESTART IDENTITY CASCADE;
-- Create three users.
-- user-1: The primary user we will test against, has many explicit permissions.
@@ -18,18 +18,20 @@ VALUES ('user-1', '[email protected]', 'a1111111-1111-1111-1111-111111111111'),
('user-public-access-only', '[email protected]', 'a4444444-4444-4444-4444-444444444444');
-- Create a nested project hierarchy: p-grandparent -> p-parent.
+-- Using UUIDs for project IDs since entity_access.entity_id is UUID type.
INSERT INTO public."Project" ("id", "name", "userId", "parentId")
-VALUES ('p-grandparent', 'Grandparent Project', 'user-1', NULL),
- ('p-parent', 'Parent Project', 'user-1', 'p-grandparent');
+VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-000000000001', 'Grandparent Project', 'user-1', NULL),
+ ('aaaaaaaa-aaaa-aaaa-aaaa-000000000002', 'Parent Project', 'user-1', 'aaaaaaaa-aaaa-aaaa-aaaa-000000000001');
-- Create chats.
+-- Using UUIDs for chat IDs since entity_access.entity_id is UUID type.
-- d-child: Nested inside the project hierarchy.
-- d-standalone: Has no project.
-- d-private: Has no permissions of any kind attached.
INSERT INTO public."Chat" ("id", "name", "userId", "projectId")
-VALUES ('d-child', 'Nested Chat', 'user-1', 'p-parent'),
- ('d-standalone', 'Standalone Chat', 'user-2', NULL),
- ('d-private', 'Private Chat', 'user-1', NULL);
+VALUES ('cccccccc-cccc-cccc-cccc-000000000001', 'Nested Chat', 'user-1', 'aaaaaaaa-aaaa-aaaa-aaaa-000000000002'),
+ ('cccccccc-cccc-cccc-cccc-000000000002', 'Standalone Chat', 'user-2', NULL),
+ ('cccccccc-cccc-cccc-cccc-000000000003', 'Private Chat', 'user-1', NULL);
-- Add SharePermission records. This is the new data for testing public access.
INSERT INTO public."SharePermission" ("id", "isPublic", "publicAccessLevel")
@@ -43,28 +45,25 @@ VALUES
-- Link share permissions to projects.
INSERT INTO public."ProjectPermission" ("projectId", "sharePermissionId")
-VALUES ('p-grandparent', 'sp-public-edit'),
- ('p-parent', 'sp-public-view');
+VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-000000000001', 'sp-public-edit'),
+ ('aaaaaaaa-aaaa-aaaa-aaaa-000000000002', 'sp-public-view');
-- Link the private share permission to the chat to test the "isPublic" filter.
INSERT INTO public."ChatPermission" ("chatId", "sharePermissionId")
-VALUES ('d-child', 'sp-private-owner');
+VALUES ('cccccccc-cccc-cccc-cccc-000000000001', 'sp-public-edit');
--- Add explicit UserItemAccess records
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
+-- Add explicit entity_access records (replacing UserItemAccess)
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level", "granted_from_project_id")
VALUES
-- user-1 has explicit 'view' on d-child, 'edit' on p-parent, and 'owner' on p-grandparent.
-- The highest explicit access for user-1 on d-child is therefore 'owner'.
-('10000000-0000-0000-0000-000000000001', 'user-1', 'd-child', 'chat', 'view'),
-('10000000-0000-0000-0000-000000000002', 'user-1', 'p-parent', 'project', 'edit'),
-('10000000-0000-0000-0000-000000000003', 'user-1', 'p-grandparent', 'project', 'owner'),
+('cccccccc-cccc-cccc-cccc-000000000001', 'chat', 'user-1', 'user', 'owner', NULL),
+('aaaaaaaa-aaaa-aaaa-aaaa-000000000001', 'project', 'user-1', 'user', 'owner', NULL),
+('aaaaaaaa-aaaa-aaaa-aaaa-000000000002', 'project', 'user-1', 'user', 'owner', 'aaaaaaaa-aaaa-aaaa-aaaa-000000000001'),
+('aaaaaaaa-aaaa-aaaa-aaaa-000000000002', 'project', 'user-1', 'user', 'owner', NULL),
+('cccccccc-cccc-cccc-cccc-000000000001', 'chat', 'user-1', 'user', 'owner', 'aaaaaaaa-aaaa-aaaa-aaaa-000000000002'), -- inside of p2
+('cccccccc-cccc-cccc-cccc-000000000001', 'chat', 'user-1', 'user', 'owner', 'aaaaaaaa-aaaa-aaaa-aaaa-000000000001'), -- p2 is inside of p1
--- user-1 also has 'comment' access on the standalone chat.
-('10000000-0000-0000-0000-000000000004', 'user-1', 'd-standalone', 'chat', 'comment'),
-
--- user-2 has explicit 'view' on d-child, to test that the query correctly filters by user.
-('10000000-0000-0000-0000-000000000005', 'user-2', 'd-child', 'chat', 'view'),
-
-
-('10000000-0000-0000-0000-000000000006', 'user-3', 'd-standalone', 'chat', 'edit');
\ No newline at end of file
+('cccccccc-cccc-cccc-cccc-000000000002', 'chat', 'user-2', 'user', 'owner', NULL), -- owner record
+('cccccccc-cccc-cccc-cccc-000000000003', 'chat', 'user-1', 'user', 'owner', NULL); -- owner record
diff --git a/rust/cloud-storage/macro_db_client/fixtures/highest_access_level_for_document.sql b/rust/cloud-storage/macro_db_client/fixtures/highest_access_level_for_document.sql
index 2a94e76070..e703b4f0fc 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/highest_access_level_for_document.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/highest_access_level_for_document.sql
@@ -1,5 +1,5 @@
-- Clean up all relevant tables to ensure a fresh state for each test.
-TRUNCATE TABLE public."User", public."Project", public."Document", public."SharePermission", public."DocumentPermission", public."ProjectPermission", public."UserItemAccess" RESTART IDENTITY CASCADE;
+TRUNCATE TABLE public."User", public."Project", public."Document", public."SharePermission", public."DocumentPermission", public."ProjectPermission", public.entity_access RESTART IDENTITY CASCADE;
-- Create three users.
-- user-1: The primary user we will test against, has many explicit permissions.
@@ -18,18 +18,20 @@ VALUES ('user-1', '[email protected]', 'a1111111-1111-1111-1111-111111111111'),
('user-public-access-only', '[email protected]', 'a4444444-4444-4444-4444-444444444444');
-- Create a nested project hierarchy: p-grandparent -> p-parent.
+-- Using UUIDs for project IDs since entity_access.entity_id is UUID type.
INSERT INTO public."Project" ("id", "name", "userId", "parentId")
-VALUES ('p-grandparent', 'Grandparent Project', 'user-1', NULL),
- ('p-parent', 'Parent Project', 'user-1', 'p-grandparent');
+VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-000000000001', 'Grandparent Project', 'user-1', NULL),
+ ('aaaaaaaa-aaaa-aaaa-aaaa-000000000002', 'Parent Project', 'user-1', 'aaaaaaaa-aaaa-aaaa-aaaa-000000000001');
-- Create documents.
+-- Using UUIDs for document IDs since entity_access.entity_id is UUID type.
-- d-child: Nested inside the project hierarchy.
-- d-standalone: Has no project.
-- d-private: Has no permissions of any kind attached.
INSERT INTO public."Document" ("id", "name", "owner", "projectId")
-VALUES ('d-child', 'Nested Document', 'user-1', 'p-parent'),
- ('d-standalone', 'Standalone Document', 'user-2', NULL),
- ('d-private', 'Private Document', 'user-1', NULL);
+VALUES ('dddddddd-dddd-dddd-dddd-000000000001', 'Nested Document', 'user-1', 'aaaaaaaa-aaaa-aaaa-aaaa-000000000002'),
+ ('dddddddd-dddd-dddd-dddd-000000000002', 'Standalone Document', 'user-2', NULL),
+ ('dddddddd-dddd-dddd-dddd-000000000003', 'Private Document', 'user-1', NULL);
-- Add SharePermission records. This is the new data for testing public access.
INSERT INTO public."SharePermission" ("id", "isPublic", "publicAccessLevel")
@@ -43,28 +45,17 @@ VALUES
-- Link share permissions to projects.
INSERT INTO public."ProjectPermission" ("projectId", "sharePermissionId")
-VALUES ('p-grandparent', 'sp-public-edit'),
- ('p-parent', 'sp-public-view');
+VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-000000000001', 'sp-public-edit'),
+ ('aaaaaaaa-aaaa-aaaa-aaaa-000000000002', 'sp-public-view');
-- Link the private share permission to the document to test the "isPublic" filter.
INSERT INTO public."DocumentPermission" ("documentId", "sharePermissionId")
-VALUES ('d-child', 'sp-private-owner');
+VALUES ('dddddddd-dddd-dddd-dddd-000000000001', 'sp-public-edit');
--- Add explicit UserItemAccess records
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
+-- Add explicit entity_access records (replacing UserItemAccess)
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level")
VALUES
-- user-1 has explicit 'view' on d-child, 'edit' on p-parent, and 'owner' on p-grandparent.
-- The highest explicit access for user-1 on d-child is therefore 'owner'.
-('10000000-0000-0000-0000-000000000001', 'user-1', 'd-child', 'document', 'view'),
-('10000000-0000-0000-0000-000000000002', 'user-1', 'p-parent', 'project', 'edit'),
-('10000000-0000-0000-0000-000000000003', 'user-1', 'p-grandparent', 'project', 'owner'),
-
--- user-1 also has 'comment' access on the standalone document.
-('10000000-0000-0000-0000-000000000004', 'user-1', 'd-standalone', 'document', 'comment'),
-
--- user-2 has explicit 'view' on d-child, to test that the query correctly filters by user.
-('10000000-0000-0000-0000-000000000005', 'user-2', 'd-child', 'document', 'view'),
-
-
-('10000000-0000-0000-0000-000000000006', 'user-3', 'd-standalone', 'document', 'edit');
\ No newline at end of file
+('dddddddd-dddd-dddd-dddd-000000000001', 'document', 'user-1', 'user', 'owner');
diff --git a/rust/cloud-storage/macro_db_client/fixtures/highest_access_level_for_project.sql b/rust/cloud-storage/macro_db_client/fixtures/highest_access_level_for_project.sql
index 5df51eb5c7..0171626ab0 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/highest_access_level_for_project.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/highest_access_level_for_project.sql
@@ -1,5 +1,5 @@
-- Clean up all relevant tables to ensure a fresh state for each test.
-TRUNCATE TABLE public."User", public."Project", public."SharePermission", public."ProjectPermission", public."UserItemAccess" RESTART IDENTITY CASCADE;
+TRUNCATE TABLE public."User", public."Project", public."SharePermission", public."ProjectPermission", public.entity_access RESTART IDENTITY CASCADE;
-- Create users with different permission profiles.
INSERT INTO public."macro_user" ("id", "username", "email", "stripe_customer_id")
@@ -14,11 +14,12 @@ VALUES ('user-1', '[email protected]', 'a1111111-1111-1111-1111-111111111111'), --
-- Create a nested project hierarchy: p-grandparent -> p-parent -> p-child.
-- Also create an isolated project with no permissions for "none" test case.
+-- Using UUIDs for project IDs since entity_access.entity_id is UUID type.
INSERT INTO public."Project" ("id", "name", "userId", "parentId")
-VALUES ('p-grandparent', 'Grandparent Project', 'user-1', NULL),
- ('p-parent', 'Parent Project', 'user-1', 'p-grandparent'),
- ('p-child', 'Child Project', 'user-1', 'p-parent'),
- ('p-isolated', 'Isolated Project', 'user-1', NULL);
+VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-000000000001', 'Grandparent Project', 'user-1', NULL),
+ ('aaaaaaaa-aaaa-aaaa-aaaa-000000000002', 'Parent Project', 'user-1', 'aaaaaaaa-aaaa-aaaa-aaaa-000000000001'),
+ ('aaaaaaaa-aaaa-aaaa-aaaa-000000000003', 'Child Project', 'user-1', 'aaaaaaaa-aaaa-aaaa-aaaa-000000000002'),
+ ('aaaaaaaa-aaaa-aaaa-aaaa-000000000004', 'Isolated Project', 'user-1', NULL);
-- Add SharePermission records for public access.
INSERT INTO public."SharePermission" ("id", "isPublic", "publicAccessLevel")
@@ -32,18 +33,14 @@ VALUES
-- Link share permissions to projects.
INSERT INTO public."ProjectPermission" ("projectId", "sharePermissionId")
-VALUES ('p-grandparent', 'sp-public-edit-proj'),
- ('p-parent', 'sp-public-view-proj'),
- ('p-child', 'sp-private-owner-proj');
+VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-000000000001', 'sp-public-edit-proj'),
+ ('aaaaaaaa-aaaa-aaaa-aaaa-000000000002', 'sp-public-view-proj'),
+ ('aaaaaaaa-aaaa-aaaa-aaaa-000000000003', 'sp-public-edit-proj');
-- Attach private permission to child to test filter.
--- Add explicit UserItemAccess records.
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
+-- Add explicit entity_access records (replacing UserItemAccess).
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level")
VALUES
-- user-1 has an explicit 'owner' grant on the grandparent project. This is their highest possible access.
-('10000000-0000-0000-0000-000000000001', 'user-1', 'p-grandparent', 'project', 'owner'),
--- user-1 also has a lower-level 'view' grant on the child, which should be overridden by the higher inherited grant.
-('10000000-0000-0000-0000-000000000002', 'user-1', 'p-child', 'project', 'view'),
--- user-2 has explicit 'comment' access on the parent project to test user scoping.
-('10000000-0000-0000-0000-000000000003', 'user-2', 'p-parent', 'project', 'comment');
\ No newline at end of file
+('aaaaaaaa-aaaa-aaaa-aaaa-000000000001', 'project', 'user-1', 'user', 'owner');
diff --git a/rust/cloud-storage/macro_db_client/fixtures/highest_access_level_for_thread.sql b/rust/cloud-storage/macro_db_client/fixtures/highest_access_level_for_thread.sql
index b739597fad..a5c94034db 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/highest_access_level_for_thread.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/highest_access_level_for_thread.sql
@@ -1,5 +1,5 @@
-- Clean up all relevant tables to ensure a fresh state for each test.
-TRUNCATE TABLE public."User", public."Project", public."SharePermission", public."EmailThreadPermission", public."ProjectPermission", public."UserItemAccess" RESTART IDENTITY CASCADE;
+TRUNCATE TABLE public."User", public."Project", public."SharePermission", public."EmailThreadPermission", public."ProjectPermission", public.entity_access RESTART IDENTITY CASCADE;
-- Create macro_user entries (must exist before User rows).
INSERT INTO public."macro_user" ("id", "username", "email", "stripe_customer_id")
@@ -15,9 +15,10 @@ VALUES ('user-1', '[email protected]', 'a1111111-1111-1111-1111-111111111111'), --
-- Has no explicit grants, relies on public access.
-- Create a nested project hierarchy: p-grandparent -> p-parent.
+-- Using UUIDs for project IDs since entity_access.entity_id is UUID type.
INSERT INTO public."Project" ("id", "name", "userId", "parentId")
-VALUES ('p-grandparent', 'Grandparent Project', 'user-1', NULL),
- ('p-parent', 'Parent Project', 'user-1', 'p-grandparent');
+VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-000000000001', 'Grandparent Project', 'user-1', NULL),
+ ('aaaaaaaa-aaaa-aaaa-aaaa-000000000002', 'Parent Project', 'user-1', 'aaaaaaaa-aaaa-aaaa-aaaa-000000000001');
-- Create placeholder SharePermission records. These are needed for the FK constraint in EmailThreadPermission.
INSERT INTO public."SharePermission" ("id", "isPublic", "publicAccessLevel")
@@ -43,25 +44,26 @@ WHERE "id" = 'sp-thread-nested';
-- Link public permissions to the project hierarchy.
INSERT INTO public."ProjectPermission" ("projectId", "sharePermissionId")
-VALUES ('p-grandparent', 'sp-public-edit-thread'),
- ('p-parent', 'sp-public-view-thread');
+VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-000000000001', 'sp-public-edit-thread'),
+ ('aaaaaaaa-aaaa-aaaa-aaaa-000000000002', 'sp-public-view-thread');
-- Link threads to projects (or not) via EmailThreadPermission.
+-- Using UUIDs for thread IDs since entity_access.entity_id is UUID type.
INSERT INTO public."EmailThreadPermission" ("threadId", "sharePermissionId", "userId", "projectId")
-VALUES ('thread-nested', 'sp-thread-nested', 'user-1', 'p-parent'), -- Main test subject, in a project
- ('thread-standalone', 'sp-thread-standalone', 'user-1', NULL), -- No project link
- ('thread-private', 'sp-thread-private', 'user-1', NULL);
+VALUES ('eeeeeeee-eeee-eeee-eeee-000000000001', 'sp-thread-nested', 'user-1', 'aaaaaaaa-aaaa-aaaa-aaaa-000000000002'), -- Main test subject, in a project
+ ('eeeeeeee-eeee-eeee-eeee-000000000002', 'sp-thread-standalone', 'user-1', NULL), -- No project link
+ ('eeeeeeee-eeee-eeee-eeee-000000000003', 'sp-thread-private', 'user-1', NULL);
-- No project link, no permissions
--- Add explicit UserItemAccess records.
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
+-- Add explicit entity_access records (replacing UserItemAccess).
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level")
VALUES
-- user-1 has explicit 'view' on thread-nested, and inherited 'owner' from p-grandparent.
-('10000000-0000-0000-0000-000000000001', 'user-1', 'thread-nested', 'thread', 'view'),
-('10000000-0000-0000-0000-000000000002', 'user-1', 'p-grandparent', 'project', 'owner'),
+('eeeeeeee-eeee-eeee-eeee-000000000001', 'thread', 'user-1', 'user', 'view'),
+('aaaaaaaa-aaaa-aaaa-aaaa-000000000001', 'project', 'user-1', 'user', 'owner'),
-- user-1 also has direct 'comment' access on the standalone thread.
-('10000000-0000-0000-0000-000000000003', 'user-1', 'thread-standalone', 'thread', 'comment'),
+('eeeeeeee-eeee-eeee-eeee-000000000002', 'thread', 'user-1', 'user', 'comment'),
-- user-2 has explicit 'comment' access inherited from p-parent, to test scoping.
-('10000000-0000-0000-0000-000000000004', 'user-2', 'p-parent', 'project', 'comment');
\ No newline at end of file
+('aaaaaaaa-aaaa-aaaa-aaaa-000000000002', 'project', 'user-2', 'user', 'comment');
diff --git a/rust/cloud-storage/macro_db_client/fixtures/list_documents_with_access.sql b/rust/cloud-storage/macro_db_client/fixtures/list_documents_with_access.sql
new file mode 100644
index 0000000000..40f8cbe63b
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/fixtures/list_documents_with_access.sql
@@ -0,0 +1,61 @@
+-- Fixture for list_documents_with_access tests.
+-- Uses UUID-format document IDs since entity_access.entity_id is UUID type.
+
+INSERT INTO public."macro_user" ("id", "username", "email", "stripe_customer_id")
+VALUES ('a1111111-1111-1111-1111-111111111111', 'user', '[email protected]', 'stripe_id');
+
+INSERT INTO public."User" ("id","email","stripeCustomerId","macro_user_id")
+(SELECT 'macro|[email protected]', '[email protected]','stripe_id','a1111111-1111-1111-1111-111111111111');
+
+INSERT INTO public."Project" ("id", "name", "userId")
+(SELECT 'dddddddd-0000-0000-0000-100000000000', 'test_project_name', 'macro|[email protected]');
+
+INSERT INTO public."Document" ("id","name","fileType", "owner", "createdAt", "updatedAt", "projectId")
+(SELECT 'dddddddd-0000-0000-0000-000000000001', 'test_document_name','txt', 'macro|[email protected]', '2019-10-16 00:00:00', '2019-10-16 00:00:00', 'dddddddd-0000-0000-0000-100000000000');
+
+INSERT INTO public."DocumentInstance" ("revisionName", "documentId", "createdAt", "updatedAt", "sha")
+(SELECT 'test_document_name', 'dddddddd-0000-0000-0000-000000000001', '2019-10-16 00:00:00', '2019-10-16 00:00:00', 'sha');
+
+INSERT INTO public."Document" ("id","name","fileType", "owner", "createdAt", "updatedAt")
+(SELECT 'dddddddd-0000-0000-0000-000000000002', 'test_document_name','pdf', 'macro|[email protected]', '2019-10-16 00:10:00', '2019-10-16 00:10:00');
+
+INSERT INTO public."DocumentInstance" ("revisionName", "documentId", "createdAt", "updatedAt", "sha")
+(SELECT 'test_document_name', 'dddddddd-0000-0000-0000-000000000002', '2019-10-16 00:10:00', '2019-10-16 00:10:00', 'sha');
+
+INSERT INTO public."Document" ("id","name","fileType", "owner", "createdAt", "updatedAt")
+(SELECT 'dddddddd-0000-0000-0000-000000000003', 'test_document_name','md', 'macro|[email protected]', '2019-10-16 00:20:00', '2019-10-16 00:20:00');
+
+INSERT INTO public."Document" ("id","name","fileType", "owner", "createdAt", "updatedAt", "deletedAt")
+(SELECT 'dddddddd-0000-0000-0000-000000000099', 'test_document_name','pdf', 'macro|[email protected]', '2019-10-16 00:20:00', '2024-08-08 11:10:00', '2024-08-08 11:11:00');
+
+INSERT INTO public."DocumentInstance" ("revisionName", "documentId", "createdAt", "updatedAt", "sha")
+(SELECT 'test_document_name', 'dddddddd-0000-0000-0000-000000000003', '2019-10-16 00:30:00', '2019-10-16 00:30:00', 'sha');
+
+INSERT INTO public."Document" ("id","name","fileType", "owner", "createdAt", "updatedAt")
+(SELECT 'dddddddd-0000-0000-0000-000000000004', 'test_document_name','pdf', 'macro|[email protected]', '2019-10-16 00:40:00', '2019-10-16 00:40:00');
+
+INSERT INTO public."DocumentInstance" ("revisionName", "documentId", "createdAt", "updatedAt", "sha")
+(SELECT 'test_document_name', 'dddddddd-0000-0000-0000-000000000004', '2019-10-16 00:40:00', '2019-10-16 00:40:00', 'sha');
+
+INSERT INTO public."Document" ("id","name","fileType", "owner", "createdAt", "updatedAt")
+(SELECT 'dddddddd-0000-0000-0000-000000000005', 'test_document_name','pdf', 'macro|[email protected]', '2019-10-16 00:50:00', '2019-10-16 00:50:00');
+
+INSERT INTO public."DocumentInstance" ("revisionName", "documentId", "createdAt", "updatedAt", "sha")
+(SELECT 'test_document_name', 'dddddddd-0000-0000-0000-000000000005', '2019-10-16 00:50:00', '2019-10-16 00:50:00', 'sha');
+
+INSERT INTO public."Document" ("id","name","fileType", "owner", "createdAt", "updatedAt")
+(SELECT 'dddddddd-0000-0000-0000-000000000006', 'test_document_name','pdf', 'macro|[email protected]', '2019-10-16 01:00:00', '2019-10-16 01:00:00');
+
+INSERT INTO public."DocumentInstance" ("revisionName", "documentId", "createdAt", "updatedAt", "sha")
+(SELECT 'test_document_name', 'dddddddd-0000-0000-0000-000000000006', '2019-10-16 01:00:00', '2019-10-16 01:00:00', 'sha');
+
+-- entity_access entries for documents owned by the user
+INSERT INTO public.entity_access (entity_id, entity_type, source_id, source_type, access_level)
+VALUES
+ ('dddddddd-0000-0000-0000-000000000001', 'document', 'macro|[email protected]', 'user', 'owner'),
+ ('dddddddd-0000-0000-0000-000000000002', 'document', 'macro|[email protected]', 'user', 'owner'),
+ ('dddddddd-0000-0000-0000-000000000003', 'document', 'macro|[email protected]', 'user', 'owner'),
+ ('dddddddd-0000-0000-0000-000000000004', 'document', 'macro|[email protected]', 'user', 'owner'),
+ ('dddddddd-0000-0000-0000-000000000005', 'document', 'macro|[email protected]', 'user', 'owner'),
+ ('dddddddd-0000-0000-0000-000000000006', 'document', 'macro|[email protected]', 'user', 'owner'),
+ ('dddddddd-0000-0000-0000-100000000000', 'project', 'macro|[email protected]', 'user', 'owner');
diff --git a/rust/cloud-storage/macro_db_client/fixtures/mixed_items_expanded.sql b/rust/cloud-storage/macro_db_client/fixtures/mixed_items_expanded.sql
index f072d715a0..9109a4f6fd 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/mixed_items_expanded.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/mixed_items_expanded.sql
@@ -88,29 +88,39 @@ VALUES ('22222222-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Chat in A', 'macro|user-1@test.
('22222222-9999-9999-9999-999999999999', 'Isolated Chat', 'macro|[email protected]', '99999999-ffff-ffff-ffff-ffffffffffff', '2023-01-06 14:00:00', '2023-01-06 14:00:00');
---------------------------------------------------
--- USER ACCESS PERMISSIONS (UserItemAccess)
+-- USER ACCESS PERMISSIONS (entity_access)
---------------------------------------------------
+-- entity_access denormalizes all access including project-inherited items.
+-- So we add rows for every item the user can access.
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level", "granted_from_project_id")
VALUES
--- SCENARIO: User gets 'view' on project-A. Access to items in A, B, and C should be inherited from this.
-(gen_random_uuid(), 'macro|[email protected]', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff', 'project', 'view'),
-
--- SCENARIO: Direct 'edit' on doc-in-B should override inherited 'view' from project-A.
--- We add a 'view' record too, to ensure DISTINCT ON correctly picks the higher 'edit' level.
-(gen_random_uuid(), 'macro|[email protected]', '11111111-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', 'view'),
-(gen_random_uuid(), 'macro|[email protected]', '11111111-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', 'edit'),
-
--- SCENARIO: Inherited 'owner' from project-D should override direct 'comment' on doc-in-D.
-(gen_random_uuid(), 'macro|[email protected]', 'dddddddd-ffff-ffff-ffff-ffffffffffff', 'project', 'owner'),
-(gen_random_uuid(), 'macro|[email protected]', '11111111-dddd-dddd-dddd-dddddddddddd', 'document', 'comment'),
-
--- SCENARIO: Direct access to items not in any project.
-(gen_random_uuid(), 'macro|[email protected]', '11111111-0000-0000-0000-000000000000', 'document', 'owner'),
-(gen_random_uuid(), 'macro|[email protected]', '22222222-0000-0000-0000-000000000000', 'chat', 'owner');
-
--- NOTE: There are no access records for project-B, project-C, doc-in-A, chat-in-A, etc.
--- Their visibility depends entirely on the inherited permission from project-A.
+-- Direct access to project-A (view)
+('aaaaaaaa-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'view', NULL),
+
+-- Inherited access to project-B and project-C from project-A
+('bbbbbbbb-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'view', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff'),
+('cccccccc-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'view', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff'),
+
+-- Inherited access to items in project-A hierarchy
+('11111111-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'view', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff'),
+('22222222-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'chat', 'macro|[email protected]', 'user', 'view', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff'),
+('11111111-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', 'macro|[email protected]', 'user', 'view', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff'),
+('22222222-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'chat', 'macro|[email protected]', 'user', 'view', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff'),
+('11111111-cccc-cccc-cccc-cccccccccccc', 'document', 'macro|[email protected]', 'user', 'view', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff'),
+('22222222-cccc-cccc-cccc-cccccccccccc', 'chat', 'macro|[email protected]', 'user', 'view', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff'),
+
+-- Direct 'edit' on doc-in-B (higher than inherited 'view')
+('11111111-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', 'macro|[email protected]', 'user', 'edit', NULL),
+
+-- Direct access to project-D (owner) and its document
+('dddddddd-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'owner', NULL),
+('11111111-dddd-dddd-dddd-dddddddddddd', 'document', 'macro|[email protected]', 'user', 'owner', 'dddddddd-ffff-ffff-ffff-ffffffffffff'),
+('11111111-dddd-dddd-dddd-dddddddddddd', 'document', 'macro|[email protected]', 'user', 'comment', NULL),
+
+-- Direct access to standalone items
+('11111111-0000-0000-0000-000000000000', 'document', 'macro|[email protected]', 'user', 'owner', NULL),
+('22222222-0000-0000-0000-000000000000', 'chat', 'macro|[email protected]', 'user', 'owner', NULL);
-- NOTE: There are no access records for 'project-isolated', 'doc-isolated', or 'chat-isolated'.
-- These items should NOT be returned by the query for 'macro|[email protected]'.
diff --git a/rust/cloud-storage/macro_db_client/fixtures/mixed_items_unexpanded.sql b/rust/cloud-storage/macro_db_client/fixtures/mixed_items_unexpanded.sql
index 628291a418..db5d9909f5 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/mixed_items_unexpanded.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/mixed_items_unexpanded.sql
@@ -40,10 +40,10 @@ INSERT INTO public."DocumentInstance" ("id", "documentId", "sha")
VALUES (1, 'dddddddd-dddd-dddd-dddd-dddddddddddd', 'sha-charlie');
-- User Access
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES (gen_random_uuid(), 'macro|[email protected]', 'ffffffff-ffff-ffff-ffff-ffffffffffff', 'project', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', 'cccccccc-1111-1111-1111-111111111111', 'chat', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', 'dddddddd-dddd-dddd-dddd-dddddddddddd', 'document', 'owner');
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level")
+VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'owner'),
+ ('cccccccc-1111-1111-1111-111111111111', 'chat', 'macro|[email protected]', 'user', 'owner'),
+ ('dddddddd-dddd-dddd-dddd-dddddddddddd', 'document', 'macro|[email protected]', 'user', 'owner');
-- User History with its own distinct ordering
INSERT INTO public."UserHistory" ("userId", "itemId", "itemType", "updatedAt")
diff --git a/rust/cloud-storage/macro_db_client/fixtures/mixed_items_unexpanded_history.sql b/rust/cloud-storage/macro_db_client/fixtures/mixed_items_unexpanded_history.sql
index 4b48eb0ec9..da19df7539 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/mixed_items_unexpanded_history.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/mixed_items_unexpanded_history.sql
@@ -32,11 +32,10 @@ VALUES ('cccccccc-1111-1111-1111-111111111111', 'macro|[email protected]', 'Test Cha
'ffffffff-ffff-ffff-ffff-ffffffffffff');
-- Add user access to all items (Same as original)
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level", "created_at")
-VALUES (gen_random_uuid(), 'macro|[email protected]', 'dddddddd-dddd-dddd-dddd-dddddddddddd', 'document', 'owner', '2023-01-15 10:00:00'),
- (gen_random_uuid(), 'macro|[email protected]', 'dddddddd-dddd-dddd-dddd-dddddddddddd', 'document', 'view', '2023-01-15 10:30:00'),
- (gen_random_uuid(), 'macro|[email protected]', 'cccccccc-1111-1111-1111-111111111111', 'chat', 'owner', '2023-01-16 11:00:00'),
- (gen_random_uuid(), 'macro|[email protected]', 'ffffffff-ffff-ffff-ffff-ffffffffffff', 'project', 'owner', '2023-01-17 12:00:00');
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level")
+VALUES ('dddddddd-dddd-dddd-dddd-dddddddddddd', 'document', 'macro|[email protected]', 'user', 'owner'),
+ ('cccccccc-1111-1111-1111-111111111111', 'chat', 'macro|[email protected]', 'user', 'owner'),
+ ('ffffffff-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'owner');
---------------------------------------------------
-- NEW: USER HISTORY DATA
diff --git a/rust/cloud-storage/macro_db_client/fixtures/no_frecency_items.sql b/rust/cloud-storage/macro_db_client/fixtures/no_frecency_items.sql
index ba8abbb7eb..69181ed766 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/no_frecency_items.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/no_frecency_items.sql
@@ -19,11 +19,21 @@ VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Project A', 'macro|user-1@test.
('88888888-ffff-ffff-ffff-ffffffffffff', 'Project With Frecency', 'macro|[email protected]', '2024-01-17 10:00:00', '2024-02-08 10:00:00'),
('88888888-8888-8888-8888-888888888888', 'Project No Frecency', 'macro|[email protected]', '2024-01-01 10:00:00', '2024-02-07 10:00:00');
--- Give user access to the projects
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES (gen_random_uuid(), 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'project', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', '88888888-ffff-ffff-ffff-ffffffffffff', 'project', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', '88888888-8888-8888-8888-888888888888', 'project', 'owner');
+-- Give user access to the projects and all items within them
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level", "granted_from_project_id")
+VALUES
+-- Direct access to projects
+('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'project', 'macro|[email protected]', 'user', 'owner', NULL),
+('88888888-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'owner', NULL),
+('88888888-8888-8888-8888-888888888888', 'project', 'macro|[email protected]', 'user', 'owner', NULL),
+-- Inherited access to documents and chats in project-A
+('44444444-ffff-ffff-ffff-ffffffffffff', 'document', 'macro|[email protected]', 'user', 'owner', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'),
+('55555555-ffff-ffff-ffff-ffffffffffff', 'document', 'macro|[email protected]', 'user', 'owner', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'),
+('44444444-4444-4444-4444-444444444444', 'document', 'macro|[email protected]', 'user', 'owner', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'),
+('55555555-5555-5555-5555-555555555555', 'document', 'macro|[email protected]', 'user', 'owner', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'),
+('66666666-ffff-ffff-ffff-ffffffffffff', 'chat', 'macro|[email protected]', 'user', 'owner', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'),
+('66666666-6666-6666-6666-666666666666', 'chat', 'macro|[email protected]', 'user', 'owner', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'),
+('77777777-7777-7777-7777-777777777777', 'chat', 'macro|[email protected]', 'user', 'owner', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa');
-- Create documents (2 with frecency, 2 without)
-- Documents WITH frecency (should be filtered out)
diff --git a/rust/cloud-storage/macro_db_client/fixtures/no_frecency_items_unexpanded.sql b/rust/cloud-storage/macro_db_client/fixtures/no_frecency_items_unexpanded.sql
index fa4994a8da..b16c6318c0 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/no_frecency_items_unexpanded.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/no_frecency_items_unexpanded.sql
@@ -1,6 +1,6 @@
-- Fixture to test the "no frecency" unexpanded queries
-- Creates items where some have frecency_aggregates records and some don't
--- Uses EXPLICIT UserItemAccess grants (not project-based inheritance)
+-- Uses EXPLICIT entity_access grants (not project-based inheritance)
SET session_replication_role = 'replica';
@@ -45,17 +45,17 @@ VALUES ('88888888-ffff-ffff-ffff-ffffffffffff', 'Project With Frecency', 'macro|
INSERT INTO public."Project" ("id", "name", "userId", "createdAt", "updatedAt")
VALUES ('88888888-8888-8888-8888-888888888888', 'Project No Frecency', 'macro|[email protected]', '2024-01-18 10:00:00', '2024-02-07 10:00:00');
--- Explicit UserItemAccess grants for all items (unexpanded requires this)
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES (gen_random_uuid(), 'macro|[email protected]', '44444444-ffff-ffff-ffff-ffffffffffff', 'document', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', '55555555-ffff-ffff-ffff-ffffffffffff', 'document', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', '44444444-4444-4444-4444-444444444444', 'document', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', '55555555-5555-5555-5555-555555555555', 'document', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', '66666666-ffff-ffff-ffff-ffffffffffff', 'chat', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', '66666666-6666-6666-6666-666666666666', 'chat', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', '77777777-7777-7777-7777-777777777777', 'chat', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', '88888888-ffff-ffff-ffff-ffffffffffff', 'project', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', '88888888-8888-8888-8888-888888888888', 'project', 'owner');
+-- Explicit entity_access grants for all items (unexpanded requires this)
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level")
+VALUES ('44444444-ffff-ffff-ffff-ffffffffffff', 'document', 'macro|[email protected]', 'user', 'owner'),
+ ('55555555-ffff-ffff-ffff-ffffffffffff', 'document', 'macro|[email protected]', 'user', 'owner'),
+ ('44444444-4444-4444-4444-444444444444', 'document', 'macro|[email protected]', 'user', 'owner'),
+ ('55555555-5555-5555-5555-555555555555', 'document', 'macro|[email protected]', 'user', 'owner'),
+ ('66666666-ffff-ffff-ffff-ffffffffffff', 'chat', 'macro|[email protected]', 'user', 'owner'),
+ ('66666666-6666-6666-6666-666666666666', 'chat', 'macro|[email protected]', 'user', 'owner'),
+ ('77777777-7777-7777-7777-777777777777', 'chat', 'macro|[email protected]', 'user', 'owner'),
+ ('88888888-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'owner'),
+ ('88888888-8888-8888-8888-888888888888', 'project', 'macro|[email protected]', 'user', 'owner');
-- Dependencies for documents
INSERT INTO public."DocumentFamily" ("id", "rootDocumentId")
diff --git a/rust/cloud-storage/macro_db_client/fixtures/simple_items.sql b/rust/cloud-storage/macro_db_client/fixtures/simple_items.sql
index 18307fe360..fdc26474e0 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/simple_items.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/simple_items.sql
@@ -34,10 +34,10 @@ VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'sha-a'),
('cccccccc-cccc-cccc-cccc-cccccccccccc', 'sha-c');
-- Give the user access to all three documents
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES (gen_random_uuid(), 'macro|[email protected]', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', 'cccccccc-cccc-cccc-cccc-cccccccccccc', 'document', 'owner');
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level")
+VALUES ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner'),
+ ('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', 'macro|[email protected]', 'user', 'owner'),
+ ('cccccccc-cccc-cccc-cccc-cccccccccccc', 'document', 'macro|[email protected]', 'user', 'owner');
-- Create UserHistory entries with their own distinct ordering
INSERT INTO public."UserHistory" ("userId", "itemId", "itemType", "updatedAt")
diff --git a/rust/cloud-storage/macro_db_client/fixtures/sorting_expanded_items.sql b/rust/cloud-storage/macro_db_client/fixtures/sorting_expanded_items.sql
index 284adccb90..1b50a167c6 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/sorting_expanded_items.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/sorting_expanded_items.sql
@@ -26,9 +26,17 @@ INSERT INTO public."Project" ("id", "name", "userId", "parentId", "createdAt", "
VALUES ('aaaaaaaa-ffff-ffff-ffff-ffffffffffff', 'Project A', 'macro|[email protected]', NULL, '2024-01-01 09:00:00', '2024-01-01 09:00:00'),
('bbbbbbbb-ffff-ffff-ffff-ffffffffffff', 'Project B', 'macro|[email protected]', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff', '2024-01-01 09:30:00', '2024-01-01 09:30:00');
--- Give user access to the top-level project to test hierarchical access
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES (gen_random_uuid(), 'macro|[email protected]', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff', 'project', 'owner');
+-- Give user access to the top-level project and all inherited items
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level", "granted_from_project_id")
+VALUES
+-- Direct access to project-A
+('aaaaaaaa-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'owner', NULL),
+-- Inherited access to project-B and all items in A and B
+('bbbbbbbb-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'owner', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff'),
+('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'owner', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff'),
+('aaaaaaaa-cccc-cccc-cccc-cccccccccccc', 'chat', 'macro|[email protected]', 'user', 'owner', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff'),
+('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', 'macro|[email protected]', 'user', 'owner', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff'),
+('bbbbbbbb-cccc-cccc-cccc-cccccccccccc', 'chat', 'macro|[email protected]', 'user', 'owner', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff');
-- Item Creation
-- Document A (in Project A): Oldest created, Middle updated, Newest viewed
diff --git a/rust/cloud-storage/macro_db_client/fixtures/soup_items_with_properties.sql b/rust/cloud-storage/macro_db_client/fixtures/soup_items_with_properties.sql
index d73aaa0525..ae79c566dd 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/soup_items_with_properties.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/soup_items_with_properties.sql
@@ -47,13 +47,20 @@ VALUES (1, '11111111-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'sha_A', '2023-01-05 10:00:00
(2, '11111111-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'sha_B', '2023-01-05 11:00:00', '2023-01-05 11:00:00');
---------------------------------------------------
--- USER ACCESS PERMISSIONS (UserItemAccess)
+-- USER ACCESS PERMISSIONS (entity_access)
---------------------------------------------------
+-- entity_access denormalizes all access including project-inherited items.
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level", "granted_from_project_id")
VALUES
-(gen_random_uuid(), 'macro|[email protected]', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff', 'project', 'view'),
-(gen_random_uuid(), 'macro|[email protected]', '11111111-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', 'edit');
+-- Direct access to project-A (view)
+('aaaaaaaa-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'view', NULL),
+-- Inherited access to project-B and items from project-A
+('bbbbbbbb-ffff-ffff-ffff-ffffffffffff', 'project', 'macro|[email protected]', 'user', 'view', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff'),
+('11111111-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'document', 'macro|[email protected]', 'user', 'view', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff'),
+('11111111-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', 'macro|[email protected]', 'user', 'view', 'aaaaaaaa-ffff-ffff-ffff-ffffffffffff'),
+-- Direct 'edit' on doc-in-B (higher than inherited 'view')
+('11111111-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'document', 'macro|[email protected]', 'user', 'edit', NULL);
---------------------------------------------------
-- ENTITY PROPERTIES FOR DOCUMENTS AND PROJECTS
diff --git a/rust/cloud-storage/macro_db_client/fixtures/tasks_with_is_completed.sql b/rust/cloud-storage/macro_db_client/fixtures/tasks_with_is_completed.sql
index ceeec761b8..83c47826e2 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/tasks_with_is_completed.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/tasks_with_is_completed.sql
@@ -49,11 +49,11 @@ VALUES ('11111111-1111-1111-1111-111111111111', 'sha-completed'),
('44444444-4444-4444-4444-444444444444', 'sha-regular');
-- Give the user access to all documents
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
-VALUES (gen_random_uuid(), 'macro|[email protected]', '11111111-1111-1111-1111-111111111111', 'document', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', '22222222-2222-2222-2222-222222222222', 'document', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', '33333333-3333-3333-3333-333333333333', 'document', 'owner'),
- (gen_random_uuid(), 'macro|[email protected]', '44444444-4444-4444-4444-444444444444', 'document', 'owner');
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level")
+VALUES ('11111111-1111-1111-1111-111111111111', 'document', 'macro|[email protected]', 'user', 'owner'),
+ ('22222222-2222-2222-2222-222222222222', 'document', 'macro|[email protected]', 'user', 'owner'),
+ ('33333333-3333-3333-3333-333333333333', 'document', 'macro|[email protected]', 'user', 'owner'),
+ ('44444444-4444-4444-4444-444444444444', 'document', 'macro|[email protected]', 'user', 'owner');
-- Entity properties: Status for completed task
-- Status property definition ID: '00000001-0000-0000-0000-000000000002'
diff --git a/rust/cloud-storage/macro_db_client/fixtures/uia_access_level_chat.sql b/rust/cloud-storage/macro_db_client/fixtures/uia_access_level_chat.sql
index 22a9f71330..9e8dfe988c 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/uia_access_level_chat.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/uia_access_level_chat.sql
@@ -8,31 +8,31 @@ VALUES ('user-1', '[email protected]', 'a1111111-1111-1111-1111-111111111111'),
-- Create a nested project hierarchy: p-grandparent -> p-parent.
INSERT INTO public."Project" ("id", "name", "userId", "parentId")
-VALUES ('p-grandparent', 'Grandparent Project', 'user-1', NULL),
- ('p-parent', 'Parent Project', 'user-1', 'p-grandparent');
+VALUES ('00000000-0000-0000-0000-000000aae002', 'Grandparent Project', 'user-1', NULL),
+ ('00000000-0000-0000-0000-000000aae001', 'Parent Project', 'user-1', '00000000-0000-0000-0000-000000aae002');
-- Create two chats.
-- 'chat-child' is nested inside the project hierarchy.
-- 'chat-standalone' has no project.
INSERT INTO public."Chat" ("id", "name", "userId", "projectId")
-VALUES ('chat-child', 'Nested Chat', 'user-1', 'p-parent'),
- ('chat-standalone', 'Standalone Chat', 'user-2', NULL);
+VALUES ('c0000000-0000-0000-0000-00000000c11d', 'Nested Chat', 'user-1', '00000000-0000-0000-0000-000000aae001'),
+ ('c0000000-0000-0000-0000-000000057a1d', 'Standalone Chat', 'user-2', NULL);
--- Create specific access records in UserItemAccess.
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
+-- Create specific access records in entity_access.
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level")
VALUES
-- Scenario 1: user-1 has DIRECT 'view' access to the nested chat 'chat-child'.
-('10000000-0000-0000-0000-000000000011', 'user-1', 'chat-child', 'chat', 'view'),
+('c0000000-0000-0000-0000-00000000c11d'::uuid, 'chat', 'user-1', 'user', 'view'),
-- Scenario 2: user-1 has INHERITED 'edit' access via the parent project 'p-parent'.
-('10000000-0000-0000-0000-000000000012', 'user-1', 'p-parent', 'project', 'edit'),
+('00000000-0000-0000-0000-000000aae001'::uuid, 'project', 'user-1', 'user', 'edit'),
-- Scenario 3: user-1 has DEEPLY INHERITED 'owner' access via the grandparent project 'p-grandparent'.
-('10000000-0000-0000-0000-000000000013', 'user-1', 'p-grandparent', 'project', 'owner'),
+('00000000-0000-0000-0000-000000aae002'::uuid, 'project', 'user-1', 'user', 'owner'),
-- Scenario 4: user-1 has access to a standalone chat.
-('10000000-0000-0000-0000-000000000014', 'user-1', 'chat-standalone', 'chat', 'comment'),
+('c0000000-0000-0000-0000-000000057a1d'::uuid, 'chat', 'user-1', 'user', 'comment'),
-- Scenario 5: user-2 also has access to 'chat-child'. This is to ensure our query for user-1 does NOT return this record.
-('10000000-0000-0000-0000-000000000015', 'user-2', 'chat-child', 'chat', 'view');
\ No newline at end of file
+('c0000000-0000-0000-0000-00000000c11d'::uuid, 'chat', 'user-2', 'user', 'view');
diff --git a/rust/cloud-storage/macro_db_client/fixtures/uia_access_level_doc.sql b/rust/cloud-storage/macro_db_client/fixtures/uia_access_level_doc.sql
index f7ab10522b..22f21fc1e9 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/uia_access_level_doc.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/uia_access_level_doc.sql
@@ -11,37 +11,37 @@ VALUES ('user-1', '[email protected]', 'a1111111-1111-1111-1111-111111111111'),
-- Create a nested project hierarchy: p-grandparent -> p-parent.
-- Also create an unrelated project to ensure it's not picked up by the query.
+-- IDs are valid UUIDs since entity_access.entity_id is UUID type.
INSERT INTO public."Project" ("id", "name", "userId", "parentId")
-VALUES ('p-grandparent', 'Grandparent Project', 'user-1', NULL),
- ('p-parent', 'Parent Project', 'user-1', 'p-grandparent'),
- ('p-unrelated', 'Unrelated Project', 'user-2', NULL);
+VALUES ('00000000-0000-0000-0000-000000aae002', 'Grandparent Project', 'user-1', NULL),
+ ('00000000-0000-0000-0000-000000aae001', 'Parent Project', 'user-1', '00000000-0000-0000-0000-000000aae002'),
+ ('00000000-0000-0000-0000-000000aae003', 'Unrelated Project', 'user-2', NULL);
-- Create two documents.
-- 'd-child' is nested inside the project hierarchy.
-- 'd-standalone' has no project.
INSERT INTO public."Document" ("id", "name", "owner", "projectId")
-VALUES ('d-child', 'Nested Document', 'user-1', 'p-parent'),
- ('d-standalone', 'Standalone Document', 'user-2', NULL);
+VALUES ('d0000000-0000-0000-0000-00000000c11d', 'Nested Document', 'user-1', '00000000-0000-0000-0000-000000aae001'),
+ ('d0000000-0000-0000-0000-000000057a1d', 'Standalone Document', 'user-2', NULL);
--- Create specific access records in UserItemAccess.
--- This is the core of our test setup.
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level", "granted_from_channel_id")
+-- Create specific access records in entity_access.
+-- source_type is 'user' since these are direct user grants.
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level")
VALUES
-- Scenario 1: user-1 has DIRECT 'view' access to the nested document 'd-child'.
-('10000000-0000-0000-0000-000000000001', 'user-1', 'd-child', 'document', 'view', NULL),
+('d0000000-0000-0000-0000-00000000c11d'::uuid, 'document', 'user-1', 'user', 'view'),
-- Scenario 2: user-1 has INHERITED 'edit' access via the parent project 'p-parent'.
-('10000000-0000-0000-0000-000000000002', 'user-1', 'p-parent', 'project', 'edit', NULL),
+('00000000-0000-0000-0000-000000aae001'::uuid, 'project', 'user-1', 'user', 'edit'),
-- Scenario 3: user-1 has DEEPLY INHERITED 'owner' access via the grandparent project 'p-grandparent'.
-('10000000-0000-0000-0000-000000000003', 'user-1', 'p-grandparent', 'project', 'owner', NULL),
+('00000000-0000-0000-0000-000000aae002'::uuid, 'project', 'user-1', 'user', 'owner'),
--- Scenario 4: user-1 has access to a standalone document, granted via a channel.
-('10000000-0000-0000-0000-000000000004', 'user-1', 'd-standalone', 'document', 'comment',
- '20000000-0000-0000-0000-00000000000c'),
+-- Scenario 4: user-1 has access to a standalone document.
+('d0000000-0000-0000-0000-000000057a1d'::uuid, 'document', 'user-1', 'user', 'comment'),
-- Scenario 5: user-2 also has access to 'd-child'. This is to ensure our query for user-1 does NOT return this record.
-('10000000-0000-0000-0000-000000000005', 'user-2', 'd-child', 'document', 'view', NULL),
+('d0000000-0000-0000-0000-00000000c11d'::uuid, 'document', 'user-2', 'user', 'view'),
-- Scenario 6: user-1 has access to an unrelated project. This should not be returned when querying for 'd-child'.
-('10000000-0000-0000-0000-000000000006', 'user-1', 'p-unrelated', 'project', 'edit', NULL);
\ No newline at end of file
+('00000000-0000-0000-0000-000000aae003'::uuid, 'project', 'user-1', 'user', 'edit');
diff --git a/rust/cloud-storage/macro_db_client/fixtures/uia_access_level_project.sql b/rust/cloud-storage/macro_db_client/fixtures/uia_access_level_project.sql
index 5d9842040f..3d00c929e6 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/uia_access_level_project.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/uia_access_level_project.sql
@@ -11,22 +11,22 @@ VALUES ('user-1', '[email protected]', 'a1111111-1111-1111-1111-111111111111'),
-- Create a nested project hierarchy: p-grandparent -> p-parent -> p-child.
-- Also create an isolated project for the "no access" test case.
INSERT INTO public."Project" ("id", "name", "userId", "parentId")
-VALUES ('p-grandparent', 'Grandparent Project', 'user-1', NULL),
- ('p-parent', 'Parent Project', 'user-1', 'p-grandparent'),
- ('p-child', 'Child Project', 'user-1', 'p-parent'),
- ('p-isolated', 'Isolated Project', 'user-2', NULL);
+VALUES ('00000000-0000-0000-0000-000000aae002', 'Grandparent Project', 'user-1', NULL),
+ ('00000000-0000-0000-0000-000000aae001', 'Parent Project', 'user-1', '00000000-0000-0000-0000-000000aae002'),
+ ('00000000-0000-0000-0000-000000aae003', 'Child Project', 'user-1', '00000000-0000-0000-0000-000000aae001'),
+ ('00000000-0000-0000-0000-000000aae004', 'Isolated Project', 'user-2', NULL);
--- Create specific access records in UserItemAccess for user-1 across the main hierarchy.
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
+-- Create specific access records in entity_access for user-1 across the main hierarchy.
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level")
VALUES
-- Scenario 1: user-1 has access to all three levels of the project hierarchy.
-('10000000-0000-0000-0000-000000000021', 'user-1', 'p-child', 'project', 'view'),
-('10000000-0000-0000-0000-000000000022', 'user-1', 'p-parent', 'project', 'edit'),
-('10000000-0000-0000-0000-000000000023', 'user-1', 'p-grandparent', 'project', 'owner'),
+('00000000-0000-0000-0000-000000aae003'::uuid, 'project', 'user-1', 'user', 'view'),
+('00000000-0000-0000-0000-000000aae001'::uuid, 'project', 'user-1', 'user', 'edit'),
+('00000000-0000-0000-0000-000000aae002'::uuid, 'project', 'user-1', 'user', 'owner'),
-- Scenario 2: user-2 also has access to the middle project. This is to ensure queries for user-1 are properly scoped.
-('10000000-0000-0000-0000-000000000024', 'user-2', 'p-parent', 'project', 'comment'),
+('00000000-0000-0000-0000-000000aae001'::uuid, 'project', 'user-2', 'user', 'comment'),
-- Scenario 3: user-2 has access to the isolated project, which user-1 does not.
-('10000000-0000-0000-0000-000000000025', 'user-2', 'p-isolated', 'project', 'owner');
\ No newline at end of file
+('00000000-0000-0000-0000-000000aae004'::uuid, 'project', 'user-2', 'user', 'owner');
diff --git a/rust/cloud-storage/macro_db_client/fixtures/uia_access_level_thread.sql b/rust/cloud-storage/macro_db_client/fixtures/uia_access_level_thread.sql
index 8aaf6dd4b0..70f555af47 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/uia_access_level_thread.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/uia_access_level_thread.sql
@@ -10,8 +10,8 @@ VALUES ('user-1', '[email protected]', 'a1111111-1111-1111-1111-111111111111'),
-- Create a nested project hierarchy: p-grandparent -> p-parent.
INSERT INTO public."Project" ("id", "name", "userId", "parentId")
-VALUES ('p-grandparent', 'Grandparent Project', 'user-1', NULL),
- ('p-parent', 'Parent Project', 'user-1', 'p-grandparent');
+VALUES ('00000000-0000-0000-0000-000000aae002', 'Grandparent Project', 'user-1', NULL),
+ ('00000000-0000-0000-0000-000000aae001', 'Parent Project', 'user-1', '00000000-0000-0000-0000-000000aae002');
-- Create placeholder SharePermission records required for foreign key constraints in EmailThreadPermission.
INSERT INTO public."SharePermission" ("id", "isPublic")
@@ -22,25 +22,25 @@ VALUES ('sp-thread-nested', false),
INSERT INTO public."EmailThreadPermission" ("threadId", "sharePermissionId", "userId", "projectId")
VALUES
-- 'thread-nested' is part of the project hierarchy.
-('thread-nested', 'sp-thread-nested', 'user-1', 'p-parent'),
+('e0000000-0000-0000-0000-000000070001', 'sp-thread-nested', 'user-1', '00000000-0000-0000-0000-000000aae001'),
-- 'thread-standalone' is not associated with any project.
-('thread-standalone', 'sp-thread-standalone', 'user-2', NULL);
+('e0000000-0000-0000-0000-000000070002', 'sp-thread-standalone', 'user-2', NULL);
--- Create specific access records in UserItemAccess.
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level")
+-- Create specific access records in entity_access.
+INSERT INTO public.entity_access ("entity_id", "entity_type", "source_id", "source_type", "access_level")
VALUES
-- Scenario 1: user-1 has DIRECT 'view' access to the nested thread.
-('10000000-0000-0000-0000-000000000031', 'user-1', 'thread-nested', 'thread', 'view'),
+('e0000000-0000-0000-0000-000000070001'::uuid, 'thread', 'user-1', 'user', 'view'),
-- Scenario 2: user-1 has INHERITED 'edit' access via the parent project 'p-parent'.
-('10000000-0000-0000-0000-000000000032', 'user-1', 'p-parent', 'project', 'edit'),
+('00000000-0000-0000-0000-000000aae001'::uuid, 'project', 'user-1', 'user', 'edit'),
-- Scenario 3: user-1 has DEEPLY INHERITED 'owner' access via the grandparent project 'p-grandparent'.
-('10000000-0000-0000-0000-000000000033', 'user-1', 'p-grandparent', 'project', 'owner'),
+('00000000-0000-0000-0000-000000aae002'::uuid, 'project', 'user-1', 'user', 'owner'),
-- Scenario 4: user-1 has direct access to a standalone thread.
-('10000000-0000-0000-0000-000000000034', 'user-1', 'thread-standalone', 'thread', 'comment'),
+('e0000000-0000-0000-0000-000000070002'::uuid, 'thread', 'user-1', 'user', 'comment'),
-- Scenario 5: user-2 also has access to 'thread-nested'. This is to ensure our query for user-1 does NOT return this record.
-('10000000-0000-0000-0000-000000000035', 'user-2', 'thread-nested', 'thread', 'view');
\ No newline at end of file
+('e0000000-0000-0000-0000-000000070001'::uuid, 'thread', 'user-2', 'user', 'view');
diff --git a/rust/cloud-storage/macro_db_client/fixtures/user_item_access.sql b/rust/cloud-storage/macro_db_client/fixtures/user_item_access.sql
index b6a7c032d9..cf0c920bed 100644
--- a/rust/cloud-storage/macro_db_client/fixtures/user_item_access.sql
+++ b/rust/cloud-storage/macro_db_client/fixtures/user_item_access.sql
@@ -59,7 +59,7 @@ VALUES ('a6666666-6666-6666-6666-666666666666', 'test-user', '[email protected]
('accccccc-cccc-cccc-cccc-cccccccccccc', 'uia_user5', '[email protected]', 'stripe_uia_user5')
ON CONFLICT (id) DO NOTHING;
--- Create test users needed for all UserItemAccess tests
+-- Create test users needed for all entity_access tests
INSERT INTO public."User" ("id", "email", "macro_user_id")
VALUES ('macro|[email protected]', '[email protected]', 'a6666666-6666-6666-6666-666666666666'),
('macro|[email protected]', '[email protected]', 'a7777777-7777-7777-7777-777777777777'),
@@ -70,21 +70,21 @@ VALUES ('macro|[email protected]', '[email protected]', 'a6666666-6666-6666-66
('macro|[email protected]', '[email protected]', 'accccccc-cccc-cccc-cccc-cccccccccccc')
ON CONFLICT (id) DO NOTHING;
--- Create single user item access record for test_delete_user_item_access
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level", "created_at")
-VALUES ('00000000-0000-0000-0000-000000000001', 'macro|[email protected]', 'test-item', 'document', 'owner', NOW());
-
--- Create multiple user item access records for test_delete_user_item_access_by_item
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level", "created_at")
-VALUES ('00000000-0000-0000-0000-000000000002', 'macro|[email protected]', 'multi-access-item', 'document', 'view', NOW()),
- ('00000000-0000-0000-0000-000000000003', 'macro|[email protected]', 'multi-access-item', 'document', 'view', NOW()),
- ('00000000-0000-0000-0000-000000000004', 'macro|[email protected]', 'multi-access-item', 'document', 'view', NOW());
-
--- Create multiple user item access records for test_delete_user_item_access_bulk
-INSERT INTO public."UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level", "created_at")
-VALUES ('00000000-0000-0000-0000-000000000005', 'macro|[email protected]', 'bulk-test-item-1', 'document', 'view', NOW()),
- ('00000000-0000-0000-0000-000000000006', 'macro|[email protected]', 'bulk-test-item-1', 'document', 'edit', NOW()),
- ('00000000-0000-0000-0000-000000000007', 'macro|[email protected]', 'bulk-test-item-2', 'document', 'view', NOW()),
- ('00000000-0000-0000-0000-000000000008', 'macro|[email protected]', 'bulk-test-item-2', 'document', 'edit', NOW()),
- ('00000000-0000-0000-0000-000000000009', 'macro|[email protected]', 'bulk-test-item-3', 'document', 'view', NOW()),
- ('00000000-0000-0000-0000-000000000010', 'macro|[email protected]', 'bulk-test-item-3', 'document', 'edit', NOW());
+-- Create single entity_access record for test_delete_user_item_access
+INSERT INTO public.entity_access (entity_id, entity_type, source_id, source_type, access_level, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-000000000001', 'document', 'macro|[email protected]', 'user', 'owner', NOW(), NOW());
+
+-- Create multiple entity_access records for test_delete_user_item_access_by_item
+INSERT INTO public.entity_access (entity_id, entity_type, source_id, source_type, access_level, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-000000000002', 'document', 'macro|[email protected]', 'user', 'view', NOW(), NOW()),
+ ('00000000-0000-0000-0000-000000000002', 'document', 'macro|[email protected]', 'user', 'view', NOW(), NOW()),
+ ('00000000-0000-0000-0000-000000000002', 'document', 'macro|[email protected]', 'user', 'view', NOW(), NOW());
+
+-- Create multiple entity_access records for test_delete_user_item_access_bulk
+INSERT INTO public.entity_access (entity_id, entity_type, source_id, source_type, access_level, created_at, updated_at)
+VALUES ('00000000-0000-0000-0000-000000000003', 'document', 'macro|[email protected]', 'user', 'view', NOW(), NOW()),
+ ('00000000-0000-0000-0000-000000000003', 'document', 'macro|[email protected]', 'user', 'edit', NOW(), NOW()),
+ ('00000000-0000-0000-0000-000000000004', 'document', 'macro|[email protected]', 'user', 'view', NOW(), NOW()),
+ ('00000000-0000-0000-0000-000000000004', 'document', 'macro|[email protected]', 'user', 'edit', NOW(), NOW()),
+ ('00000000-0000-0000-0000-000000000005', 'document', 'macro|[email protected]', 'user', 'view', NOW(), NOW()),
+ ('00000000-0000-0000-0000-000000000005', 'document', 'macro|[email protected]', 'user', 'edit', NOW(), NOW());
diff --git a/rust/cloud-storage/macro_db_client/migrations/20260421120000_call_share_with_team.sql b/rust/cloud-storage/macro_db_client/migrations/20260421120000_call_share_with_team.sql
new file mode 100644
index 0000000000..e6d8f13079
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/migrations/20260421120000_call_share_with_team.sql
@@ -0,0 +1,2 @@
+ALTER TABLE calls
+ ADD COLUMN share_with_team BOOLEAN NOT NULL DEFAULT TRUE;
diff --git a/rust/cloud-storage/macro_db_client/src/chat/delete.rs b/rust/cloud-storage/macro_db_client/src/chat/delete.rs
index d195f2bb0c..d45efb3df0 100644
--- a/rust/cloud-storage/macro_db_client/src/chat/delete.rs
+++ b/rust/cloud-storage/macro_db_client/src/chat/delete.rs
@@ -1,3 +1,4 @@
+use model_entity::EntityType;
use sqlx::{Postgres, Transaction};
/// Soft deletes a chat
@@ -87,7 +88,15 @@ pub async fn delete_chat_bulk_tsx(
.execute(transaction.as_mut())
.await?;
- crate::item_access::delete::delete_user_item_access_bulk(transaction, chat_ids, "chat").await?;
+ crate::item_access::delete::delete_user_entity_access_bulk(
+ transaction,
+ &chat_ids
+ .iter()
+ .filter_map(|p| macro_uuid::string_to_uuid(p).ok())
+ .collect::<Vec<uuid::Uuid>>(),
+ EntityType::Chat,
+ )
+ .await?;
sqlx::query!(
r#"
@@ -151,8 +160,12 @@ pub async fn delete_chat(db: &sqlx::Pool<sqlx::Postgres>, chat_id: &str) -> anyh
.await?;
}
- crate::item_access::delete::delete_user_item_access_by_item(&mut transaction, chat_id, "chat")
- .await?;
+ crate::item_access::delete::delete_user_entity_access_by_item(
+ &mut transaction,
+ &macro_uuid::string_to_uuid(chat_id).unwrap(),
+ EntityType::Chat,
+ )
+ .await?;
sqlx::query!(
r#"
diff --git a/rust/cloud-storage/macro_db_client/src/chat/patch.rs b/rust/cloud-storage/macro_db_client/src/chat/patch.rs
index 826b5099c4..92ba3bb093 100644
--- a/rust/cloud-storage/macro_db_client/src/chat/patch.rs
+++ b/rust/cloud-storage/macro_db_client/src/chat/patch.rs
@@ -1,102 +1,5 @@
-use models_permissions::share_permission::UpdateSharePermissionRequestV2;
use sqlx::{Postgres, Transaction};
-use crate::projects;
-use crate::share_permission;
-
-#[tracing::instrument(skip(transaction))]
-pub async fn patch_chat(
- transaction: &mut sqlx::Transaction<'_, Postgres>,
- chat_id: &str,
- name: Option<&str>,
- model: Option<&str>,
- token_count: Option<&i64>,
- share_permissions: Option<&UpdateSharePermissionRequestV2>,
- project_id: Option<&str>,
-) -> anyhow::Result<()> {
- patch_chat_transaction(
- transaction,
- chat_id,
- name,
- model,
- token_count,
- share_permissions,
- )
- .await?;
-
- if let Some(project_id) = project_id {
- projects::move_item::move_item_to_project(transaction, project_id, chat_id, "chat").await?;
- }
- Ok(())
-}
-
-/// Patches a chat
-#[tracing::instrument(skip(transaction))]
-pub async fn patch_chat_transaction(
- transaction: &mut Transaction<'_, Postgres>,
- chat_id: &str,
- name: Option<&str>,
- model: Option<&str>,
- token_count: Option<&i64>,
- share_permissions: Option<&UpdateSharePermissionRequestV2>,
-) -> anyhow::Result<()> {
- // Update compare updated at time
- sqlx::query!(
- r#"
- UPDATE "Chat" SET "updatedAt" = NOW()
- WHERE id = $1
- "#,
- chat_id,
- )
- .execute(transaction.as_mut())
- .await?;
-
- if let Some(name) = name {
- sqlx::query!(
- r#"
- UPDATE "Chat" SET "name" = $1
- WHERE id = $2
- "#,
- name,
- chat_id,
- )
- .execute(transaction.as_mut())
- .await?;
- }
-
- if let Some(model) = model {
- sqlx::query!(
- r#"
- UPDATE "Chat" SET "model" = $1
- WHERE id = $2
- "#,
- model,
- chat_id,
- )
- .execute(transaction.as_mut())
- .await?;
- }
-
- if let Some(token_count) = token_count {
- sqlx::query!(
- r#"
- UPDATE "Chat" SET "tokenCount" = $1
- WHERE id = $2
- "#,
- token_count,
- chat_id,
- )
- .execute(transaction.as_mut())
- .await?;
- }
-
- if let Some(share_permissions) = share_permissions {
- share_permission::edit::edit_chat_permission(transaction, chat_id, share_permissions)
- .await?;
- }
- Ok(())
-}
-
pub async fn update_chat_token_count(
transaction: &mut Transaction<'_, Postgres>,
chat_id: &str,
diff --git a/rust/cloud-storage/macro_db_client/src/dcs/create_chat.rs b/rust/cloud-storage/macro_db_client/src/dcs/create_chat.rs
index 730b14adf6..f03c5e03de 100644
--- a/rust/cloud-storage/macro_db_client/src/dcs/create_chat.rs
+++ b/rust/cloud-storage/macro_db_client/src/dcs/create_chat.rs
@@ -3,6 +3,7 @@ use crate::history::{upsert_item_last_accessed, upsert_user_history};
use ai::types::Model;
use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};
use model::{IDWithTimeStamps, chat::NewChatAttachment};
+use model_entity::EntityType;
use models_permissions::share_permission::SharePermissionV2;
use models_permissions::share_permission::access_level::AccessLevel;
use sqlx::{Pool, Postgres};
@@ -66,13 +67,13 @@ pub async fn create_chat_v2(
append_attachment_to_chat(&mut transaction, attachment).await?;
}
- crate::item_access::insert::insert_user_item_access(
+ entity_access_db_utils::insert_entity_access_row(
&mut transaction,
- user_id.copied(),
- &chat.id,
- "chat",
+ &macro_uuid::string_to_uuid(&chat.id).unwrap(),
+ EntityType::Chat,
+ user_id.as_ref(),
+ entity_access_db_utils::EntityAccessSourceType::User,
AccessLevel::Owner,
- None,
)
.await?;
diff --git a/rust/cloud-storage/macro_db_client/src/document/copy_document/copy_pdf_parts.rs b/rust/cloud-storage/macro_db_client/src/document/copy_document/copy_pdf_parts.rs
deleted file mode 100644
index c2a12d6811..0000000000
--- a/rust/cloud-storage/macro_db_client/src/document/copy_document/copy_pdf_parts.rs
+++ /dev/null
@@ -1,96 +0,0 @@
-use sqlx::{Pool, Postgres};
-
-/// Copies a documents pdf specific parts. Such as document text extraction and pdf preprocess result.
-#[tracing::instrument(skip(db))]
-pub async fn copy_pdf_parts(
- db: Pool<Postgres>,
- new_document_id: &str,
- original_document_id: &str,
-) -> anyhow::Result<()> {
- let mut transaction = db.begin().await?;
-
- // Copy Document Text Extraction
- tracing::trace!("copying document text extraction");
- sqlx::query!(
- r#"
- INSERT INTO "DocumentText" ("documentId", "content", "tokenCount")
- SELECT $1, content, "tokenCount" FROM "DocumentText"
- WHERE "documentId" = $2
- "#,
- new_document_id,
- original_document_id
- )
- .execute(transaction.as_mut())
- .await?;
-
- // Copy Document Preprocess Result
- tracing::trace!("copying document preprocess result");
- sqlx::query!(
- r#"
- INSERT INTO "DocumentProcessResult" ("documentId", "content", "jobType")
- SELECT $1, content, 'pdf_preprocess' FROM "DocumentProcessResult"
- WHERE "documentId" = $2 and "jobType" = 'pdf_preprocess'
- "#,
- new_document_id,
- original_document_id
- )
- .execute(transaction.as_mut())
- .await?;
-
- transaction.commit().await?;
-
- Ok(())
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
- use sqlx::{Pool, Postgres};
-
- #[sqlx::test(fixtures(path = "../../../fixtures", scripts("basic_user_with_documents")))]
- async fn test_copy_pdf_parts(pool: Pool<Postgres>) -> anyhow::Result<()> {
- sqlx::query!(
- r#"
- INSERT INTO "DocumentText" ("documentId", "content", "tokenCount")
- VALUES ('document-one', 'testing-content', 123)
- "#,
- )
- .execute(&pool)
- .await?;
-
- sqlx::query!(
- r#"
- INSERT INTO "DocumentProcessResult" ("documentId", "content", "jobType")
- VALUES ('document-one', 'testing-content', 'pdf_preprocess')
- "#,
- )
- .execute(&pool)
- .await?;
-
- copy_pdf_parts(pool.clone(), "document-two", "document-one").await?;
-
- let document_text = sqlx::query!(
- r#"
- SELECT "content" FROM "DocumentText"
- WHERE "documentId" = 'document-two'
- "#,
- )
- .fetch_one(&pool)
- .await?;
-
- assert_eq!(document_text.content, "testing-content");
-
- let document_process_result = sqlx::query!(
- r#"
- SELECT "content" FROM "DocumentProcessResult"
- WHERE "documentId" = 'document-two' and "jobType" = 'pdf_preprocess'
- "#,
- )
- .fetch_one(&pool)
- .await?;
-
- assert_eq!(document_process_result.content, "testing-content");
-
- Ok(())
- }
-}
diff --git a/rust/cloud-storage/macro_db_client/src/document/copy_document/mod.rs b/rust/cloud-storage/macro_db_client/src/document/copy_document/mod.rs
deleted file mode 100644
index e38bdbae48..0000000000
--- a/rust/cloud-storage/macro_db_client/src/document/copy_document/mod.rs
+++ /dev/null
@@ -1,395 +0,0 @@
-use crate::{
- document::document_bom::create_bom_parts, share_permission::create::create_document_permission,
-};
-use document_sub_type::DocumentSubType;
-use macro_user_id::user_id::MacroUserIdStr;
-use model::document::{
- BomPart, DocumentMetadata, FileType, IDWithTimeStamps, VersionIDWithTimeStamps,
- VersionIDWithTimeStampsNoSha,
-};
-use models_permissions::share_permission::SharePermissionV2;
-use sqlx::{Pool, Postgres, Transaction};
-
-pub mod copy_pdf_parts;
-
-/// Copies a given document
-#[tracing::instrument(skip(db))]
-pub async fn copy_document(
- db: Pool<Postgres>,
- original_document: &DocumentMetadata,
- user_id: MacroUserIdStr<'static>,
- new_document_name: &str,
- file_type: &FileType,
- document_share_permissions: &SharePermissionV2,
-) -> anyhow::Result<DocumentMetadata> {
- let mut transaction = db.begin().await?;
- let document = match file_type {
- FileType::Docx => {
- copy_docx_document(
- &mut transaction,
- original_document,
- user_id,
- new_document_name,
- )
- .await
- }
- _ => {
- copy_non_docx_document(
- &mut transaction,
- original_document,
- user_id,
- new_document_name,
- )
- .await
- }
- }?;
-
- // Create documet permissions
- let _ = create_document_permission(
- &mut transaction,
- document.document_id.as_str(),
- document_share_permissions,
- )
- .await?;
-
- if let Err(transaction_err) = transaction.commit().await {
- tracing::error!(
- error=?transaction_err,
- "copy_document transaction error",
- );
- return Err(transaction_err.into());
- }
-
- Ok(document)
-}
-
-/// Copies a given docx document
-#[tracing::instrument(skip(transaction))]
-pub(in crate::document) async fn copy_docx_document(
- transaction: &mut Transaction<'_, Postgres>,
- original_document: &DocumentMetadata,
- user_id: MacroUserIdStr<'static>,
- new_document_name: &str,
-) -> anyhow::Result<DocumentMetadata> {
- let original_document_id = &original_document.document_id;
- let original_document_version_id = original_document.document_version_id;
- // Create document
- let document = sqlx::query_as!(
- IDWithTimeStamps,
- r#"
- INSERT INTO "Document" (owner, name, "fileType", "documentFamilyId", "branchedFromId", "branchedFromVersionId", "projectId")
- VALUES ($1, $2, $3, $4, $5, $6, $7)
- RETURNING id, "createdAt"::timestamptz as created_at, "updatedAt"::timestamptz as updated_at;
- "#,
- user_id.as_ref(),
- &new_document_name,
- original_document.file_type,
- original_document.document_family_id,
- &original_document_id,
- &original_document_version_id,
- original_document.project_id,
- )
- .fetch_one(transaction.as_mut())
- .await
- .map_err(|err| {
- tracing::error!(error=?err, "unable to copy document");
- let no_user_found = "error returned from database: insert or update on table \"Document\" violates foreign key constraint \"Document_owner_fkey\"";
- let err_string = err.to_string();
- if err_string.contains(no_user_found) {
- return anyhow::Error::msg("no user found");
- }
- anyhow::Error::msg("unable to copy document")
- })?;
-
- // Create document bom id
- let document_bom = sqlx::query_as!(
- VersionIDWithTimeStampsNoSha,
- r#"
- INSERT INTO "DocumentBom" ("documentId")
- VALUES ($1)
- RETURNING id, "createdAt"::timestamptz as created_at, "updatedAt"::timestamptz as updated_at;
- "#,
- &document.id,
- )
- .fetch_one(transaction.as_mut())
- .await?;
-
- // Create document bom
- // We error out in the copy_document_handler if the document bom is missing
- let document_bom_parts: Vec<BomPart> =
- serde_json::from_value(original_document.document_bom.as_ref().unwrap().clone())?;
-
- let saved_bom_parts: Vec<BomPart> = create_bom_parts(
- transaction,
- document_bom.id,
- document_bom_parts.into_iter().map(|b| b.into()).collect(),
- )
- .await?;
-
- let saved_bom_parts = serde_json::to_value(saved_bom_parts)?;
-
- Ok(DocumentMetadata {
- document_id: document.id.clone(),
- owner: user_id,
- document_name: new_document_name.to_string(),
- file_type: original_document.file_type.clone(),
- sha: None,
- modification_data: None,
- branched_from_id: Some(original_document_id.to_string()),
- branched_from_version_id: Some(original_document_version_id),
- document_family_id: original_document.document_family_id,
- project_id: original_document.project_id.clone(),
- project_name: original_document.project_name.clone(),
- document_version_id: document_bom.id,
- document_bom: Some(saved_bom_parts),
- created_at: document.created_at,
- updated_at: document.updated_at,
- sub_type: None,
- deleted_at: None,
- })
-}
-
-/// Copies a given non-docx document
-#[tracing::instrument(skip(transaction))]
-pub(in crate::document) async fn copy_non_docx_document(
- transaction: &mut Transaction<'_, Postgres>,
- original_document: &DocumentMetadata,
- user_id: MacroUserIdStr<'static>,
- new_document_name: &str,
-) -> anyhow::Result<DocumentMetadata> {
- let original_document_id = &original_document.document_id;
- let original_document_version_id = original_document.document_version_id;
- let sha = match &original_document.sha {
- Some(sha) => sha.as_str(),
- None => {
- tracing::error!("unable to copy pdf document, sha is missing");
- anyhow::bail!("unable to copy document");
- }
- };
-
- // Create document
- let document = sqlx::query_as!(
- IDWithTimeStamps,
- r#"
- INSERT INTO "Document" (owner, name, "fileType", "documentFamilyId", "branchedFromId", "branchedFromVersionId", "projectId")
- VALUES ($1, $2, $3, $4, $5, $6, $7)
- RETURNING id, "createdAt"::timestamptz as created_at, "updatedAt"::timestamptz as updated_at;
- "#,
- user_id.as_ref(),
- &new_document_name,
- original_document.file_type,
- original_document.document_family_id,
- &original_document_id,
- &original_document_version_id,
- original_document.project_id,
- )
- .fetch_one(transaction.as_mut())
- .await
- .map_err(|err| {
- tracing::error!(error=?err, "unable to copy document");
- let no_user_found = "error returned from database: insert or update on table \"Document\" violates foreign key constraint \"Document_owner_fkey\"";
- let err_string = err.to_string();
- if err_string.contains(no_user_found) {
- return anyhow::Error::msg("no user found");
- }
- anyhow::Error::msg("unable to copy document")
- })?;
-
- // Create document bom id
- let document_instance = sqlx::query_as!(
- VersionIDWithTimeStamps,
- r#"
- INSERT INTO "DocumentInstance" ("documentId", "sha")
- VALUES ($1, $2)
- RETURNING id, sha, "createdAt"::timestamptz as created_at, "updatedAt"::timestamptz as updated_at;
- "#,
- &document.id,
- sha,
- )
- .fetch_one(transaction.as_mut())
- .await?;
-
- let original_document_modification = sqlx::query!(
- r#"
- SELECT "modificationData" as modification_data
- FROM "DocumentInstanceModificationData"
- WHERE "documentInstanceId" = $1
- "#,
- original_document_version_id
- )
- .fetch_optional(transaction.as_mut())
- .await?;
-
- let original_modification_data = if let Some(original_document_modification) =
- original_document_modification
- {
- sqlx::query!(
- r#"
- INSERT INTO "DocumentInstanceModificationData" ("documentInstanceId", "modificationData")
- VALUES ($1, $2);
- "#,
- document_instance.id,
- original_document_modification.modification_data
- ).execute(transaction.as_mut()).await?;
-
- Some(original_document_modification.modification_data)
- } else {
- None
- };
-
- if original_document.sub_type == Some(DocumentSubType::Task) {
- sqlx::query!(
- r#"
- INSERT INTO document_sub_type (document_id, sub_type)
- VALUES ($1, $2)
- "#,
- document.id,
- DocumentSubType::Task as _,
- )
- .execute(transaction.as_mut())
- .await?;
- }
-
- Ok(DocumentMetadata {
- document_id: document.id.clone(),
- owner: user_id,
- document_name: new_document_name.to_string(),
- file_type: original_document.file_type.clone(),
- sha: Some(document_instance.sha),
- branched_from_id: Some(original_document_id.to_string()),
- branched_from_version_id: Some(original_document_version_id),
- document_family_id: original_document.document_family_id,
- document_version_id: document_instance.id,
- document_bom: None,
- project_id: original_document.project_id.clone(),
- project_name: original_document.project_name.clone(),
- modification_data: original_modification_data,
- created_at: document.created_at,
- updated_at: document.updated_at,
- sub_type: original_document.sub_type,
- deleted_at: None,
- })
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
- use sqlx::{Pool, Postgres};
-
- #[sqlx::test(fixtures(path = "../../../fixtures", scripts("basic_user_with_documents")))]
- async fn test_copy_non_docx_document(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let mut transaction = pool.begin().await.unwrap();
- let document_metadata = copy_non_docx_document(
- &mut transaction,
- &DocumentMetadata::new_document(
- "document-one",
- 1,
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- "name",
- Some(FileType::Txt),
- "sha",
- None,
- None,
- None,
- None,
- None,
- None,
- None,
- None,
- ),
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- "new name",
- )
- .await?;
-
- if let Err(e) = transaction.commit().await {
- return Err(e.into());
- }
-
- assert!(!document_metadata.document_id.is_empty());
- assert_eq!(document_metadata.sha.unwrap(), "sha");
- assert_eq!(document_metadata.document_name, "new name".to_string());
- assert_eq!(document_metadata.owner.as_ref(), "macro|[email protected]");
- assert_eq!(document_metadata.branched_from_id.unwrap(), "document-one");
- assert_eq!(document_metadata.branched_from_version_id.unwrap(), 1);
- assert_eq!(
- document_metadata.modification_data.unwrap().to_string(),
- "{\"testing\":true}"
- );
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../../fixtures", scripts("basic_user_with_documents")))]
- async fn test_copy_document(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let document_metadata = copy_document(
- pool.clone(),
- &DocumentMetadata::new_docx(
- "document-one",
- 1,
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- "name",
- "docx",
- None,
- None,
- None,
- None,
- None,
- None,
- None,
- ),
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- "new name",
- &FileType::Docx,
- &SharePermissionV2::new_document_share_permission(Some(FileType::Docx)),
- )
- .await?;
-
- assert!(!document_metadata.document_id.is_empty());
- assert!(document_metadata.sha.is_none());
- assert_eq!(document_metadata.document_name, "new name".to_string());
- assert_eq!(document_metadata.owner.as_ref(), "macro|[email protected]");
- assert_eq!(document_metadata.branched_from_id.unwrap(), "document-one");
- assert_eq!(document_metadata.branched_from_version_id.unwrap(), 1);
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../../fixtures", scripts("basic_user_with_documents")))]
- async fn test_copy_docx_document(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let mut transaction = pool.begin().await.unwrap();
- let document_metadata = copy_docx_document(
- &mut transaction,
- &DocumentMetadata::new_docx(
- "document-one",
- 1,
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- "name",
- "docx",
- None,
- None,
- None,
- None,
- None,
- None,
- None,
- ),
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- "new name",
- )
- .await?;
-
- if let Err(e) = transaction.commit().await {
- return Err(e.into());
- }
-
- assert!(!document_metadata.document_id.is_empty());
- assert!(document_metadata.sha.is_none());
- assert_eq!(document_metadata.document_name, "new name".to_string());
- assert_eq!(document_metadata.owner.as_ref(), "macro|[email protected]");
- assert_eq!(document_metadata.branched_from_id.unwrap(), "document-one");
- assert_eq!(document_metadata.branched_from_version_id.unwrap(), 1);
-
- Ok(())
- }
-}
diff --git a/rust/cloud-storage/macro_db_client/src/document/delete_document.rs b/rust/cloud-storage/macro_db_client/src/document/delete_document.rs
index 6941ed7e2d..ca612d6070 100644
--- a/rust/cloud-storage/macro_db_client/src/document/delete_document.rs
+++ b/rust/cloud-storage/macro_db_client/src/document/delete_document.rs
@@ -1,52 +1,6 @@
-use anyhow::Context;
+use model_entity::EntityType;
use sqlx::{Pool, Postgres, Transaction};
-/// Soft deletes a document from the database.
-/// Removing the history and pins for the document as well
-#[tracing::instrument(skip(db))]
-pub async fn soft_delete_document(db: &Pool<Postgres>, document_id: &str) -> anyhow::Result<()> {
- let mut transaction = db.begin().await?;
- // Delete pins
- sqlx::query!(
- r#"
- DELETE FROM "Pin" WHERE "pinnedItemId" = $1 AND "pinnedItemType" = $2
- "#,
- document_id,
- "document",
- )
- .execute(&mut *transaction)
- .await?;
-
- // Delete from history
- sqlx::query!(
- r#"
- DELETE FROM "UserHistory" WHERE "itemId" = $1 AND "itemType" = $2
- "#,
- document_id,
- "document",
- )
- .execute(&mut *transaction)
- .await?;
-
- // Delete document
- sqlx::query!(
- r#"
- UPDATE "Document"
- SET "deletedAt" = NOW()
- WHERE id = $1"#,
- document_id
- )
- .execute(&mut *transaction)
- .await?;
-
- transaction
- .commit()
- .await
- .context("unable to soft delete document")?;
-
- Ok(())
-}
-
/// Hard deletes a document from the database.
/// Removing the history and pins for the document as well.
#[tracing::instrument(skip(db))]
@@ -102,10 +56,10 @@ pub async fn delete_document(db: &Pool<Postgres>, document_id: &str) -> anyhow::
.execute(&mut *transaction)
.await?;
- crate::item_access::delete::delete_user_item_access_by_item(
+ crate::item_access::delete::delete_user_entity_access_by_item(
&mut transaction,
- document_id,
- "document",
+ &macro_uuid::string_to_uuid(document_id).unwrap(),
+ EntityType::Document,
)
.await?;
@@ -169,10 +123,13 @@ pub async fn delete_document_bulk_tsx(
.execute(transaction.as_mut())
.await?;
- crate::item_access::delete::delete_user_item_access_bulk(
+ crate::item_access::delete::delete_user_entity_access_bulk(
transaction,
- &document_ids,
- "document",
+ &document_ids
+ .iter()
+ .filter_map(|p| macro_uuid::string_to_uuid(p).ok())
+ .collect::<Vec<uuid::Uuid>>(),
+ EntityType::Document,
)
.await?;
@@ -256,48 +213,6 @@ mod tests {
use super::*;
use sqlx::{Pool, Postgres};
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("basic_user_with_lots_of_documents")))]
- async fn test_soft_delete_document(pool: Pool<Postgres>) -> anyhow::Result<()> {
- soft_delete_document(&pool, "document-one").await?;
-
- let deleted_at = sqlx::query!(
- r#"
- SELECT
- d."createdAt"::timestamptz as deleted_at
- FROM
- "Document" d
- WHERE
- d.id = $1
- "#,
- "document-one"
- )
- .fetch_one(&pool)
- .await?;
-
- assert_eq!(deleted_at.deleted_at.is_some(), true);
-
- // get pins
- let pins = sqlx::query!(
- r#"SELECT COUNT(*) as count FROM "Pin" WHERE "pinnedItemId"=$1"#,
- "document-one"
- )
- .fetch_one(&pool)
- .await?;
-
- assert_eq!(pins.count.unwrap(), 0);
-
- // get history
- let history = sqlx::query!(
- r#"SELECT COUNT(*) as count FROM "UserHistory" WHERE "itemId"=$1"#,
- "document-one"
- )
- .fetch_one(&pool)
- .await?;
- assert_eq!(history.count.unwrap(), 0);
-
- Ok(())
- }
-
#[sqlx::test(fixtures(path = "../../fixtures", scripts("docx_example")))]
async fn test_get_shas_for_deletion(pool: Pool<Postgres>) {
let mut shas = get_shas_for_deletion(pool.clone(), "document-one")
diff --git a/rust/cloud-storage/macro_db_client/src/document/document_bom.rs b/rust/cloud-storage/macro_db_client/src/document/document_bom.rs
deleted file mode 100644
index 11c1ab1b25..0000000000
--- a/rust/cloud-storage/macro_db_client/src/document/document_bom.rs
+++ /dev/null
@@ -1,41 +0,0 @@
-use sqlx::{Postgres, Transaction};
-
-use model::document::{BomPart, SaveBomPart};
-
-pub(in crate::document) async fn create_bom_parts(
- transaction: &mut Transaction<'_, Postgres>,
- document_bom_id: i64,
- bom_parts: Vec<SaveBomPart>,
-) -> anyhow::Result<Vec<BomPart>> {
- if bom_parts.is_empty() {
- return Ok(Vec::new());
- }
- let mut query =
- "INSERT INTO \"BomPart\" (\"documentBomId\", \"sha\", \"path\") VALUES ".to_string();
- let mut set_parts: Vec<String> = Vec::new();
- let mut parameters: Vec<String> = Vec::new();
-
- for bom_part in &bom_parts {
- // Start counting at 2 because 1 is the document bom id
- let param_number = parameters.len() + 2;
- set_parts.push(format!("($1, ${}, ${})", param_number, param_number + 1));
-
- parameters.push(bom_part.sha.clone());
- parameters.push(bom_part.path.clone());
- }
-
- query += &set_parts.join(", ");
-
- query += ";";
-
- let mut query = sqlx::query_as::<_, BomPart>(&query);
- query = query.bind(document_bom_id);
-
- for param in parameters {
- query = query.bind(param);
- }
-
- let saved_bom_parts: Vec<BomPart> = query.fetch_all(transaction.as_mut()).await?;
-
- Ok(saved_bom_parts)
-}
diff --git a/rust/cloud-storage/macro_db_client/src/document/initialize_onboarding_documents.rs b/rust/cloud-storage/macro_db_client/src/document/initialize_onboarding_documents.rs
index 8a96b63b14..5aaf979902 100644
--- a/rust/cloud-storage/macro_db_client/src/document/initialize_onboarding_documents.rs
+++ b/rust/cloud-storage/macro_db_client/src/document/initialize_onboarding_documents.rs
@@ -6,6 +6,7 @@ use macro_user_id::user_id::MacroUserIdStr;
use model::document::{BasicDocument, FileType};
use model::document::{ID, SaveBomPart, VersionID};
use model::project::Project;
+use model_entity::EntityType;
use models_permissions::share_permission::SharePermissionV2;
use models_permissions::share_permission::access_level::AccessLevel;
use sqlx::{Postgres, Transaction};
@@ -38,13 +39,13 @@ pub async fn create_project_transaction(
create_project_permission(transaction, &project.id, share_permission).await?;
upsert_user_history(transaction, user_id.copied(), &project.id, "project").await?;
- crate::item_access::insert::insert_user_item_access(
+ entity_access_db_utils::insert_entity_access_row(
transaction,
- user_id,
- &project.id,
- "project",
+ &macro_uuid::string_to_uuid(&project.id).unwrap(),
+ EntityType::Project,
+ user_id.as_ref(),
+ entity_access_db_utils::EntityAccessSourceType::User,
AccessLevel::Owner,
- None,
)
.await?;
diff --git a/rust/cloud-storage/macro_db_client/src/document/list_documents_with_access.rs b/rust/cloud-storage/macro_db_client/src/document/list_documents_with_access.rs
index cede49a5eb..489ba19d4f 100644
--- a/rust/cloud-storage/macro_db_client/src/document/list_documents_with_access.rs
+++ b/rust/cloud-storage/macro_db_client/src/document/list_documents_with_access.rs
@@ -19,34 +19,24 @@ pub async fn list_documents_with_access(
let documents: Vec<DocumentListItem> = sqlx::query!(
r#"
- WITH RECURSIVE ProjectHierarchy AS (
- SELECT p.id, uia.access_level
- FROM "Project" p
- JOIN "UserItemAccess" uia ON p.id = uia.item_id AND uia.item_type = 'project'
- WHERE uia.user_id = $1 AND p."deletedAt" IS NULL
+ WITH user_source_ids AS (
+ SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp
+ WHERE cp.user_id = $1 AND cp.left_at IS NULL
UNION ALL
- SELECT p.id, ph.access_level
- FROM "Project" p
- JOIN ProjectHierarchy ph ON p."parentId" = ph.id
- WHERE p."deletedAt" IS NULL
- ),
- AllAccessGrants AS (
- SELECT item_id, item_type, access_level
- FROM "UserItemAccess"
- WHERE user_id = $1 AND item_type = 'document'
+ SELECT t.team_id::text FROM team_user t
+ WHERE t.user_id = $1
UNION ALL
- SELECT d.id AS item_id, 'document' AS item_type, ph.access_level
- FROM "Document" d
- JOIN ProjectHierarchy ph ON d."projectId" = ph.id
- WHERE d."projectId" IS NOT NULL AND d."deletedAt" IS NULL
+ SELECT $1
),
UserAccessibleDocuments AS (
- SELECT DISTINCT ON (item_id) item_id, access_level
- FROM AllAccessGrants
- ORDER BY item_id,
- CASE access_level
+ SELECT DISTINCT ON (entity_id) entity_id, access_level
+ FROM entity_access
+ WHERE source_id = ANY(SELECT source_id FROM user_source_ids)
+ AND entity_type = 'document'
+ ORDER BY entity_id,
+ CASE access_level::text
WHEN 'owner' THEN 4
- WHEN 'edit' THEN 3
+ WHEN 'edit' THEN 3
WHEN 'comment' THEN 2
WHEN 'view' THEN 1
ELSE 0
@@ -63,7 +53,7 @@ pub async fn list_documents_with_access(
d."deletedAt"::timestamptz as "deleted_at",
uad.access_level::text as "access_level!"
FROM "Document" d
- INNER JOIN UserAccessibleDocuments uad ON uad.item_id = d.id
+ INNER JOIN UserAccessibleDocuments uad ON uad.entity_id = d.id::uuid
WHERE d."deletedAt" IS NULL
AND ($2::text[] IS NULL OR d."fileType" = ANY($2))
AND (
@@ -73,7 +63,7 @@ pub async fn list_documents_with_access(
WHEN 'comment' THEN 2
WHEN 'view' THEN 1
ELSE 0
- END >=
+ END >=
CASE $3
WHEN 'owner' THEN 4
WHEN 'edit' THEN 3
@@ -122,7 +112,7 @@ mod tests {
use models_permissions::share_permission::access_level::AccessLevel;
use sqlx::{Pool, Postgres};
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("basic_user_with_lots_of_documents")))]
+ #[sqlx::test(fixtures(path = "../../fixtures", scripts("list_documents_with_access")))]
async fn test_list_documents_with_access_owned_documents(
pool: Pool<Postgres>,
) -> anyhow::Result<()> {
@@ -152,7 +142,7 @@ mod tests {
Ok(())
}
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("basic_user_with_lots_of_documents")))]
+ #[sqlx::test(fixtures(path = "../../fixtures", scripts("list_documents_with_access")))]
async fn test_list_documents_with_file_type_filter(pool: Pool<Postgres>) -> anyhow::Result<()> {
let filters = DocumentListFilters {
file_types: Some(vec!["md".to_string()]),
@@ -181,7 +171,7 @@ mod tests {
Ok(())
}
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("basic_user_with_lots_of_documents")))]
+ #[sqlx::test(fixtures(path = "../../fixtures", scripts("list_documents_with_access")))]
async fn test_list_documents_with_pagination(pool: Pool<Postgres>) -> anyhow::Result<()> {
let filters = DocumentListFilters::default();
diff --git a/rust/cloud-storage/macro_db_client/src/document/mod.rs b/rust/cloud-storage/macro_db_client/src/document/mod.rs
index 1acab09f14..50d70e45e4 100644
--- a/rust/cloud-storage/macro_db_client/src/document/mod.rs
+++ b/rust/cloud-storage/macro_db_client/src/document/mod.rs
@@ -8,8 +8,6 @@ mod list_documents_with_access;
mod save_document;
pub mod v2;
-pub mod copy_document;
-pub mod document_bom;
pub use delete_document::*;
pub use get_document::*;
pub use get_document_list::*;
diff --git a/rust/cloud-storage/macro_db_client/src/document/v2/copy.rs b/rust/cloud-storage/macro_db_client/src/document/v2/copy.rs
deleted file mode 100644
index f622aaee54..0000000000
--- a/rust/cloud-storage/macro_db_client/src/document/v2/copy.rs
+++ /dev/null
@@ -1,113 +0,0 @@
-use crate::{
- document::copy_document::{copy_docx_document, copy_non_docx_document},
- share_permission::create::create_document_permission,
-};
-use macro_user_id::user_id::MacroUserIdStr;
-use model::document::{DocumentMetadata, FileType};
-use models_permissions::share_permission::SharePermissionV2;
-use models_permissions::share_permission::access_level::AccessLevel;
-use sqlx::{Pool, Postgres};
-
-/// Copies a given document
-#[tracing::instrument(skip(db))]
-pub async fn copy_document(
- db: &Pool<Postgres>,
- original_document: &DocumentMetadata,
- user_id: MacroUserIdStr<'static>,
- new_document_name: &str,
- file_type: Option<&FileType>,
- document_share_permissions: &SharePermissionV2,
-) -> anyhow::Result<DocumentMetadata> {
- let mut transaction = db.begin().await?;
- let document = match file_type {
- Some(FileType::Docx) => {
- copy_docx_document(
- &mut transaction,
- original_document,
- user_id.clone(),
- new_document_name,
- )
- .await
- }
- _ => {
- copy_non_docx_document(
- &mut transaction,
- original_document,
- user_id.clone(),
- new_document_name,
- )
- .await
- }
- }?;
-
- // Create documet permissions
- let _ = create_document_permission(
- &mut transaction,
- document.document_id.as_str(),
- document_share_permissions,
- )
- .await?;
-
- crate::item_access::insert::insert_user_item_access(
- &mut transaction,
- user_id,
- document.document_id.as_str(),
- "document",
- AccessLevel::Owner,
- None,
- )
- .await?;
-
- if let Err(transaction_err) = transaction.commit().await {
- tracing::error!(
- error=?transaction_err,
- "copy_document transaction error",
- );
- return Err(transaction_err.into());
- }
-
- Ok(document)
-}
-
-#[cfg(test)]
-mod tests {
- use models_permissions::share_permission::access_level::AccessLevel;
-
- use super::*;
- use sqlx::{Pool, Postgres};
-
- #[sqlx::test(fixtures(path = "../../../fixtures", scripts("basic_user_with_documents")))]
- async fn test_copy_document(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let document_metadata = copy_document(
- &pool,
- &DocumentMetadata::new_docx(
- "document-one",
- 1,
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- "name",
- "docx",
- None,
- None,
- None,
- None,
- None,
- None,
- None,
- ),
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- "new name",
- Some(&FileType::Docx),
- &SharePermissionV2::new_document_share_permission(Some(FileType::Docx)),
- )
- .await?;
-
- assert!(!document_metadata.document_id.is_empty());
- assert!(document_metadata.sha.is_none());
- assert_eq!(document_metadata.document_name, "new name".to_string());
- assert_eq!(document_metadata.owner.as_ref(), "macro|[email protected]");
- assert_eq!(document_metadata.branched_from_id.unwrap(), "document-one");
- assert_eq!(document_metadata.branched_from_version_id.unwrap(), 1);
-
- Ok(())
- }
-}
diff --git a/rust/cloud-storage/macro_db_client/src/document/v2/create.rs b/rust/cloud-storage/macro_db_client/src/document/v2/create.rs
index 1a1016cc15..dba13421d1 100644
--- a/rust/cloud-storage/macro_db_client/src/document/v2/create.rs
+++ b/rust/cloud-storage/macro_db_client/src/document/v2/create.rs
@@ -7,6 +7,7 @@ use model::document::DocumentMetadata;
use model::document::FileType;
use model::document::ID;
use model::document::VersionIDWithTimeStamps;
+use model_entity::EntityType;
use models_permissions::share_permission::SharePermissionV2;
use models_permissions::share_permission::access_level::AccessLevel;
use sqlx::Pool;
@@ -37,6 +38,7 @@ pub struct CreateDocumentArgs<'a> {
}
/// Creates a new document
+/// NOTE: this is only used in seed_cli at the moment and needs to be deprecated
#[instrument(skip(db))]
pub async fn create_document(
db: &Pool<Postgres>,
@@ -208,13 +210,13 @@ pub async fn create_document_txn(
.await?;
}
- crate::item_access::insert::insert_user_item_access(
+ entity_access_db_utils::insert_entity_access_row(
transaction,
- user_id.copied(),
- &document_id,
- "document",
+ &macro_uuid::string_to_uuid(&document_id).unwrap(),
+ EntityType::Document,
+ user_id.as_ref(),
+ entity_access_db_utils::EntityAccessSourceType::User,
AccessLevel::Owner,
- None,
)
.await?;
diff --git a/rust/cloud-storage/macro_db_client/src/document/v2/edit.rs b/rust/cloud-storage/macro_db_client/src/document/v2/edit.rs
deleted file mode 100644
index 5e3df086b6..0000000000
--- a/rust/cloud-storage/macro_db_client/src/document/v2/edit.rs
+++ /dev/null
@@ -1,184 +0,0 @@
-use models_permissions::share_permission::UpdateSharePermissionRequestV2;
-
-use crate::share_permission;
-
-#[tracing::instrument(skip(transaction))]
-/// `file_type`: None = no change, Some(None) = set to NULL, Some(Some(ft)) = set to ft.
-pub async fn edit_document(
- transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
- document_id: &str,
- document_name: Option<&str>,
- project_id: Option<&str>,
- file_type: Option<Option<&str>>,
- share_permission: Option<&UpdateSharePermissionRequestV2>,
-) -> anyhow::Result<()> {
- let mut query = "UPDATE \"Document\" SET ".to_string();
- let mut parameters: Vec<Option<&str>> = Vec::new();
- let mut set_parts = Vec::new();
-
- if let Some(name) = document_name {
- set_parts.push("\"name\" = $".to_string() + &(parameters.len() + 2).to_string());
- parameters.push(Some(name));
- }
-
- if let Some(project_id) = project_id {
- set_parts.push("\"projectId\" = $".to_string() + &(parameters.len() + 2).to_string());
- if project_id.is_empty() {
- parameters.push(None);
- } else {
- parameters.push(Some(project_id));
- }
- }
-
- if let Some(ft_update) = file_type {
- set_parts.push("\"fileType\" = $".to_string() + &(parameters.len() + 2).to_string());
- parameters.push(ft_update);
- }
-
- query += &set_parts.join(", ");
-
- if !set_parts.is_empty() {
- query += ", ";
- }
-
- query += "\"updatedAt\" = NOW() WHERE id = $1";
-
- let mut query = sqlx::query(&query);
- query = query.bind(document_id);
-
- for param in parameters {
- query = query.bind(param);
- }
-
- query.execute(transaction.as_mut()).await?;
-
- if let Some(share_permission) = share_permission {
- tracing::trace!("editing share permissions for document");
-
- share_permission::edit::edit_document_permission(
- transaction,
- document_id,
- share_permission,
- )
- .await?;
- }
-
- Ok(())
-}
-
-#[cfg(test)]
-mod tests {
- use models_permissions::share_permission::UpdateSharePermissionRequestV2;
-
- use crate::document::get_document;
-
- use super::*;
- use models_permissions::share_permission::access_level::AccessLevel;
- use sqlx::{Pool, Postgres};
-
- #[sqlx::test(fixtures(path = "../../../fixtures", scripts("basic_user_with_documents")))]
- async fn test_edit_document(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let mut transaction = pool.begin().await?;
-
- edit_document(
- &mut transaction,
- "document-one",
- Some("new-name"),
- Some("new-project"),
- None,
- Some(&UpdateSharePermissionRequestV2 {
- is_public: Some(true),
- public_access_level: Some(AccessLevel::Edit),
- channel_share_permissions: None,
- }),
- )
- .await?;
-
- transaction.commit().await?;
-
- let mut transaction = pool.begin().await?;
- let document_metadata = get_document(&pool, "document-one").await?;
-
- assert!(!document_metadata.document_id.is_empty());
- assert!(document_metadata.document_version_id > 0);
- assert_eq!(document_metadata.document_name, "new-name".to_string());
- assert_eq!(document_metadata.owner.as_ref(), "macro|[email protected]");
- assert_eq!(
- document_metadata.project_id,
- Some("new-project".to_string())
- );
- edit_document(&mut transaction, "document-one", None, None, None, None).await?;
- transaction.commit().await?;
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../../fixtures", scripts("basic_user_with_documents")))]
- async fn test_edit_document_set_file_type(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let mut transaction = pool.begin().await?;
-
- edit_document(
- &mut transaction,
- "document-one",
- None,
- None,
- Some(Some("rs")),
- None,
- )
- .await?;
-
- transaction.commit().await?;
-
- let document_metadata = get_document(&pool, "document-one").await?;
- assert_eq!(document_metadata.file_type, Some("rs".to_string()));
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../../fixtures", scripts("basic_user_with_documents")))]
- async fn test_edit_document_clear_file_type(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let mut transaction = pool.begin().await?;
-
- edit_document(
- &mut transaction,
- "document-one",
- None,
- None,
- Some(None),
- None,
- )
- .await?;
-
- transaction.commit().await?;
-
- let document_metadata = get_document(&pool, "document-one").await?;
- assert_eq!(document_metadata.file_type, None);
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(
- path = "../../../fixtures",
- scripts("basic_user_with_lots_of_documents")
- ))]
- async fn test_remove_document_from_project(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let document_metadata = get_document(&pool, "document-one").await?;
-
- assert!(!document_metadata.document_id.is_empty());
- assert_eq!(
- document_metadata.project_id,
- Some("project-one".to_string())
- );
-
- let mut transaction = pool.begin().await?;
- edit_document(&mut transaction, "document-one", None, Some(""), None, None).await?;
- transaction.commit().await?;
-
- let document_metadata = get_document(&pool, "document-one").await?;
-
- assert!(!document_metadata.document_id.is_empty());
- assert_eq!(document_metadata.project_id, None);
-
- Ok(())
- }
-}
diff --git a/rust/cloud-storage/macro_db_client/src/document/v2/mod.rs b/rust/cloud-storage/macro_db_client/src/document/v2/mod.rs
index bf46a6aab8..c5fb369c1d 100644
--- a/rust/cloud-storage/macro_db_client/src/document/v2/mod.rs
+++ b/rust/cloud-storage/macro_db_client/src/document/v2/mod.rs
@@ -1,3 +1 @@
-pub mod copy;
pub mod create;
-pub mod edit;
diff --git a/rust/cloud-storage/macro_db_client/src/item_access/delete.rs b/rust/cloud-storage/macro_db_client/src/item_access/delete.rs
index c16ab2fcde..39d1e72bf1 100644
--- a/rust/cloud-storage/macro_db_client/src/item_access/delete.rs
+++ b/rust/cloud-storage/macro_db_client/src/item_access/delete.rs
@@ -1,541 +1,71 @@
-use anyhow::Context;
-use macro_user_id::user_id::MacroUserIdStr;
+use model_entity::EntityType;
use sqlx::{Postgres, Transaction};
/// Deletes all user access records for a specific item
#[tracing::instrument(skip(transaction))]
-pub async fn delete_user_item_access_by_item(
+pub async fn delete_user_entity_access_by_item(
transaction: &mut Transaction<'_, Postgres>,
- item_id: &str,
- item_type: &str,
+ entity_id: &uuid::Uuid,
+ entity_type: EntityType,
) -> anyhow::Result<u64> {
let result = sqlx::query!(
r#"
- DELETE FROM "UserItemAccess"
- WHERE "item_id" = $1 AND "item_type" = $2
+ DELETE FROM "entity_access"
+ WHERE "entity_id" = $1 AND "entity_type" = $2
"#,
- item_id,
- item_type,
+ entity_id,
+ entity_type.as_ref(),
)
.execute(transaction.as_mut())
- .await
- .with_context(|| format!("Failed to delete access for item ID {}", item_id))?;
+ .await?;
Ok(result.rows_affected())
}
#[tracing::instrument(skip(transaction))]
-pub async fn delete_user_item_access_bulk(
+pub async fn delete_user_entity_access_bulk(
transaction: &mut Transaction<'_, Postgres>,
- item_ids: &[String],
- item_type: &str,
+ entity_ids: &[uuid::Uuid],
+ entity_type: EntityType,
) -> anyhow::Result<u64> {
- if item_ids.is_empty() {
+ if entity_ids.is_empty() {
return Ok(0);
}
- let result = sqlx::query!(
- r#"
- DELETE FROM "UserItemAccess"
- WHERE "item_id" = ANY($1) AND "item_type" = $2
- "#,
- item_ids,
- item_type,
- )
- .execute(transaction.as_mut())
- .await
- .with_context(|| {
- format!(
- "Failed to delete access for multiple items of type {}",
- item_type
- )
- })?;
-
- Ok(result.rows_affected())
-}
-
-/// Deletes a specific user's access to an item
-#[tracing::instrument(skip(transaction))]
-pub async fn delete_user_item_access(
- transaction: &mut Transaction<'_, Postgres>,
- user_id: &str,
- item_id: &str,
- item_type: &str,
-) -> anyhow::Result<u64> {
- let result = sqlx::query!(
- r#"
- DELETE FROM "UserItemAccess"
- WHERE "user_id" = $1 AND "item_id" = $2 AND "item_type" = $3
- "#,
- user_id,
- item_id,
- item_type,
- )
- .execute(transaction.as_mut())
- .await
- .with_context(|| {
- format!(
- "Failed to delete access for user {} to item {}",
- user_id, item_id
- )
- })?;
-
- Ok(result.rows_affected())
-}
-
-#[tracing::instrument(skip_all)]
-pub async fn delete_user_item_access_by_users_and_channel(
- executor: impl sqlx::Executor<'_, Database = Postgres>,
- user_ids: &[MacroUserIdStr<'_>],
- item_id: &str,
- item_type: &str,
- granted_from_channel_id: uuid::Uuid,
-) -> anyhow::Result<u64> {
- if user_ids.is_empty() {
- return Ok(0);
- }
-
- let macro_ids: Vec<String> = user_ids.iter().map(|s| s.to_string()).collect();
-
- let result = sqlx::query!(
- r#"
- DELETE FROM "UserItemAccess"
- WHERE "user_id" = ANY($1)
- AND "item_id" = $2
- AND "item_type" = $3
- AND "granted_from_channel_id" = $4
- "#,
- macro_ids.as_slice(),
- item_id,
- item_type,
- granted_from_channel_id,
- )
- .execute(executor)
- .await
- .with_context(|| {
- format!(
- "Failed to delete access for users to item {} from channel {}",
- item_id, granted_from_channel_id
- )
- })?;
-
- Ok(result.rows_affected())
-}
-
-#[tracing::instrument(skip(transaction))]
-pub async fn delete_user_item_access_by_channel(
- transaction: &mut Transaction<'_, Postgres>,
- granted_from_channel_id: uuid::Uuid,
-) -> anyhow::Result<u64> {
- let result = sqlx::query!(
- r#"
- DELETE FROM "UserItemAccess"
- WHERE "granted_from_channel_id" = $1
- "#,
- granted_from_channel_id,
- )
- .execute(transaction.as_mut())
- .await
- .with_context(|| {
- format!(
- "Failed to delete access records from channel {}",
- granted_from_channel_id
- )
- })?;
-
- Ok(result.rows_affected())
-}
-
-/// Deletes all UserItemAccess records for specific users from a specific channel
-/// This is useful when users are removed from a channel and need to lose access to channel-shared items
-#[tracing::instrument(skip(db))]
-pub async fn delete_user_item_access_by_channel_and_users(
- db: &sqlx::Pool<sqlx::Postgres>,
- channel_id: uuid::Uuid,
- user_ids: &[String],
-) -> anyhow::Result<u64> {
- if user_ids.is_empty() {
- return Ok(0);
- }
-
- let result = sqlx::query!(
- r#"
- DELETE FROM "UserItemAccess"
- WHERE "granted_from_channel_id" = $1 AND "user_id" = ANY($2)
- "#,
- channel_id,
- user_ids,
- )
- .execute(db)
- .await
- .with_context(|| {
- format!(
- "Failed to delete access records for users from channel {}",
- channel_id
- )
- })?;
-
- Ok(result.rows_affected())
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
- use sqlx::{Pool, Postgres};
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("user_item_access.sql")))]
- async fn test_delete_user_item_access(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let user_id = "macro|[email protected]";
- let item_id = "test-item";
- let item_type = "document";
-
- let mut transaction = pool.begin().await?;
-
- // Delete the record
- let affected =
- delete_user_item_access(&mut transaction, user_id, item_id, item_type).await?;
-
- assert_eq!(affected, 1, "Should have deleted exactly one record");
-
- // Verify it's gone
- let result = sqlx::query!(
- r#"
- SELECT COUNT(*) as count
- FROM "UserItemAccess"
- WHERE "user_id" = $1 AND "item_id" = $2 AND "item_type" = $3
- "#,
- user_id,
- item_id,
- item_type
- )
- .fetch_one(&mut *transaction)
- .await?;
-
- assert_eq!(result.count.unwrap(), 0);
-
- transaction.commit().await?;
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("user_item_access.sql")))]
- async fn test_delete_user_item_access_by_item(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let item_id = "multi-access-item";
- let item_type = "document";
-
- let mut transaction = pool.begin().await?;
-
- // Delete all records for the item
- let affected =
- delete_user_item_access_by_item(&mut transaction, item_id, item_type).await?;
-
- assert_eq!(affected, 3, "Should have deleted all three records");
-
- // Verify they're all gone
- let result = sqlx::query!(
- r#"
- SELECT COUNT(*) as count
- FROM "UserItemAccess"
- WHERE "item_id" = $1 AND "item_type" = $2
- "#,
- item_id,
- item_type
- )
- .fetch_one(&mut *transaction)
- .await?;
-
- assert_eq!(result.count.unwrap(), 0);
-
- transaction.commit().await?;
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("user_item_access.sql")))]
- async fn test_delete_user_item_access_bulk(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let item_type = "document";
- let item_ids = vec![
- "bulk-test-item-1".to_string(),
- "bulk-test-item-2".to_string(),
- "bulk-test-item-3".to_string(),
- ];
-
- let mut transaction = pool.begin().await?;
-
- // Delete all records for the items
- let affected = delete_user_item_access_bulk(&mut transaction, &item_ids, item_type).await?;
-
- assert_eq!(
- affected, 6,
- "Should have deleted all six records (2 users × 3 items)"
- );
-
- // Verify they're all gone
- let result = sqlx::query!(
- r#"
- SELECT COUNT(*) as count
- FROM "UserItemAccess"
- WHERE "item_id" = ANY($1) AND "item_type" = $2
- "#,
- &item_ids,
- item_type
- )
- .fetch_one(&mut *transaction)
- .await?;
-
- assert_eq!(result.count.unwrap(), 0);
-
- transaction.commit().await?;
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("user_item_access.sql")))]
- async fn test_delete_user_item_access_bulk_empty(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let mut transaction = pool.begin().await?;
-
- // Test with empty array
- let affected = delete_user_item_access_bulk(&mut transaction, &[], "document").await?;
-
- assert_eq!(affected, 0, "Should return 0 for empty array");
-
- transaction.commit().await?;
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("user_item_access.sql")))]
- async fn test_delete_user_item_access_by_users_and_channel(
- pool: Pool<Postgres>,
- ) -> anyhow::Result<()> {
- let item_id = "channel-shared-item";
- let item_type = "document";
- let channel_id = uuid::Uuid::parse_str("00000000-0000-0000-0000-000000000001")?;
- let user_ids = vec![
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- ];
-
- // First ensure test data exists
- for user_id in &user_ids {
- sqlx::query!(
- r#"
- INSERT INTO "UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level", "granted_from_channel_id")
- VALUES ($1, $2, $3, $4, 'view', $5)
- ON CONFLICT DO NOTHING
- "#,
- uuid::Uuid::now_v7(),
- user_id.as_ref(),
- item_id,
- item_type,
- channel_id,
- )
- .execute(&pool)
- .await?;
+ let result = match entity_type {
+ EntityType::User | EntityType::Team | EntityType::Channel => {
+ anyhow::bail!("invalid entity type")
}
-
- // Delete the records
- let affected = delete_user_item_access_by_users_and_channel(
- &pool, &user_ids, item_id, item_type, channel_id,
- )
- .await?;
-
- assert_eq!(affected, 2, "Should have deleted exactly two records");
-
- let ids: Vec<_> = user_ids.iter().map(|x| x.to_string()).collect();
-
- // Verify they're gone
- let result = sqlx::query!(
- r#"
- SELECT COUNT(*) as count
- FROM "UserItemAccess"
- WHERE "user_id" = ANY($1) AND "item_id" = $2 AND "item_type" = $3 AND "granted_from_channel_id" = $4
- "#,
- &ids,
- item_id,
- item_type,
- channel_id
- )
- .fetch_one(&pool)
- .await?;
-
- assert_eq!(result.count.unwrap(), 0);
-
- Ok(())
- }
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("user_item_access.sql")))]
- async fn test_delete_user_item_access_by_channel(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let channel_id = uuid::Uuid::parse_str("00000000-0000-0000-0000-000000000001")?;
-
- // First ensure test data exists
- let test_users = vec!["user1", "user2", "user3"];
- let test_items = vec!["item1", "item2"];
-
- for user_id in &test_users {
- for item_id in &test_items {
- sqlx::query!(
+ EntityType::Project => {
+ sqlx::query!(
r#"
- INSERT INTO "UserItemAccess" ("id", "user_id", "item_id", "item_type", "access_level", "granted_from_channel_id")
- VALUES ($1, $2, $3, $4, 'view', $5)
- ON CONFLICT DO NOTHING
- "#,
- uuid::Uuid::now_v7(),
- user_id,
- item_id,
- "document",
- channel_id,
+ DELETE FROM "entity_access"
+ WHERE (entity_id = ANY($1) AND entity_type = $2)
+ OR granted_from_project_id = ANY($3)
+ "#,
+ entity_ids,
+ entity_type.as_ref(),
+ &entity_ids
+ .iter()
+ .map(|p| p.to_string())
+ .collect::<Vec<String>>()
)
- .execute(&pool)
- .await?;
- }
+ .execute(transaction.as_mut())
+ .await?
}
-
- // Count how many records we expect to delete
- let count_before = sqlx::query!(
- r#"
- SELECT COUNT(*) as count
- FROM "UserItemAccess"
- WHERE "granted_from_channel_id" = $1
- "#,
- channel_id
- )
- .fetch_one(&pool)
- .await?
- .count
- .unwrap_or(0);
-
- assert!(count_before > 0, "Test data should exist before deletion");
-
- let mut transaction = pool.begin().await?;
-
- // Delete all records for the channel
- let affected = delete_user_item_access_by_channel(&mut transaction, channel_id).await?;
-
- assert_eq!(
- affected, count_before as u64,
- "Should have deleted all records from the channel"
- );
-
- // Verify they're all gone
- let result = sqlx::query!(
- r#"
- SELECT COUNT(*) as count
- FROM "UserItemAccess"
- WHERE "granted_from_channel_id" = $1
+ EntityType::Chat | EntityType::Document | EntityType::EmailThread | EntityType::Call => {
+ sqlx::query!(
+ r#"
+ DELETE FROM "entity_access"
+ WHERE entity_id = ANY($1) AND entity_type = $2
"#,
- channel_id
- )
- .fetch_one(&mut *transaction)
- .await?;
-
- assert_eq!(
- result.count.unwrap(),
- 0,
- "No records should remain for this channel"
- );
-
- transaction.commit().await?;
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("user_item_access.sql")))]
- async fn test_delete_user_item_access_by_channel_and_users(
- pool: Pool<Postgres>,
- ) -> anyhow::Result<()> {
- let channel_id = uuid::Uuid::parse_str("00000000-0000-0000-0000-000000000001")?;
- let user_ids = vec!["user1".to_string(), "user2".to_string()];
-
- // First ensure we have test data
- // Count how many records we expect to delete
- let count_before = sqlx::query!(
- r#"
- SELECT COUNT(*) as count
- FROM "UserItemAccess"
- WHERE "granted_from_channel_id" = $1 AND "user_id" = ANY($2)
- "#,
- channel_id,
- &user_ids
- )
- .fetch_one(&pool)
- .await?
- .count
- .unwrap_or(0);
-
- // If we don't have test data, we need to skip the test
- if count_before == 0 {
- println!("Test data for channel and users doesn't exist, skipping test");
- return Ok(());
+ entity_ids,
+ entity_type.as_ref(),
+ )
+ .execute(transaction.as_mut())
+ .await?
}
+ };
- // Delete the records
- let affected =
- delete_user_item_access_by_channel_and_users(&pool, channel_id, &user_ids).await?;
-
- assert_eq!(
- affected, count_before as u64,
- "Should have deleted the correct number of records"
- );
-
- // Verify the targeted records are gone
- let result = sqlx::query!(
- r#"
- SELECT COUNT(*) as count
- FROM "UserItemAccess"
- WHERE "granted_from_channel_id" = $1 AND "user_id" = ANY($2)
- "#,
- channel_id,
- &user_ids
- )
- .fetch_one(&pool)
- .await?;
-
- assert_eq!(
- result.count.unwrap(),
- 0,
- "No records should remain for these users in this channel"
- );
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("user_item_access.sql")))]
- async fn test_delete_user_item_access_by_channel_and_users_empty_users(
- pool: Pool<Postgres>,
- ) -> anyhow::Result<()> {
- let channel_id = uuid::Uuid::parse_str("00000000-0000-0000-0000-000000000001")?;
- let empty_user_ids: Vec<String> = vec![];
-
- // Test with empty users array
- let affected =
- delete_user_item_access_by_channel_and_users(&pool, channel_id, &empty_user_ids)
- .await?;
-
- assert_eq!(affected, 0, "Should return 0 for empty users array");
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("user_item_access.sql")))]
- async fn test_delete_user_item_access_by_channel_and_users_nonexistent(
- pool: Pool<Postgres>,
- ) -> anyhow::Result<()> {
- // Test with non-existent channel and users
- let non_existent_channel = uuid::Uuid::parse_str("99999999-9999-9999-9999-999999999999")?;
- let non_existent_users = vec!["nonexistent1".to_string(), "nonexistent2".to_string()];
-
- let affected = delete_user_item_access_by_channel_and_users(
- &pool,
- non_existent_channel,
- &non_existent_users,
- )
- .await?;
-
- assert_eq!(
- affected, 0,
- "Should return 0 for non-existent channel and users"
- );
-
- Ok(())
- }
+ Ok(result.rows_affected())
}
diff --git a/rust/cloud-storage/macro_db_client/src/item_access/get.rs b/rust/cloud-storage/macro_db_client/src/item_access/get.rs
index 2c483d2da4..cf2e9ab946 100644
--- a/rust/cloud-storage/macro_db_client/src/item_access/get.rs
+++ b/rust/cloud-storage/macro_db_client/src/item_access/get.rs
@@ -1,6 +1,22 @@
use chrono::{DateTime, Utc};
use models_permissions::share_permission::access_level::AccessLevel;
-use models_permissions::user_item_access::UserItemAccess;
+
+/// A record from entity_access representing a user's access to an entity.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct EntityAccessRecord {
+ /// The entity ID (as a string, cast from UUID)
+ pub entity_id: String,
+ /// The entity type (e.g., "document", "project", "chat", "thread")
+ pub entity_type: String,
+ /// The source ID (user_id, team_id, or channel_id)
+ pub source_id: String,
+ /// The level of access granted
+ pub access_level: AccessLevel,
+ /// When this access record was created
+ pub created_at: DateTime<Utc>,
+ /// When this access record was last updated
+ pub updated_at: DateTime<Utc>,
+}
/// Gets the items owner and whether it's deleted
#[tracing::instrument(skip(db), err)]
@@ -40,680 +56,3 @@ pub async fn get_owner_and_deleted(
Ok(result)
}
-
-/// Finds all explicit access permissions for a given user on a project and its entire parent hierarchy.
-#[tracing::instrument(skip(db))]
-pub async fn get_user_item_access_for_project(
- db: &sqlx::Pool<sqlx::Postgres>,
- project_id: &str,
- user_id: &str,
-) -> anyhow::Result<Vec<UserItemAccess>> {
- let access_records = sqlx::query_as!(
- UserItemAccess,
- r#"
- -- recursively finds all parent projects for the given project.
- WITH RECURSIVE project_hierarchy AS (
- -- Base case: Start with the provided project itself.
- SELECT
- p.id as project_id
- FROM
- "Project" p
- WHERE
- p.id = $1 AND p."deletedAt" IS NULL
-
- UNION ALL
-
- -- Recursive case: Find the parent of the project from the previous step.
- SELECT
- parent.id as project_id
- FROM
- project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
- )
- )
- -- The main query to select from UserItemAccess
- SELECT
- id,
- user_id,
- item_id,
- item_type,
- granted_from_channel_id,
- access_level as "access_level!: AccessLevel",
- created_at as "created_at!: DateTime<Utc>",
- updated_at as "updated_at!: DateTime<Utc>"
- FROM "UserItemAccess"
- WHERE
- -- Filter for the specific user we are interested in.
- user_id = $2
- -- Filter for items that are either the project itself or one of the projects in its hierarchy.
- AND item_id IN (
- SELECT project_id FROM project_hierarchy
- )
- "#,
- project_id,
- user_id,
- )
- .fetch_all(db)
- .await?;
-
- Ok(access_records)
-}
-
-#[tracing::instrument(skip(db))]
-pub async fn get_user_item_access_for_document(
- db: &sqlx::Pool<sqlx::Postgres>,
- document_id: &str,
- user_id: &str,
-) -> anyhow::Result<Vec<UserItemAccess>> {
- let access_records = sqlx::query_as!(
- UserItemAccess,
- r#"
- -- recursively finds all parent projects for the given document.
- WITH RECURSIVE project_hierarchy AS (
- -- Base case: Start with the project directly associated with the document.
- SELECT
- p.id as project_id
- FROM
- "Document" d
- JOIN "Project" p ON d."projectId" = p.id AND p."deletedAt" IS NULL
- WHERE
- d.id = $1 AND d."deletedAt" IS NULL
-
- UNION ALL
-
- -- Recursive case: Find the parent of the project from the previous step.
- SELECT
- parent.id as project_id
- FROM
- project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
- )
- )
- -- The main query to select from UserItemAccess
- SELECT
- id,
- user_id,
- item_id,
- item_type,
- granted_from_channel_id,
- -- The `access_level` column is mapped directly to the `AccessLevel` Rust enum
- -- thanks to `#[derive(sqlx::Type)]`.
- access_level as "access_level!: AccessLevel",
- created_at as "created_at!: DateTime<Utc>",
- updated_at as "updated_at!: DateTime<Utc>"
- FROM "UserItemAccess"
- WHERE
- -- Filter for the specific user we are interested in.
- user_id = $2
- AND item_id IN (
- -- The document ID itself
- SELECT $1
- UNION
- -- All project IDs from the recursive CTE
- SELECT project_id FROM project_hierarchy
- )
- "#,
- document_id,
- user_id,
- )
- .fetch_all(db)
- .await?;
-
- Ok(access_records)
-}
-
-/// Finds all explicit access permissions for a given user on a chat and its entire project hierarchy.
-#[tracing::instrument(skip(db))]
-pub async fn get_user_item_access_for_chat(
- db: &sqlx::Pool<sqlx::Postgres>,
- chat_id: &str,
- user_id: &str,
-) -> anyhow::Result<Vec<UserItemAccess>> {
- let access_records = sqlx::query_as!(
- UserItemAccess,
- r#"
- -- recursively finds all parent projects for the given chat.
- WITH RECURSIVE project_hierarchy AS (
- -- Base case: Start with the project directly associated with the chat.
- SELECT
- p.id as project_id
- FROM
- "Chat" c
- JOIN "Project" p ON c."projectId" = p.id AND p."deletedAt" IS NULL
- WHERE
- c.id = $1 AND c."deletedAt" IS NULL
-
- UNION ALL
-
- -- Recursive case: Find the parent of the project from the previous step.
- SELECT
- parent.id as project_id
- FROM
- project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
- )
- )
- -- The main query to select from UserItemAccess
- SELECT
- id,
- user_id,
- item_id,
- item_type,
- granted_from_channel_id,
- access_level as "access_level!: AccessLevel",
- created_at as "created_at!: DateTime<Utc>",
- updated_at as "updated_at!: DateTime<Utc>"
- FROM "UserItemAccess"
- WHERE
- -- Filter for the specific user we are interested in.
- user_id = $2
- AND item_id IN (
- -- The chat ID itself
- SELECT $1
- UNION
- -- All project IDs from the recursive CTE
- SELECT project_id FROM project_hierarchy
- )
- "#,
- chat_id,
- user_id,
- )
- .fetch_all(db)
- .await?;
-
- Ok(access_records)
-}
-
-/// Finds all explicit access permissions for a given user on an email thread and its entire project hierarchy.
-#[tracing::instrument(skip(db))]
-pub async fn get_user_item_access_for_thread(
- db: &sqlx::Pool<sqlx::Postgres>,
- thread_id: &str,
- user_id: &str,
-) -> anyhow::Result<Vec<UserItemAccess>> {
- let access_records = sqlx::query_as!(
- UserItemAccess,
- r#"
- -- recursively finds all parent projects for the given email thread.
- WITH RECURSIVE project_hierarchy AS (
- -- Base case: Start with the project directly associated with the thread.
- SELECT
- p.id as project_id
- FROM
- "EmailThreadPermission" etp
- JOIN "Project" p ON etp."projectId" = p.id AND p."deletedAt" IS NULL
- WHERE
- etp."threadId" = $1
-
- UNION ALL
-
- -- Recursive case: Find the parent of the project from the previous step.
- SELECT
- parent.id as project_id
- FROM
- project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
- )
- )
- -- The main query to select from UserItemAccess
- SELECT
- id,
- user_id,
- item_id,
- item_type,
- granted_from_channel_id,
- access_level as "access_level!: AccessLevel",
- created_at as "created_at!: DateTime<Utc>",
- updated_at as "updated_at!: DateTime<Utc>"
- FROM "UserItemAccess"
- WHERE
- -- Filter for the specific user we are interested in.
- user_id = $2
- AND item_id IN (
- -- The thread ID itself
- SELECT $1
- UNION
- -- All project IDs from the recursive CTE
- SELECT project_id FROM project_hierarchy
- )
- "#,
- thread_id,
- user_id,
- )
- .fetch_all(db)
- .await?;
-
- Ok(access_records)
-}
-
-#[cfg(test)]
-mod tests {
- use crate::item_access::get::{
- get_user_item_access_for_chat, get_user_item_access_for_document,
- get_user_item_access_for_project, get_user_item_access_for_thread,
- };
- use models_permissions::share_permission::access_level::AccessLevel;
- use models_permissions::user_item_access::UserItemAccess;
- use std::collections::HashSet;
- use uuid::Uuid;
-
- // Helper function to make test assertions cleaner
- fn to_item_id_set(records: &[UserItemAccess]) -> HashSet<String> {
- records.iter().map(|r| r.item_id.clone()).collect()
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("uia_access_level_doc")))]
- async fn test_get_access_for_nested_document(
- pool: sqlx::Pool<sqlx::Postgres>,
- ) -> anyhow::Result<()> {
- // SCENARIO: Get all permissions for 'user-1' on the deeply nested document 'd-child'.
- // EXPECTATION: Should return 3 records:
- // 1. Direct access on 'd-child'.
- // 2. Inherited access from 'p-parent'.
- // 3. Inherited access from 'p-grandparent'.
-
- let permissions = get_user_item_access_for_document(&pool, "d-child", "user-1").await?;
-
- assert_eq!(
- permissions.len(),
- 3,
- "Expected to find 3 access records (direct + 2 inherited)"
- );
-
- let expected_item_ids: HashSet<String> = [
- "d-child".to_string(),
- "p-parent".to_string(),
- "p-grandparent".to_string(),
- ]
- .into_iter()
- .collect();
-
- assert_eq!(to_item_id_set(&permissions), expected_item_ids);
-
- // Verify the details of each permission
- for p in permissions {
- match p.item_id.as_str() {
- "d-child" => assert_eq!(p.access_level, AccessLevel::View),
- "p-parent" => assert_eq!(p.access_level, AccessLevel::Edit),
- "p-grandparent" => assert_eq!(p.access_level, AccessLevel::Owner),
- _ => panic!("Unexpected item_id found in results"),
- }
- }
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("uia_access_level_doc")))]
- async fn test_get_access_for_standalone_document(
- pool: sqlx::Pool<sqlx::Postgres>,
- ) -> anyhow::Result<()> {
- // SCENARIO: Get permissions for 'user-1' on 'd-standalone', which has no project parent.
- // EXPECTATION: Should return exactly 1 record for the direct permission.
-
- let permissions =
- get_user_item_access_for_document(&pool, "d-standalone", "user-1").await?;
-
- assert_eq!(
- permissions.len(),
- 1,
- "Expected only one direct access record"
- );
- let perm = &permissions[0];
- assert_eq!(perm.item_id, "d-standalone");
- assert_eq!(perm.access_level, AccessLevel::Comment);
- assert_eq!(
- perm.granted_from_channel_id,
- Some(Uuid::parse_str("20000000-0000-0000-0000-00000000000c")?)
- );
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("uia_access_level_doc")))]
- async fn test_access_is_correctly_scoped_to_user(
- pool: sqlx::Pool<sqlx::Postgres>,
- ) -> anyhow::Result<()> {
- // SCENARIO: Get permissions for 'user-2' on 'd-child'.
- // EXPECTATION: Should return only the single permission granted to 'user-2', and none of user-1's permissions.
-
- let permissions = get_user_item_access_for_document(&pool, "d-child", "user-2").await?;
-
- assert_eq!(
- permissions.len(),
- 1,
- "Expected only the access record for user-2"
- );
- let perm = &permissions[0];
- assert_eq!(perm.user_id, "user-2");
- assert_eq!(perm.item_id, "d-child");
- assert_eq!(perm.access_level, AccessLevel::View);
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("uia_access_level_doc")))]
- async fn test_no_access_returns_empty(pool: sqlx::Pool<sqlx::Postgres>) -> anyhow::Result<()> {
- // SCENARIO: Query for a user who has no access at all to the item or its hierarchy.
- // We'll use 'user-2' and ask for 'd-standalone', which only 'user-1' has access to.
- // EXPECTATION: Should return an empty vector.
-
- let permissions =
- get_user_item_access_for_document(&pool, "d-standalone", "user-2").await?;
- assert!(
- permissions.is_empty(),
- "Expected no permissions to be returned"
- );
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("uia_access_level_chat")))]
- async fn test_get_access_for_nested_chat(
- pool: sqlx::Pool<sqlx::Postgres>,
- ) -> anyhow::Result<()> {
- // SCENARIO: Get all permissions for 'user-1' on the nested chat 'chat-child'.
- // EXPECTATION: Should return 3 records:
- // 1. Direct access on 'chat-child'.
- // 2. Inherited access from 'p-parent'.
- // 3. Inherited access from 'p-grandparent'.
-
- let permissions = get_user_item_access_for_chat(&pool, "chat-child", "user-1").await?;
-
- assert_eq!(
- permissions.len(),
- 3,
- "Expected 3 access records (direct + 2 inherited)"
- );
-
- let expected_item_ids: HashSet<String> = [
- "chat-child".to_string(),
- "p-parent".to_string(),
- "p-grandparent".to_string(),
- ]
- .into_iter()
- .collect();
-
- assert_eq!(to_item_id_set(&permissions), expected_item_ids);
-
- // Verify the details of each permission
- for p in permissions {
- match p.item_id.as_str() {
- "chat-child" => assert_eq!(p.access_level, AccessLevel::View),
- "p-parent" => assert_eq!(p.access_level, AccessLevel::Edit),
- "p-grandparent" => assert_eq!(p.access_level, AccessLevel::Owner),
- _ => panic!("Unexpected item_id found in results: {}", p.item_id),
- }
- }
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("uia_access_level_chat")))]
- async fn test_get_access_for_standalone_chat(
- pool: sqlx::Pool<sqlx::Postgres>,
- ) -> anyhow::Result<()> {
- // SCENARIO: Get permissions for 'user-1' on 'chat-standalone', which has no project parent.
- // EXPECTATION: Should return exactly 1 record for the direct permission.
-
- let permissions = get_user_item_access_for_chat(&pool, "chat-standalone", "user-1").await?;
-
- assert_eq!(
- permissions.len(),
- 1,
- "Expected only one direct access record"
- );
- let perm = &permissions[0];
- assert_eq!(perm.item_id, "chat-standalone");
- assert_eq!(perm.access_level, AccessLevel::Comment);
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("uia_access_level_chat")))]
- async fn test_chat_access_is_correctly_scoped_to_user(
- pool: sqlx::Pool<sqlx::Postgres>,
- ) -> anyhow::Result<()> {
- // SCENARIO: Get permissions for 'user-2' on 'chat-child'.
- // EXPECTATION: Should return only the single permission granted to 'user-2', not any of user-1's permissions.
-
- let permissions = get_user_item_access_for_chat(&pool, "chat-child", "user-2").await?;
-
- assert_eq!(
- permissions.len(),
- 1,
- "Expected only the access record for user-2"
- );
- let perm = &permissions[0];
- assert_eq!(perm.user_id, "user-2");
- assert_eq!(perm.item_id, "chat-child");
- assert_eq!(perm.access_level, AccessLevel::View);
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("uia_access_level_chat")))]
- async fn test_no_access_for_chat_returns_empty(
- pool: sqlx::Pool<sqlx::Postgres>,
- ) -> anyhow::Result<()> {
- // SCENARIO: Query for a user who has no access at all to the item or its hierarchy.
- // We'll use 'user-2' and ask for 'chat-standalone', which only 'user-1' has access to.
- // EXPECTATION: Should return an empty vector.
-
- let permissions = get_user_item_access_for_chat(&pool, "chat-standalone", "user-2").await?;
- assert!(
- permissions.is_empty(),
- "Expected no permissions to be returned"
- );
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("uia_access_level_project")))]
- async fn test_get_access_starting_from_child_project(
- pool: sqlx::Pool<sqlx::Postgres>,
- ) -> anyhow::Result<()> {
- // SCENARIO: Get all permissions for 'user-1' starting from the lowest project 'p-child'.
- // EXPECTATION: Should return 3 records, one for the child, parent, and grandparent project.
-
- let permissions = get_user_item_access_for_project(&pool, "p-child", "user-1").await?;
-
- assert_eq!(
- permissions.len(),
- 3,
- "Expected 3 access records (self + 2 ancestors)"
- );
-
- let expected_item_ids: HashSet<String> = [
- "p-child".to_string(),
- "p-parent".to_string(),
- "p-grandparent".to_string(),
- ]
- .into_iter()
- .collect();
-
- assert_eq!(to_item_id_set(&permissions), expected_item_ids);
-
- // Verify the details of each permission
- for p in permissions {
- match p.item_id.as_str() {
- "p-child" => assert_eq!(p.access_level, AccessLevel::View),
- "p-parent" => assert_eq!(p.access_level, AccessLevel::Edit),
- "p-grandparent" => assert_eq!(p.access_level, AccessLevel::Owner),
- _ => panic!("Unexpected item_id found in results: {}", p.item_id),
- }
- }
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("uia_access_level_project")))]
- async fn test_get_access_starting_from_parent_project(
- pool: sqlx::Pool<sqlx::Postgres>,
- ) -> anyhow::Result<()> {
- // SCENARIO: Get permissions for 'user-1' starting from the middle project 'p-parent'.
- // EXPECTATION: Should return 2 records: 'p-parent' and 'p-grandparent'. It should NOT include 'p-child'.
-
- let permissions = get_user_item_access_for_project(&pool, "p-parent", "user-1").await?;
-
- assert_eq!(
- permissions.len(),
- 2,
- "Expected 2 access records (self + 1 ancestor)"
- );
-
- let expected_item_ids: HashSet<String> =
- ["p-parent".to_string(), "p-grandparent".to_string()]
- .into_iter()
- .collect();
-
- assert_eq!(to_item_id_set(&permissions), expected_item_ids);
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("uia_access_level_project")))]
- async fn test_project_access_is_correctly_scoped_to_user(
- pool: sqlx::Pool<sqlx::Postgres>,
- ) -> anyhow::Result<()> {
- // SCENARIO: Get permissions for 'user-2' on 'p-parent'.
- // EXPECTATION: Should return only the single permission granted to 'user-2', not any of user-1's.
-
- let permissions = get_user_item_access_for_project(&pool, "p-parent", "user-2").await?;
-
- assert_eq!(
- permissions.len(),
- 1,
- "Expected only the access record for user-2"
- );
- let perm = &permissions[0];
- assert_eq!(perm.user_id, "user-2");
- assert_eq!(perm.item_id, "p-parent");
- assert_eq!(perm.access_level, AccessLevel::Comment);
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("uia_access_level_project")))]
- async fn test_no_access_for_project_returns_empty(
- pool: sqlx::Pool<sqlx::Postgres>,
- ) -> anyhow::Result<()> {
- // SCENARIO: Query for a user who has no access to a project or its hierarchy.
- // We'll use 'user-1' and ask for 'p-isolated', which only 'user-2' has access to.
- // EXPECTATION: Should return an empty vector.
-
- let permissions = get_user_item_access_for_project(&pool, "p-isolated", "user-1").await?;
- assert!(
- permissions.is_empty(),
- "Expected no permissions to be returned"
- );
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("uia_access_level_thread")))]
- async fn test_get_access_for_nested_thread(
- pool: sqlx::Pool<sqlx::Postgres>,
- ) -> anyhow::Result<()> {
- // SCENARIO: Get all permissions for 'user-1' on the nested thread 'thread-nested'.
- // EXPECTATION: Should return 3 records:
- // 1. Direct access on 'thread-nested'.
- // 2. Inherited access from 'p-parent'.
- // 3. Inherited access from 'p-grandparent'.
-
- let permissions = get_user_item_access_for_thread(&pool, "thread-nested", "user-1").await?;
-
- assert_eq!(
- permissions.len(),
- 3,
- "Expected 3 access records (direct + 2 inherited)"
- );
-
- let expected_item_ids: HashSet<String> = [
- "thread-nested".to_string(),
- "p-parent".to_string(),
- "p-grandparent".to_string(),
- ]
- .into_iter()
- .collect();
-
- assert_eq!(to_item_id_set(&permissions), expected_item_ids);
-
- // Verify the details of each permission
- for p in permissions {
- match p.item_id.as_str() {
- "thread-nested" => assert_eq!(p.access_level, AccessLevel::View),
- "p-parent" => assert_eq!(p.access_level, AccessLevel::Edit),
- "p-grandparent" => assert_eq!(p.access_level, AccessLevel::Owner),
- _ => panic!("Unexpected item_id found in results: {}", p.item_id),
- }
- }
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("uia_access_level_thread")))]
- async fn test_get_access_for_standalone_thread(
- pool: sqlx::Pool<sqlx::Postgres>,
- ) -> anyhow::Result<()> {
- // SCENARIO: Get permissions for 'user-1' on 'thread-standalone', which has no project parent.
- // EXPECTATION: Should return exactly 1 record for the direct permission.
-
- let permissions =
- get_user_item_access_for_thread(&pool, "thread-standalone", "user-1").await?;
-
- assert_eq!(
- permissions.len(),
- 1,
- "Expected only one direct access record"
- );
- let perm = &permissions[0];
- assert_eq!(perm.item_id, "thread-standalone");
- assert_eq!(perm.access_level, AccessLevel::Comment);
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("uia_access_level_thread")))]
- async fn test_thread_access_is_correctly_scoped_to_user(
- pool: sqlx::Pool<sqlx::Postgres>,
- ) -> anyhow::Result<()> {
- // SCENARIO: Get permissions for 'user-2' on 'thread-nested'.
- // EXPECTATION: Should return only the single permission granted to 'user-2', not any of user-1's permissions.
-
- let permissions = get_user_item_access_for_thread(&pool, "thread-nested", "user-2").await?;
-
- assert_eq!(
- permissions.len(),
- 1,
- "Expected only the access record for user-2"
- );
- let perm = &permissions[0];
- assert_eq!(perm.user_id, "user-2");
- assert_eq!(perm.item_id, "thread-nested");
- assert_eq!(perm.access_level, AccessLevel::View);
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("uia_access_level_thread")))]
- async fn test_no_access_for_thread_returns_empty(
- pool: sqlx::Pool<sqlx::Postgres>,
- ) -> anyhow::Result<()> {
- // SCENARIO: Query for a user who has no access at all to the item or its hierarchy.
- // We'll use 'user-2' and ask for 'thread-standalone', which only 'user-1' has access to.
- // EXPECTATION: Should return an empty vector.
-
- let permissions =
- get_user_item_access_for_thread(&pool, "thread-standalone", "user-2").await?;
- assert!(
- permissions.is_empty(),
- "Expected no permissions to be returned"
- );
-
- Ok(())
- }
-}
diff --git a/rust/cloud-storage/macro_db_client/src/item_access/get_accessible_items.rs b/rust/cloud-storage/macro_db_client/src/item_access/get_accessible_items.rs
index b08bf870f4..b70f23f42a 100644
--- a/rust/cloud-storage/macro_db_client/src/item_access/get_accessible_items.rs
+++ b/rust/cloud-storage/macro_db_client/src/item_access/get_accessible_items.rs
@@ -4,7 +4,8 @@ use cached::proc_macro::cached;
use model::item::UserAccessibleItem;
use sqlx::{Pool, Postgres};
-/// gets all accessible items for a user, traversing nested project structure
+/// Gets all accessible items for a user by querying entity_access with the user's source IDs
+/// (user ID, team memberships, and channel participations).
#[tracing::instrument(skip(db))]
#[cfg_attr(
not(test),
@@ -23,97 +24,40 @@ pub async fn get_user_accessible_items(
) -> anyhow::Result<Vec<UserAccessibleItem>> {
let results = sqlx::query!(
r#"
- WITH RECURSIVE ProjectHierarchy AS (
- -- Find direct user access to projects first as starting point
- SELECT
- p.id,
- uia.access_level
- FROM "Project" p
- JOIN "UserItemAccess" uia ON p.id = uia.item_id AND uia.item_type = 'project'
- WHERE uia.user_id = $1 AND p."deletedAt" IS NULL
- AND ($3 = false OR p."userId" != $1) -- Exclude owned projects if exclude_owned = true
-
+ WITH user_source_ids AS (
+ SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp
+ WHERE cp.user_id = $1 AND cp.left_at IS NULL
UNION ALL
-
- -- Then walk down the project tree and grab child projects, keeping parent's access
- SELECT
- p.id,
- ph.access_level
- FROM "Project" p
- JOIN ProjectHierarchy ph ON p."parentId" = ph.id
- WHERE p."deletedAt" IS NULL
- AND ($3 = false OR p."userId" != $1) -- Exclude owned projects if exclude_owned = true
- ),
- -- Now build up all the ways a user can have access to stuff
- AllAccessGrants AS (
- -- Explicit access to items via UserItemAccess table
- SELECT uia.item_id, uia.item_type, uia.access_level
- FROM "UserItemAccess" uia
- -- We join to each table to check its "deletedAt" status.
- -- This is more explicit and robust than using subqueries.
- LEFT JOIN "Document" d ON uia.item_type = 'document' AND uia.item_id = d.id
- LEFT JOIN "Chat" c ON uia.item_type = 'chat' AND uia.item_id = c.id
- LEFT JOIN "Project" p ON uia.item_type = 'project' AND uia.item_id = p.id
- WHERE uia.user_id = $1
- AND ($2::text IS NULL OR uia.item_type = $2)
- -- Rule: The item must not be deleted.
- AND (
- (uia.item_type = 'document' AND d."deletedAt" IS NULL) OR
- (uia.item_type = 'chat' AND c."deletedAt" IS NULL) OR
- (uia.item_type = 'project' AND p."deletedAt" IS NULL)
- )
- -- Rule: If exclude_owned is true, the user must not be the creator of the item.
- AND ($3 = false OR (
- (uia.item_type = 'document' AND d.owner != $1) OR
- (uia.item_type = 'chat' AND c."userId" != $1) OR
- (uia.item_type = 'project' AND p."userId" != $1)
- ))
-
- -- The rest of the unions are to get implicit access to items via project access
- UNION ALL
-
- -- Access to docs in visible projects
- SELECT
- d.id AS item_id,
- 'document' AS item_type,
- ph.access_level
- FROM "Document" d
- JOIN ProjectHierarchy ph ON d."projectId" = ph.id
- WHERE ($2::text IS NULL OR 'document' = $2)
- AND d."projectId" IS NOT NULL AND d."deletedAt" IS NULL
- AND ($3 = false OR d.owner != $1)
-
- UNION ALL
-
- -- Access to chats in visible projects
- SELECT
- c.id AS item_id,
- 'chat' AS item_type,
- ph.access_level
- FROM "Chat" c
- JOIN ProjectHierarchy ph ON c."projectId" = ph.id
- WHERE ($2::text IS NULL OR 'chat' = $2)
- AND c."projectId" IS NOT NULL AND c."deletedAt" IS NULL
- AND ($3 = false OR c."userId" != $1)
-
+ SELECT t.team_id::text FROM team_user t
+ WHERE t.user_id = $1
UNION ALL
-
- -- Include the projects we found earlier
- SELECT
- ph.id AS item_id,
- 'project' AS item_type,
- ph.access_level
- FROM ProjectHierarchy ph
- WHERE ($2::text IS NULL OR 'project' = $2)
+ SELECT $1
+ ),
+ -- Get all entities the user has access to via entity_access
+ UserAccessibleEntities AS (
+ SELECT DISTINCT
+ ea.entity_id,
+ ea.entity_type
+ FROM entity_access ea
+ WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)
+ AND ($2::text IS NULL OR ea.entity_type = $2)
),
- UserAccessibleItems AS (
- SELECT
- item_id,
- item_type
- FROM AllAccessGrants
- GROUP BY item_id, item_type
+ -- Filter out deleted items and optionally exclude owned
+ FilteredItems AS (
+ SELECT uae.entity_id::text as item_id, uae.entity_type as item_type
+ FROM UserAccessibleEntities uae
+ LEFT JOIN "Document" d ON uae.entity_type = 'document' AND uae.entity_id::text = d.id
+ LEFT JOIN "Chat" c ON uae.entity_type = 'chat' AND uae.entity_id::text = c.id
+ LEFT JOIN "Project" p ON uae.entity_type = 'project' AND uae.entity_id::text = p.id
+ WHERE
+ (uae.entity_type = 'document' AND d."deletedAt" IS NULL
+ AND ($3 = false OR d.owner != $1)) OR
+ (uae.entity_type = 'chat' AND c."deletedAt" IS NULL
+ AND ($3 = false OR c."userId" != $1)) OR
+ (uae.entity_type = 'project' AND p."deletedAt" IS NULL
+ AND ($3 = false OR p."userId" != $1))
)
- SELECT item_id as "item_id!", item_type as "item_type!" FROM UserAccessibleItems
+ SELECT item_id as "item_id!", item_type as "item_type!" FROM FilteredItems
"#,
user_id,
item_type_filter,
@@ -123,8 +67,8 @@ pub async fn get_user_accessible_items(
item_id: r.item_id,
item_type: r.item_type,
})
- .fetch_all(db)
- .await?;
+ .fetch_all(db)
+ .await?;
Ok(results)
}
@@ -144,12 +88,12 @@ mod tests {
let items = get_user_accessible_items(&pool, user_id, None, false).await?;
let item_ids: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
let expected_ids: HashSet<String> = [
- "project-owned",
- "chat-owned",
- "doc-owned",
- "project-shared",
- "chat-shared",
- "doc-shared",
+ "a0000000-0000-0000-0000-0000000e0001",
+ "a0000000-0000-0000-0000-0000000e0002",
+ "a0000000-0000-0000-0000-0000000e0003",
+ "a0000000-0000-0000-0000-0000000e0004",
+ "a0000000-0000-0000-0000-0000000e0005",
+ "a0000000-0000-0000-0000-0000000e0006",
]
.into_iter()
.map(String::from)
@@ -164,10 +108,14 @@ mod tests {
{
let items = get_user_accessible_items(&pool, user_id, None, true).await?;
let item_ids: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
- let expected_ids: HashSet<String> = ["project-shared", "chat-shared", "doc-shared"]
- .into_iter()
- .map(String::from)
- .collect();
+ let expected_ids: HashSet<String> = [
+ "a0000000-0000-0000-0000-0000000e0004",
+ "a0000000-0000-0000-0000-0000000e0005",
+ "a0000000-0000-0000-0000-0000000e0006",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
assert_eq!(
item_ids, expected_ids,
"Core function (exclude owned) failed"
@@ -180,10 +128,13 @@ mod tests {
get_user_accessible_items(&pool, user_id, Some("document".to_string()), false)
.await?;
let id_set: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
- let expected_ids: HashSet<String> = ["doc-owned", "doc-shared"]
- .into_iter()
- .map(String::from)
- .collect();
+ let expected_ids: HashSet<String> = [
+ "a0000000-0000-0000-0000-0000000e0003",
+ "a0000000-0000-0000-0000-0000000e0006",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
assert_eq!(
id_set, expected_ids,
"Documents wrapper (include owned) failed"
@@ -198,7 +149,7 @@ mod tests {
let ids: Vec<String> = items.into_iter().map(|item| item.item_id).collect();
assert_eq!(
ids,
- vec!["doc-shared"],
+ vec!["a0000000-0000-0000-0000-0000000e0006"],
"Documents wrapper (exclude owned) failed"
);
}
@@ -208,10 +159,13 @@ mod tests {
let items =
get_user_accessible_items(&pool, user_id, Some("chat".to_string()), false).await?;
let id_set: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
- let expected_ids: HashSet<String> = ["chat-owned", "chat-shared"]
- .into_iter()
- .map(String::from)
- .collect();
+ let expected_ids: HashSet<String> = [
+ "a0000000-0000-0000-0000-0000000e0002",
+ "a0000000-0000-0000-0000-0000000e0005",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
assert_eq!(id_set, expected_ids, "Chats wrapper (include owned) failed");
}
@@ -222,7 +176,7 @@ mod tests {
let ids: Vec<String> = items.into_iter().map(|item| item.item_id).collect();
assert_eq!(
ids,
- vec!["chat-shared"],
+ vec!["a0000000-0000-0000-0000-0000000e0005"],
"Chats wrapper (exclude owned) failed"
);
}
@@ -233,10 +187,13 @@ mod tests {
get_user_accessible_items(&pool, user_id, Some("project".to_string()), false)
.await?;
let id_set: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
- let expected_ids: HashSet<String> = ["project-owned", "project-shared"]
- .into_iter()
- .map(String::from)
- .collect();
+ let expected_ids: HashSet<String> = [
+ "a0000000-0000-0000-0000-0000000e0001",
+ "a0000000-0000-0000-0000-0000000e0004",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
assert_eq!(
id_set, expected_ids,
"Projects wrapper (include owned) failed"
@@ -251,7 +208,7 @@ mod tests {
let ids: Vec<String> = items.into_iter().map(|item| item.item_id).collect();
assert_eq!(
ids,
- vec!["project-shared"],
+ vec!["a0000000-0000-0000-0000-0000000e0004"],
"Projects wrapper (exclude owned) failed"
);
}
@@ -267,10 +224,15 @@ mod tests {
{
let items = get_user_accessible_items(&pool, user_id, None, false).await?;
let item_ids: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
- let expected_ids: HashSet<String> = ["project-A", "project-B", "chat-A", "doc-A"]
- .into_iter()
- .map(String::from)
- .collect();
+ let expected_ids: HashSet<String> = [
+ "b0000000-0000-0000-0000-0000000e0001",
+ "b0000000-0000-0000-0000-0000000e0002",
+ "b0000000-0000-0000-0000-0000000e0003",
+ "b0000000-0000-0000-0000-0000000e0004",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
assert_eq!(
item_ids, expected_ids,
"Core function (include owned) failed on hierarchical permissions"
@@ -282,10 +244,15 @@ mod tests {
{
let items = get_user_accessible_items(&pool, user_id, None, true).await?;
let item_ids: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
- let expected_ids: HashSet<String> = ["project-A", "project-B", "chat-A", "doc-A"]
- .into_iter()
- .map(String::from)
- .collect();
+ let expected_ids: HashSet<String> = [
+ "b0000000-0000-0000-0000-0000000e0001",
+ "b0000000-0000-0000-0000-0000000e0002",
+ "b0000000-0000-0000-0000-0000000e0003",
+ "b0000000-0000-0000-0000-0000000e0004",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
assert_eq!(
item_ids, expected_ids,
"Core function (exclude owned) should not change the result when the user owns nothing"
@@ -300,7 +267,7 @@ mod tests {
let ids: Vec<String> = items.into_iter().map(|item| item.item_id).collect();
assert_eq!(
ids,
- vec!["doc-A"],
+ vec!["b0000000-0000-0000-0000-0000000e0004"],
"Documents wrapper (include owned) failed on hierarchical"
);
}
@@ -313,7 +280,7 @@ mod tests {
let ids: Vec<String> = items.into_iter().map(|item| item.item_id).collect();
assert_eq!(
ids,
- vec!["doc-A"],
+ vec!["b0000000-0000-0000-0000-0000000e0004"],
"Documents wrapper (exclude owned) failed on hierarchical"
);
}
@@ -325,7 +292,7 @@ mod tests {
let ids: Vec<String> = items.into_iter().map(|item| item.item_id).collect();
assert_eq!(
ids,
- vec!["chat-A"],
+ vec!["b0000000-0000-0000-0000-0000000e0003"],
"Chats wrapper (include owned) failed on hierarchical"
);
}
@@ -337,7 +304,7 @@ mod tests {
let ids: Vec<String> = items.into_iter().map(|item| item.item_id).collect();
assert_eq!(
ids,
- vec!["chat-A"],
+ vec!["b0000000-0000-0000-0000-0000000e0003"],
"Chats wrapper (exclude owned) failed on hierarchical"
);
}
@@ -348,10 +315,13 @@ mod tests {
get_user_accessible_items(&pool, user_id, Some("project".to_string()), false)
.await?;
let id_set: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
- let expected_ids: HashSet<String> = ["project-A", "project-B"]
- .into_iter()
- .map(String::from)
- .collect();
+ let expected_ids: HashSet<String> = [
+ "b0000000-0000-0000-0000-0000000e0001",
+ "b0000000-0000-0000-0000-0000000e0002",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
assert_eq!(
id_set, expected_ids,
"Projects wrapper (include owned) failed on hierarchical"
@@ -364,10 +334,13 @@ mod tests {
get_user_accessible_items(&pool, user_id, Some("project".to_string()), true)
.await?;
let id_set: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
- let expected_ids: HashSet<String> = ["project-A", "project-B"]
- .into_iter()
- .map(String::from)
- .collect();
+ let expected_ids: HashSet<String> = [
+ "b0000000-0000-0000-0000-0000000e0001",
+ "b0000000-0000-0000-0000-0000000e0002",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
assert_eq!(
id_set, expected_ids,
"Projects wrapper (exclude owned) failed on hierarchical"
@@ -386,11 +359,16 @@ mod tests {
{
let items = get_user_accessible_items(&pool, user_id, None, false).await?;
let item_ids: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
- let expected_ids: HashSet<String> =
- ["project-A", "project-B", "project-C", "chat-C", "doc-C"]
- .into_iter()
- .map(String::from)
- .collect();
+ let expected_ids: HashSet<String> = [
+ "c0000000-0000-0000-0000-0000000e0001",
+ "c0000000-0000-0000-0000-0000000e0002",
+ "c0000000-0000-0000-0000-0000000e0003",
+ "c0000000-0000-0000-0000-0000000e0004",
+ "c0000000-0000-0000-0000-0000000e0005",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
assert_eq!(
item_ids, expected_ids,
"Core function (include owned) failed on deep hierarchy"
@@ -402,11 +380,16 @@ mod tests {
{
let items = get_user_accessible_items(&pool, user_id, None, true).await?;
let item_ids: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
- let expected_ids: HashSet<String> =
- ["project-A", "project-B", "project-C", "chat-C", "doc-C"]
- .into_iter()
- .map(String::from)
- .collect();
+ let expected_ids: HashSet<String> = [
+ "c0000000-0000-0000-0000-0000000e0001",
+ "c0000000-0000-0000-0000-0000000e0002",
+ "c0000000-0000-0000-0000-0000000e0003",
+ "c0000000-0000-0000-0000-0000000e0004",
+ "c0000000-0000-0000-0000-0000000e0005",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
assert_eq!(
item_ids, expected_ids,
"Core function (exclude owned) failed on deep hierarchy"
@@ -421,7 +404,7 @@ mod tests {
let ids: Vec<String> = items.into_iter().map(|item| item.item_id).collect();
assert_eq!(
ids,
- vec!["doc-C"],
+ vec!["c0000000-0000-0000-0000-0000000e0005"],
"Documents wrapper (include owned) failed on deep hierarchy"
);
}
@@ -434,7 +417,7 @@ mod tests {
let ids: Vec<String> = items.into_iter().map(|item| item.item_id).collect();
assert_eq!(
ids,
- vec!["doc-C"],
+ vec!["c0000000-0000-0000-0000-0000000e0005"],
"Documents wrapper (exclude owned) failed on deep hierarchy"
);
}
@@ -446,7 +429,7 @@ mod tests {
let ids: Vec<String> = items.into_iter().map(|item| item.item_id).collect();
assert_eq!(
ids,
- vec!["chat-C"],
+ vec!["c0000000-0000-0000-0000-0000000e0004"],
"Chats wrapper (include owned) failed on deep hierarchy"
);
}
@@ -458,7 +441,7 @@ mod tests {
let ids: Vec<String> = items.into_iter().map(|item| item.item_id).collect();
assert_eq!(
ids,
- vec!["chat-C"],
+ vec!["c0000000-0000-0000-0000-0000000e0004"],
"Chats wrapper (exclude owned) failed on deep hierarchy"
);
}
@@ -469,10 +452,14 @@ mod tests {
get_user_accessible_items(&pool, user_id, Some("project".to_string()), false)
.await?;
let id_set: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
- let expected_ids: HashSet<String> = ["project-A", "project-B", "project-C"]
- .into_iter()
- .map(String::from)
- .collect();
+ let expected_ids: HashSet<String> = [
+ "c0000000-0000-0000-0000-0000000e0001",
+ "c0000000-0000-0000-0000-0000000e0002",
+ "c0000000-0000-0000-0000-0000000e0003",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
assert_eq!(
id_set, expected_ids,
"Projects wrapper (include owned) failed on deep hierarchy"
@@ -485,10 +472,14 @@ mod tests {
get_user_accessible_items(&pool, user_id, Some("project".to_string()), true)
.await?;
let id_set: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
- let expected_ids: HashSet<String> = ["project-A", "project-B", "project-C"]
- .into_iter()
- .map(String::from)
- .collect();
+ let expected_ids: HashSet<String> = [
+ "c0000000-0000-0000-0000-0000000e0001",
+ "c0000000-0000-0000-0000-0000000e0002",
+ "c0000000-0000-0000-0000-0000000e0003",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
assert_eq!(
id_set, expected_ids,
"Projects wrapper (exclude owned) failed on deep hierarchy"
diff --git a/rust/cloud-storage/macro_db_client/src/item_access/insert.rs b/rust/cloud-storage/macro_db_client/src/item_access/insert.rs
deleted file mode 100644
index 6df76b950c..0000000000
--- a/rust/cloud-storage/macro_db_client/src/item_access/insert.rs
+++ /dev/null
@@ -1,685 +0,0 @@
-use macro_user_id::user_id::MacroUserIdStr;
-use models_permissions::share_permission::access_level::AccessLevel;
-use models_permissions::user_item_access::UserItemAccess;
-use sqlx::{Executor, Postgres, Transaction};
-use uuid::Uuid;
-
-#[tracing::instrument(skip(transaction))]
-pub async fn insert_user_item_access(
- transaction: &mut Transaction<'_, Postgres>,
- user_id: MacroUserIdStr<'_>,
- item_id: &str,
- item_type: &str,
- access_level: AccessLevel,
- granted_from_channel_id: Option<Uuid>,
-) -> anyhow::Result<()> {
- let id = macro_uuid::generate_uuid_v7();
-
- sqlx::query!(
- r#"
- INSERT INTO "UserItemAccess" (
- "id",
- "user_id",
- "item_id",
- "item_type",
- "access_level",
- "granted_from_channel_id",
- "created_at",
- "updated_at"
- )
- VALUES (
- $1,
- $2,
- $3,
- $4,
- $5,
- $6,
- NOW(),
- NOW()
- )
- "#,
- id,
- user_id.as_ref(),
- item_id,
- item_type,
- access_level as _,
- granted_from_channel_id
- )
- .execute(transaction.as_mut())
- .await?;
-
- Ok(())
-}
-
-#[tracing::instrument(skip(executor))]
-pub async fn upsert_user_item_access_bulk<'e, E>(
- executor: E,
- user_ids: &[MacroUserIdStr<'_>],
- item_id: &str,
- item_type: &str,
- access_level: AccessLevel,
- granted_from_channel_id: Option<Uuid>,
-) -> anyhow::Result<()>
-where
- E: Executor<'e, Database = Postgres>,
-{
- if user_ids.is_empty() {
- return Ok(());
- }
-
- let macro_ids: Vec<String> = user_ids.iter().map(|s| s.to_string()).collect();
-
- // Generate UUIDs for each user
- let ids: Vec<Uuid> = user_ids
- .iter()
- .map(|_| macro_uuid::generate_uuid_v7())
- .collect();
-
- // Execute bulk insert using unnest with ON CONFLICT DO UPDATE
- sqlx::query!(
- r#"
- INSERT INTO "UserItemAccess" (
- "id",
- "user_id",
- "item_id",
- "item_type",
- "access_level",
- "granted_from_channel_id",
- "created_at",
- "updated_at"
- )
- SELECT
- u.id,
- u.user_id,
- $1 as item_id,
- $2 as item_type,
- $3 as access_level,
- $4 as granted_from_channel_id,
- NOW() as created_at,
- NOW() as updated_at
- FROM UNNEST($5::uuid[], $6::text[]) as u(id, user_id)
- ON CONFLICT ("user_id", "item_id", "item_type", "granted_from_channel_id") DO UPDATE
- SET
- "access_level" = EXCLUDED."access_level",
- "updated_at" = NOW()
- "#,
- item_id,
- item_type,
- access_level as _,
- granted_from_channel_id,
- &ids,
- macro_ids.as_slice(),
- )
- .execute(executor)
- .await?;
-
- Ok(())
-}
-
-/// Inserts multiple UserItemAccess records in a single database query
-/// The created_at and updated_at fields from the structs are ignored and NOW() is used instead
-#[tracing::instrument(skip(db, access_records))]
-pub async fn insert_user_item_access_batch(
- db: &sqlx::PgPool,
- access_records: &[UserItemAccess],
-) -> anyhow::Result<()> {
- if access_records.is_empty() {
- return Ok(());
- }
-
- // First, filter out records for users that don't exist
- // This query gets a list of user_ids that exist in the database
- let user_ids: Vec<String> = access_records
- .iter()
- .map(|record| record.user_id.clone())
- .collect();
-
- let existing_users = sqlx::query!(
- r#"
- SELECT "id" FROM "User" WHERE "id" = ANY($1)
- "#,
- &user_ids as &[String]
- )
- .fetch_all(db)
- .await?;
-
- // Create a set of existing user IDs for quick lookup
- let existing_user_set: std::collections::HashSet<String> =
- existing_users.into_iter().map(|row| row.id).collect();
-
- // Filter the access records to only include those with existing users
- let valid_records: Vec<&UserItemAccess> = access_records
- .iter()
- .filter(|record| existing_user_set.contains(&record.user_id))
- .collect();
-
- if valid_records.is_empty() {
- // No valid records to insert
- return Ok(());
- }
-
- // Extract the fields we need from each valid UserItemAccess record
- let ids: Vec<Uuid> = valid_records.iter().map(|record| record.id).collect();
- let user_ids: Vec<String> = valid_records
- .iter()
- .map(|record| record.user_id.clone())
- .collect();
- let item_ids: Vec<String> = valid_records
- .iter()
- .map(|record| record.item_id.clone())
- .collect();
- let item_types: Vec<String> = valid_records
- .iter()
- .map(|record| record.item_type.clone())
- .collect();
-
- // Convert AccessLevel enum to strings
- let access_level_strings: Vec<String> = valid_records
- .iter()
- .map(|record| record.access_level.to_string().to_lowercase())
- .collect();
-
- // For optional fields, we need to handle them differently
- let granted_from_channel_ids: Vec<Option<Uuid>> = valid_records
- .iter()
- .map(|record| record.granted_from_channel_id)
- .collect();
-
- // Execute the batch insert with ON CONFLICT DO NOTHING for handling unique constraint violations
- sqlx::query!(
- r#"
- INSERT INTO "UserItemAccess" (
- "id",
- "user_id",
- "item_id",
- "item_type",
- "access_level",
- "granted_from_channel_id",
- "created_at",
- "updated_at"
- )
- SELECT
- u.id,
- u.user_id,
- u.item_id,
- u.item_type,
- u.access_level::"AccessLevel",
- u.granted_from_channel_id,
- NOW() as created_at,
- NOW() as updated_at
- FROM UNNEST(
- $1::uuid[],
- $2::text[],
- $3::text[],
- $4::text[],
- $5::text[],
- $6::uuid[]
- ) as u(
- id,
- user_id,
- item_id,
- item_type,
- access_level,
- granted_from_channel_id
- )
- ON CONFLICT ("user_id", "item_id", "item_type", "granted_from_channel_id")
- DO NOTHING
- "#,
- &ids,
- &user_ids as &[String],
- &item_ids as &[String],
- &item_types as &[String],
- &access_level_strings as &[String],
- &granted_from_channel_ids as &[Option<Uuid>],
- )
- .execute(db)
- .await?;
-
- // Log how many records were skipped due to missing users
- let skipped_count = access_records.len() - valid_records.len();
- if skipped_count > 0 {
- tracing::info!(
- "Skipped {} records due to non-existent users",
- skipped_count
- );
- }
-
- Ok(())
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
- use models_permissions::share_permission::access_level::AccessLevel;
- use sqlx::{Pool, Postgres};
- // Existing tests...
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("user_item_access.sql")))]
- async fn test_insert_user_item_access(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
- let item_id = "new-test-item";
- let item_type = "document";
- let access_level = AccessLevel::Edit;
- let granted_from_channel_id = Some(Uuid::now_v7());
-
- let mut transaction = pool.begin().await?;
-
- // Insert a new record
- insert_user_item_access(
- &mut transaction,
- user_id.clone(),
- item_id,
- item_type,
- access_level,
- granted_from_channel_id,
- )
- .await?;
-
- // Verify it exists
- let result = sqlx::query!(
- r#"
- SELECT COUNT(*) as count
- FROM "UserItemAccess"
- WHERE "user_id" = $1 AND "item_id" = $2 AND "item_type" = $3
- AND "access_level"::text = $4 AND "granted_from_channel_id" = $5
- "#,
- user_id.as_ref(),
- item_id,
- item_type,
- access_level.to_string(),
- granted_from_channel_id,
- )
- .fetch_one(&mut *transaction)
- .await?;
-
- assert_eq!(
- result.count.unwrap(),
- 1,
- "Should have inserted exactly one record"
- );
-
- transaction.commit().await?;
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("user_item_access.sql")))]
- async fn test_insert_user_item_access_bulk(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let item_id = "bulk-insert-test-item";
- let item_type = "document";
- let access_level = AccessLevel::View;
- let granted_from_channel_id = Some(Uuid::now_v7());
- let user_ids = vec![
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- ];
-
- let mut transaction = pool.begin().await?;
-
- // Insert multiple records at once
- upsert_user_item_access_bulk(
- &mut *transaction,
- &user_ids,
- item_id,
- item_type,
- access_level,
- granted_from_channel_id,
- )
- .await?;
-
- let ids: Vec<_> = user_ids.iter().map(|x| x.to_string()).collect();
-
- // Verify all records exist
- let result = sqlx::query!(
- r#"
- SELECT COUNT(*) as count
- FROM "UserItemAccess"
- WHERE "user_id" = ANY($1) AND "item_id" = $2 AND "item_type" = $3
- AND "access_level"::text = $4 AND "granted_from_channel_id" = $5
- "#,
- &ids,
- item_id,
- item_type,
- access_level.to_string(),
- granted_from_channel_id,
- )
- .fetch_one(&mut *transaction)
- .await?;
-
- assert_eq!(
- result.count.unwrap(),
- user_ids.len() as i64,
- "Should have inserted exactly {} records",
- user_ids.len()
- );
-
- // Check each user individually to ensure proper data
- for user_id in &user_ids {
- let result = sqlx::query!(
- r#"
- SELECT
- "user_id",
- "item_id",
- "item_type",
- "access_level"::text as "access_level",
- "granted_from_channel_id"
- FROM "UserItemAccess"
- WHERE "user_id" = $1 AND "item_id" = $2
- "#,
- user_id.as_ref(),
- item_id,
- )
- .fetch_one(&mut *transaction)
- .await?;
-
- assert_eq!(result.user_id, user_id.as_ref());
- assert_eq!(result.item_id, item_id);
- assert_eq!(result.item_type, item_type);
- assert_eq!(result.access_level, Some(access_level.to_string()));
- assert_eq!(result.granted_from_channel_id, granted_from_channel_id);
- }
-
- transaction.commit().await?;
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("user_item_access.sql")))]
- async fn test_insert_user_item_access_bulk_empty(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let mut transaction = pool.begin().await?;
-
- // Test with empty array
- upsert_user_item_access_bulk(
- &mut *transaction,
- &[],
- "empty-test-item",
- "document",
- AccessLevel::View,
- None,
- )
- .await?;
-
- // Verify no records were inserted
- let result = sqlx::query!(
- r#"
- SELECT COUNT(*) as count
- FROM "UserItemAccess"
- WHERE "item_id" = $1
- "#,
- "empty-test-item",
- )
- .fetch_one(&mut *transaction)
- .await?;
-
- assert_eq!(
- result.count.unwrap(),
- 0,
- "Should not have inserted any records"
- );
-
- transaction.commit().await?;
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("user_item_access.sql")))]
- async fn test_insert_user_item_access_bulk_with_pool(
- pool: Pool<Postgres>,
- ) -> anyhow::Result<()> {
- let item_id = "pool-insert-test-item";
- let item_type = "document";
- let access_level = AccessLevel::Owner;
- let granted_from_channel_id = Some(Uuid::now_v7());
- let user_ids = vec![
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- ];
-
- // Insert using the pool directly
- upsert_user_item_access_bulk(
- &pool,
- &user_ids,
- item_id,
- item_type,
- access_level,
- granted_from_channel_id,
- )
- .await?;
-
- let ids: Vec<_> = user_ids.iter().map(|x| x.to_string()).collect();
-
- // Verify all records exist
- let result = sqlx::query!(
- r#"
- SELECT COUNT(*) as count
- FROM "UserItemAccess"
- WHERE "user_id" = ANY($1) AND "item_id" = $2 AND "item_type" = $3
- AND "access_level"::text = $4 AND "granted_from_channel_id" = $5
- "#,
- &ids,
- item_id,
- item_type,
- access_level.to_string(),
- granted_from_channel_id,
- )
- .fetch_one(&pool)
- .await?;
-
- assert_eq!(
- result.count.unwrap(),
- user_ids.len() as i64,
- "Should have inserted exactly {} records",
- user_ids.len()
- );
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("user_item_access.sql")))]
- async fn test_insert_user_item_access_bulk_upsert(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let item_id = "upsert-test-item";
- let item_type = "document";
- let granted_from_channel_id = Some(Uuid::now_v7());
- let user_ids = vec![
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
- ];
-
- let mut transaction = pool.begin().await?;
-
- // Initial insert with View access level
- let initial_access_level = AccessLevel::View;
- upsert_user_item_access_bulk(
- &mut *transaction,
- &user_ids,
- item_id,
- item_type,
- initial_access_level,
- granted_from_channel_id,
- )
- .await?;
-
- let ids: Vec<_> = user_ids.iter().map(|x| x.to_string()).collect();
-
- // Verify initial insert
- let initial_result = sqlx::query!(
- r#"
- SELECT "id", "user_id", "access_level"::text as "access_level"
- FROM "UserItemAccess"
- WHERE "user_id" = ANY($1) AND "item_id" = $2 AND "item_type" = $3
- AND "granted_from_channel_id" = $4
- ORDER BY "user_id"
- "#,
- &ids,
- item_id,
- item_type,
- granted_from_channel_id,
- )
- .fetch_all(&mut *transaction)
- .await?;
-
- assert_eq!(
- initial_result.len(),
- 2,
- "Should have inserted 2 records initially"
- );
-
- // Store the initial IDs to verify they don't change during upsert
- let initial_ids: Vec<Uuid> = initial_result.iter().map(|r| r.id).collect();
-
- // Verify initial access level
- for record in &initial_result {
- assert_eq!(record.access_level, Some(initial_access_level.to_string()));
- }
-
- // Now perform an upsert with a higher access level
- let updated_access_level = AccessLevel::Edit;
- upsert_user_item_access_bulk(
- &mut *transaction,
- &user_ids,
- item_id,
- item_type,
- updated_access_level,
- granted_from_channel_id,
- )
- .await?;
-
- let ids: Vec<_> = user_ids.iter().map(|x| x.to_string()).collect();
-
- // Verify the upsert updated the access levels but kept the same records
- let updated_result = sqlx::query!(
- r#"
- SELECT
- "id",
- "user_id",
- "access_level"::text as "access_level"
- FROM "UserItemAccess"
- WHERE "user_id" = ANY($1) AND "item_id" = $2 AND "item_type" = $3
- AND "granted_from_channel_id" = $4
- ORDER BY "user_id"
- "#,
- &ids,
- item_id,
- item_type,
- granted_from_channel_id,
- )
- .fetch_all(&mut *transaction)
- .await?;
-
- assert_eq!(
- updated_result.len(),
- 2,
- "Should still have 2 records after upsert (no duplicates)"
- );
-
- // Verify that the records were updated not replaced
- for (i, record) in updated_result.iter().enumerate() {
- // Access level should be updated to the new value
- assert_eq!(
- record.access_level,
- Some(updated_access_level.to_string()),
- "Access level should be updated to {:?}",
- updated_access_level
- );
-
- // The ID should remain unchanged (same record, just updated)
- assert_eq!(
- record.id, initial_ids[i],
- "Record ID should not change during upsert, confirming same row was updated"
- );
- }
-
- // Test with both updates and new inserts
- let mixed_user_ids = vec![
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(), // existing
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(), // new
- MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(), // new
- ];
-
- let final_access_level = AccessLevel::Owner;
-
- // Perform mixed upsert (updating one record, inserting two new ones)
- upsert_user_item_access_bulk(
- &mut *transaction,
- &mixed_user_ids,
- item_id,
- item_type,
- final_access_level,
- granted_from_channel_id,
- )
- .await?;
-
- let ids: Vec<_> = mixed_user_ids.iter().map(|x| x.to_string()).collect();
-
- // Verify the result
- let final_result = sqlx::query!(
- r#"
- SELECT
- "id",
- "user_id",
- "access_level"::text as "access_level"
- FROM "UserItemAccess"
- WHERE "user_id" = ANY($1) AND "item_id" = $2 AND "item_type" = $3
- AND "granted_from_channel_id" = $4
- ORDER BY "user_id"
- "#,
- &ids,
- item_id,
- item_type,
- granted_from_channel_id,
- )
- .fetch_all(&mut *transaction)
- .await?;
-
- assert_eq!(
- final_result.len(),
- 3,
- "Should have 3 records after mixed upsert"
- );
-
- // Verify each record has the right access level
- for record in &final_result {
- assert_eq!(
- record.access_level,
- Some(final_access_level.to_string()),
- "All records should have Owner access level"
- );
- }
-
- // Verify the first user's ID remains unchanged (updated record)
- assert_eq!(
- final_result[0].id, initial_ids[0],
- "Previously existing record should maintain its ID"
- );
-
- // Verify that all users now have records
- let total_count = sqlx::query!(
- r#"
- SELECT COUNT(*) as count
- FROM "UserItemAccess"
- WHERE ("user_id" = ANY($1) OR "user_id" = ANY($2))
- AND "item_id" = $3 AND "item_type" = $4
- AND "granted_from_channel_id" = $5
- "#,
- &ids,
- &["macro|[email protected]".to_string()], // user2 from original insert, not in mixed_user_ids
- item_id,
- item_type,
- granted_from_channel_id,
- )
- .fetch_one(&mut *transaction)
- .await?;
-
- assert_eq!(
- total_count.count.unwrap(),
- 4, // 2 original users + 2 new users
- "Should have 4 total records (including user2 that wasn't in the last operation)"
- );
-
- transaction.commit().await?;
-
- Ok(())
- }
-}
diff --git a/rust/cloud-storage/macro_db_client/src/item_access/mod.rs b/rust/cloud-storage/macro_db_client/src/item_access/mod.rs
index c61c9ac05e..cd9f9ea17d 100644
--- a/rust/cloud-storage/macro_db_client/src/item_access/mod.rs
+++ b/rust/cloud-storage/macro_db_client/src/item_access/mod.rs
@@ -1,7 +1,6 @@
pub mod delete;
pub mod get;
pub mod get_accessible_items;
-pub mod insert;
mod validate_accessible_items;
pub use validate_accessible_items::*;
diff --git a/rust/cloud-storage/macro_db_client/src/item_access/validate_accessible_items.rs b/rust/cloud-storage/macro_db_client/src/item_access/validate_accessible_items.rs
index 4ce8fc17fe..431732f26f 100644
--- a/rust/cloud-storage/macro_db_client/src/item_access/validate_accessible_items.rs
+++ b/rust/cloud-storage/macro_db_client/src/item_access/validate_accessible_items.rs
@@ -4,8 +4,9 @@ use cached::proc_macro::cached;
use model::item::{ShareableItem, ShareableItemType, UserAccessibleItem};
use sqlx::{Pool, Postgres};
-/// given a list of shareable items, returns all accessible items for a user, traversing nested project structure
-#[tracing::instrument(skip(db, items))]
+/// Given a list of shareable items, returns the subset that are accessible to the user,
+/// querying entity_access with the user's source IDs (user ID, team memberships, channel participations).
+#[tracing::instrument(skip(db, items), err)]
#[cfg_attr(
not(test),
cached(
@@ -46,93 +47,47 @@ pub async fn validate_user_accessible_items(
let results = sqlx::query!(
r#"
- WITH RECURSIVE ProjectHierarchy AS (
- -- Find direct user access to ALL projects (not filtered) as starting point
- SELECT
- p.id,
- uia.access_level
- FROM "Project" p
- JOIN "UserItemAccess" uia ON p.id = uia.item_id AND uia.item_type = 'project'
- WHERE uia.user_id = $1 AND p."deletedAt" IS NULL
-
+ WITH user_source_ids AS (
+ SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp
+ WHERE cp.user_id = $1 AND cp.left_at IS NULL
UNION ALL
-
- -- Then walk down the project tree and grab child projects, keeping parent's access
- SELECT
- p.id,
- ph.access_level
- FROM "Project" p
- JOIN ProjectHierarchy ph ON p."parentId" = ph.id
- WHERE p."deletedAt" IS NULL
+ SELECT t.team_id::text FROM team_user t
+ WHERE t.user_id = $1
+ UNION ALL
+ SELECT $1
),
- -- Now build up all the ways a user can have access to stuff
+ -- Get all entities the user has access to via entity_access, filtered to requested items
AllAccessGrants AS (
- -- Explicit access to documents via UserItemAccess table
- SELECT uia.item_id, uia.item_type, uia.access_level
- FROM "UserItemAccess" uia
- LEFT JOIN "Document" d ON uia.item_type = 'document' AND uia.item_id = d.id
- WHERE uia.user_id = $1
- AND uia.item_type = 'document'
- AND uia.item_id = ANY($2)
+ -- Documents the user has access to
+ SELECT ea.entity_id::text as item_id, ea.entity_type as item_type
+ FROM entity_access ea
+ LEFT JOIN "Document" d ON ea.entity_type = 'document' AND ea.entity_id::text = d.id
+ WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)
+ AND ea.entity_type = 'document'
+ AND ea.entity_id::text = ANY($2)
AND d."deletedAt" IS NULL
UNION ALL
- -- Explicit access to chats via UserItemAccess table
- SELECT uia.item_id, uia.item_type, uia.access_level
- FROM "UserItemAccess" uia
- LEFT JOIN "Chat" c ON uia.item_type = 'chat' AND uia.item_id = c.id
- WHERE uia.user_id = $1
- AND uia.item_type = 'chat'
- AND uia.item_id = ANY($3)
+ -- Chats the user has access to
+ SELECT ea.entity_id::text as item_id, ea.entity_type as item_type
+ FROM entity_access ea
+ LEFT JOIN "Chat" c ON ea.entity_type = 'chat' AND ea.entity_id::text = c.id
+ WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)
+ AND ea.entity_type = 'chat'
+ AND ea.entity_id::text = ANY($3)
AND c."deletedAt" IS NULL
UNION ALL
- -- Explicit access to projects via UserItemAccess table
- SELECT uia.item_id, uia.item_type, uia.access_level
- FROM "UserItemAccess" uia
- LEFT JOIN "Project" p ON uia.item_type = 'project' AND uia.item_id = p.id
- WHERE uia.user_id = $1
- AND uia.item_type = 'project'
- AND uia.item_id = ANY($4)
+ -- Projects the user has access to
+ SELECT ea.entity_id::text as item_id, ea.entity_type as item_type
+ FROM entity_access ea
+ LEFT JOIN "Project" p ON ea.entity_type = 'project' AND ea.entity_id::text = p.id
+ WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)
+ AND ea.entity_type = 'project'
+ AND ea.entity_id::text = ANY($4)
AND p."deletedAt" IS NULL
-
- UNION ALL
-
- -- Access to docs in visible projects (only filter by requested doc IDs)
- SELECT
- d.id AS item_id,
- 'document' AS item_type,
- ph.access_level
- FROM "Document" d
- JOIN ProjectHierarchy ph ON d."projectId" = ph.id
- WHERE d.id = ANY($2)
- AND d."projectId" IS NOT NULL
- AND d."deletedAt" IS NULL
-
- UNION ALL
-
- -- Access to chats in visible projects (only filter by requested chat IDs)
- SELECT
- c.id AS item_id,
- 'chat' AS item_type,
- ph.access_level
- FROM "Chat" c
- JOIN ProjectHierarchy ph ON c."projectId" = ph.id
- WHERE c.id = ANY($3)
- AND c."projectId" IS NOT NULL
- AND c."deletedAt" IS NULL
-
- UNION ALL
-
- -- Include the projects we found earlier (only filter by requested project IDs)
- SELECT
- ph.id AS item_id,
- 'project' AS item_type,
- ph.access_level
- FROM ProjectHierarchy ph
- WHERE ph.id = ANY($4)
),
UserAccessibleItems AS (
SELECT
@@ -170,27 +125,27 @@ mod tests {
// All accessible items
let items: Vec<ShareableItem> = vec![
ShareableItem {
- item_id: "project-owned".to_string(),
+ item_id: "a0000000-0000-0000-0000-0000000e0001".to_string(),
item_type: ShareableItemType::Project,
},
ShareableItem {
- item_id: "chat-owned".to_string(),
+ item_id: "a0000000-0000-0000-0000-0000000e0002".to_string(),
item_type: ShareableItemType::Chat,
},
ShareableItem {
- item_id: "doc-owned".to_string(),
+ item_id: "a0000000-0000-0000-0000-0000000e0003".to_string(),
item_type: ShareableItemType::Document,
},
ShareableItem {
- item_id: "project-shared".to_string(),
+ item_id: "a0000000-0000-0000-0000-0000000e0004".to_string(),
item_type: ShareableItemType::Project,
},
ShareableItem {
- item_id: "chat-shared".to_string(),
+ item_id: "a0000000-0000-0000-0000-0000000e0005".to_string(),
item_type: ShareableItemType::Chat,
},
ShareableItem {
- item_id: "doc-shared".to_string(),
+ item_id: "a0000000-0000-0000-0000-0000000e0006".to_string(),
item_type: ShareableItemType::Document,
},
];
@@ -198,12 +153,12 @@ mod tests {
let items = validate_user_accessible_items(&pool, user_id, items).await?;
let item_ids: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
let expected_ids: HashSet<String> = [
- "project-owned",
- "chat-owned",
- "doc-owned",
- "project-shared",
- "chat-shared",
- "doc-shared",
+ "a0000000-0000-0000-0000-0000000e0001",
+ "a0000000-0000-0000-0000-0000000e0002",
+ "a0000000-0000-0000-0000-0000000e0003",
+ "a0000000-0000-0000-0000-0000000e0004",
+ "a0000000-0000-0000-0000-0000000e0005",
+ "a0000000-0000-0000-0000-0000000e0006",
]
.into_iter()
.map(String::from)
@@ -214,25 +169,29 @@ mod tests {
// Only includes what you pass in
let items: Vec<ShareableItem> = vec![
ShareableItem {
- item_id: "project-owned".to_string(),
+ item_id: "a0000000-0000-0000-0000-0000000e0001".to_string(),
item_type: ShareableItemType::Project,
},
ShareableItem {
- item_id: "chat-owned".to_string(),
+ item_id: "a0000000-0000-0000-0000-0000000e0002".to_string(),
item_type: ShareableItemType::Chat,
},
ShareableItem {
- item_id: "doc-owned".to_string(),
+ item_id: "a0000000-0000-0000-0000-0000000e0003".to_string(),
item_type: ShareableItemType::Document,
},
];
{
let items = validate_user_accessible_items(&pool, user_id, items).await?;
let item_ids: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
- let expected_ids: HashSet<String> = ["project-owned", "chat-owned", "doc-owned"]
- .into_iter()
- .map(String::from)
- .collect();
+ let expected_ids: HashSet<String> = [
+ "a0000000-0000-0000-0000-0000000e0001",
+ "a0000000-0000-0000-0000-0000000e0002",
+ "a0000000-0000-0000-0000-0000000e0003",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
assert_eq!(
item_ids, expected_ids,
"only include what you pass in failed"
@@ -242,11 +201,11 @@ mod tests {
// Only test documents
let items: Vec<ShareableItem> = vec![
ShareableItem {
- item_id: "doc-owned".to_string(),
+ item_id: "a0000000-0000-0000-0000-0000000e0003".to_string(),
item_type: ShareableItemType::Document,
},
ShareableItem {
- item_id: "doc-shared".to_string(),
+ item_id: "a0000000-0000-0000-0000-0000000e0006".to_string(),
item_type: ShareableItemType::Document,
},
];
@@ -254,21 +213,24 @@ mod tests {
{
let items = validate_user_accessible_items(&pool, user_id, items).await?;
let item_ids: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
- let expected_ids: HashSet<String> = ["doc-owned", "doc-shared"]
- .into_iter()
- .map(String::from)
- .collect();
+ let expected_ids: HashSet<String> = [
+ "a0000000-0000-0000-0000-0000000e0003",
+ "a0000000-0000-0000-0000-0000000e0006",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
assert_eq!(item_ids, expected_ids, "only test documents failed");
}
// Only test chats
let items: Vec<ShareableItem> = vec![
ShareableItem {
- item_id: "chat-owned".to_string(),
+ item_id: "a0000000-0000-0000-0000-0000000e0002".to_string(),
item_type: ShareableItemType::Chat,
},
ShareableItem {
- item_id: "chat-shared".to_string(),
+ item_id: "a0000000-0000-0000-0000-0000000e0005".to_string(),
item_type: ShareableItemType::Chat,
},
];
@@ -276,21 +238,24 @@ mod tests {
{
let items = validate_user_accessible_items(&pool, user_id, items).await?;
let item_ids: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
- let expected_ids: HashSet<String> = ["chat-owned", "chat-shared"]
- .into_iter()
- .map(String::from)
- .collect();
+ let expected_ids: HashSet<String> = [
+ "a0000000-0000-0000-0000-0000000e0002",
+ "a0000000-0000-0000-0000-0000000e0005",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
assert_eq!(item_ids, expected_ids, "only test chats failed");
}
// Only test projects
let items: Vec<ShareableItem> = vec![
ShareableItem {
- item_id: "project-owned".to_string(),
+ item_id: "a0000000-0000-0000-0000-0000000e0001".to_string(),
item_type: ShareableItemType::Project,
},
ShareableItem {
- item_id: "project-shared".to_string(),
+ item_id: "a0000000-0000-0000-0000-0000000e0004".to_string(),
item_type: ShareableItemType::Project,
},
];
@@ -298,10 +263,13 @@ mod tests {
{
let items = validate_user_accessible_items(&pool, user_id, items).await?;
let item_ids: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
- let expected_ids: HashSet<String> = ["project-owned", "project-shared"]
- .into_iter()
- .map(String::from)
- .collect();
+ let expected_ids: HashSet<String> = [
+ "a0000000-0000-0000-0000-0000000e0001",
+ "a0000000-0000-0000-0000-0000000e0004",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
assert_eq!(item_ids, expected_ids, "only test projects failed");
}
@@ -316,29 +284,34 @@ mod tests {
// Since user-1 owns nothing, this should return all 4 accessible items.
let items: Vec<ShareableItem> = vec![
ShareableItem {
- item_id: "project-A".to_string(),
+ item_id: "b0000000-0000-0000-0000-0000000e0001".to_string(),
item_type: ShareableItemType::Project,
},
ShareableItem {
- item_id: "project-B".to_string(),
+ item_id: "b0000000-0000-0000-0000-0000000e0002".to_string(),
item_type: ShareableItemType::Project,
},
ShareableItem {
- item_id: "chat-A".to_string(),
+ item_id: "b0000000-0000-0000-0000-0000000e0003".to_string(),
item_type: ShareableItemType::Chat,
},
ShareableItem {
- item_id: "doc-A".to_string(),
+ item_id: "b0000000-0000-0000-0000-0000000e0004".to_string(),
item_type: ShareableItemType::Document,
},
];
{
let items = validate_user_accessible_items(&pool, user_id, items).await?;
let item_ids: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
- let expected_ids: HashSet<String> = ["project-A", "project-B", "chat-A", "doc-A"]
- .into_iter()
- .map(String::from)
- .collect();
+ let expected_ids: HashSet<String> = [
+ "b0000000-0000-0000-0000-0000000e0001",
+ "b0000000-0000-0000-0000-0000000e0002",
+ "b0000000-0000-0000-0000-0000000e0003",
+ "b0000000-0000-0000-0000-0000000e0004",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
assert_eq!(
item_ids, expected_ids,
"Core function (include owned) failed on hierarchical permissions"
@@ -355,34 +328,39 @@ mod tests {
// --- Core Function: include_owned ---
let items: Vec<ShareableItem> = vec![
ShareableItem {
- item_id: "project-A".to_string(),
+ item_id: "c0000000-0000-0000-0000-0000000e0001".to_string(),
item_type: ShareableItemType::Project,
},
ShareableItem {
- item_id: "project-B".to_string(),
+ item_id: "c0000000-0000-0000-0000-0000000e0002".to_string(),
item_type: ShareableItemType::Project,
},
ShareableItem {
- item_id: "project-C".to_string(),
+ item_id: "c0000000-0000-0000-0000-0000000e0003".to_string(),
item_type: ShareableItemType::Project,
},
ShareableItem {
- item_id: "chat-C".to_string(),
+ item_id: "c0000000-0000-0000-0000-0000000e0004".to_string(),
item_type: ShareableItemType::Chat,
},
ShareableItem {
- item_id: "doc-C".to_string(),
+ item_id: "c0000000-0000-0000-0000-0000000e0005".to_string(),
item_type: ShareableItemType::Document,
},
];
{
let items = validate_user_accessible_items(&pool, user_id, items).await?;
let item_ids: HashSet<String> = items.into_iter().map(|item| item.item_id).collect();
- let expected_ids: HashSet<String> =
- ["project-A", "project-B", "project-C", "chat-C", "doc-C"]
- .into_iter()
- .map(String::from)
- .collect();
+ let expected_ids: HashSet<String> = [
+ "c0000000-0000-0000-0000-0000000e0001",
+ "c0000000-0000-0000-0000-0000000e0002",
+ "c0000000-0000-0000-0000-0000000e0003",
+ "c0000000-0000-0000-0000-0000000e0004",
+ "c0000000-0000-0000-0000-0000000e0005",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
assert_eq!(
item_ids, expected_ids,
"Core function (include owned) failed on deep hierarchy"
@@ -403,19 +381,19 @@ mod tests {
// --- Core Function: include_owned ---
let items: Vec<ShareableItem> = vec![
ShareableItem {
- item_id: "project-A-iso".to_string(),
+ item_id: "d0000000-0000-0000-0000-0000000e0001".to_string(),
item_type: ShareableItemType::Project,
},
ShareableItem {
- item_id: "project-B-iso".to_string(),
+ item_id: "d0000000-0000-0000-0000-0000000e0002".to_string(),
item_type: ShareableItemType::Project,
},
ShareableItem {
- item_id: "chat-A-iso".to_string(),
+ item_id: "d0000000-0000-0000-0000-0000000e0003".to_string(),
item_type: ShareableItemType::Chat,
},
ShareableItem {
- item_id: "doc-B-iso".to_string(),
+ item_id: "d0000000-0000-0000-0000-0000000e0004".to_string(),
item_type: ShareableItemType::Document,
},
];
diff --git a/rust/cloud-storage/macro_db_client/src/projects/create_project.rs b/rust/cloud-storage/macro_db_client/src/projects/create_project.rs
index 1e115e13de..be3a2d472d 100644
--- a/rust/cloud-storage/macro_db_client/src/projects/create_project.rs
+++ b/rust/cloud-storage/macro_db_client/src/projects/create_project.rs
@@ -2,7 +2,6 @@ use crate::{history::upsert_user_history, share_permission};
use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};
use model::project::Project;
use models_permissions::share_permission::SharePermissionV2;
-use models_permissions::share_permission::access_level::AccessLevel;
use sqlx::{Pool, Postgres};
#[tracing::instrument(skip(db))]
@@ -39,13 +38,16 @@ pub async fn create_project_v2(
upsert_user_history(&mut transaction, user_id.copied(), &project.id, "project").await?;
- crate::item_access::insert::insert_user_item_access(
+ // SAFETY: this is a UUID
+ let project_id = macro_uuid::string_to_uuid(&project.id).unwrap();
+
+ entity_access_db_utils::insert_entity_access_row(
&mut transaction,
- user_id,
- &project.id,
- "project",
- AccessLevel::Owner,
- None,
+ &project_id,
+ entity_access_db_utils::EntityType::Project,
+ user_id.as_ref(),
+ entity_access_db_utils::EntityAccessSourceType::User,
+ entity_access_db_utils::AccessLevel::Owner,
)
.await?;
diff --git a/rust/cloud-storage/macro_db_client/src/projects/delete.rs b/rust/cloud-storage/macro_db_client/src/projects/delete.rs
index e229acbb6d..fbf181dae9 100644
--- a/rust/cloud-storage/macro_db_client/src/projects/delete.rs
+++ b/rust/cloud-storage/macro_db_client/src/projects/delete.rs
@@ -1,6 +1,7 @@
use super::get_project::get_project_chats::get_chats_from_project_ids;
use super::get_project::get_project_documents::get_documents_from_project_ids;
use anyhow::Context;
+use model_entity::EntityType;
use sqlx::{Pool, Postgres, Transaction};
use super::get_project::get_sub_items::get_all_sub_project_ids;
@@ -138,10 +139,10 @@ pub async fn delete_project(db: Pool<Postgres>, project_id: &str) -> anyhow::Res
.await?;
}
- crate::item_access::delete::delete_user_item_access_by_item(
+ crate::item_access::delete::delete_user_entity_access_by_item(
&mut transaction,
- project_id,
- "project",
+ &macro_uuid::string_to_uuid(project_id).unwrap(),
+ EntityType::Project,
)
.await?;
@@ -166,37 +167,7 @@ pub async fn delete_projects_bulk(
) -> anyhow::Result<()> {
let mut transaction = db.begin().await.context("unable to begin transaction")?;
- sqlx::query!(
- r#"
- DELETE FROM "SharePermission"
- WHERE id IN (
- SELECT "sharePermissionId"
- FROM "ProjectPermission"
- WHERE "projectId" = ANY($1)
- )
- "#,
- project_ids
- )
- .execute(&mut *transaction)
- .await
- .context("unable to delete share permissions")?;
-
- crate::item_access::delete::delete_user_item_access_bulk(
- &mut transaction,
- project_ids,
- "project",
- )
- .await?;
-
- sqlx::query!(
- r#"
- DELETE FROM "Project"
- WHERE id = ANY($1)"#,
- project_ids
- )
- .execute(&mut *transaction)
- .await
- .context("unable to delete projects")?;
+ delete_projects_bulk_tsx(&mut transaction, project_ids).await?;
transaction
.commit()
@@ -252,8 +223,15 @@ pub async fn delete_projects_bulk_tsx(
.await
.context("unable to delete share permissions")?;
- crate::item_access::delete::delete_user_item_access_bulk(transaction, project_ids, "project")
- .await?;
+ crate::item_access::delete::delete_user_entity_access_bulk(
+ transaction,
+ &project_ids
+ .iter()
+ .map(|p| macro_uuid::string_to_uuid(p).unwrap())
+ .collect::<Vec<uuid::Uuid>>(),
+ EntityType::Project,
+ )
+ .await?;
sqlx::query!(
r#"
diff --git a/rust/cloud-storage/macro_db_client/src/projects/upload_folder/mod.rs b/rust/cloud-storage/macro_db_client/src/projects/upload_folder/mod.rs
index ddbf2f4e4b..eb09092181 100644
--- a/rust/cloud-storage/macro_db_client/src/projects/upload_folder/mod.rs
+++ b/rust/cloud-storage/macro_db_client/src/projects/upload_folder/mod.rs
@@ -11,6 +11,7 @@ use model::{
folder::{FileSystemNode, FileSystemNodeWithIds, UploadFolderWithIdsResponse},
project::Project,
};
+use model_entity::EntityType;
use models_permissions::share_permission::SharePermissionV2;
use models_permissions::share_permission::access_level::AccessLevel;
use sqlx::{Pool, Postgres, Transaction};
@@ -213,13 +214,13 @@ async fn create_project(
// Create share permission
create_project_permission(transaction, &project.id, share_permission).await?;
- crate::item_access::insert::insert_user_item_access(
+ entity_access_db_utils::insert_entity_access_row(
transaction,
- user_id,
- &project.id,
- "project",
+ &macro_uuid::string_to_uuid(&project.id).unwrap(),
+ EntityType::Project,
+ user_id.as_ref(),
+ entity_access_db_utils::EntityAccessSourceType::User,
AccessLevel::Owner,
- None,
)
.await?;
diff --git a/rust/cloud-storage/macro_db_client/src/share_permission/access_level/chat.rs b/rust/cloud-storage/macro_db_client/src/share_permission/access_level/chat.rs
index 6f46cfb418..e1a41d2aa1 100644
--- a/rust/cloud-storage/macro_db_client/src/share_permission/access_level/chat.rs
+++ b/rust/cloud-storage/macro_db_client/src/share_permission/access_level/chat.rs
@@ -2,150 +2,8 @@ use models_permissions::share_permission::access_level::AccessLevel;
use std::collections::HashMap;
use std::str::FromStr;
-/// Gets the public access level for a chat (no user required).
-///
-/// This function checks only public `SharePermission` records (where `isPublic=true`),
-/// applied either directly to the chat or inherited from its project hierarchy.
-/// It does NOT check user-specific `UserItemAccess` records.
-///
-/// Use this for unauthenticated access to publicly shared chats.
-///
-/// # Arguments
-/// * `db` - A reference to the `sqlx` database connection pool.
-/// * `chat_id` - The ID of the chat to check.
-///
-/// # Returns
-/// A `Result` containing an `Option<AccessLevel>`:
-/// - `Ok(Some(AccessLevel))` if there is public access.
-/// - `Ok(None)` if there is no public access.
-/// - `Err(_)` if a database error occurs.
-#[tracing::instrument(skip(db), err)]
-pub async fn get_public_access_level_for_chat(
- db: &sqlx::Pool<sqlx::Postgres>,
- chat_id: &str,
-) -> anyhow::Result<Option<AccessLevel>> {
- let public_levels: Vec<Option<String>> = sqlx::query_scalar!(
- r#"
- WITH RECURSIVE project_hierarchy AS (
- SELECT p.id as project_id
- FROM "Chat" c
- JOIN "Project" p ON c."projectId" = p.id AND p."deletedAt" IS NULL
- WHERE c.id = $1 AND c."deletedAt" IS NULL
- UNION ALL
- SELECT parent.id as project_id
- FROM project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id
- AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
- )
- )
- SELECT "publicAccessLevel" as access_level
- FROM "SharePermission"
- WHERE "isPublic" = true AND "publicAccessLevel" IS NOT NULL AND id IN (
- SELECT "sharePermissionId" FROM "ChatPermission" WHERE "chatId" = $1
- UNION
- SELECT "sharePermissionId" FROM "ProjectPermission"
- WHERE "projectId" IN (SELECT project_id FROM project_hierarchy)
- )
- "#,
- chat_id
- )
- .fetch_all(db)
- .await?;
-
- let highest_level = public_levels
- .iter()
- .filter_map(|opt| opt.as_ref().and_then(|s| AccessLevel::from_str(s).ok()))
- .max();
-
- Ok(highest_level)
-}
-
-/// Calculates the highest effective access level a user has for a chat.
-///
-/// This function determines the best possible permission by considering two sources:
-/// 1. **Explicit Grants**: Any `UserItemAccess` records for the specified user, applied either
-/// directly to the chat or inherited from its entire project hierarchy.
-/// 2. **Public Access**: Any `SharePermission` records marked as `isPublic=true`, applied either
-/// directly to the chat or inherited from its project hierarchy.
-///
-/// It combines all possible access levels from these sources, sorts them from highest (`Owner`)
-/// to lowest (`View`), and returns the single highest level.
-///
-/// # Arguments
-/// * `db` - A reference to the `sqlx` database connection pool.
-/// * `chat_id` - The ID of the chat to check.
-/// * `user_id` - The ID of the user whose access is being checked.
-///
-/// # Returns
-/// A `Result` containing an `Option<AccessLevel>`:
-/// - `Ok(Some(AccessLevel))` if the user has any level of access.
-/// - `Ok(None)` if the user has no access at all.
-/// - `Err(_)` if a database error occurs.
-#[tracing::instrument(skip(db), err)]
-pub async fn get_highest_access_level_for_chat(
- db: &sqlx::Pool<sqlx::Postgres>,
- chat_id: &str,
- user_id: &str,
-) -> anyhow::Result<Option<AccessLevel>> {
- // have to use strings because the SharePermission and UserItemAccess access_level rows use different sql types
- let all_level_strings: Vec<Option<String>> = sqlx::query_scalar!(
- r#"
- WITH RECURSIVE project_hierarchy AS (
- SELECT p.id as project_id
- FROM "Chat" c
- JOIN "Project" p ON c."projectId" = p.id AND p."deletedAt" IS NULL
- WHERE c.id = $1 AND c."deletedAt" IS NULL
- UNION ALL
- SELECT parent.id as project_id
- FROM project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
- )
- )
- SELECT access_level FROM (
- -- Source 1: Cast the AccessLevel enum to text.
- SELECT access_level::text FROM "UserItemAccess"
- WHERE user_id = $2 AND item_id IN (
- SELECT $1 -- The chat itself
- UNION
- SELECT project_id FROM project_hierarchy -- All parent projects
- )
- UNION ALL
- -- Source 2: Select the publicAccessLevel (which is already text).
- SELECT "publicAccessLevel" as access_level
- FROM "SharePermission"
- WHERE "isPublic" = true AND "publicAccessLevel" IS NOT NULL AND id IN (
- SELECT "sharePermissionId" FROM "ChatPermission" WHERE "chatId" = $1
- UNION
- SELECT "sharePermissionId" FROM "ProjectPermission" WHERE "projectId" IN (SELECT project_id FROM project_hierarchy)
- )
- ) as all_levels
- "#,
- chat_id,
- user_id
- )
- .fetch_all(db)
- .await?;
-
- let highest_level = all_level_strings
- .iter()
- .filter_map(|optional_string| {
- // `optional_string` is &Option<String>.
- // We use `and_then` to proceed only if it's Some.
- optional_string
- .as_ref()
- .and_then(|s| AccessLevel::from_str(s).ok())
- })
- .max();
-
- Ok(highest_level)
-}
-
/// Calculates the highest effective access level a user has for multiple chats.
///
-/// This is a batch version of `get_highest_access_level_for_chat` that processes
-/// multiple chat IDs in a single database query for better performance.
///
/// # Arguments
/// * `db` - A reference to the `sqlx` database connection pool.
@@ -169,57 +27,36 @@ pub async fn get_highest_access_level_for_chats(
let records = sqlx::query!(
r#"
- WITH RECURSIVE project_hierarchy AS (
- SELECT c.id as chat_id, p.id as project_id
- FROM "Chat" c
- JOIN "Project" p ON c."projectId" = p.id AND p."deletedAt" IS NULL
- WHERE c.id = ANY($1) AND c."deletedAt" IS NULL
+ WITH user_source_ids AS (
+ SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp
+ WHERE cp.user_id = $2 AND cp.left_at IS NULL
+ UNION ALL
+ SELECT t.team_id::text FROM team_user t
+ WHERE t.user_id = $2
UNION ALL
- SELECT ph.chat_id, parent.id as project_id
- FROM project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
- )
+ SELECT $2
)
- SELECT
+ SELECT
chat_id,
access_level
FROM (
- -- Source 1: Cast the AccessLevel enum to text.
- SELECT
- ph.chat_id,
- uia.access_level::text as access_level
- FROM project_hierarchy ph
- JOIN "UserItemAccess" uia ON uia.user_id = $2 AND (
- uia.item_id = ph.chat_id OR uia.item_id = ph.project_id
- )
- UNION ALL
- -- Source 2: Select the publicAccessLevel (which is already text).
- SELECT
- ph.chat_id,
- sp."publicAccessLevel" as access_level
- FROM project_hierarchy ph
- JOIN "ProjectPermission" pp ON pp."projectId" = ph.project_id
- JOIN "SharePermission" sp ON sp.id = pp."sharePermissionId"
- AND sp."isPublic" = true
- AND sp."publicAccessLevel" IS NOT NULL
- UNION ALL
- -- Source 3: Direct chat permissions
- SELECT
- c.id as chat_id,
- uia.access_level::text as access_level
- FROM "Chat" c
- JOIN "UserItemAccess" uia ON uia.user_id = $2 AND uia.item_id = c.id
- WHERE c.id = ANY($1) AND c."deletedAt" IS NULL
+ -- Source 1: entity_access for chats
+ SELECT
+ ea.entity_id::text as chat_id,
+ ea.access_level::text as access_level
+ FROM entity_access ea
+ WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)
+ AND ea.entity_id = ANY(SELECT id::uuid FROM "Chat" WHERE id = ANY($1) AND "deletedAt" IS NULL)
+ AND ea.entity_type = 'chat'
UNION ALL
- -- Source 4: Direct chat public permissions
- SELECT
+ -- Source 2: Direct chat public permissions
+ SELECT
c.id as chat_id,
sp."publicAccessLevel" as access_level
FROM "Chat" c
JOIN "ChatPermission" cp ON cp."chatId" = c.id
JOIN "SharePermission" sp ON sp.id = cp."sharePermissionId"
- AND sp."isPublic" = true
+ AND sp."isPublic" = true
AND sp."publicAccessLevel" IS NOT NULL
WHERE c.id = ANY($1) AND c."deletedAt" IS NULL
) as all_levels
diff --git a/rust/cloud-storage/macro_db_client/src/share_permission/access_level/chat_tests.rs b/rust/cloud-storage/macro_db_client/src/share_permission/access_level/chat_tests.rs
index 3819846385..c6bdbbef37 100644
--- a/rust/cloud-storage/macro_db_client/src/share_permission/access_level/chat_tests.rs
+++ b/rust/cloud-storage/macro_db_client/src/share_permission/access_level/chat_tests.rs
@@ -1,147 +1,27 @@
use super::*;
-#[sqlx::test(fixtures(path = "../../../fixtures", scripts("highest_access_level_for_chat")))]
-async fn test_highest_level_is_from_explicit_access(
- pool: sqlx::Pool<sqlx::Postgres>,
-) -> anyhow::Result<()> {
- // SCENARIO: Get highest access for 'user-1' on 'd-child'.
- // EXPLICIT ACCESS: view (direct), edit (parent), owner (grandparent). Max is 'owner'.
- // PUBLIC ACCESS: view (parent), edit (grandparent). Max is 'edit'.
- // EXPECTATION: The overall highest level should be 'owner' from the explicit grant.
-
- let highest_level = get_highest_access_level_for_chat(&pool, "d-child", "user-1").await?;
-
- assert_eq!(
- highest_level,
- Some(AccessLevel::Owner),
- "Expected highest level to be 'owner' from an explicit UserItemAccess record"
- );
-
- // highest public access is edit via grandparent
-
- let highest_level =
- get_highest_access_level_for_chat(&pool, "d-child", "user-public-access-only").await?;
-
- assert_eq!(
- highest_level,
- Some(AccessLevel::Edit),
- "Expected highest level to be 'edit' from a public SharePermission record"
- );
-
- Ok(())
-}
-
-#[sqlx::test(fixtures(path = "../../../fixtures", scripts("highest_access_level_for_chat")))]
-async fn test_user_scoping_is_correct(pool: sqlx::Pool<sqlx::Postgres>) -> anyhow::Result<()> {
- // SCENARIO: Get highest access for 'user-2' on 'd-child'.
- // EXPLICIT ACCESS: 'user-2' only has 'view' access.
- // PUBLIC ACCESS: view (parent), edit (grandparent). Max is 'edit'.
- // EXPECTATION: The overall highest level is 'edit' (from public), not 'owner' (from user-1's grant).
-
- let highest_level = get_highest_access_level_for_chat(&pool, "d-child", "user-2").await?;
-
- assert_eq!(
- highest_level,
- Some(AccessLevel::Edit),
- "User-2's highest access should be 'edit' from public, not 'owner' from user-1's explicit grant"
- );
-
- Ok(())
-}
-
-#[sqlx::test(fixtures(path = "../../../fixtures", scripts("highest_access_level_for_chat")))]
-async fn test_simple_uia_case(pool: sqlx::Pool<sqlx::Postgres>) -> anyhow::Result<()> {
- // SCENARIO: User has edit UIA access on private chat
- // EXPECTATION: The user should have edit access to chat
-
- let highest_level = get_highest_access_level_for_chat(&pool, "d-standalone", "user-3").await?;
-
- assert_eq!(
- highest_level,
- Some(AccessLevel::Edit),
- "User-3's highest access should be 'edit' from explicit grant"
- );
-
- Ok(())
-}
-
-#[sqlx::test(fixtures(path = "../../../fixtures", scripts("highest_access_level_for_chat")))]
-async fn test_no_permissions_returns_none(pool: sqlx::Pool<sqlx::Postgres>) -> anyhow::Result<()> {
- // SCENARIO: Get access for any user on 'd-private'.
- // This chat has no project, no UserItemAccess, and no SharePermission records.
- // EXPECTATION: The query should return an empty list, resulting in `None`.
-
- let highest_level = get_highest_access_level_for_chat(&pool, "d-private", "user-1").await?;
-
- assert_eq!(
- highest_level, None,
- "Expected None for a chat with no permissions"
- );
-
- Ok(())
-}
-
-// Tests for the batch function get_highest_access_level_for_chats
-
-#[sqlx::test(fixtures(path = "../../../fixtures", scripts("highest_access_level_for_chat")))]
-async fn test_batch_multiple_chats_different_access_levels(
- pool: sqlx::Pool<sqlx::Postgres>,
-) -> anyhow::Result<()> {
- // SCENARIO: Get access for 'user-1' on multiple chats with different access levels
- let chat_ids = vec![
- "d-child".to_string(),
- "d-standalone".to_string(),
- "d-private".to_string(),
- ];
-
- let access_levels = get_highest_access_level_for_chats(&pool, &chat_ids, "user-1").await?;
-
- // d-child: user-1 has owner access (from explicit grants)
- assert_eq!(
- access_levels.get("d-child"),
- Some(&Some(AccessLevel::Owner)),
- "Expected 'owner' access for d-child"
- );
-
- // d-standalone: Check what user-1 actually has (test shows Comment access)
- // We'll verify consistency with individual function rather than hardcode expectation
- let individual_access =
- get_highest_access_level_for_chat(&pool, "d-standalone", "user-1").await?;
- assert_eq!(
- access_levels.get("d-standalone"),
- Some(&individual_access),
- "Expected batch result to match individual function result for d-standalone"
- );
-
- // d-private: user-1 should have no access (private chat with no permissions)
- assert_eq!(
- access_levels.get("d-private"),
- Some(&None),
- "Expected no access for d-private"
- );
-
- Ok(())
-}
-
#[sqlx::test(fixtures(path = "../../../fixtures", scripts("highest_access_level_for_chat")))]
async fn test_batch_public_access_user(pool: sqlx::Pool<sqlx::Postgres>) -> anyhow::Result<()> {
// SCENARIO: Get access for 'user-public-access-only' on multiple chats
// This user has no explicit grants but should get public access where available
- let chat_ids = vec!["d-child".to_string(), "d-private".to_string()];
+ let chat_ids = vec![
+ "cccccccc-cccc-cccc-cccc-000000000001".to_string(),
+ "cccccccc-cccc-cccc-cccc-000000000003".to_string(),
+ ];
let access_levels =
get_highest_access_level_for_chats(&pool, &chat_ids, "user-public-access-only").await?;
// d-child: public access is edit via grandparent
assert_eq!(
- access_levels.get("d-child"),
+ access_levels.get("cccccccc-cccc-cccc-cccc-000000000001"),
Some(&Some(AccessLevel::Edit)),
"Expected 'edit' access from public permissions"
);
// d-private: no public or explicit access
assert_eq!(
- access_levels.get("d-private"),
+ access_levels.get("cccccccc-cccc-cccc-cccc-000000000003"),
Some(&None),
"Expected no access for d-private"
);
@@ -152,13 +32,13 @@ async fn test_batch_public_access_user(pool: sqlx::Pool<sqlx::Postgres>) -> anyh
#[sqlx::test(fixtures(path = "../../../fixtures", scripts("highest_access_level_for_chat")))]
async fn test_batch_user_with_mixed_access(pool: sqlx::Pool<sqlx::Postgres>) -> anyhow::Result<()> {
// SCENARIO: Get access for 'user-2' who has limited explicit access but benefits from public access
- let chat_ids = vec!["d-child".to_string()];
+ let chat_ids = vec!["cccccccc-cccc-cccc-cccc-000000000001".to_string()];
let access_levels = get_highest_access_level_for_chats(&pool, &chat_ids, "user-2").await?;
// user-2 has view explicit access, but public access is edit, so should get edit
assert_eq!(
- access_levels.get("d-child"),
+ access_levels.get("cccccccc-cccc-cccc-cccc-000000000001"),
Some(&Some(AccessLevel::Edit)),
"Expected 'edit' access from higher public permissions"
);
@@ -202,34 +82,3 @@ async fn test_batch_nonexistent_chats(pool: sqlx::Pool<sqlx::Postgres>) -> anyho
Ok(())
}
-
-#[sqlx::test(fixtures(path = "../../../fixtures", scripts("highest_access_level_for_chat")))]
-async fn test_batch_consistency_with_single_function(
- pool: sqlx::Pool<sqlx::Postgres>,
-) -> anyhow::Result<()> {
- // SCENARIO: Ensure batch function returns same results as individual calls
- let chat_ids = vec!["d-child".to_string(), "d-standalone".to_string()];
- let user_id = "user-1";
-
- // Get results from batch function
- let batch_results = get_highest_access_level_for_chats(&pool, &chat_ids, user_id).await?;
-
- // Get results from individual function calls
- let individual_d_child = get_highest_access_level_for_chat(&pool, "d-child", user_id).await?;
- let individual_d_standalone =
- get_highest_access_level_for_chat(&pool, "d-standalone", user_id).await?;
-
- // Compare results
- assert_eq!(
- batch_results.get("d-child"),
- Some(&individual_d_child),
- "Batch and individual results should match for d-child"
- );
- assert_eq!(
- batch_results.get("d-standalone"),
- Some(&individual_d_standalone),
- "Batch and individual results should match for d-standalone"
- );
-
- Ok(())
-}
diff --git a/rust/cloud-storage/macro_db_client/src/share_permission/access_level/document.rs b/rust/cloud-storage/macro_db_client/src/share_permission/access_level/document.rs
deleted file mode 100644
index 3afcefd88e..0000000000
--- a/rust/cloud-storage/macro_db_client/src/share_permission/access_level/document.rs
+++ /dev/null
@@ -1,195 +0,0 @@
-use models_permissions::share_permission::access_level::AccessLevel;
-use std::str::FromStr;
-
-/// Gets the public access level for a document (no user required).
-///
-/// This function checks only public `SharePermission` records (where `isPublic=true`),
-/// applied either directly to the document or inherited from its project hierarchy.
-/// It does NOT check user-specific `UserItemAccess` records.
-///
-/// Use this for unauthenticated access to publicly shared documents.
-///
-/// # Arguments
-/// * `db` - A reference to the `sqlx` database connection pool.
-/// * `document_id` - The ID of the document to check.
-///
-/// # Returns
-/// A `Result` containing an `Option<AccessLevel>`:
-/// - `Ok(Some(AccessLevel))` if there is public access.
-/// - `Ok(None)` if there is no public access.
-/// - `Err(_)` if a database error occurs.
-#[tracing::instrument(skip(db), err)]
-pub async fn get_public_access_level_for_document(
- db: &sqlx::Pool<sqlx::Postgres>,
- document_id: &str,
-) -> anyhow::Result<Option<AccessLevel>> {
- let public_levels: Vec<Option<String>> = sqlx::query_scalar!(
- r#"
- WITH RECURSIVE project_hierarchy AS (
- SELECT p.id as project_id
- FROM "Document" d
- JOIN "Project" p ON d."projectId" = p.id AND p."deletedAt" IS NULL
- WHERE d.id = $1 AND d."deletedAt" IS NULL
- UNION ALL
- SELECT parent.id as project_id
- FROM project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id
- AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
- )
- )
- SELECT "publicAccessLevel" as access_level
- FROM "SharePermission"
- WHERE "isPublic" = true AND "publicAccessLevel" IS NOT NULL AND id IN (
- SELECT "sharePermissionId" FROM "DocumentPermission" WHERE "documentId" = $1
- UNION
- SELECT "sharePermissionId" FROM "ProjectPermission"
- WHERE "projectId" IN (SELECT project_id FROM project_hierarchy)
- )
- "#,
- document_id
- )
- .fetch_all(db)
- .await?;
-
- let highest_level = public_levels
- .iter()
- .filter_map(|opt| opt.as_ref().and_then(|s| AccessLevel::from_str(s).ok()))
- .max();
-
- Ok(highest_level)
-}
-
-/// Calculates the highest effective access level a user has for a document.
-///
-/// This function determines the best possible permission by considering three sources:
-/// 1. **Explicit Grants**: Any `UserItemAccess` records for the specified user, applied either
-/// directly to the document or inherited from its entire project hierarchy.
-/// 2. **Public Access**: Any `SharePermission` records marked as `isPublic=true`, applied either
-/// directly to the document or inherited from its project hierarchy.
-/// 3. **Email Thread Inheritance**: If the document is an email attachment, the user's access
-/// to the parent email thread is also considered.
-///
-/// It combines all possible access levels from these sources, sorts them from highest (`Owner`)
-/// to lowest (`View`), and returns the single highest level.
-///
-/// # Arguments
-/// * `db` - A reference to the `sqlx` database connection pool.
-/// * `document_id` - The ID of the document to check.
-/// * `user_id` - The ID of the user whose access is being checked.
-///
-/// # Returns
-/// A `Result` containing an `Option<AccessLevel>`:
-/// - `Ok(Some(AccessLevel))` if the user has any level of access.
-/// - `Ok(None)` if the user has no access at all.
-/// - `Err(_)` if a database error occurs.
-#[tracing::instrument(skip(db), err)]
-pub async fn get_highest_access_level_for_document(
- db: &sqlx::Pool<sqlx::Postgres>,
- document_id: &str,
- user_id: &str,
-) -> anyhow::Result<Option<AccessLevel>> {
- // Run the document access query and the email thread lookup concurrently
- let (doc_access_result, thread_id_result) = tokio::join!(
- get_document_direct_access_level(db, document_id, user_id),
- get_parent_thread_id_for_document(db, document_id)
- );
-
- let mut highest_level = doc_access_result?;
-
- // If the document is an email attachment, also check the user's access to the parent thread
- if let Some(thread_id) = thread_id_result? {
- let thread_access =
- super::thread::get_highest_access_level_for_thread(db, &thread_id, user_id).await?;
- highest_level = std::cmp::max(highest_level, thread_access);
- }
-
- Ok(highest_level)
-}
-
-/// Gets the document's direct access level from UserItemAccess and public SharePermissions.
-#[tracing::instrument(skip(db), err)]
-async fn get_document_direct_access_level(
- db: &sqlx::Pool<sqlx::Postgres>,
- document_id: &str,
- user_id: &str,
-) -> anyhow::Result<Option<AccessLevel>> {
- // have to use strings because the SharePermission and UserItemAccess access_level rows use different sql types
- let all_level_strings: Vec<Option<String>> = sqlx::query_scalar!(
- r#"
- WITH RECURSIVE project_hierarchy AS (
- SELECT p.id as project_id
- FROM "Document" d
- JOIN "Project" p ON d."projectId" = p.id AND p."deletedAt" IS NULL
- WHERE d.id = $1 AND d."deletedAt" IS NULL
- UNION ALL
- SELECT parent.id as project_id
- FROM project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
- )
- )
- SELECT access_level FROM (
- -- Source 1: Cast the AccessLevel enum to text.
- SELECT access_level::text FROM "UserItemAccess"
- WHERE user_id = $2 AND item_id IN (
- SELECT $1
- UNION
- SELECT project_id FROM project_hierarchy
- )
- UNION ALL
- -- Source 2: Select the publicAccessLevel (which is already text).
- SELECT "publicAccessLevel" as access_level
- FROM "SharePermission"
- WHERE "isPublic" = true AND "publicAccessLevel" IS NOT NULL AND id IN (
- SELECT "sharePermissionId" FROM "DocumentPermission" WHERE "documentId" = $1
- UNION
- SELECT "sharePermissionId" FROM "ProjectPermission" WHERE "projectId" IN (SELECT project_id FROM project_hierarchy)
- )
- ) as all_levels
- "#,
- document_id,
- user_id
- )
- .fetch_all(db)
- .await?;
-
- let highest_level = all_level_strings
- .iter()
- .filter_map(|optional_string| {
- optional_string
- .as_ref()
- .and_then(|s| AccessLevel::from_str(s).ok())
- })
- .max();
-
- Ok(highest_level)
-}
-
-/// If a document is an email attachment, returns the thread ID it belongs to.
-#[tracing::instrument(skip(db), err)]
-async fn get_parent_thread_id_for_document(
- db: &sqlx::Pool<sqlx::Postgres>,
- document_id: &str,
-) -> anyhow::Result<Option<String>> {
- let result = sqlx::query_scalar!(
- r#"
- SELECT et.id::text as "thread_id!"
- FROM document_email de
- JOIN email_attachments ea ON de.email_attachment_id = ea.id
- JOIN email_messages em ON ea.message_id = em.id
- JOIN email_threads et ON em.thread_id = et.id
- WHERE de.document_id = $1
- LIMIT 1
- "#,
- document_id
- )
- .fetch_optional(db)
- .await?;
-
- Ok(result)
-}
-
-#[cfg(test)]
-#[path = "document_tests.rs"]
-mod tests;
diff --git a/rust/cloud-storage/macro_db_client/src/share_permission/access_level/document_tests.rs b/rust/cloud-storage/macro_db_client/src/share_permission/access_level/document_tests.rs
deleted file mode 100644
index f8e2bddb56..0000000000
--- a/rust/cloud-storage/macro_db_client/src/share_permission/access_level/document_tests.rs
+++ /dev/null
@@ -1,190 +0,0 @@
-use super::*;
-
-#[sqlx::test(fixtures(
- path = "../../../fixtures",
- scripts("highest_access_level_for_document")
-))]
-async fn test_highest_level_is_from_explicit_access(
- pool: sqlx::Pool<sqlx::Postgres>,
-) -> anyhow::Result<()> {
- // SCENARIO: Get highest access for 'user-1' on 'd-child'.
- // EXPLICIT ACCESS: view (direct), edit (parent), owner (grandparent). Max is 'owner'.
- // PUBLIC ACCESS: view (parent), edit (grandparent). Max is 'edit'.
- // EXPECTATION: The overall highest level should be 'owner' from the explicit grant.
-
- let highest_level = get_highest_access_level_for_document(&pool, "d-child", "user-1").await?;
-
- assert_eq!(
- highest_level,
- Some(AccessLevel::Owner),
- "Expected highest level to be 'owner' from an explicit UserItemAccess record"
- );
-
- // highest public access is edit via grandparent
-
- let highest_level =
- get_highest_access_level_for_document(&pool, "d-child", "user-public-access-only").await?;
-
- assert_eq!(
- highest_level,
- Some(AccessLevel::Edit),
- "Expected highest level to be 'edit' from a public SharePermission record"
- );
-
- Ok(())
-}
-
-#[sqlx::test(fixtures(
- path = "../../../fixtures",
- scripts("highest_access_level_for_document")
-))]
-async fn test_user_scoping_is_correct(pool: sqlx::Pool<sqlx::Postgres>) -> anyhow::Result<()> {
- // SCENARIO: Get highest access for 'user-2' on 'd-child'.
- // EXPLICIT ACCESS: 'user-2' only has 'view' access.
- // PUBLIC ACCESS: view (parent), edit (grandparent). Max is 'edit'.
- // EXPECTATION: The overall highest level is 'edit' (from public), not 'owner' (from user-1's grant).
-
- let highest_level = get_highest_access_level_for_document(&pool, "d-child", "user-2").await?;
-
- assert_eq!(
- highest_level,
- Some(AccessLevel::Edit),
- "User-2's highest access should be 'edit' from public, not 'owner' from user-1's explicit grant"
- );
-
- Ok(())
-}
-
-#[sqlx::test(fixtures(
- path = "../../../fixtures",
- scripts("highest_access_level_for_document")
-))]
-async fn test_simple_uia_case(pool: sqlx::Pool<sqlx::Postgres>) -> anyhow::Result<()> {
- // SCENARIO: User has edit UIA access on private document
- // EXPECTATION: The user should have edit access to document
-
- let highest_level =
- get_highest_access_level_for_document(&pool, "d-standalone", "user-3").await?;
-
- assert_eq!(
- highest_level,
- Some(AccessLevel::Edit),
- "User-3's highest access should be 'edit' from explicit grant"
- );
-
- Ok(())
-}
-
-#[sqlx::test(fixtures(
- path = "../../../fixtures",
- scripts("highest_access_level_for_document")
-))]
-async fn test_no_permissions_returns_none(pool: sqlx::Pool<sqlx::Postgres>) -> anyhow::Result<()> {
- // SCENARIO: Get access for any user on 'd-private'.
- // This document has no project, no UserItemAccess, and no SharePermission records.
- // EXPECTATION: The query should return an empty list, resulting in `None`.
-
- let highest_level = get_highest_access_level_for_document(&pool, "d-private", "user-1").await?;
-
- assert_eq!(
- highest_level, None,
- "Expected None for a document with no permissions"
- );
-
- Ok(())
-}
-
-// --- Email thread inheritance tests ---
-
-#[sqlx::test(fixtures(
- path = "../../../fixtures",
- scripts("document_access_via_email_thread")
-))]
-async fn test_thread_access_grants_document_access(
- pool: sqlx::Pool<sqlx::Postgres>,
-) -> anyhow::Result<()> {
- // SCENARIO: user-thread-access has 'view' on the email thread but no direct document access.
- // The document is an email attachment of that thread.
- // EXPECTATION: The user should get 'view' access to the document via thread inheritance.
-
- let highest_level =
- get_highest_access_level_for_document(&pool, "d-attachment", "user-thread-access").await?;
-
- assert_eq!(
- highest_level,
- Some(AccessLevel::View),
- "User should get 'view' access to the attachment document via thread access"
- );
-
- Ok(())
-}
-
-#[sqlx::test(fixtures(
- path = "../../../fixtures",
- scripts("document_access_via_email_thread")
-))]
-async fn test_no_thread_access_means_no_document_access(
- pool: sqlx::Pool<sqlx::Postgres>,
-) -> anyhow::Result<()> {
- // SCENARIO: user-no-access has no access to the thread or the document.
- // EXPECTATION: Should return None.
-
- let highest_level =
- get_highest_access_level_for_document(&pool, "d-attachment", "user-no-access").await?;
-
- assert_eq!(
- highest_level, None,
- "User with no thread access should have no access to the attachment document"
- );
-
- Ok(())
-}
-
-#[sqlx::test(fixtures(
- path = "../../../fixtures",
- scripts("document_access_via_email_thread")
-))]
-async fn test_thread_access_combined_with_direct_access(
- pool: sqlx::Pool<sqlx::Postgres>,
-) -> anyhow::Result<()> {
- // SCENARIO: user-both-access has direct 'view' on the document AND 'edit' on the thread.
- // EXPECTATION: The highest level should be 'edit' from the thread, not 'view' from direct.
-
- let highest_level = get_highest_access_level_for_document(
- &pool,
- "d-attachment-with-direct",
- "user-both-access",
- )
- .await?;
-
- assert_eq!(
- highest_level,
- Some(AccessLevel::Edit),
- "Thread access ('edit') should be higher than direct document access ('view')"
- );
-
- Ok(())
-}
-
-#[sqlx::test(fixtures(
- path = "../../../fixtures",
- scripts("document_access_via_email_thread")
-))]
-async fn test_non_attachment_document_unaffected(
- pool: sqlx::Pool<sqlx::Postgres>,
-) -> anyhow::Result<()> {
- // SCENARIO: d-not-attachment is a regular document not linked to any email.
- // No user has any permissions on it.
- // EXPECTATION: Thread inheritance should not apply; result should be None.
-
- let highest_level =
- get_highest_access_level_for_document(&pool, "d-not-attachment", "user-thread-access")
- .await?;
-
- assert_eq!(
- highest_level, None,
- "Non-attachment documents should not get access from thread permissions"
- );
-
- Ok(())
-}
diff --git a/rust/cloud-storage/macro_db_client/src/share_permission/access_level/mod.rs b/rust/cloud-storage/macro_db_client/src/share_permission/access_level/mod.rs
index d3bc9f41d0..30a62fc508 100644
--- a/rust/cloud-storage/macro_db_client/src/share_permission/access_level/mod.rs
+++ b/rust/cloud-storage/macro_db_client/src/share_permission/access_level/mod.rs
@@ -1,4 +1 @@
pub mod chat;
-pub mod document;
-pub mod project;
-pub mod thread;
diff --git a/rust/cloud-storage/macro_db_client/src/share_permission/access_level/project.rs b/rust/cloud-storage/macro_db_client/src/share_permission/access_level/project.rs
deleted file mode 100644
index ba4c12a406..0000000000
--- a/rust/cloud-storage/macro_db_client/src/share_permission/access_level/project.rs
+++ /dev/null
@@ -1,145 +0,0 @@
-use models_permissions::share_permission::access_level::AccessLevel;
-use std::str::FromStr;
-
-/// Gets the public access level for a project (no user required).
-///
-/// This function checks only public `SharePermission` records (where `isPublic=true`),
-/// applied either directly to the project or inherited from its parent hierarchy.
-/// It does NOT check user-specific `UserItemAccess` records.
-///
-/// Use this for unauthenticated access to publicly shared projects.
-///
-/// # Arguments
-/// * `db` - A reference to the `sqlx` database connection pool.
-/// * `project_id` - The ID of the project to check.
-///
-/// # Returns
-/// A `Result` containing an `Option<AccessLevel>`:
-/// - `Ok(Some(AccessLevel))` if there is public access.
-/// - `Ok(None)` if there is no public access.
-/// - `Err(_)` if a database error occurs.
-#[tracing::instrument(skip(db), err)]
-pub async fn get_public_access_level_for_project(
- db: &sqlx::Pool<sqlx::Postgres>,
- project_id: &str,
-) -> anyhow::Result<Option<AccessLevel>> {
- let public_levels: Vec<Option<String>> = sqlx::query_scalar!(
- r#"
- WITH RECURSIVE project_hierarchy AS (
- SELECT id as project_id
- FROM "Project"
- WHERE id = $1 AND "deletedAt" IS NULL
- UNION ALL
- SELECT parent.id as project_id
- FROM project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id
- AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
- )
- )
- SELECT "publicAccessLevel" as access_level
- FROM "SharePermission"
- WHERE "isPublic" = true AND "publicAccessLevel" IS NOT NULL AND id IN (
- SELECT "sharePermissionId" FROM "ProjectPermission"
- WHERE "projectId" IN (SELECT project_id FROM project_hierarchy)
- )
- "#,
- project_id
- )
- .fetch_all(db)
- .await?;
-
- let highest_level = public_levels
- .iter()
- .filter_map(|opt| opt.as_ref().and_then(|s| AccessLevel::from_str(s).ok()))
- .max();
-
- Ok(highest_level)
-}
-
-/// Calculates the highest effective access level a user has for a project.
-///
-/// This function determines the best possible permission by considering two sources:
-/// 1. **Explicit Grants**: Any `UserItemAccess` records for the specified user, applied either
-/// directly to the project or inherited from its entire project hierarchy.
-/// 2. **Public Access**: Any `SharePermission` records marked as `isPublic=true`, applied either
-/// directly to the project or inherited from its project hierarchy.
-///
-/// It combines all possible access levels from these sources, sorts them from highest (`Owner`)
-/// to lowest (`View`), and returns the single highest level.
-///
-/// # Arguments
-/// * `db` - A reference to the `sqlx` database connection pool.
-/// * `project_id` - The ID of the project to check.
-/// * `user_id` - The ID of the user whose access is being checked.
-///
-/// # Returns
-/// A `Result` containing an `Option<AccessLevel>`:
-/// - `Ok(Some(AccessLevel))` if the user has any level of access.
-/// - `Ok(None)` if the user has no access at all.
-/// - `Err(_)` if a database error occurs.
-#[tracing::instrument(skip(db), err)]
-pub async fn get_highest_access_level_for_project(
- db: &sqlx::Pool<sqlx::Postgres>,
- project_id: &str,
- user_id: &str,
-) -> anyhow::Result<Option<AccessLevel>> {
- // have to use strings because the SharePermission and UserItemAccess access_level rows use different sql types
- let all_level_strings: Vec<Option<String>> = sqlx::query_scalar!(
- r#"
- -- CTE to recursively find all parent projects, starting from the given project.
- WITH RECURSIVE project_hierarchy AS (
- -- Base case: Start with the project ID provided.
- SELECT id as project_id
- FROM "Project"
- WHERE id = $1 AND "deletedAt" IS NULL
- UNION ALL
- -- Recursive case: Find the parent of the project from the previous step.
- SELECT parent.id as project_id
- FROM project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
- )
- )
- -- The subquery now gathers all levels as plain text.
- SELECT access_level FROM (
- -- Source 1: Cast the AccessLevel enum to text.
- SELECT access_level::text FROM "UserItemAccess"
- WHERE user_id = $2 AND item_id IN (
- -- The hierarchy CTE includes the starting project, so this is all we need.
- SELECT project_id FROM project_hierarchy
- )
- UNION ALL
- -- Source 2: Select the publicAccessLevel (which is already text).
- SELECT "publicAccessLevel" as access_level
- FROM "SharePermission"
- WHERE "isPublic" = true AND "publicAccessLevel" IS NOT NULL AND id IN (
- -- We only need to check ProjectPermission for the items in the hierarchy.
- SELECT "sharePermissionId" FROM "ProjectPermission"
- WHERE "projectId" IN (SELECT project_id FROM project_hierarchy)
- )
- ) as all_levels
- "#,
- project_id,
- user_id
- )
- .fetch_all(db)
- .await?;
-
- let highest_level = all_level_strings
- .iter()
- .filter_map(|optional_string| {
- // `optional_string` is &Option<String>.
- // We use `and_then` to proceed only if it's Some.
- optional_string
- .as_ref()
- .and_then(|s| AccessLevel::from_str(s).ok())
- })
- .max();
-
- Ok(highest_level)
-}
-
-#[cfg(test)]
-#[path = "project_tests.rs"]
-mod tests;
diff --git a/rust/cloud-storage/macro_db_client/src/share_permission/access_level/project_tests.rs b/rust/cloud-storage/macro_db_client/src/share_permission/access_level/project_tests.rs
deleted file mode 100644
index 371f37d28c..0000000000
--- a/rust/cloud-storage/macro_db_client/src/share_permission/access_level/project_tests.rs
+++ /dev/null
@@ -1,121 +0,0 @@
-use super::*;
-
-#[sqlx::test(fixtures(
- path = "../../../fixtures",
- scripts("highest_access_level_for_project")
-))]
-async fn test_highest_level_is_from_explicit_access_on_project(
- pool: sqlx::Pool<sqlx::Postgres>,
-) -> anyhow::Result<()> {
- // SCENARIO: Get highest access for 'user-1' on 'p-child'.
- // EXPLICIT ACCESS: view (direct on p-child), owner (inherited from p-grandparent). Max is 'owner'.
- // PUBLIC ACCESS: view (from p-parent), edit (from p-grandparent). Max is 'edit'.
- // EXPECTATION: The overall highest level should be 'owner' from the explicit grant on the grandparent.
-
- let highest_level = get_highest_access_level_for_project(&pool, "p-child", "user-1").await?;
-
- assert_eq!(
- highest_level,
- Some(AccessLevel::Owner),
- "Expected highest level to be 'owner' from an inherited UserItemAccess record"
- );
-
- Ok(())
-}
-
-#[sqlx::test(fixtures(
- path = "../../../fixtures",
- scripts("highest_access_level_for_project")
-))]
-async fn test_highest_level_is_from_public_access_on_project(
- pool: sqlx::Pool<sqlx::Postgres>,
-) -> anyhow::Result<()> {
- // SCENARIO: Get highest access for 'user-public-access-only' on 'p-child'.
- // This user has no explicit access grants.
- // PUBLIC ACCESS: view (from p-parent), edit (from p-grandparent). Max is 'edit'.
- // EXPECTATION: The overall highest level must be 'edit' from a public SharePermission.
-
- let highest_level =
- get_highest_access_level_for_project(&pool, "p-child", "user-public-access-only").await?;
-
- assert_eq!(
- highest_level,
- Some(AccessLevel::Edit),
- "Expected highest level to be 'edit' from a public SharePermission record"
- );
-
- Ok(())
-}
-
-#[sqlx::test(fixtures(
- path = "../../../fixtures",
- scripts("highest_access_level_for_project")
-))]
-async fn test_user_scoping_is_correct_on_project(
- pool: sqlx::Pool<sqlx::Postgres>,
-) -> anyhow::Result<()> {
- // SCENARIO: Get highest access for 'user-2' on 'p-child'.
- // EXPLICIT ACCESS: 'user-2' has 'comment' access inherited from p-parent.
- // PUBLIC ACCESS: view (from p-parent), edit (from p-grandparent). Max is 'edit'.
- // EXPECTATION: The overall highest level is 'edit' (from public), which is higher than
- // the user's explicit 'comment' grant.
-
- let highest_level = get_highest_access_level_for_project(&pool, "p-child", "user-2").await?;
-
- assert_eq!(
- highest_level,
- Some(AccessLevel::Edit),
- "User-2's highest access should be 'edit' from public, which is higher than their explicit 'comment' grant"
- );
-
- Ok(())
-}
-
-#[sqlx::test(fixtures(
- path = "../../../fixtures",
- scripts("highest_access_level_for_project")
-))]
-async fn test_private_share_permissions_are_ignored_on_project(
- pool: sqlx::Pool<sqlx::Postgres>,
-) -> anyhow::Result<()> {
- // SCENARIO: A private 'owner' SharePermission is attached directly to 'p-child'.
- // Get access for a user who would otherwise only have public access.
- // EXPECTATION: The private permission must be ignored.
-
- let highest_level =
- get_highest_access_level_for_project(&pool, "p-child", "user-public-access-only").await?;
-
- assert_ne!(
- highest_level,
- Some(AccessLevel::Owner),
- "A private SharePermission should not grant owner access"
- );
- assert_eq!(
- highest_level,
- Some(AccessLevel::Edit),
- "The highest access should still come from the public grandparent permission"
- );
-
- Ok(())
-}
-
-#[sqlx::test(fixtures(
- path = "../../../fixtures",
- scripts("highest_access_level_for_project")
-))]
-async fn test_no_permissions_returns_none_for_project(
- pool: sqlx::Pool<sqlx::Postgres>,
-) -> anyhow::Result<()> {
- // SCENARIO: Get access for any user on 'p-isolated'.
- // This project has no permissions of any kind for user-1 and no public access.
- // EXPECTATION: The query should return an empty list, resulting in `None`.
-
- let highest_level = get_highest_access_level_for_project(&pool, "p-isolated", "user-1").await?;
-
- assert_eq!(
- highest_level, None,
- "Expected None for a project with no permissions for the user"
- );
-
- Ok(())
-}
diff --git a/rust/cloud-storage/macro_db_client/src/share_permission/access_level/thread.rs b/rust/cloud-storage/macro_db_client/src/share_permission/access_level/thread.rs
deleted file mode 100644
index ca364bb6ba..0000000000
--- a/rust/cloud-storage/macro_db_client/src/share_permission/access_level/thread.rs
+++ /dev/null
@@ -1,155 +0,0 @@
-use models_permissions::share_permission::access_level::AccessLevel;
-use std::str::FromStr;
-
-/// Gets the public access level for a thread (no user required).
-///
-/// This function checks only public `SharePermission` records (where `isPublic=true`),
-/// applied either directly to the thread or inherited from its project hierarchy.
-/// It does NOT check user-specific `UserItemAccess` records.
-///
-/// Use this for unauthenticated access to publicly shared threads.
-///
-/// # Arguments
-/// * `db` - A reference to the `sqlx` database connection pool.
-/// * `thread_id` - The ID of the thread to check.
-///
-/// # Returns
-/// A `Result` containing an `Option<AccessLevel>`:
-/// - `Ok(Some(AccessLevel))` if there is public access.
-/// - `Ok(None)` if there is no public access.
-/// - `Err(_)` if a database error occurs.
-#[tracing::instrument(skip(db), err)]
-pub async fn get_public_access_level_for_thread(
- db: &sqlx::Pool<sqlx::Postgres>,
- thread_id: &str,
-) -> anyhow::Result<Option<AccessLevel>> {
- let public_levels: Vec<Option<String>> = sqlx::query_scalar!(
- r#"
- WITH RECURSIVE project_hierarchy AS (
- SELECT p.id as project_id
- FROM "EmailThreadPermission" etp
- JOIN "Project" p ON etp."projectId" = p.id AND p."deletedAt" IS NULL
- WHERE etp."threadId" = $1
- UNION ALL
- SELECT parent.id as project_id
- FROM project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id
- AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
- )
- )
- SELECT "publicAccessLevel" as access_level
- FROM "SharePermission"
- WHERE "isPublic" = true AND "publicAccessLevel" IS NOT NULL AND id IN (
- SELECT "sharePermissionId" FROM "EmailThreadPermission" WHERE "threadId" = $1
- UNION
- SELECT "sharePermissionId" FROM "ProjectPermission"
- WHERE "projectId" IN (SELECT project_id FROM project_hierarchy)
- )
- "#,
- thread_id
- )
- .fetch_all(db)
- .await?;
-
- let highest_level = public_levels
- .iter()
- .filter_map(|opt| opt.as_ref().and_then(|s| AccessLevel::from_str(s).ok()))
- .max();
-
- Ok(highest_level)
-}
-
-/// Calculates the highest effective access level a user has for a thread.
-///
-/// This function determines the best possible permission by considering two sources:
-/// 1. **Explicit Grants**: Any `UserItemAccess` records for the specified user, applied either
-/// directly to the thread or inherited from its entire project hierarchy.
-/// 2. **Public Access**: Any `SharePermission` records marked as `isPublic=true`, applied either
-/// directly to the thread or inherited from its project hierarchy.
-///
-/// It combines all possible access levels from these sources, sorts them from highest (`Owner`)
-/// to lowest (`View`), and returns the single highest level.
-///
-/// # Arguments
-/// * `db` - A reference to the `sqlx` database connection pool.
-/// * `thread_id` - The ID of the thread to check.
-/// * `user_id` - The ID of the user whose access is being checked.
-///
-/// # Returns
-/// A `Result` containing an `Option<AccessLevel>`:
-/// - `Ok(Some(AccessLevel))` if the user has any level of access.
-/// - `Ok(None)` if the user has no access at all.
-/// - `Err(_)` if a database error occurs.
-#[tracing::instrument(skip(db), err)]
-pub async fn get_highest_access_level_for_thread(
- db: &sqlx::Pool<sqlx::Postgres>,
- thread_id: &str,
- user_id: &str,
-) -> anyhow::Result<Option<AccessLevel>> {
- // have to use strings because the SharePermission and UserItemAccess access_level rows use different sql types
- let all_level_strings: Vec<Option<String>> = sqlx::query_scalar!(
- r#"
- -- CTE to recursively find all parent projects for the given email thread.
- WITH RECURSIVE project_hierarchy AS (
- -- Base case: Start with the project directly associated with the thread.
- SELECT
- p.id as project_id
- FROM
- "EmailThreadPermission" etp
- JOIN "Project" p ON etp."projectId" = p.id AND p."deletedAt" IS NULL
- WHERE
- etp."threadId" = $1
- UNION ALL
- -- Recursive case: Find the parent of the project from the previous step.
- SELECT
- parent.id as project_id
- FROM
- project_hierarchy ph
- JOIN "Project" parent ON parent.id = (
- SELECT "parentId" FROM "Project" WHERE id = ph.project_id AND "parentId" IS NOT NULL AND "deletedAt" IS NULL
- )
- )
- -- The subquery now gathers all levels as plain text.
- SELECT access_level FROM (
- -- Source 1: Cast the AccessLevel enum to text.
- SELECT access_level::text FROM "UserItemAccess"
- WHERE user_id = $2 AND item_id IN (
- SELECT $1 -- The thread ID itself
- UNION
- SELECT project_id FROM project_hierarchy -- All parent projects
- )
- UNION ALL
- -- Source 2: Select the publicAccessLevel (which is already text).
- SELECT "publicAccessLevel" as access_level
- FROM "SharePermission"
- WHERE "isPublic" = true AND "publicAccessLevel" IS NOT NULL AND id IN (
- SELECT "sharePermissionId" FROM "EmailThreadPermission" WHERE "threadId" = $1
- UNION
- SELECT "sharePermissionId" FROM "ProjectPermission" WHERE "projectId" IN (SELECT project_id FROM project_hierarchy)
- )
- ) as all_levels
- "#,
- thread_id,
- user_id
- )
- .fetch_all(db)
- .await?;
-
- let highest_level = all_level_strings
- .iter()
- .filter_map(|optional_string| {
- // `optional_string` is &Option<String>.
- // We use `and_then` to proceed only if it's Some.
- optional_string
- .as_ref()
- .and_then(|s| AccessLevel::from_str(s).ok())
- })
- .max();
-
- Ok(highest_level)
-}
-
-#[cfg(test)]
-#[path = "thread_tests.rs"]
-mod tests;
diff --git a/rust/cloud-storage/macro_db_client/src/share_permission/access_level/thread_tests.rs b/rust/cloud-storage/macro_db_client/src/share_permission/access_level/thread_tests.rs
deleted file mode 100644
index 4e98c6e073..0000000000
--- a/rust/cloud-storage/macro_db_client/src/share_permission/access_level/thread_tests.rs
+++ /dev/null
@@ -1,111 +0,0 @@
-use super::*;
-
-#[sqlx::test(fixtures(path = "../../../fixtures", scripts("highest_access_level_for_thread")))]
-async fn test_highest_level_is_from_explicit_access_on_thread(
- pool: sqlx::Pool<sqlx::Postgres>,
-) -> anyhow::Result<()> {
- // SCENARIO: Get highest access for 'user-1' on 'thread-nested'.
- // EXPLICIT ACCESS: view (direct), owner (inherited from p-grandparent). Max is 'owner'.
- // PUBLIC ACCESS: view (from p-parent), edit (from p-grandparent). Max is 'edit'.
- // EXPECTATION: The overall highest level should be 'owner' from the explicit grant.
-
- let highest_level =
- get_highest_access_level_for_thread(&pool, "thread-nested", "user-1").await?;
-
- assert_eq!(
- highest_level,
- Some(AccessLevel::Owner),
- "Expected highest level to be 'owner' from an inherited UserItemAccess record"
- );
-
- Ok(())
-}
-
-#[sqlx::test(fixtures(path = "../../../fixtures", scripts("highest_access_level_for_thread")))]
-async fn test_highest_level_is_from_public_access_on_thread(
- pool: sqlx::Pool<sqlx::Postgres>,
-) -> anyhow::Result<()> {
- // SCENARIO: Get highest access for 'user-public-access-only' on 'thread-nested'.
- // This user has no explicit access grants.
- // PUBLIC ACCESS: view (from p-parent), edit (from p-grandparent). Max is 'edit'.
- // EXPECTATION: The overall highest level must be 'edit' from a public SharePermission.
-
- let highest_level =
- get_highest_access_level_for_thread(&pool, "thread-nested", "user-public-access-only")
- .await?;
-
- assert_eq!(
- highest_level,
- Some(AccessLevel::Edit),
- "Expected highest level to be 'edit' from a public SharePermission record"
- );
-
- Ok(())
-}
-
-#[sqlx::test(fixtures(path = "../../../fixtures", scripts("highest_access_level_for_thread")))]
-async fn test_user_scoping_is_correct_on_thread(
- pool: sqlx::Pool<sqlx::Postgres>,
-) -> anyhow::Result<()> {
- // SCENARIO: Get highest access for 'user-2' on 'thread-nested'.
- // EXPLICIT ACCESS: 'user-2' has 'comment' access inherited from p-parent.
- // PUBLIC ACCESS: view (from p-parent), edit (from p-grandparent). Max is 'edit'.
- // EXPECTATION: The overall highest level is 'edit' (from public), which is higher than
- // the user's explicit 'comment' grant.
-
- let highest_level =
- get_highest_access_level_for_thread(&pool, "thread-nested", "user-2").await?;
-
- assert_eq!(
- highest_level,
- Some(AccessLevel::Edit),
- "User-2's highest access should be 'edit' from public, which is higher than their explicit 'comment' grant"
- );
-
- Ok(())
-}
-
-#[sqlx::test(fixtures(path = "../../../fixtures", scripts("highest_access_level_for_thread")))]
-async fn test_private_share_permissions_are_ignored_on_thread(
- pool: sqlx::Pool<sqlx::Postgres>,
-) -> anyhow::Result<()> {
- // SCENARIO: A private 'owner' SharePermission is attached directly to 'thread-nested'.
- // Get access for a user who would otherwise only have public access.
- // EXPECTATION: The private permission must be ignored.
-
- let highest_level =
- get_highest_access_level_for_thread(&pool, "thread-nested", "user-public-access-only")
- .await?;
-
- assert_ne!(
- highest_level,
- Some(AccessLevel::Owner),
- "A private SharePermission should not grant owner access"
- );
- assert_eq!(
- highest_level,
- Some(AccessLevel::Edit),
- "The highest access should still come from the public grandparent permission"
- );
-
- Ok(())
-}
-
-#[sqlx::test(fixtures(path = "../../../fixtures", scripts("highest_access_level_for_thread")))]
-async fn test_no_permissions_returns_none_for_thread(
- pool: sqlx::Pool<sqlx::Postgres>,
-) -> anyhow::Result<()> {
- // SCENARIO: Get access for any user on 'thread-private'.
- // This thread has no project and no other permissions attached.
- // EXPECTATION: The query should return an empty list, resulting in `None`.
-
- let highest_level =
- get_highest_access_level_for_thread(&pool, "thread-private", "user-1").await?;
-
- assert_eq!(
- highest_level, None,
- "Expected None for a thread with no permissions for the user"
- );
-
- Ok(())
-}
diff --git a/rust/cloud-storage/macro_db_client/src/share_permission/edit.rs b/rust/cloud-storage/macro_db_client/src/share_permission/edit.rs
index ca36a8451b..763853f34c 100644
--- a/rust/cloud-storage/macro_db_client/src/share_permission/edit.rs
+++ b/rust/cloud-storage/macro_db_client/src/share_permission/edit.rs
@@ -1,4 +1,5 @@
use crate::Parameters;
+use model_entity::EntityType;
use models_permissions::share_permission::UpdateSharePermissionRequestV2;
use sqlx::{Postgres, Transaction};
@@ -7,6 +8,8 @@ use super::channel_permission::edit::edit_channel_share_permission;
#[tracing::instrument(skip(transaction))]
pub async fn edit_share_permission(
transaction: &mut Transaction<'_, Postgres>,
+ entity_id: &uuid::Uuid,
+ entity_type: EntityType,
share_permission_id: &str,
share_permission: &UpdateSharePermissionRequestV2,
) -> anyhow::Result<()> {
@@ -77,31 +80,34 @@ pub async fn edit_share_permission(
if let Some(channel_share_permissions) = share_permission.channel_share_permissions.as_ref() {
edit_channel_share_permission(transaction, share_permission_id, channel_share_permissions)
.await?;
+
+ entity_access_db_utils::update_entity_access_channel_share_permissions(
+ transaction,
+ entity_id,
+ entity_type,
+ channel_share_permissions,
+ )
+ .await?;
}
Ok(())
}
#[tracing::instrument(skip(transaction))]
-pub async fn edit_document_permission(
+pub async fn edit_thread_permission(
transaction: &mut Transaction<'_, Postgres>,
- document_id: &str,
+ thread_id: &uuid::Uuid,
+ share_permission_id: &str,
share_permission: &UpdateSharePermissionRequestV2,
) -> anyhow::Result<()> {
- let share_id: String = sqlx::query!(
- r#"
- SELECT
- dp."sharePermissionId" as share_permission_id
- FROM "DocumentPermission" dp
- WHERE dp."documentId" = $1
- "#,
- document_id
+ edit_share_permission(
+ transaction,
+ thread_id,
+ EntityType::EmailThread,
+ share_permission_id,
+ share_permission,
)
- .map(|row| row.share_permission_id)
- .fetch_one(transaction.as_mut())
- .await?;
-
- edit_share_permission(transaction, &share_id, share_permission).await
+ .await
}
#[tracing::instrument(skip(transaction))]
@@ -123,182 +129,12 @@ pub async fn edit_project_permission(
.fetch_one(transaction.as_mut())
.await?;
- edit_share_permission(transaction, &share_id, share_permission).await
-}
-
-#[tracing::instrument(skip(transaction))]
-pub async fn edit_chat_permission(
- transaction: &mut Transaction<'_, Postgres>,
- chat_id: &str,
- share_permission: &UpdateSharePermissionRequestV2,
-) -> anyhow::Result<()> {
- let share_id: String = sqlx::query!(
- r#"
- SELECT
- cp."sharePermissionId" as share_permission_id
- FROM "ChatPermission" cp
- WHERE cp."chatId" = $1
- "#,
- chat_id
+ edit_share_permission(
+ transaction,
+ &macro_uuid::string_to_uuid(project_id).unwrap(),
+ EntityType::Project,
+ &share_id,
+ share_permission,
)
- .map(|row| row.share_permission_id)
- .fetch_one(transaction.as_mut())
- .await?;
-
- edit_share_permission(transaction, &share_id, share_permission).await
-}
-
-#[tracing::instrument(skip(transaction))]
-pub async fn edit_thread_permission(
- transaction: &mut Transaction<'_, Postgres>,
- share_permission: &UpdateSharePermissionRequestV2,
- share_permission_id: &str,
-) -> anyhow::Result<()> {
- // at this time the share permission of a thread can't be updated. threads cannot be public.
- // only the channel share permissions within can be modified.
-
- if let Some(channel_share_permissions) = &share_permission.channel_share_permissions {
- edit_channel_share_permission(transaction, share_permission_id, channel_share_permissions)
- .await?;
- }
- Ok(())
-}
-
-#[cfg(test)]
-mod tests {
- use models_permissions::share_permission::channel_share_permission::{
- ChannelSharePermission, UpdateChannelSharePermission, UpdateOperation,
- };
-
- use super::*;
- use models_permissions::share_permission::access_level::AccessLevel;
- use sqlx::{Pool, Postgres};
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("document_permissions")))]
- async fn test_edit_document_permission(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let mut transaction = pool.begin().await?;
- let share_permission = UpdateSharePermissionRequestV2 {
- is_public: None,
- public_access_level: Some(AccessLevel::Edit),
- channel_share_permissions: None,
- };
-
- edit_document_permission(&mut transaction, "document-one", &share_permission).await?;
-
- let result = sqlx::query!(
- r#"
- SELECT
- sp.id as id,
- sp."isPublic" as is_public,
- sp."publicAccessLevel" as "public_access_level?"
- FROM
- "SharePermission" sp
- WHERE
- sp.id = $1
- "#,
- "sp-1"
- )
- .fetch_one(&mut *transaction)
- .await?;
-
- assert!(result.is_public);
- assert_eq!(result.public_access_level, Some("edit".to_string()));
-
- let share_permission = UpdateSharePermissionRequestV2 {
- is_public: Some(false),
- public_access_level: None,
- channel_share_permissions: None,
- };
- edit_document_permission(&mut transaction, "document-one", &share_permission).await?;
- let result = sqlx::query!(
- r#"
- SELECT
- sp.id as id,
- sp."isPublic" as is_public,
- sp."publicAccessLevel" as "public_access_level?"
- FROM
- "SharePermission" sp
- WHERE
- sp.id = $1
- "#,
- "sp-1"
- )
- .fetch_one(&mut *transaction)
- .await?;
-
- assert!(!result.is_public);
- assert!(result.public_access_level.is_none());
-
- transaction.commit().await?;
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("document_permissions")))]
- async fn test_edit_document_permission_document_channel_updates(
- pool: Pool<Postgres>,
- ) -> anyhow::Result<()> {
- let mut transaction = pool.begin().await?;
- let share_permission = UpdateSharePermissionRequestV2 {
- is_public: None,
- public_access_level: None,
- channel_share_permissions: Some(vec![
- // Add new
- UpdateChannelSharePermission {
- channel_id: "channel-three".to_string(),
- access_level: Some(AccessLevel::Edit),
- operation: UpdateOperation::Add,
- },
- // Replace existing
- UpdateChannelSharePermission {
- channel_id: "channel-one".to_string(),
- access_level: Some(AccessLevel::Owner),
- operation: UpdateOperation::Replace,
- },
- // Remove existing
- UpdateChannelSharePermission {
- channel_id: "channel-two".to_string(),
- access_level: None,
- operation: UpdateOperation::Remove,
- },
- ]),
- };
- edit_document_permission(&mut transaction, "document-one", &share_permission).await?;
- transaction.commit().await?;
-
- let channel_share_permissions: Vec<ChannelSharePermission> = sqlx::query_as!(
- ChannelSharePermission,
- r#"
- SELECT
- csp."channel_id",
- csp."access_level" as "access_level:AccessLevel"
- FROM
- "ChannelSharePermission" csp
- WHERE
- csp."share_permission_id" = $1
- ORDER BY
- csp."channel_id"
- "#,
- "sp-1"
- )
- .fetch_all(&pool)
- .await?;
-
- assert_eq!(channel_share_permissions.len(), 2);
- assert_eq!(
- channel_share_permissions[0].channel_id,
- "channel-one".to_string()
- );
- assert_eq!(
- channel_share_permissions[0].access_level,
- AccessLevel::Owner
- );
- assert_eq!(
- channel_share_permissions[1].channel_id,
- "channel-three".to_string()
- );
- assert_eq!(channel_share_permissions[1].access_level, AccessLevel::Edit);
-
- Ok(())
- }
+ .await
}
diff --git a/rust/cloud-storage/macro_db_client/src/share_permission/get.rs b/rust/cloud-storage/macro_db_client/src/share_permission/get.rs
index 1ab9676d69..65258d2205 100644
--- a/rust/cloud-storage/macro_db_client/src/share_permission/get.rs
+++ b/rust/cloud-storage/macro_db_client/src/share_permission/get.rs
@@ -80,6 +80,22 @@ pub async fn get_share_permission_id(
.await?
.id
}
+ "call" => {
+ sqlx::query_scalar!(
+ r#"
+ SELECT share_permission_id as "share_permission_id!"
+ FROM (
+ SELECT share_permission_id FROM calls WHERE id = $1
+ UNION ALL
+ SELECT share_permission_id FROM call_records WHERE id = $1
+ ) t
+ LIMIT 1
+ "#,
+ macro_uuid::string_to_uuid(item_id).unwrap(),
+ )
+ .fetch_one(db)
+ .await?
+ }
_ => {
anyhow::bail!("unsupported item type {item_type}");
}
diff --git a/rust/cloud-storage/macro_db_client/src/user/delete_user_dss_items/delete_chats.rs b/rust/cloud-storage/macro_db_client/src/user/delete_user_dss_items/delete_chats.rs
index 253af1078d..12306ecb22 100644
--- a/rust/cloud-storage/macro_db_client/src/user/delete_user_dss_items/delete_chats.rs
+++ b/rust/cloud-storage/macro_db_client/src/user/delete_user_dss_items/delete_chats.rs
@@ -1,3 +1,5 @@
+use model_entity::EntityType;
+
/// Deletes all chats for a user
/// Does not commit the transaction
#[tracing::instrument(skip(transaction))]
@@ -52,8 +54,15 @@ pub async fn delete_user_chats(
.execute(transaction.as_mut())
.await?;
- crate::item_access::delete::delete_user_item_access_bulk(transaction, &user_chats, "chat")
- .await?;
+ crate::item_access::delete::delete_user_entity_access_bulk(
+ transaction,
+ &user_chats
+ .iter()
+ .filter_map(|p| macro_uuid::string_to_uuid(p).ok())
+ .collect::<Vec<uuid::Uuid>>(),
+ EntityType::Chat,
+ )
+ .await?;
// Delete chats
sqlx::query!(
diff --git a/rust/cloud-storage/macro_db_client/src/user/delete_user_dss_items/delete_projects.rs b/rust/cloud-storage/macro_db_client/src/user/delete_user_dss_items/delete_projects.rs
index 241cfd20db..ea62dcd963 100644
--- a/rust/cloud-storage/macro_db_client/src/user/delete_user_dss_items/delete_projects.rs
+++ b/rust/cloud-storage/macro_db_client/src/user/delete_user_dss_items/delete_projects.rs
@@ -1,3 +1,5 @@
+use model_entity::EntityType;
+
/// Deletes all projects for a user
/// Does not commit the transaction
#[tracing::instrument(skip(transaction))]
@@ -52,10 +54,13 @@ pub async fn delete_user_projects(
.execute(transaction.as_mut())
.await?;
- crate::item_access::delete::delete_user_item_access_bulk(
+ crate::item_access::delete::delete_user_entity_access_bulk(
transaction,
- &user_projects,
- "project",
+ &user_projects
+ .iter()
+ .filter_map(|p| macro_uuid::string_to_uuid(p).ok())
+ .collect::<Vec<uuid::Uuid>>(),
+ EntityType::Project,
)
.await?;
diff --git a/rust/cloud-storage/macro_middleware/Cargo.toml b/rust/cloud-storage/macro_middleware/Cargo.toml
index ddc5b156ff..0f13f2ec01 100644
--- a/rust/cloud-storage/macro_middleware/Cargo.toml
+++ b/rust/cloud-storage/macro_middleware/Cargo.toml
@@ -8,7 +8,7 @@ version = "0.1.0"
all = ["auth", "cloud_storage", "tracking", "user_permissions"]
auth = ["dep:decode_jwt", "dep:macro_auth", "dep:url"]
cloud_storage = [
- "dep:macro_share_permissions",
+ "dep:entity_access_db_utils",
"dep:macro_user_id",
"dep:model_user",
"dep:permission",
@@ -25,13 +25,13 @@ anyhow = { workspace = true }
axum = { workspace = true, features = ["macros"] }
axum-extra = { workspace = true }
decode_jwt = { path = "../decode_jwt", optional = true }
+entity_access_db_utils = { path = "../entity_access_db_utils", optional = true }
http-body-util = { workspace = true }
ip_extractor = { path = "../ip_extractor", optional = true }
macro_auth = { path = "../macro_auth", optional = true }
macro_db_client = { path = "../macro_db_client", optional = true }
macro_env = { path = "../macro_env" }
macro_env_var = { path = "../macro_env_var" }
-macro_share_permissions = { path = "../macro_share_permissions", optional = true }
macro_user_id = { path = "../macro_user_id", optional = true }
macro_uuid = { path = "../macro_uuid" }
model = { path = "../model" }
diff --git a/rust/cloud-storage/macro_middleware/src/cloud_storage/thread/ensure_thread_exists.rs b/rust/cloud-storage/macro_middleware/src/cloud_storage/thread/ensure_thread_exists.rs
index 74cf8d5cae..1d7b907af5 100644
--- a/rust/cloud-storage/macro_middleware/src/cloud_storage/thread/ensure_thread_exists.rs
+++ b/rust/cloud-storage/macro_middleware/src/cloud_storage/thread/ensure_thread_exists.rs
@@ -7,6 +7,7 @@ use axum::response::Response;
use macro_user_id::cowlike::CowLike;
use macro_user_id::user_id::MacroUserIdStr;
use model::thread::EmailThreadPermission;
+use model_entity::EntityType;
use models_permissions::share_permission::SharePermissionV2;
use models_permissions::share_permission::access_level::AccessLevel;
use serde::Deserialize;
@@ -84,17 +85,17 @@ pub async fn insert_thread_share_permissions(
.await
.context("failed to create thread permission")?;
- // insert UserItemAccess for owner
- macro_db_client::item_access::insert::insert_user_item_access(
+ // insert entity_access row for owner
+ entity_access_db_utils::insert_entity_access_row(
&mut tx,
- owner_id,
- thread_id,
- "thread",
+ &macro_uuid::string_to_uuid(thread_id).unwrap(),
+ EntityType::EmailThread,
+ owner_id.as_ref(),
+ entity_access_db_utils::EntityAccessSourceType::User,
AccessLevel::Owner,
- None,
)
.await
- .context("failed to insert UserItemAccess row for owner")?;
+ .context("failed to insert entity_access row for owner")?;
tx.commit().await.context("failed to commit transaction")?;
diff --git a/rust/cloud-storage/macro_share_permissions/README.md b/rust/cloud-storage/macro_share_permissions/README.md
deleted file mode 100644
index ba79b6f102..0000000000
--- a/rust/cloud-storage/macro_share_permissions/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# macro_share_permissions
-
-This crate contains logic for manipulating the share permissions object.
diff --git a/rust/cloud-storage/macro_share_permissions/src/lib.rs b/rust/cloud-storage/macro_share_permissions/src/lib.rs
deleted file mode 100644
index 865b2fcc37..0000000000
--- a/rust/cloud-storage/macro_share_permissions/src/lib.rs
+++ /dev/null
@@ -1 +0,0 @@
-pub mod user_item_access;
diff --git a/rust/cloud-storage/macro_share_permissions/src/user_item_access.rs b/rust/cloud-storage/macro_share_permissions/src/user_item_access.rs
deleted file mode 100644
index fbb509521a..0000000000
--- a/rust/cloud-storage/macro_share_permissions/src/user_item_access.rs
+++ /dev/null
@@ -1,76 +0,0 @@
-use anyhow::Context;
-use models_permissions::share_permission::UpdateSharePermissionRequestV2;
-use models_permissions::share_permission::access_level::AccessLevel;
-use models_permissions::share_permission::channel_share_permission::UpdateOperation;
-use sqlx::Postgres;
-use sqlx::types::uuid;
-
-/// Updates user access for channel share permissions
-///
-/// This function handles the logic for adding/removing user access items based on
-/// channel share permissions in the UpdateSharePermissionRequestV2
-#[tracing::instrument(skip(transaction))]
-pub async fn update_user_item_access<'t>(
- transaction: &mut sqlx::Transaction<'t, Postgres>,
- user_id: &str,
- item_id: &str,
- item_type: &str,
- share_permission: &UpdateSharePermissionRequestV2,
-) -> anyhow::Result<()> {
- if let Some(csps) = &share_permission.channel_share_permissions {
- for csp in csps.iter() {
- let channel_id = uuid::Uuid::parse_str(&csp.channel_id)
- .with_context(|| format!("Failed to parse channel_id {}", &csp.channel_id))?;
-
- let channel_participants =
- comms_db_client::participants::get_participants::get_participants_tsx(
- transaction,
- &channel_id,
- )
- .await
- .with_context(|| {
- format!(
- "Failed to get channel participants for channel {}",
- &csp.channel_id
- )
- })?
- .into_iter()
- // don't make another entry for the owner of the item
- .filter(|p| p.user_id.as_ref() != user_id && p.left_at.is_none())
- .map(|p| p.user_id)
- .collect::<Vec<_>>();
-
- if channel_participants.is_empty() {
- continue;
- }
-
- match csp.operation {
- UpdateOperation::Add | UpdateOperation::Replace => {
- macro_db_client::item_access::insert::upsert_user_item_access_bulk(
- &mut **transaction,
- &channel_participants,
- item_id,
- item_type,
- csp.access_level.unwrap_or(AccessLevel::View),
- Some(channel_id),
- )
- .await
- .with_context(|| "Failed to insert user item access rows")?;
- }
- UpdateOperation::Remove => {
- macro_db_client::item_access::delete::delete_user_item_access_by_users_and_channel(
- &mut **transaction,
- &channel_participants,
- item_id,
- item_type,
- channel_id,
- )
- .await
- .with_context(|| "Failed to delete user item access rows")?;
- }
- }
- }
- }
-
- Ok(())
-}
diff --git a/rust/cloud-storage/mcp_service/Cargo.toml b/rust/cloud-storage/mcp_service/Cargo.toml
index 52749066d2..14e27999dc 100644
--- a/rust/cloud-storage/mcp_service/Cargo.toml
+++ b/rust/cloud-storage/mcp_service/Cargo.toml
@@ -19,6 +19,7 @@ documents = { path = "../documents", features = ["ai_tools"] }
email = { path = "../email", features = ["outbound"] }
email_service_client = { path = "../email_service_client" }
entity_access = { path = "../entity_access" }
+entity_access_management = { path = "../entity_access_management" }
frecency = { path = "../frecency", features = ["outbound", "postgres"] }
fusionauth = { path = "../fusionauth" }
http = { workspace = true }
diff --git a/rust/cloud-storage/mcp_service/src/context.rs b/rust/cloud-storage/mcp_service/src/context.rs
index 5816c12034..da0c5315cd 100644
--- a/rust/cloud-storage/mcp_service/src/context.rs
+++ b/rust/cloud-storage/mcp_service/src/context.rs
@@ -218,6 +218,9 @@ async fn build_tool_context(
s3_upload_adapter,
NoOpTaskProperties,
NoOpConnectionService,
+ entity_access_management::domain::service::EntityAccessManagementServiceImpl::new(
+ entity_access_management::outbound::PgRepository::new(db.clone()),
+ ),
);
let entity_access_service = EntityAccessServiceImpl::new(PgAccessRepository::new(db.clone()));
let lexical_client_for_tools = (*lexical_client).clone();
diff --git a/rust/cloud-storage/memory/Cargo.toml b/rust/cloud-storage/memory/Cargo.toml
index 829bb5dc31..6f75468f5b 100644
--- a/rust/cloud-storage/memory/Cargo.toml
+++ b/rust/cloud-storage/memory/Cargo.toml
@@ -1,30 +1,55 @@
[package]
-name = "memory"
-version = "0.1.0"
edition = "2024"
+name = "memory"
publish = false
+version = "0.1.0"
[dependencies]
-macro_user_id = { path = "../macro_user_id" }
-macro_uuid = { path = "../macro_uuid" }
-thiserror = { workspace = true }
+ai = { path = "../ai" }
ai_tools = { path = "../ai_tools" }
ai_toolset = { path = "../ai_toolset" }
-ai = { path = "../ai" }
+anyhow = { workspace = true }
+axum = { workspace = true }
+chrono = { workspace = true }
futures = { workspace = true }
+macro_entrypoint = { path = "../macro_entrypoint" }
+macro_env = { path = "../macro_env" }
+macro_env_var = { path = "../macro_env_var" }
+macro_user_id = { path = "../macro_user_id" }
+macro_uuid = { path = "../macro_uuid" }
+model_user = { path = "../model_user", features = ["axum"] }
serde = { workspace = true }
serde_json = { workspace = true }
-chrono = { workspace = true }
sqlx = { workspace = true }
+thiserror = { workspace = true }
tokio = { workspace = true }
-anyhow = { workspace = true }
-axum = { workspace = true }
-model_user = { path = "../model_user", features = ["axum"] }
tracing = { workspace = true }
utoipa = { workspace = true }
-macro_entrypoint = { path = "../macro_entrypoint" }
-macro_env = { path = "../macro_env" }
-macro_env_var = { path = "../macro_env_var" }
+# For building ToolServiceContext
+comms = { path = "../comms" }
+document_storage_service_client = { path = "../document_storage_service_client" }
+documents = { path = "../documents" }
+email = { path = "../email" }
+email_service_client = { path = "../email_service_client" }
+entity_access = { path = "../entity_access" }
+entity_access_management = { path = "../entity_access_management" }
+frecency = { path = "../frecency" }
+lexical_client = { path = "../lexical_client" }
+macro_aws_config = { path = "../macro_aws_config" }
+properties = { path = "../properties" }
+readonly_pool = { path = "../readonly_pool" }
+scribe = { path = "../scribe" }
+search_service_client = { path = "../search_service_client" }
+soup = { path = "../soup", features = ["all"] }
+sqs_client = { path = "../sqs_client", default-features = false, features = [
+ "email",
+ "gmail",
+] }
+static_file_service_client = { path = "../static_file_service_client" }
+sync_service_client = { path = "../sync_service_client" }
+
+
+[dev-dependencies]
macro_db_migrator = { path = "../macro_db_migrator" }
diff --git a/rust/cloud-storage/memory/src/context.rs b/rust/cloud-storage/memory/src/context.rs
new file mode 100644
index 0000000000..f2e6281229
--- /dev/null
+++ b/rust/cloud-storage/memory/src/context.rs
@@ -0,0 +1,196 @@
+use ai_tools::{
+ NoOpConnectionService, NoOpNotificationService, NoOpTaskProperties, ToolServiceContext,
+};
+use comms::domain::service::ChannelServiceImpl;
+use comms::outbound::postgres::comms_repo::PgCommsRepo;
+use comms::outbound::postgres::user_repo::PgUserRepo;
+use document_storage_service_client::DocumentStorageServiceClient;
+use documents::domain::models::CloudFrontConfig;
+use documents::inbound::toolset::DocumentToolContext;
+use documents::outbound::pg_document_repo::PgDocumentRepo;
+use documents::outbound::s3_upload_url::S3UploadUrlAdapter;
+use email::domain::ports::ReadonlyEmailPreviewAdapter;
+use email::domain::service::EmailServiceImpl;
+use email::outbound::EmailPgRepo;
+use email_service_client::{EmailServiceClient, EmailServiceClientExternal};
+use entity_access::domain::service::EntityAccessServiceImpl;
+use entity_access::outbound::PgAccessRepository;
+use frecency::domain::services::FrecencyQueryServiceImpl;
+use frecency::outbound::postgres::FrecencyPgStorage;
+use lexical_client::LexicalClient;
+use scribe::ScribeClient;
+use scribe::document::DocumentClient;
+use search_service_client::SearchServiceClient;
+use soup::domain::service::SoupImpl;
+use soup::outbound::pg_soup_repo::PgSoupRepo;
+use static_file_service_client::StaticFileServiceClient;
+use std::sync::Arc;
+use sync_service_client::SyncServiceClient;
+
+use crate::config::Config;
+
+/// Builds a [`ToolServiceContext`] from environment variables and a database pool.
+///
+/// Required env vars: `INTERNAL_API_SECRET_KEY`, `DOCUMENT_STORAGE_SERVICE_URL`,
+/// `SEARCH_SERVICE_URL`, `EMAIL_SERVICE_URL`, `SYNC_SERVICE_URL`,
+/// `DOCUMENT_COGNITION_SERVICE_URL`, `STATIC_FILE_SERVICE_URL`,
+/// `DOCUMENT_STORAGE_BUCKET`, `DOCX_DOCUMENT_UPLOAD_BUCKET`,
+/// `EMAIL_SCHEDULED_QUEUE`,
+/// `DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_DISTRIBUTION_URL`,
+/// `DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_SIGNER_PUBLIC_KEY_ID`,
+/// `DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_SIGNER_PRIVATE_KEY_SECRET_NAME`
+#[tracing::instrument(skip(pool, config), err)]
+pub async fn build_tool_service_context(
+ pool: sqlx::PgPool,
+ config: &Config,
+) -> anyhow::Result<ToolServiceContext> {
+ let aws_config = macro_aws_config::get_macro_aws_config().await;
+ let sqs_client = sqs_client::SQS::new(aws_sdk_sqs::Client::new(&aws_config))
+ .email_scheduled_queue(&config.email_scheduled_queue);
+
+ // Service clients
+ let dss_client = Arc::new(DocumentStorageServiceClient::new(
+ config.internal_api_secret_key.clone(),
+ config.document_storage_service_url.clone(),
+ ));
+ let search_client = Arc::new(SearchServiceClient::new(
+ config.internal_api_secret_key.clone(),
+ config.search_service_url.clone(),
+ ));
+ let sync_client = Arc::new(SyncServiceClient::new(
+ config.internal_api_secret_key.clone(),
+ config.sync_service_url.clone(),
+ ));
+ let email_client = Arc::new(EmailServiceClient::new(
+ config.internal_api_secret_key.clone(),
+ config.email_service_url.clone(),
+ ));
+ let sfs_client = Arc::new(StaticFileServiceClient::new(
+ config.internal_api_secret_key.clone(),
+ config.static_file_service_url.clone(),
+ ));
+ let email_ext_client = Arc::new(EmailServiceClientExternal::new(
+ config.email_service_url.clone(),
+ ));
+ let lexical_client = LexicalClient::new(
+ config.internal_api_secret_key.clone(),
+ config.lexical_service_url.clone(),
+ );
+
+ // Scribe
+ let scribe = Arc::new(
+ ScribeClient::new()
+ .with_document_client(
+ DocumentClient::builder()
+ .with_dss_client(dss_client.clone())
+ .with_lexical_client(Arc::new(lexical_client.clone()))
+ .with_sync_service_client(sync_client.clone())
+ .with_macro_db(pool.clone())
+ .build(),
+ )
+ .with_channel_client(pool.clone())
+ .with_dcs_client(pool.clone())
+ .with_email_client(email_client)
+ .with_static_file_client(sfs_client),
+ );
+
+ // Soup service
+ let frecency_storage = FrecencyPgStorage::new(pool.clone());
+ let frecency_service = FrecencyQueryServiceImpl::new(frecency_storage.clone());
+ let email_service = EmailServiceImpl::new(
+ EmailPgRepo::new(pool.clone()),
+ frecency_service.clone(),
+ email::domain::ports::NoOpEnqueuer,
+ 0,
+ );
+ let channels_service = ChannelServiceImpl::new(
+ PgCommsRepo::new(readonly_pool::ReadOnlyPool(pool.clone())),
+ PgUserRepo::new(pool.clone()),
+ frecency_storage,
+ );
+ let email_service_for_tools: Arc<ai_tools::ToolEmailService> = Arc::new(email_service.clone());
+ let soup_service = Arc::new(SoupImpl::new(
+ PgSoupRepo::new(readonly_pool::ReadOnlyPool(pool.clone())),
+ frecency_service,
+ ReadonlyEmailPreviewAdapter(email_service),
+ channels_service,
+ call::domain::ports::NoOpCallRecordQueryService,
+ ));
+
+ // Document tool context
+ let s3_client = macro_aws_config::s3_client().await;
+ let s3_upload_adapter = S3UploadUrlAdapter::new(
+ s3_client,
+ &config.document_storage_bucket,
+ &config.docx_document_upload_bucket,
+ );
+ let document_repo = PgDocumentRepo::new(pool.clone());
+ let cloudfront_config = CloudFrontConfig {
+ distribution_url: config
+ .document_storage_service_cloudfront_distribution_url
+ .clone(),
+ signer_public_key_id: config
+ .document_storage_service_cloudfront_signer_public_key_id
+ .clone(),
+ signer_private_key: config
+ .document_storage_service_cloudfront_signer_private_key_secret_name
+ .clone(),
+ presigned_url_expiry_seconds: 3600,
+ browser_cache_expiry_seconds: 86400,
+ };
+ let document_service = documents::domain::service::DocumentServiceImpl::new(
+ document_repo,
+ cloudfront_config,
+ sync_client.as_ref().clone(),
+ s3_upload_adapter,
+ NoOpTaskProperties,
+ NoOpConnectionService,
+ entity_access_management::domain::service::EntityAccessManagementServiceImpl::new(
+ entity_access_management::outbound::PgRepository::new(pool.clone()),
+ ),
+ );
+ let entity_access_service = EntityAccessServiceImpl::new(PgAccessRepository::new(pool.clone()));
+ let entity_access_service = Arc::new(entity_access_service);
+ let document_tool_context = DocumentToolContext::new(
+ document_service,
+ (*entity_access_service).clone(),
+ lexical_client,
+ );
+
+ // Properties tool context
+ let properties_service = properties::PropertiesServiceImpl::new(
+ properties::PropertiesPgRepo::new(pool.clone()),
+ Some(properties::PermissionServiceImpl::new(
+ pool.clone(),
+ entity_access_service.clone(),
+ )),
+ Some(NoOpNotificationService),
+ );
+ let properties_tool_context =
+ properties::inbound::toolset::PropertiesToolContext::new(properties_service);
+
+ // Email tool context
+ let email_tool_context = email::inbound::toolset::EmailToolContext::new(
+ Arc::new(EmailServiceImpl::new(
+ EmailPgRepo::new(pool.clone()),
+ FrecencyQueryServiceImpl::new(FrecencyPgStorage::new(pool.clone())),
+ sqs_client,
+ 0,
+ )),
+ Arc::new(email::domain::ports::NoOpGmailTokenProvider),
+ Arc::new(EntityAccessServiceImpl::new(PgAccessRepository::new(
+ pool.clone(),
+ ))),
+ );
+
+ Ok(ToolServiceContext {
+ search_service_client: search_client,
+ email_service_client: email_ext_client,
+ scribe,
+ soup_service,
+ email_service: email_service_for_tools,
+ document_tool_context,
+ properties_tool_context,
+ email_tool_context,
+ })
+}
diff --git a/rust/cloud-storage/model-entity/src/lib.rs b/rust/cloud-storage/model-entity/src/lib.rs
index 82f9f98025..1f349fd3cd 100644
--- a/rust/cloud-storage/model-entity/src/lib.rs
+++ b/rust/cloud-storage/model-entity/src/lib.rs
@@ -7,7 +7,7 @@ use cowlike::CowLike;
use serde::{Deserialize, Serialize};
use std::{borrow::Cow, str::FromStr};
pub use strum::ParseError;
-use strum::{Display, EnumString, IntoStaticStr};
+use strum::{AsRefStr, Display, EnumString, IntoStaticStr};
use utoipa::ToSchema;
#[cfg(test)]
@@ -27,6 +27,7 @@ mod tests;
ToSchema,
Eq,
IntoStaticStr,
+ AsRefStr,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
diff --git a/rust/cloud-storage/model/src/item/mod.rs b/rust/cloud-storage/model/src/item/mod.rs
index 88e9bdd754..0e71b37437 100644
--- a/rust/cloud-storage/model/src/item/mod.rs
+++ b/rust/cloud-storage/model/src/item/mod.rs
@@ -176,6 +176,7 @@ pub enum ShareableItemType {
Chat,
Project,
Thread,
+ Call,
}
/// represents a shareable item with its id and type
diff --git a/rust/cloud-storage/model/src/project/request.rs b/rust/cloud-storage/model/src/project/request.rs
index aa05049952..6712f4b483 100644
--- a/rust/cloud-storage/model/src/project/request.rs
+++ b/rust/cloud-storage/model/src/project/request.rs
@@ -6,7 +6,7 @@ pub struct CreateProjectRequest {
/// The name of the project.
pub name: String,
/// The project that the new project will belong to.
- pub project_parent_id: Option<String>,
+ pub project_parent_id: Option<uuid::Uuid>,
}
#[derive(serde::Serialize, serde::Deserialize, Debug, ToSchema)]
diff --git a/rust/cloud-storage/model/src/thread/mod.rs b/rust/cloud-storage/model/src/thread/mod.rs
index c941cdede6..ccca1ec48a 100644
--- a/rust/cloud-storage/model/src/thread/mod.rs
+++ b/rust/cloud-storage/model/src/thread/mod.rs
@@ -1,4 +1,3 @@
-pub mod request;
pub mod response;
use serde::{Deserialize, Serialize};
diff --git a/rust/cloud-storage/model/src/thread/request.rs b/rust/cloud-storage/model/src/thread/request.rs
deleted file mode 100644
index 22be972c2e..0000000000
--- a/rust/cloud-storage/model/src/thread/request.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-use utoipa::ToSchema;
-
-#[derive(serde::Serialize, serde::Deserialize, Debug, ToSchema)]
-#[serde(rename_all = "camelCase")]
-pub struct PatchThreadRequestV2 {
- /// The new project that the thread will belong to.
- pub project_id: Option<String>,
- /// The share permissions for the thread.
- pub share_permission:
- Option<models_permissions::share_permission::UpdateSharePermissionRequestV2>,
-}
diff --git a/rust/cloud-storage/models_entity_access_management/Cargo.toml b/rust/cloud-storage/models_entity_access_management/Cargo.toml
new file mode 100644
index 0000000000..cdd1ff6245
--- /dev/null
+++ b/rust/cloud-storage/models_entity_access_management/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+edition = "2024"
+name = "models_entity_access_management"
+publish = false
+version = "0.1.0"
+
+[features]
+db = ["dep:sqlx"]
+default = ["db"]
+
+[dependencies]
+serde = { workspace = true }
+sqlx = { workspace = true, optional = true }
diff --git a/rust/cloud-storage/models_entity_access_management/src/lib.rs b/rust/cloud-storage/models_entity_access_management/src/lib.rs
new file mode 100644
index 0000000000..68db472374
--- /dev/null
+++ b/rust/cloud-storage/models_entity_access_management/src/lib.rs
@@ -0,0 +1,19 @@
+#![deny(missing_docs)]
+
+//! Contains common models for entity_access_management that need to be shared across multiple crates.
+
+/// Entity access source type
+#[derive(Debug, Clone, Copy)]
+#[cfg_attr(feature = "db", derive(sqlx::Type))]
+#[cfg_attr(
+ feature = "db",
+ sqlx(type_name = "entity_access_source_type", rename_all = "lowercase")
+)]
+pub enum EntityAccessSourceType {
+ /// Channel source
+ Channel,
+ /// Team source
+ Team,
+ /// User source
+ User,
+}
diff --git a/rust/cloud-storage/properties/Cargo.toml b/rust/cloud-storage/properties/Cargo.toml
index 82f2847df0..87bad2a7bf 100644
--- a/rust/cloud-storage/properties/Cargo.toml
+++ b/rust/cloud-storage/properties/Cargo.toml
@@ -18,6 +18,7 @@ anyhow = { workspace = true }
async-trait = { workspace = true, optional = true }
chrono = { workspace = true, optional = true }
entity_access = { path = "../entity_access" }
+entity_access_db_utils = { path = "../entity_access_db_utils" }
futures = { workspace = true }
email_db_client = { path = "../email_db_client" }
macro_db_client = { path = "../macro_db_client" }
diff --git a/rust/cloud-storage/properties/src/outbound/permission_service.rs b/rust/cloud-storage/properties/src/outbound/permission_service.rs
index 73f3800112..551f80b051 100644
--- a/rust/cloud-storage/properties/src/outbound/permission_service.rs
+++ b/rust/cloud-storage/properties/src/outbound/permission_service.rs
@@ -103,17 +103,13 @@ impl<Svc: EntityAccessService> PermissionService for PermissionServiceImpl<Svc>
return Ok(());
}
- // Tasks are stored as "document" type in the permission system
- let item_type = "document";
-
// Grant edit permissions to all users
- macro_db_client::item_access::insert::upsert_user_item_access_bulk(
+ entity_access_db_utils::upsert_user_entity_access_bulk(
&self.db,
user_ids,
- task_id,
- item_type,
+ &macro_uuid::string_to_uuid(task_id).unwrap(),
+ model_entity::EntityType::Document,
AccessLevel::Edit,
- None, // No channel association for direct task assignee permissions
)
.await?;
diff --git a/rust/cloud-storage/seed_cli/Cargo.toml b/rust/cloud-storage/seed_cli/Cargo.toml
index 5f5036388e..fe0d4b991c 100644
--- a/rust/cloud-storage/seed_cli/Cargo.toml
+++ b/rust/cloud-storage/seed_cli/Cargo.toml
@@ -6,31 +6,34 @@ version = "0.1.0"
[dependencies]
anyhow = { workspace = true }
-serde = { workspace = true }
-serde_json = { workspace = true }
+aws-sdk-s3 = { workspace = true }
+chrono = { workspace = true }
clap = { workspace = true }
-reqwest = { workspace = true }
+comms_db_client = { path = "../comms_db_client" }
+email_db_client = { path = "../email_db_client" }
+entity_access_db_utils = { path = "../entity_access_db_utils" }
+fusionauth = { path = "../fusionauth" }
+futures = { workspace = true }
+macro_aws_config = { path = "../macro_aws_config", features = ["s3"] }
+macro_db_client = { path = "../macro_db_client" }
macro_entrypoint = { path = "../macro_entrypoint" }
-tracing = { workspace = true }
-tokio = { workspace = true }
-macro_env_var = { path = "../macro_env_var" }
macro_env = { path = "../macro_env" }
-sqlx = { workspace = true }
+macro_env_var = { path = "../macro_env_var" }
macro_user_id = { path = "../macro_user_id" }
-fusionauth = { path = "../fusionauth" }
+macro_uuid = { path = "../macro_uuid" }
mockall = { workspace = true }
-comms_db_client = { path = "../comms_db_client" }
model = { path = "../model" }
-uuid = { workspace = true }
-email_db_client = { path = "../email_db_client" }
+model-entity = { path = "../model-entity" }
models_email = { path = "../models_email" }
-chrono = { workspace = true }
-rand = { workspace = true }
-futures = { workspace = true }
-macro_db_client = { path = "../macro_db_client" }
-macro_aws_config = {path = "../macro_aws_config", features = ["s3"] }
-aws-sdk-s3 = { workspace = true }
models_permissions = { path = "../models_permissions" }
+rand = { workspace = true }
+reqwest = { workspace = true }
+serde = { workspace = true }
+serde_json = { workspace = true }
+sqlx = { workspace = true }
+tokio = { workspace = true }
+tracing = { workspace = true }
+uuid = { workspace = true }
[dev-dependencies]
tempfile = "3"
diff --git a/rust/cloud-storage/seed_cli/src/service/db/mod.rs b/rust/cloud-storage/seed_cli/src/service/db/mod.rs
index f1248a9916..4e1d1c8383 100644
--- a/rust/cloud-storage/seed_cli/src/service/db/mod.rs
+++ b/rust/cloud-storage/seed_cli/src/service/db/mod.rs
@@ -1,5 +1,7 @@
//! Database service wrapper.
+use std::str::FromStr;
+
#[cfg(test)]
pub use MockSeedDb as Db;
#[cfg(not(test))]
@@ -124,27 +126,17 @@ impl SeedDb {
tracing::warn!(error=?e, "channel share permission may already exist, continuing");
}
- let participants = comms_db_client::participants::get_participants::get_participants(
- &self.inner,
- &channel_id,
- )
- .await?;
-
- let active_user_ids: Vec<_> = participants
- .into_iter()
- .filter(|p| p.left_at.is_none())
- .map(|p| p.user_id)
- .collect();
-
- macro_db_client::item_access::insert::upsert_user_item_access_bulk(
- &self.inner,
- &active_user_ids,
- item_id,
- item_type,
+ let mut tx = self.inner.begin().await?;
+ entity_access_db_utils::insert_entity_access_row(
+ &mut tx,
+ &macro_uuid::string_to_uuid(item_id).unwrap(),
+ model_entity::EntityType::from_str(item_type).unwrap(),
+ &channel_id.to_string(),
+ entity_access_db_utils::EntityAccessSourceType::Channel,
AccessLevel::View,
- Some(channel_id),
)
.await?;
+ tx.commit().await?;
Ok(())
}
diff --git a/rust/cloud-storage/soup/.sqlx/query-0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d.json b/rust/cloud-storage/soup/.sqlx/query-0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d.json
new file mode 100644
index 0000000000..99a3b6f452
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id FROM (\n -- Direct user grants\n SELECT source_id as user_id FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'user'\n\n UNION ALL\n\n -- Channel Members\n SELECT cp.user_id FROM comms_channel_participants cp\n WHERE cp.left_at IS NULL AND cp.channel_id IN (\n SELECT source_id::uuid FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'channel'\n )\n\n UNION ALL\n\n -- Team Members\n SELECT tu.user_id FROM team_user tu\n WHERE tu.team_id IN (\n SELECT source_id::uuid FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2 AND source_type = 'team'\n )\n )\n \n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "0c0d2d2d944ff26d1b60d890ffb5becd7ce6250a3becf484a65ecfa99a0c0d2d"
+}
diff --git a/rust/cloud-storage/soup/.sqlx/query-1b30e7bb6b67b93826781122a191e243db4c43ec8630b32ea48b1c7e31724264.json b/rust/cloud-storage/soup/.sqlx/query-1b30e7bb6b67b93826781122a191e243db4c43ec8630b32ea48b1c7e31724264.json
new file mode 100644
index 0000000000..cb09769f7a
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-1b30e7bb6b67b93826781122a191e243db4c43ec8630b32ea48b1c7e31724264.json
@@ -0,0 +1,137 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n UserAccessibleItems AS (\n SELECT DISTINCT\n ea.entity_id::text as item_id,\n ea.entity_type as item_type\n FROM entity_access ea\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n ),\n Combined AS (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $4\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status \n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id \n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $5\n INNER JOIN UserAccessibleItems uai \n ON uai.item_id = d.id \n AND uai.item_type = 'document'\n LEFT JOIN \"UserHistory\" uh \n ON uh.\"itemId\" = d.id \n AND uh.\"itemType\" = 'document' \n AND uh.\"userId\" = $1\n LEFT JOIN LATERAL (\n SELECT b.id \n FROM \"DocumentBom\" b \n WHERE b.\"documentId\" = d.id \n ORDER BY b.\"createdAt\" DESC \n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha \n FROM \"DocumentInstance\" i \n WHERE i.\"documentId\" = d.id \n ORDER BY i.\"updatedAt\" DESC \n LIMIT 1\n ) di ON true\n WHERE d.\"deletedAt\" IS NULL\n AND d.id = ANY($2::text[])\n\n UNION ALL\n \n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = c.id\n AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = c.id\n AND uh.\"itemType\" = 'chat'\n AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n AND c.id = ANY($3::text[])\n )\n SELECT * \n FROM Combined\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_version_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "user_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "name!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "branched_from_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "branched_from_version_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 7,
+ "name": "document_family_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 8,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 9,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 11,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 12,
+ "name": "is_persistent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 13,
+ "name": "sha",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 14,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 15,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 16,
+ "name": "is_completed",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 17,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray",
+ "TextArray",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "1b30e7bb6b67b93826781122a191e243db4c43ec8630b32ea48b1c7e31724264"
+}
diff --git a/rust/cloud-storage/soup/.sqlx/query-1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6.json b/rust/cloud-storage/soup/.sqlx/query-1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6.json
new file mode 100644
index 0000000000..f97907a55c
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" = $1\n )\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "1b7983a9a8a54322fd63d2bf169f27b45f853652a757123e3508017861b5c7c6"
+}
diff --git a/rust/cloud-storage/soup/.sqlx/query-31df7fdfa81e8a92373c62309b14486268a5a99e5371e7f08fab2716d7688192.json b/rust/cloud-storage/soup/.sqlx/query-31df7fdfa81e8a92373c62309b14486268a5a99e5371e7f08fab2716d7688192.json
deleted file mode 100644
index 5a9bcfe5b6..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-31df7fdfa81e8a92373c62309b14486268a5a99e5371e7f08fab2716d7688192.json
+++ /dev/null
@@ -1,145 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": " \n WITH RECURSIVE ProjectHierarchy AS (\n SELECT p.id, uia.access_level \n FROM \"Project\" p\n JOIN \"UserItemAccess\" uia ON p.id = uia.item_id AND uia.item_type = 'project'\n WHERE uia.user_id = $1 AND p.\"deletedAt\" IS NULL\n UNION ALL\n SELECT p.id, ph.access_level\n FROM \"Project\" p \n JOIN ProjectHierarchy ph ON p.\"parentId\" = ph.id\n WHERE p.\"deletedAt\" IS NULL\n ),\n AllAccessGrants AS (\n SELECT item_id, item_type, access_level \n FROM \"UserItemAccess\" \n WHERE user_id = $1\n UNION ALL\n SELECT d.id AS item_id, 'document' AS item_type, ph.access_level\n FROM \"Document\" d \n JOIN ProjectHierarchy ph ON d.\"projectId\" = ph.id\n WHERE d.\"projectId\" IS NOT NULL AND d.\"deletedAt\" IS NULL\n UNION ALL\n SELECT c.id AS item_id, 'chat' AS item_type, ph.access_level\n FROM \"Chat\" c \n JOIN ProjectHierarchy ph ON c.\"projectId\" = ph.id\n WHERE c.\"projectId\" IS NOT NULL AND c.\"deletedAt\" IS NULL\n UNION ALL\n SELECT ph.id AS item_id, 'project' AS item_type, ph.access_level \n FROM ProjectHierarchy ph\n ),\n UserAccessibleItems AS (\n SELECT DISTINCT ON (item_id, item_type) item_id, item_type\n FROM AllAccessGrants\n ORDER BY item_id, item_type, \n CASE access_level\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3 \n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END DESC\n ),\n Combined AS (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", d.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN d.\"createdAt\"\n ELSE d.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $6\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status\n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id\n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $7\n INNER JOIN UserAccessibleItems uai ON uai.item_id = d.id AND uai.item_type = 'document'\n -- This MUST be a LEFT JOIN to support all three sort methods\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = d.id AND uh.\"itemType\" = 'document' AND uh.\"userId\" = $1\n LEFT JOIN LATERAL (\n SELECT b.id\n FROM \"DocumentBom\" b\n WHERE b.\"documentId\" = d.id\n ORDER BY b.\"createdAt\" DESC\n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha\n FROM \"DocumentInstance\" i\n WHERE i.\"documentId\" = d.id\n ORDER BY i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON true\n WHERE d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", c.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN c.\"createdAt\"\n ELSE c.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai ON uai.item_id = c.id AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = c.id AND uh.\"itemType\" = 'chat' AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'project' as \"item_type!\",\n p.id as \"id!\",\n NULL as \"document_version_id\",\n p.\"userId\" as \"user_id!\",\n p.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n p.\"createdAt\"::timestamptz as \"created_at!\",\n p.\"updatedAt\"::timestamptz as \"updated_at!\",\n p.\"parentId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", p.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN p.\"createdAt\"\n ELSE p.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n p.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Project\" p\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = p.id\n AND uai.item_type = 'project'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = p.id\n AND uh.\"itemType\" = 'project'\n AND uh.\"userId\" = $1\n WHERE p.\"deletedAt\" IS NULL\n )\n SELECT Combined.* FROM Combined\n LEFT JOIN frecency_aggregates fa\n ON fa.entity_id = Combined.\"id!\"\n AND fa.entity_type = Combined.\"item_type!\"\n AND fa.user_id = $1\n WHERE fa.id IS NULL\n AND (\n ($4::timestamptz IS NULL)\n OR\n (Combined.\"sort_ts!\", Combined.\"id!\"::text) < ($4, $5)\n )\n ORDER BY Combined.\"sort_ts!\" DESC, Combined.\"id!\" DESC\n LIMIT $3\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "item_type!",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "id!",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "document_version_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "user_id!",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "name!",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
- "name": "branched_from_id",
- "type_info": "Text"
- },
- {
- "ordinal": 6,
- "name": "branched_from_version_id",
- "type_info": "Int8"
- },
- {
- "ordinal": 7,
- "name": "document_family_id",
- "type_info": "Int8"
- },
- {
- "ordinal": 8,
- "name": "file_type",
- "type_info": "Text"
- },
- {
- "ordinal": 9,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 10,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 11,
- "name": "project_id",
- "type_info": "Text"
- },
- {
- "ordinal": 12,
- "name": "is_persistent",
- "type_info": "Bool"
- },
- {
- "ordinal": 13,
- "name": "sha",
- "type_info": "Text"
- },
- {
- "ordinal": 14,
- "name": "sub_type?: DocumentSubType",
- "type_info": {
- "Custom": {
- "name": "document_sub_type_value",
- "kind": {
- "Enum": [
- "task"
- ]
- }
- }
- }
- },
- {
- "ordinal": 15,
- "name": "viewed_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 16,
- "name": "sort_ts!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 17,
- "name": "is_completed",
- "type_info": "Bool"
- },
- {
- "ordinal": 18,
- "name": "deleted_at",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text",
- "Int8",
- "Timestamptz",
- "Text",
- "Text",
- "Uuid"
- ]
- },
- "nullable": [
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null
- ]
- },
- "hash": "31df7fdfa81e8a92373c62309b14486268a5a99e5371e7f08fab2716d7688192"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08.json b/rust/cloud-storage/soup/.sqlx/query-377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08.json
new file mode 100644
index 0000000000..9348d25315
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"DocumentPermission\" WHERE \"documentId\" = $1\n )\n \n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "377f7c130cc3d834870fa692f5ba36d070bce17512b9ab348d0cb40ebe4d1b08"
+}
diff --git a/rust/cloud-storage/soup/.sqlx/query-41ef28446ebbd766c0778fd56fb8ee8094c2cb84ed3f4dab9e890d441611722b.json b/rust/cloud-storage/soup/.sqlx/query-41ef28446ebbd766c0778fd56fb8ee8094c2cb84ed3f4dab9e890d441611722b.json
new file mode 100644
index 0000000000..c88fd987e6
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-41ef28446ebbd766c0778fd56fb8ee8094c2cb84ed3f4dab9e890d441611722b.json
@@ -0,0 +1,145 @@
+{
+ "db_name": "PostgreSQL",
+ "query": " \n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n UserAccessibleItems AS (\n SELECT DISTINCT\n ea.entity_id::text as item_id,\n ea.entity_type as item_type\n FROM entity_access ea\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n ),\n Combined AS (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", d.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN d.\"createdAt\"\n ELSE d.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $6\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status\n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id\n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $7\n INNER JOIN UserAccessibleItems uai ON uai.item_id = d.id AND uai.item_type = 'document'\n -- This MUST be a LEFT JOIN to support all three sort methods\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = d.id AND uh.\"itemType\" = 'document' AND uh.\"userId\" = $1\n LEFT JOIN LATERAL (\n SELECT b.id\n FROM \"DocumentBom\" b\n WHERE b.\"documentId\" = d.id\n ORDER BY b.\"createdAt\" DESC\n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha\n FROM \"DocumentInstance\" i\n WHERE i.\"documentId\" = d.id\n ORDER BY i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON true\n WHERE d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", c.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN c.\"createdAt\"\n ELSE c.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai ON uai.item_id = c.id AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = c.id AND uh.\"itemType\" = 'chat' AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'project' as \"item_type!\",\n p.id as \"id!\",\n NULL as \"document_version_id\",\n p.\"userId\" as \"user_id!\",\n p.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n p.\"createdAt\"::timestamptz as \"created_at!\",\n p.\"updatedAt\"::timestamptz as \"updated_at!\",\n p.\"parentId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", p.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN p.\"createdAt\"\n ELSE p.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n p.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Project\" p\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = p.id\n AND uai.item_type = 'project'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = p.id\n AND uh.\"itemType\" = 'project'\n AND uh.\"userId\" = $1\n WHERE p.\"deletedAt\" IS NULL\n )\n SELECT Combined.* FROM Combined\n LEFT JOIN frecency_aggregates fa\n ON fa.entity_id = Combined.\"id!\"\n AND fa.entity_type = Combined.\"item_type!\"\n AND fa.user_id = $1\n WHERE fa.id IS NULL\n AND (\n ($4::timestamptz IS NULL)\n OR\n (Combined.\"sort_ts!\", Combined.\"id!\"::text) < ($4, $5)\n )\n ORDER BY Combined.\"sort_ts!\" DESC, Combined.\"id!\" DESC\n LIMIT $3\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_version_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "user_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "name!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "branched_from_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "branched_from_version_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 7,
+ "name": "document_family_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 8,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 9,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 11,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 12,
+ "name": "is_persistent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 13,
+ "name": "sha",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 14,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 15,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 16,
+ "name": "sort_ts!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 17,
+ "name": "is_completed",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 18,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Int8",
+ "Timestamptz",
+ "Text",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "41ef28446ebbd766c0778fd56fb8ee8094c2cb84ed3f4dab9e890d441611722b"
+}
diff --git a/rust/cloud-storage/soup/.sqlx/query-4df1044ff7642fbea4254b739c0ca0d8a5cc652dcec4e22d9eaf01f3cd5da22d.json b/rust/cloud-storage/soup/.sqlx/query-4df1044ff7642fbea4254b739c0ca0d8a5cc652dcec4e22d9eaf01f3cd5da22d.json
deleted file mode 100644
index 157e13c050..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-4df1044ff7642fbea4254b739c0ca0d8a5cc652dcec4e22d9eaf01f3cd5da22d.json
+++ /dev/null
@@ -1,144 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH UserAccessibleItems AS (\n SELECT DISTINCT ON (\"item_id\", \"item_type\")\n \"item_id\",\n \"item_type\"\n FROM \"UserItemAccess\" \n WHERE \"user_id\" = $1\n ORDER BY \"item_id\", \"item_type\", \n CASE \"access_level\"\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3 \n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END DESC\n ),\n Combined AS (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\", \n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n d.\"updatedAt\"::timestamptz as \"sort_ts!\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $5\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status\n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id\n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $6\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = d.id\n AND uai.item_type = 'document'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = d.id\n AND uh.\"itemType\" = 'document'\n AND uh.\"userId\" = $1\n LEFT JOIN LATERAL (\n SELECT b.id\n FROM \"DocumentBom\" b\n WHERE b.\"documentId\" = d.id\n ORDER BY b.\"createdAt\" DESC\n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha\n FROM \"DocumentInstance\" i\n WHERE i.\"documentId\" = d.id\n ORDER BY i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON true\n WHERE d.\"deletedAt\" IS NULL\n AND d.id = ANY($2::text[])\n\n UNION ALL\n\n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n c.\"updatedAt\"::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = c.id\n AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = c.id\n AND uh.\"itemType\" = 'chat'\n AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n AND c.id = ANY($3::text[])\n\n UNION ALL\n\n SELECT\n 'project' as \"item_type!\",\n p.id as \"id!\",\n NULL as \"document_version_id\",\n p.\"userId\" as \"user_id!\",\n p.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n p.\"createdAt\"::timestamptz as \"created_at!\",\n p.\"updatedAt\"::timestamptz as \"updated_at!\",\n p.\"parentId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n p.\"updatedAt\"::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n p.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Project\" p\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = p.id\n AND uai.item_type = 'project'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = p.id\n AND uh.\"itemType\" = 'project'\n AND uh.\"userId\" = $1\n WHERE p.\"deletedAt\" IS NULL\n AND p.id = ANY($4::text[])\n )\n SELECT * \n FROM Combined\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "item_type!",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "id!",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "document_version_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "user_id!",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "name!",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
- "name": "branched_from_id",
- "type_info": "Text"
- },
- {
- "ordinal": 6,
- "name": "branched_from_version_id",
- "type_info": "Int8"
- },
- {
- "ordinal": 7,
- "name": "document_family_id",
- "type_info": "Int8"
- },
- {
- "ordinal": 8,
- "name": "file_type",
- "type_info": "Text"
- },
- {
- "ordinal": 9,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 10,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 11,
- "name": "project_id",
- "type_info": "Text"
- },
- {
- "ordinal": 12,
- "name": "is_persistent",
- "type_info": "Bool"
- },
- {
- "ordinal": 13,
- "name": "sha",
- "type_info": "Text"
- },
- {
- "ordinal": 14,
- "name": "sub_type?: DocumentSubType",
- "type_info": {
- "Custom": {
- "name": "document_sub_type_value",
- "kind": {
- "Enum": [
- "task"
- ]
- }
- }
- }
- },
- {
- "ordinal": 15,
- "name": "viewed_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 16,
- "name": "sort_ts!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 17,
- "name": "is_completed",
- "type_info": "Bool"
- },
- {
- "ordinal": 18,
- "name": "deleted_at",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "TextArray",
- "TextArray",
- "TextArray",
- "Text",
- "Uuid"
- ]
- },
- "nullable": [
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null
- ]
- },
- "hash": "4df1044ff7642fbea4254b739c0ca0d8a5cc652dcec4e22d9eaf01f3cd5da22d"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-5293063d6203fdce622e3265581cb505e07534de33d0275ed860aea9f6614fc7.json b/rust/cloud-storage/soup/.sqlx/query-5293063d6203fdce622e3265581cb505e07534de33d0275ed860aea9f6614fc7.json
new file mode 100644
index 0000000000..b434884797
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-5293063d6203fdce622e3265581cb505e07534de33d0275ed860aea9f6614fc7.json
@@ -0,0 +1,144 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n UserAccessibleItems AS (\n SELECT DISTINCT\n ea.entity_id::text as item_id,\n ea.entity_type as item_type\n FROM entity_access ea\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n ),\n Combined AS (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\", \n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n d.\"updatedAt\"::timestamptz as \"sort_ts!\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $5\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status\n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id\n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $6\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = d.id\n AND uai.item_type = 'document'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = d.id\n AND uh.\"itemType\" = 'document'\n AND uh.\"userId\" = $1\n LEFT JOIN LATERAL (\n SELECT b.id\n FROM \"DocumentBom\" b\n WHERE b.\"documentId\" = d.id\n ORDER BY b.\"createdAt\" DESC\n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha\n FROM \"DocumentInstance\" i\n WHERE i.\"documentId\" = d.id\n ORDER BY i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON true\n WHERE d.\"deletedAt\" IS NULL\n AND d.id = ANY($2::text[])\n\n UNION ALL\n\n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n c.\"updatedAt\"::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = c.id\n AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = c.id\n AND uh.\"itemType\" = 'chat'\n AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n AND c.id = ANY($3::text[])\n\n UNION ALL\n\n SELECT\n 'project' as \"item_type!\",\n p.id as \"id!\",\n NULL as \"document_version_id\",\n p.\"userId\" as \"user_id!\",\n p.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n p.\"createdAt\"::timestamptz as \"created_at!\",\n p.\"updatedAt\"::timestamptz as \"updated_at!\",\n p.\"parentId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n p.\"updatedAt\"::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n p.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Project\" p\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = p.id\n AND uai.item_type = 'project'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = p.id\n AND uh.\"itemType\" = 'project'\n AND uh.\"userId\" = $1\n WHERE p.\"deletedAt\" IS NULL\n AND p.id = ANY($4::text[])\n )\n SELECT * \n FROM Combined\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_version_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "user_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "name!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "branched_from_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "branched_from_version_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 7,
+ "name": "document_family_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 8,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 9,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 11,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 12,
+ "name": "is_persistent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 13,
+ "name": "sha",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 14,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 15,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 16,
+ "name": "sort_ts!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 17,
+ "name": "is_completed",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 18,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray",
+ "TextArray",
+ "TextArray",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "5293063d6203fdce622e3265581cb505e07534de33d0275ed860aea9f6614fc7"
+}
diff --git a/rust/cloud-storage/soup/.sqlx/query-5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf.json b/rust/cloud-storage/soup/.sqlx/query-5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf.json
new file mode 100644
index 0000000000..514e8d9770
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ChatPermission\" WHERE \"chatId\" = $1\n )\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "5915728325fe5163ae5f18a99350e0cb5153d368eceb75d03b4cf1adfd1f58bf"
+}
diff --git a/rust/cloud-storage/soup/.sqlx/query-6abeabf893d033f575f7814b49d57ac0f37d2a2f012002d01453e698f120fd96.json b/rust/cloud-storage/soup/.sqlx/query-6abeabf893d033f575f7814b49d57ac0f37d2a2f012002d01453e698f120fd96.json
deleted file mode 100644
index 88b3d044bb..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-6abeabf893d033f575f7814b49d57ac0f37d2a2f012002d01453e698f120fd96.json
+++ /dev/null
@@ -1,145 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n -- =============================================================================\n -- EXPANDED GENERIC CURSOR SOUP QUERY\n -- =============================================================================\n -- Retrieves all items (documents, chats, projects) that a user has access to,\n -- including both explicit permissions and inherited permissions through the\n -- project hierarchy.\n -- =============================================================================\n\n -- Build the project hierarchy tree using recursive CTE.\n -- Starting from projects the user has explicit access to, recursively find\n -- all child projects. This enables inherited access - if you can access a\n -- parent project, you can access all its descendants.\n WITH RECURSIVE ProjectHierarchy AS (\n -- Base case: projects the user has direct access to\n SELECT p.id, uia.access_level\n FROM \"Project\" p\n JOIN \"UserItemAccess\" uia ON p.id = uia.item_id AND uia.item_type = 'project'\n WHERE uia.user_id = $1 AND p.\"deletedAt\" IS NULL\n UNION ALL\n -- Recursive case: find child projects, inheriting parent's access level\n SELECT p.id, ph.access_level\n FROM \"Project\" p\n JOIN ProjectHierarchy ph ON p.\"parentId\" = ph.id\n WHERE p.\"deletedAt\" IS NULL\n ),\n\n -- Collect all access grants from multiple sources.\n -- Aggregates explicit permissions AND implicit permissions inherited\n -- through project membership.\n AllAccessGrants AS (\n -- Direct/explicit access grants to any item type\n SELECT item_id, item_type, access_level\n FROM \"UserItemAccess\"\n WHERE user_id = $1\n\n UNION ALL\n\n -- Documents within accessible projects (inherited access).\n -- Uses ANY(ARRAY(...)) pattern to reduce intermediate result set size.\n SELECT d.id AS item_id, 'document' AS item_type,\n (SELECT ph.access_level FROM ProjectHierarchy ph WHERE ph.id = d.\"projectId\" LIMIT 1) as access_level\n FROM \"Document\" d\n WHERE d.\"projectId\" = ANY(ARRAY(SELECT id FROM ProjectHierarchy))\n AND d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- Chats within accessible projects (inherited access)\n SELECT c.id AS item_id, 'chat' AS item_type, ph.access_level\n FROM \"Chat\" c\n JOIN ProjectHierarchy ph ON c.\"projectId\" = ph.id\n WHERE c.\"projectId\" IS NOT NULL AND c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n -- The projects themselves from the hierarchy\n SELECT ph.id AS item_id, 'project' AS item_type, ph.access_level\n FROM ProjectHierarchy ph\n ),\n\n -- Deduplicate access grants, keeping the highest permission level.\n -- When a user has multiple access paths to the same item (e.g., direct + inherited),\n -- we keep only one row with the highest privilege level.\n UserAccessibleItems AS (\n SELECT DISTINCT ON (item_id, item_type) item_id, item_type\n FROM AllAccessGrants\n ORDER BY item_id, item_type,\n -- Priority: owner > edit > comment > view\n CASE access_level\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3\n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END DESC\n ),\n\n -- Identify the top N items with minimal columns before joining full details.\n -- Performs early filtering and sorting to reduce the data processed in\n -- subsequent joins.\n TopItems AS (\n SELECT item_type, id, sort_ts, updated_at FROM (\n SELECT\n 'document'::text as item_type,\n d.id,\n -- Dynamic sort column based on user's selected sort method\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", d.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN d.\"createdAt\"\n ELSE d.\"updatedAt\"\n END::timestamptz as sort_ts,\n d.\"updatedAt\"::timestamptz as updated_at\n FROM \"Document\" d\n INNER JOIN UserAccessibleItems uai ON uai.item_id = d.id AND uai.item_type = 'document'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = d.id AND uh.\"itemType\" = 'document' AND uh.\"userId\" = $1\n WHERE d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'chat'::text,\n c.id,\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", c.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN c.\"createdAt\"\n ELSE c.\"updatedAt\"\n END::timestamptz,\n c.\"updatedAt\"::timestamptz\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai ON uai.item_id = c.id AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = c.id AND uh.\"itemType\" = 'chat' AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'project'::text,\n p.id,\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", p.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN p.\"createdAt\"\n ELSE p.\"updatedAt\"\n END::timestamptz,\n p.\"updatedAt\"::timestamptz\n FROM \"Project\" p\n INNER JOIN UserAccessibleItems uai ON uai.item_id = p.id AND uai.item_type = 'project'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = p.id AND uh.\"itemType\" = 'project' AND uh.\"userId\" = $1\n WHERE p.\"deletedAt\" IS NULL\n ) all_items\n WHERE\n -- Cursor-based pagination: skip items we've already seen.\n -- NULL cursor means first page (no items to skip).\n ($4::timestamptz IS NULL)\n OR\n -- Seek method: find items \"before\" the cursor position\n -- using (sort_ts, id) tuple comparison for deterministic ordering\n (sort_ts, id::text) < ($4, $5)\n ORDER BY sort_ts DESC, id DESC\n LIMIT $3\n )\n\n -- Join full item details only for the filtered top items.\n SELECT * FROM (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n t.sort_ts as \"sort_ts!\",\n -- Task completion status: check if status property matches \"completed\"\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $6\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM TopItems t\n INNER JOIN \"Document\" d ON d.id = t.id\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status\n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id\n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $7\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = d.id AND uh.\"itemType\" = 'document' AND uh.\"userId\" = $1\n -- LATERAL joins to get the latest version info\n LEFT JOIN LATERAL (\n SELECT b.id\n FROM \"DocumentBom\" b\n WHERE b.\"documentId\" = d.id\n ORDER BY b.\"createdAt\" DESC\n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha\n FROM \"DocumentInstance\" i\n WHERE i.\"documentId\" = d.id\n ORDER BY i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON true\n WHERE t.item_type = 'document'\n\n UNION ALL\n\n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n t.sort_ts as \"sort_ts!\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM TopItems t\n INNER JOIN \"Chat\" c ON c.id = t.id\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = c.id AND uh.\"itemType\" = 'chat' AND uh.\"userId\" = $1\n WHERE t.item_type = 'chat'\n\n UNION ALL\n\n SELECT\n 'project' as \"item_type!\",\n p.id as \"id!\",\n NULL as \"document_version_id\",\n p.\"userId\" as \"user_id!\",\n p.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n p.\"createdAt\"::timestamptz as \"created_at!\",\n p.\"updatedAt\"::timestamptz as \"updated_at!\",\n p.\"parentId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n t.sort_ts as \"sort_ts!\",\n NULL as \"is_completed\",\n p.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM TopItems t\n INNER JOIN \"Project\" p ON p.id = t.id\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = p.id AND uh.\"itemType\" = 'project' AND uh.\"userId\" = $1\n WHERE t.item_type = 'project'\n ) Combined\n -- Sort by timestamp descending, with ID as tiebreaker for deterministic pagination.\n -- This ensures consistent ordering when multiple items share the same timestamp,\n -- preventing items from being skipped or duplicated across pages.\n ORDER BY \"sort_ts!\" DESC, \"id!\" DESC\n LIMIT $3\n",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "item_type!",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "id!",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "document_version_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "user_id!",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "name!",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
- "name": "branched_from_id",
- "type_info": "Text"
- },
- {
- "ordinal": 6,
- "name": "branched_from_version_id",
- "type_info": "Int8"
- },
- {
- "ordinal": 7,
- "name": "document_family_id",
- "type_info": "Int8"
- },
- {
- "ordinal": 8,
- "name": "file_type",
- "type_info": "Text"
- },
- {
- "ordinal": 9,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 10,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 11,
- "name": "project_id",
- "type_info": "Text"
- },
- {
- "ordinal": 12,
- "name": "is_persistent",
- "type_info": "Bool"
- },
- {
- "ordinal": 13,
- "name": "sha",
- "type_info": "Text"
- },
- {
- "ordinal": 14,
- "name": "sub_type?: DocumentSubType",
- "type_info": {
- "Custom": {
- "name": "document_sub_type_value",
- "kind": {
- "Enum": [
- "task"
- ]
- }
- }
- }
- },
- {
- "ordinal": 15,
- "name": "viewed_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 16,
- "name": "sort_ts!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 17,
- "name": "is_completed",
- "type_info": "Bool"
- },
- {
- "ordinal": 18,
- "name": "deleted_at",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text",
- "Int8",
- "Timestamptz",
- "Text",
- "Text",
- "Uuid"
- ]
- },
- "nullable": [
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null
- ]
- },
- "hash": "6abeabf893d033f575f7814b49d57ac0f37d2a2f012002d01453e698f120fd96"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-9ec774ab99220caf9d64207c5546aed513a93a52ef3438c3f67485ef1ebe12c2.json b/rust/cloud-storage/soup/.sqlx/query-9ec774ab99220caf9d64207c5546aed513a93a52ef3438c3f67485ef1ebe12c2.json
deleted file mode 100644
index cbd9cbef34..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-9ec774ab99220caf9d64207c5546aed513a93a52ef3438c3f67485ef1ebe12c2.json
+++ /dev/null
@@ -1,137 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE ProjectHierarchy AS (\n SELECT p.id, uia.access_level \n FROM \"Project\" p\n JOIN \"UserItemAccess\" uia ON p.id = uia.item_id AND uia.item_type = 'project'\n WHERE uia.user_id = $1 AND p.\"deletedAt\" IS NULL\n UNION ALL\n SELECT p.id, ph.access_level\n FROM \"Project\" p \n JOIN ProjectHierarchy ph ON p.\"parentId\" = ph.id\n WHERE p.\"deletedAt\" IS NULL\n ),\n AllAccessGrants AS (\n SELECT item_id, item_type, access_level \n FROM \"UserItemAccess\" \n WHERE user_id = $1\n UNION ALL\n SELECT d.id AS item_id, 'document' AS item_type, ph.access_level\n FROM \"Document\" d \n JOIN ProjectHierarchy ph ON d.\"projectId\" = ph.id\n WHERE d.\"projectId\" IS NOT NULL AND d.\"deletedAt\" IS NULL\n UNION ALL\n SELECT c.id AS item_id, 'chat' AS item_type, ph.access_level\n FROM \"Chat\" c \n JOIN ProjectHierarchy ph ON c.\"projectId\" = ph.id\n WHERE c.\"projectId\" IS NOT NULL AND c.\"deletedAt\" IS NULL\n UNION ALL\n SELECT ph.id AS item_id, 'project' AS item_type, ph.access_level \n FROM ProjectHierarchy ph\n ),\n UserAccessibleItems AS (\n SELECT DISTINCT ON (item_id, item_type) item_id, item_type\n FROM AllAccessGrants\n ORDER BY item_id, item_type, \n CASE access_level\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3 \n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END DESC\n ),\n Combined AS (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $4\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status \n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id \n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $5\n INNER JOIN UserAccessibleItems uai \n ON uai.item_id = d.id \n AND uai.item_type = 'document'\n LEFT JOIN \"UserHistory\" uh \n ON uh.\"itemId\" = d.id \n AND uh.\"itemType\" = 'document' \n AND uh.\"userId\" = $1\n LEFT JOIN LATERAL (\n SELECT b.id \n FROM \"DocumentBom\" b \n WHERE b.\"documentId\" = d.id \n ORDER BY b.\"createdAt\" DESC \n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha \n FROM \"DocumentInstance\" i \n WHERE i.\"documentId\" = d.id \n ORDER BY i.\"updatedAt\" DESC \n LIMIT 1\n ) di ON true\n WHERE d.\"deletedAt\" IS NULL\n AND d.id = ANY($2::text[])\n\n UNION ALL\n \n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = c.id\n AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = c.id\n AND uh.\"itemType\" = 'chat'\n AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n AND c.id = ANY($3::text[])\n )\n SELECT * \n FROM Combined\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "item_type!",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "id!",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "document_version_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "user_id!",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "name!",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
- "name": "branched_from_id",
- "type_info": "Text"
- },
- {
- "ordinal": 6,
- "name": "branched_from_version_id",
- "type_info": "Int8"
- },
- {
- "ordinal": 7,
- "name": "document_family_id",
- "type_info": "Int8"
- },
- {
- "ordinal": 8,
- "name": "file_type",
- "type_info": "Text"
- },
- {
- "ordinal": 9,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 10,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 11,
- "name": "project_id",
- "type_info": "Text"
- },
- {
- "ordinal": 12,
- "name": "is_persistent",
- "type_info": "Bool"
- },
- {
- "ordinal": 13,
- "name": "sha",
- "type_info": "Text"
- },
- {
- "ordinal": 14,
- "name": "sub_type?: DocumentSubType",
- "type_info": {
- "Custom": {
- "name": "document_sub_type_value",
- "kind": {
- "Enum": [
- "task"
- ]
- }
- }
- }
- },
- {
- "ordinal": 15,
- "name": "viewed_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 16,
- "name": "is_completed",
- "type_info": "Bool"
- },
- {
- "ordinal": 17,
- "name": "deleted_at",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "TextArray",
- "TextArray",
- "Text",
- "Uuid"
- ]
- },
- "nullable": [
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null
- ]
- },
- "hash": "9ec774ab99220caf9d64207c5546aed513a93a52ef3438c3f67485ef1ebe12c2"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24.json b/rust/cloud-storage/soup/.sqlx/query-a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24.json
new file mode 100644
index 0000000000..f214362a1f
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'call'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE id in (\n SELECT share_permission_id\n FROM calls\n WHERE id = $1\n UNION ALL\n SELECT share_permission_id\n FROM call_records\n WHERE id = $1\n LIMIT 1\n )\n AND \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "a94e5ac730ba6bdb11e9b27b11babb1552e787c0920e1102882acc4381245f24"
+}
diff --git a/rust/cloud-storage/soup/.sqlx/query-ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10.json b/rust/cloud-storage/soup/.sqlx/query-ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10.json
new file mode 100644
index 0000000000..b0fb258d2d
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT l.macro_id\n FROM email_threads et\n JOIN email_links l ON et.link_id = l.id\n WHERE et.id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "macro_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "ac30668bed9f5d19db9e0a0cacda6ee156a13fae34c5ccb129794c9d16e95e10"
+}
diff --git a/rust/cloud-storage/soup/.sqlx/query-b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815.json b/rust/cloud-storage/soup/.sqlx/query-b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815.json
new file mode 100644
index 0000000000..aa74e2b98b
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'email_thread'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"EmailThreadPermission\" WHERE \"threadId\" = $3\n )\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "b1ca353c3b2a80e3dadf3415cc79d4a08684a7a76ecaf47edfc5bedf5a0e1815"
+}
diff --git a/rust/cloud-storage/soup/.sqlx/query-b509140ce307b4e440349fae476518b06d6247bf27821c9bea2f04c1eb999768.json b/rust/cloud-storage/soup/.sqlx/query-b509140ce307b4e440349fae476518b06d6247bf27821c9bea2f04c1eb999768.json
new file mode 100644
index 0000000000..8b8ac7b5ce
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-b509140ce307b4e440349fae476518b06d6247bf27821c9bea2f04c1eb999768.json
@@ -0,0 +1,145 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n -- =============================================================================\n -- EXPANDED GENERIC CURSOR SOUP QUERY\n -- =============================================================================\n -- Retrieves all items (documents, chats, projects) that a user has access to,\n -- including both explicit permissions and inherited permissions through the\n -- project hierarchy.\n -- =============================================================================\n\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n\n UserAccessibleItems AS (\n SELECT DISTINCT\n ea.entity_id::text as item_id,\n ea.entity_type as item_type\n FROM entity_access ea\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n ),\n\n -- Identify the top N items with minimal columns before joining full details.\n -- Performs early filtering and sorting to reduce the data processed in\n -- subsequent joins.\n TopItems AS (\n SELECT item_type, id, sort_ts, updated_at FROM (\n SELECT\n 'document'::text as item_type,\n d.id,\n -- Dynamic sort column based on user's selected sort method\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", d.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN d.\"createdAt\"\n ELSE d.\"updatedAt\"\n END::timestamptz as sort_ts,\n d.\"updatedAt\"::timestamptz as updated_at\n FROM \"Document\" d\n INNER JOIN UserAccessibleItems uai ON uai.item_id = d.id AND uai.item_type = 'document'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = d.id AND uh.\"itemType\" = 'document' AND uh.\"userId\" = $1\n WHERE d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'chat'::text,\n c.id,\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", c.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN c.\"createdAt\"\n ELSE c.\"updatedAt\"\n END::timestamptz,\n c.\"updatedAt\"::timestamptz\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai ON uai.item_id = c.id AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = c.id AND uh.\"itemType\" = 'chat' AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'project'::text,\n p.id,\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", p.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN p.\"createdAt\"\n ELSE p.\"updatedAt\"\n END::timestamptz,\n p.\"updatedAt\"::timestamptz\n FROM \"Project\" p\n INNER JOIN UserAccessibleItems uai ON uai.item_id = p.id AND uai.item_type = 'project'\n LEFT JOIN \"UserHistory\" uh ON uh.\"itemId\" = p.id AND uh.\"itemType\" = 'project' AND uh.\"userId\" = $1\n WHERE p.\"deletedAt\" IS NULL\n ) all_items\n WHERE\n -- Cursor-based pagination: skip items we've already seen.\n -- NULL cursor means first page (no items to skip).\n ($4::timestamptz IS NULL)\n OR\n -- Seek method: find items \"before\" the cursor position\n -- using (sort_ts, id) tuple comparison for deterministic ordering\n (sort_ts, id::text) < ($4, $5)\n ORDER BY sort_ts DESC, id DESC\n LIMIT $3\n )\n\n -- Join full item details only for the filtered top items.\n SELECT * FROM (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n t.sort_ts as \"sort_ts!\",\n -- Task completion status: check if status property matches \"completed\"\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $6\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM TopItems t\n INNER JOIN \"Document\" d ON d.id = t.id\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status\n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id\n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $7\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = d.id AND uh.\"itemType\" = 'document' AND uh.\"userId\" = $1\n -- LATERAL joins to get the latest version info\n LEFT JOIN LATERAL (\n SELECT b.id\n FROM \"DocumentBom\" b\n WHERE b.\"documentId\" = d.id\n ORDER BY b.\"createdAt\" DESC\n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha\n FROM \"DocumentInstance\" i\n WHERE i.\"documentId\" = d.id\n ORDER BY i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON true\n WHERE t.item_type = 'document'\n\n UNION ALL\n\n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n t.sort_ts as \"sort_ts!\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM TopItems t\n INNER JOIN \"Chat\" c ON c.id = t.id\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = c.id AND uh.\"itemType\" = 'chat' AND uh.\"userId\" = $1\n WHERE t.item_type = 'chat'\n\n UNION ALL\n\n SELECT\n 'project' as \"item_type!\",\n p.id as \"id!\",\n NULL as \"document_version_id\",\n p.\"userId\" as \"user_id!\",\n p.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n p.\"createdAt\"::timestamptz as \"created_at!\",\n p.\"updatedAt\"::timestamptz as \"updated_at!\",\n p.\"parentId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n t.sort_ts as \"sort_ts!\",\n NULL as \"is_completed\",\n p.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM TopItems t\n INNER JOIN \"Project\" p ON p.id = t.id\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = p.id AND uh.\"itemType\" = 'project' AND uh.\"userId\" = $1\n WHERE t.item_type = 'project'\n ) Combined\n -- Sort by timestamp descending, with ID as tiebreaker for deterministic pagination.\n -- This ensures consistent ordering when multiple items share the same timestamp,\n -- preventing items from being skipped or duplicated across pages.\n ORDER BY \"sort_ts!\" DESC, \"id!\" DESC\n LIMIT $3\n",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_version_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "user_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "name!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "branched_from_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "branched_from_version_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 7,
+ "name": "document_family_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 8,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 9,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 11,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 12,
+ "name": "is_persistent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 13,
+ "name": "sha",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 14,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 15,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 16,
+ "name": "sort_ts!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 17,
+ "name": "is_completed",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 18,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Int8",
+ "Timestamptz",
+ "Text",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "b509140ce307b4e440349fae476518b06d6247bf27821c9bea2f04c1eb999768"
+}
diff --git a/rust/cloud-storage/soup/.sqlx/query-b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524.json b/rust/cloud-storage/soup/.sqlx/query-b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524.json
new file mode 100644
index 0000000000..be13d76b25
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'document'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"DocumentPermission\" WHERE \"documentId\" = $3\n ) \n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "b56786cafd46e138a172ca008f6586c551794b50c95616b56b7c94ac7c2d4524"
+}
diff --git a/rust/cloud-storage/soup/.sqlx/query-b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157.json b/rust/cloud-storage/soup/.sqlx/query-b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157.json
new file mode 100644
index 0000000000..d560cb7eb3
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'chat'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ChatPermission\" WHERE \"chatId\" = $3\n )\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "b9fc3c761760c8e3d0013e064f23a9ad1f17396c8f5f91e9cc27e2ba9ba02157"
+}
diff --git a/rust/cloud-storage/soup/.sqlx/query-bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682.json b/rust/cloud-storage/soup/.sqlx/query-bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682.json
new file mode 100644
index 0000000000..3ed3f3db5e
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE id in (SELECT share_permission_id\n FROM calls\n WHERE id = $1\n UNION ALL\n SELECT share_permission_id\n FROM call_records\n WHERE id = $1\n LIMIT 1)\n AND \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "bdb882d426cf81329dd6d824a5d945cfd0ea2fffa26b5324ef641dfe3e304682"
+}
diff --git a/rust/cloud-storage/soup/.sqlx/query-c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476.json b/rust/cloud-storage/soup/.sqlx/query-c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476.json
new file mode 100644
index 0000000000..1216b39a3c
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476.json
@@ -0,0 +1,24 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT access_level FROM (\n -- Source 1: entity_access source_id match\n SELECT\n access_level::text FROM entity_access\n WHERE entity_id = $1\n AND entity_type = 'project'\n AND source_id = ANY($2)\n\n UNION ALL\n -- Source 2: items share permission\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"ProjectPermission\" WHERE \"projectId\" = $3\n )\n )\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "c8f152fcf66d2a28cb74bd5e5bd00494b195ba6fa890f7ed840a04dc49088476"
+}
diff --git a/rust/cloud-storage/soup/.sqlx/query-cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580.json b/rust/cloud-storage/soup/.sqlx/query-cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580.json
new file mode 100644
index 0000000000..ddcaf87146
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT cp.channel_id::text FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "channel_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "cac5e246875c3539f7a03cee8271708be47a56582c2f0323716f206ab905a580"
+}
diff --git a/rust/cloud-storage/soup/.sqlx/query-db2a1d38763a3639c61d093c4be67c135a99719555af1d4dcf71ae497a56533c.json b/rust/cloud-storage/soup/.sqlx/query-db2a1d38763a3639c61d093c4be67c135a99719555af1d4dcf71ae497a56533c.json
deleted file mode 100644
index 598fb6d7d1..0000000000
--- a/rust/cloud-storage/soup/.sqlx/query-db2a1d38763a3639c61d093c4be67c135a99719555af1d4dcf71ae497a56533c.json
+++ /dev/null
@@ -1,145 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH UserAccessibleItems AS (\n SELECT DISTINCT ON (\"item_id\", \"item_type\")\n \"item_id\",\n \"item_type\"\n FROM \"UserItemAccess\" \n WHERE \"user_id\" = $1\n ORDER BY \"item_id\", \"item_type\", \n CASE \"access_level\"\n WHEN 'owner' THEN 4\n WHEN 'edit' THEN 3 \n WHEN 'comment' THEN 2\n WHEN 'view' THEN 1\n ELSE 0\n END DESC\n ),\n Combined AS (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\", \n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", d.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN d.\"createdAt\"\n ELSE d.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $6\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status\n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id\n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $7\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = d.id\n AND uai.item_type = 'document'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = d.id\n AND uh.\"itemType\" = 'document'\n AND uh.\"userId\" = $1\n LEFT JOIN LATERAL (\n SELECT b.id\n FROM \"DocumentBom\" b\n WHERE b.\"documentId\" = d.id\n ORDER BY b.\"createdAt\" DESC\n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha\n FROM \"DocumentInstance\" i\n WHERE i.\"documentId\" = d.id\n ORDER BY i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON true\n WHERE d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", c.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN c.\"createdAt\"\n ELSE c.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = c.id\n AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = c.id\n AND uh.\"itemType\" = 'chat'\n AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'project' as \"item_type!\",\n p.id as \"id!\",\n NULL as \"document_version_id\",\n p.\"userId\" as \"user_id!\",\n p.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n p.\"createdAt\"::timestamptz as \"created_at!\",\n p.\"updatedAt\"::timestamptz as \"updated_at!\",\n p.\"parentId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", p.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN p.\"createdAt\"\n ELSE p.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n p.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Project\" p\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = p.id\n AND uai.item_type = 'project'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = p.id\n AND uh.\"itemType\" = 'project'\n AND uh.\"userId\" = $1\n WHERE p.\"deletedAt\" IS NULL\n )\n SELECT * \n FROM Combined\n WHERE ($4::timestamptz IS NULL)\n OR (\"sort_ts!\", \"id!\") < ($4, $5)\n ORDER BY \"sort_ts!\" DESC, \"id!\" DESC\n LIMIT $3\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "item_type!",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "id!",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "document_version_id",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "user_id!",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "name!",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
- "name": "branched_from_id",
- "type_info": "Text"
- },
- {
- "ordinal": 6,
- "name": "branched_from_version_id",
- "type_info": "Int8"
- },
- {
- "ordinal": 7,
- "name": "document_family_id",
- "type_info": "Int8"
- },
- {
- "ordinal": 8,
- "name": "file_type",
- "type_info": "Text"
- },
- {
- "ordinal": 9,
- "name": "created_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 10,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 11,
- "name": "project_id",
- "type_info": "Text"
- },
- {
- "ordinal": 12,
- "name": "is_persistent",
- "type_info": "Bool"
- },
- {
- "ordinal": 13,
- "name": "sha",
- "type_info": "Text"
- },
- {
- "ordinal": 14,
- "name": "sub_type?: DocumentSubType",
- "type_info": {
- "Custom": {
- "name": "document_sub_type_value",
- "kind": {
- "Enum": [
- "task"
- ]
- }
- }
- }
- },
- {
- "ordinal": 15,
- "name": "viewed_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 16,
- "name": "sort_ts!",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 17,
- "name": "is_completed",
- "type_info": "Bool"
- },
- {
- "ordinal": 18,
- "name": "deleted_at",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text",
- "Int8",
- "Timestamptz",
- "Text",
- "Text",
- "Uuid"
- ]
- },
- "nullable": [
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null
- ]
- },
- "hash": "db2a1d38763a3639c61d093c4be67c135a99719555af1d4dcf71ae497a56533c"
-}
diff --git a/rust/cloud-storage/soup/.sqlx/query-dd4f7c4b90b6340ea7f4a7d6eb16347612e9d197979f9d4a4df40314f22559f8.json b/rust/cloud-storage/soup/.sqlx/query-dd4f7c4b90b6340ea7f4a7d6eb16347612e9d197979f9d4a4df40314f22559f8.json
new file mode 100644
index 0000000000..e4ffd6dc3c
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-dd4f7c4b90b6340ea7f4a7d6eb16347612e9d197979f9d4a4df40314f22559f8.json
@@ -0,0 +1,145 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1\n ),\n UserAccessibleItems AS (\n SELECT DISTINCT\n ea.entity_id::text as item_id,\n ea.entity_type as item_type\n FROM entity_access ea\n WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)\n ),\n Combined AS (\n SELECT\n 'document' as \"item_type!\",\n d.id as \"id!\",\n CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n d.owner as \"user_id!\",\n d.name as \"name!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\", \n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"fileType\" as \"file_type\",\n d.\"createdAt\"::timestamptz as \"created_at!\",\n d.\"updatedAt\"::timestamptz as \"updated_at!\",\n d.\"projectId\" as \"project_id\",\n NULL as \"is_persistent\",\n di.sha as \"sha\",\n dt.sub_type as \"sub_type?: DocumentSubType\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", d.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN d.\"createdAt\"\n ELSE d.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n CASE\n WHEN dt.sub_type = 'task'\n AND ep_status.values->'value' ? $6\n THEN true\n WHEN dt.sub_type = 'task'\n THEN false\n ELSE NULL\n END as \"is_completed\",\n d.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN entity_properties ep_status\n ON dt.sub_type = 'task'\n AND ep_status.entity_id = d.id\n AND ep_status.entity_type = 'TASK'\n AND ep_status.property_definition_id = $7\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = d.id\n AND uai.item_type = 'document'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = d.id\n AND uh.\"itemType\" = 'document'\n AND uh.\"userId\" = $1\n LEFT JOIN LATERAL (\n SELECT b.id\n FROM \"DocumentBom\" b\n WHERE b.\"documentId\" = d.id\n ORDER BY b.\"createdAt\" DESC\n LIMIT 1\n ) db ON true\n LEFT JOIN LATERAL (\n SELECT i.id, i.sha\n FROM \"DocumentInstance\" i\n WHERE i.\"documentId\" = d.id\n ORDER BY i.\"updatedAt\" DESC\n LIMIT 1\n ) di ON true\n WHERE d.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'chat' as \"item_type!\",\n c.id as \"id!\",\n NULL as \"document_version_id\",\n c.\"userId\" as \"user_id!\",\n c.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n c.\"createdAt\"::timestamptz as \"created_at!\",\n c.\"updatedAt\"::timestamptz as \"updated_at!\",\n c.\"projectId\" as \"project_id\",\n c.\"isPersistent\" as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", c.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN c.\"createdAt\"\n ELSE c.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n c.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Chat\" c\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = c.id\n AND uai.item_type = 'chat'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = c.id\n AND uh.\"itemType\" = 'chat'\n AND uh.\"userId\" = $1\n WHERE c.\"deletedAt\" IS NULL\n\n UNION ALL\n\n SELECT\n 'project' as \"item_type!\",\n p.id as \"id!\",\n NULL as \"document_version_id\",\n p.\"userId\" as \"user_id!\",\n p.name as \"name!\",\n NULL as \"branched_from_id\",\n NULL as \"branched_from_version_id\",\n NULL as \"document_family_id\",\n NULL as \"file_type\",\n p.\"createdAt\"::timestamptz as \"created_at!\",\n p.\"updatedAt\"::timestamptz as \"updated_at!\",\n p.\"parentId\" as \"project_id\",\n NULL as \"is_persistent\",\n NULL as \"sha\",\n NULL as \"sub_type\",\n uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n CASE $2\n WHEN 'viewed_updated' THEN COALESCE(uh.\"updatedAt\", p.\"updatedAt\")\n WHEN 'viewed_at' THEN COALESCE(uh.\"updatedAt\", '1970-01-01 00:00:00+00')\n WHEN 'created_at' THEN p.\"createdAt\"\n ELSE p.\"updatedAt\"\n END::timestamptz as \"sort_ts!\",\n NULL as \"is_completed\",\n p.\"deletedAt\"::timestamptz as \"deleted_at\"\n FROM \"Project\" p\n INNER JOIN UserAccessibleItems uai\n ON uai.item_id = p.id\n AND uai.item_type = 'project'\n LEFT JOIN \"UserHistory\" uh\n ON uh.\"itemId\" = p.id\n AND uh.\"itemType\" = 'project'\n AND uh.\"userId\" = $1\n WHERE p.\"deletedAt\" IS NULL\n )\n SELECT * \n FROM Combined\n WHERE ($4::timestamptz IS NULL)\n OR (\"sort_ts!\", \"id!\") < ($4, $5)\n ORDER BY \"sort_ts!\" DESC, \"id!\" DESC\n LIMIT $3\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "item_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "document_version_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "user_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "name!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "branched_from_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "branched_from_version_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 7,
+ "name": "document_family_id",
+ "type_info": "Int8"
+ },
+ {
+ "ordinal": 8,
+ "name": "file_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 9,
+ "name": "created_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 11,
+ "name": "project_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 12,
+ "name": "is_persistent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 13,
+ "name": "sha",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 14,
+ "name": "sub_type?: DocumentSubType",
+ "type_info": {
+ "Custom": {
+ "name": "document_sub_type_value",
+ "kind": {
+ "Enum": [
+ "task"
+ ]
+ }
+ }
+ }
+ },
+ {
+ "ordinal": 15,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 16,
+ "name": "sort_ts!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 17,
+ "name": "is_completed",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 18,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Int8",
+ "Timestamptz",
+ "Text",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "dd4f7c4b90b6340ea7f4a7d6eb16347612e9d197979f9d4a4df40314f22559f8"
+}
diff --git a/rust/cloud-storage/soup/.sqlx/query-e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437.json b/rust/cloud-storage/soup/.sqlx/query-e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437.json
new file mode 100644
index 0000000000..3ac1b029f6
--- /dev/null
+++ b/rust/cloud-storage/soup/.sqlx/query-e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n \"publicAccessLevel\" as \"access_level!\"\n FROM \"SharePermission\"\n WHERE \"isPublic\" = true\n AND \"publicAccessLevel\" IS NOT NULL\n AND id IN (\n SELECT \"sharePermissionId\" FROM \"EmailThreadPermission\" WHERE \"threadId\" = $1\n )\n\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "access_level!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "e35594f0b886c9eaba037a0b13ccb3baf21cd37b638190889fb5383180a8e437"
+}
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_cursor.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_cursor.rs
index 98f9a133c7..9eafe037c8 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_cursor.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_cursor.rs
@@ -42,73 +42,22 @@ r#"
-- project hierarchy.
-- =============================================================================
- -- Build the project hierarchy tree using recursive CTE.
- -- Starting from projects the user has explicit access to, recursively find
- -- all child projects. This enables inherited access - if you can access a
- -- parent project, you can access all its descendants.
- WITH RECURSIVE ProjectHierarchy AS (
- -- Base case: projects the user has direct access to
- SELECT p.id, uia.access_level
- FROM "Project" p
- JOIN "UserItemAccess" uia ON p.id = uia.item_id AND uia.item_type = 'project'
- WHERE uia.user_id = $1 AND p."deletedAt" IS NULL
- UNION ALL
- -- Recursive case: find child projects, inheriting parent's access level
- SELECT p.id, ph.access_level
- FROM "Project" p
- JOIN ProjectHierarchy ph ON p."parentId" = ph.id
- WHERE p."deletedAt" IS NULL
- ),
-
- -- Collect all access grants from multiple sources.
- -- Aggregates explicit permissions AND implicit permissions inherited
- -- through project membership.
- AllAccessGrants AS (
- -- Direct/explicit access grants to any item type
- SELECT item_id, item_type, access_level
- FROM "UserItemAccess"
- WHERE user_id = $1
-
- UNION ALL
-
- -- Documents within accessible projects (inherited access).
- -- Uses ANY(ARRAY(...)) pattern to reduce intermediate result set size.
- SELECT d.id AS item_id, 'document' AS item_type,
- (SELECT ph.access_level FROM ProjectHierarchy ph WHERE ph.id = d."projectId" LIMIT 1) as access_level
- FROM "Document" d
- WHERE d."projectId" = ANY(ARRAY(SELECT id FROM ProjectHierarchy))
- AND d."deletedAt" IS NULL
-
+ WITH user_source_ids AS (
+ SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp
+ WHERE cp.user_id = $1 AND cp.left_at IS NULL
UNION ALL
-
- -- Chats within accessible projects (inherited access)
- SELECT c.id AS item_id, 'chat' AS item_type, ph.access_level
- FROM "Chat" c
- JOIN ProjectHierarchy ph ON c."projectId" = ph.id
- WHERE c."projectId" IS NOT NULL AND c."deletedAt" IS NULL
-
+ SELECT t.team_id::text FROM team_user t
+ WHERE t.user_id = $1
UNION ALL
-
- -- The projects themselves from the hierarchy
- SELECT ph.id AS item_id, 'project' AS item_type, ph.access_level
- FROM ProjectHierarchy ph
+ SELECT $1
),
- -- Deduplicate access grants, keeping the highest permission level.
- -- When a user has multiple access paths to the same item (e.g., direct + inherited),
- -- we keep only one row with the highest privilege level.
UserAccessibleItems AS (
- SELECT DISTINCT ON (item_id, item_type) item_id, item_type
- FROM AllAccessGrants
- ORDER BY item_id, item_type,
- -- Priority: owner > edit > comment > view
- CASE access_level
- WHEN 'owner' THEN 4
- WHEN 'edit' THEN 3
- WHEN 'comment' THEN 2
- WHEN 'view' THEN 1
- ELSE 0
- END DESC
+ SELECT DISTINCT
+ ea.entity_id::text as item_id,
+ ea.entity_type as item_type
+ FROM entity_access ea
+ WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)
),
-- Identify the top N items with minimal columns before joining full details.
@@ -333,46 +282,21 @@ pub async fn no_frecency_expanded_generic_soup(
let mut items: Vec<SoupItem> = sqlx::query!(
r#"
- WITH RECURSIVE ProjectHierarchy AS (
- SELECT p.id, uia.access_level
- FROM "Project" p
- JOIN "UserItemAccess" uia ON p.id = uia.item_id AND uia.item_type = 'project'
- WHERE uia.user_id = $1 AND p."deletedAt" IS NULL
- UNION ALL
- SELECT p.id, ph.access_level
- FROM "Project" p
- JOIN ProjectHierarchy ph ON p."parentId" = ph.id
- WHERE p."deletedAt" IS NULL
- ),
- AllAccessGrants AS (
- SELECT item_id, item_type, access_level
- FROM "UserItemAccess"
- WHERE user_id = $1
- UNION ALL
- SELECT d.id AS item_id, 'document' AS item_type, ph.access_level
- FROM "Document" d
- JOIN ProjectHierarchy ph ON d."projectId" = ph.id
- WHERE d."projectId" IS NOT NULL AND d."deletedAt" IS NULL
+ WITH user_source_ids AS (
+ SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp
+ WHERE cp.user_id = $1 AND cp.left_at IS NULL
UNION ALL
- SELECT c.id AS item_id, 'chat' AS item_type, ph.access_level
- FROM "Chat" c
- JOIN ProjectHierarchy ph ON c."projectId" = ph.id
- WHERE c."projectId" IS NOT NULL AND c."deletedAt" IS NULL
+ SELECT t.team_id::text FROM team_user t
+ WHERE t.user_id = $1
UNION ALL
- SELECT ph.id AS item_id, 'project' AS item_type, ph.access_level
- FROM ProjectHierarchy ph
+ SELECT $1
),
UserAccessibleItems AS (
- SELECT DISTINCT ON (item_id, item_type) item_id, item_type
- FROM AllAccessGrants
- ORDER BY item_id, item_type,
- CASE access_level
- WHEN 'owner' THEN 4
- WHEN 'edit' THEN 3
- WHEN 'comment' THEN 2
- WHEN 'view' THEN 1
- ELSE 0
- END DESC
+ SELECT DISTINCT
+ ea.entity_id::text as item_id,
+ ea.entity_type as item_type
+ FROM entity_access ea
+ WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)
),
Combined AS (
SELECT
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs
index 933139094c..1c41bcd678 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/by_ids.rs
@@ -43,46 +43,21 @@ pub async fn expanded_soup_by_ids<'a>(
let mut items: Vec<SoupItem> = sqlx::query!(
r#"
- WITH RECURSIVE ProjectHierarchy AS (
- SELECT p.id, uia.access_level
- FROM "Project" p
- JOIN "UserItemAccess" uia ON p.id = uia.item_id AND uia.item_type = 'project'
- WHERE uia.user_id = $1 AND p."deletedAt" IS NULL
+ WITH user_source_ids AS (
+ SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp
+ WHERE cp.user_id = $1 AND cp.left_at IS NULL
UNION ALL
- SELECT p.id, ph.access_level
- FROM "Project" p
- JOIN ProjectHierarchy ph ON p."parentId" = ph.id
- WHERE p."deletedAt" IS NULL
- ),
- AllAccessGrants AS (
- SELECT item_id, item_type, access_level
- FROM "UserItemAccess"
- WHERE user_id = $1
- UNION ALL
- SELECT d.id AS item_id, 'document' AS item_type, ph.access_level
- FROM "Document" d
- JOIN ProjectHierarchy ph ON d."projectId" = ph.id
- WHERE d."projectId" IS NOT NULL AND d."deletedAt" IS NULL
- UNION ALL
- SELECT c.id AS item_id, 'chat' AS item_type, ph.access_level
- FROM "Chat" c
- JOIN ProjectHierarchy ph ON c."projectId" = ph.id
- WHERE c."projectId" IS NOT NULL AND c."deletedAt" IS NULL
+ SELECT t.team_id::text FROM team_user t
+ WHERE t.user_id = $1
UNION ALL
- SELECT ph.id AS item_id, 'project' AS item_type, ph.access_level
- FROM ProjectHierarchy ph
+ SELECT $1
),
UserAccessibleItems AS (
- SELECT DISTINCT ON (item_id, item_type) item_id, item_type
- FROM AllAccessGrants
- ORDER BY item_id, item_type,
- CASE access_level
- WHEN 'owner' THEN 4
- WHEN 'edit' THEN 3
- WHEN 'comment' THEN 2
- WHEN 'view' THEN 1
- ELSE 0
- END DESC
+ SELECT DISTINCT
+ ea.entity_id::text as item_id,
+ ea.entity_type as item_type
+ FROM entity_access ea
+ WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)
),
Combined AS (
SELECT
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs
index d55c21c756..94bd577fef 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/expanded/dynamic.rs
@@ -29,47 +29,21 @@ use uuid::Uuid;
use crate::outbound::pg_soup_repo::{populate_properties, type_err};
static PREFIX: &str = r#"
- WITH RECURSIVE ProjectHierarchy AS (
- SELECT p.id, uia.access_level
- FROM "Project" p
- JOIN "UserItemAccess" uia ON p.id = uia.item_id AND uia.item_type = 'project'
- WHERE uia.user_id = $1 AND p."deletedAt" IS NULL
+ WITH user_source_ids AS (
+ SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp
+ WHERE cp.user_id = $1 AND cp.left_at IS NULL
UNION ALL
- SELECT p.id, ph.access_level
- FROM "Project" p
- JOIN ProjectHierarchy ph ON p."parentId" = ph.id
- WHERE p."deletedAt" IS NULL
- ),
- AllAccessGrants AS (
- SELECT item_id, item_type, access_level
- FROM "UserItemAccess"
- WHERE user_id = $1
- UNION ALL
- SELECT d.id AS item_id, 'document' AS item_type,
- (SELECT ph.access_level FROM ProjectHierarchy ph WHERE ph.id = d."projectId" LIMIT 1) as access_level
- FROM "Document" d
- WHERE d."projectId" = ANY(ARRAY(SELECT id FROM ProjectHierarchy))
- AND d."deletedAt" IS NULL
- UNION ALL
- SELECT c.id AS item_id, 'chat' AS item_type, ph.access_level
- FROM "Chat" c
- JOIN ProjectHierarchy ph ON c."projectId" = ph.id
- WHERE c."projectId" IS NOT NULL AND c."deletedAt" IS NULL
+ SELECT t.team_id::text FROM team_user t
+ WHERE t.user_id = $1
UNION ALL
- SELECT ph.id AS item_id, 'project' AS item_type, ph.access_level
- FROM ProjectHierarchy ph
+ SELECT $1
),
UserAccessibleItems AS (
- SELECT DISTINCT ON (item_id, item_type) item_id, item_type
- FROM AllAccessGrants
- ORDER BY item_id, item_type,
- CASE access_level
- WHEN 'owner' THEN 4
- WHEN 'edit' THEN 3
- WHEN 'comment' THEN 2
- WHEN 'view' THEN 1
- ELSE 0
- END DESC
+ SELECT DISTINCT
+ ea.entity_id::text as item_id,
+ ea.entity_type as item_type
+ FROM entity_access ea
+ WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)
),
"#;
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_cursor.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_cursor.rs
index d0864b4bbe..1c2d9c8283 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_cursor.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_cursor.rs
@@ -35,20 +35,21 @@ pub async fn unexpanded_generic_cursor_soup(
let mut items: Vec<SoupItem> = sqlx::query!(
r#"
- WITH UserAccessibleItems AS (
- SELECT DISTINCT ON ("item_id", "item_type")
- "item_id",
- "item_type"
- FROM "UserItemAccess"
- WHERE "user_id" = $1
- ORDER BY "item_id", "item_type",
- CASE "access_level"
- WHEN 'owner' THEN 4
- WHEN 'edit' THEN 3
- WHEN 'comment' THEN 2
- WHEN 'view' THEN 1
- ELSE 0
- END DESC
+ WITH user_source_ids AS (
+ SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp
+ WHERE cp.user_id = $1 AND cp.left_at IS NULL
+ UNION ALL
+ SELECT t.team_id::text FROM team_user t
+ WHERE t.user_id = $1
+ UNION ALL
+ SELECT $1
+ ),
+ UserAccessibleItems AS (
+ SELECT DISTINCT
+ ea.entity_id::text as item_id,
+ ea.entity_type as item_type
+ FROM entity_access ea
+ WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)
),
Combined AS (
SELECT
diff --git a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_ids.rs b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_ids.rs
index cfadade422..7df34c77d4 100644
--- a/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_ids.rs
+++ b/rust/cloud-storage/soup/src/outbound/pg_soup_repo/unexpanded/by_ids.rs
@@ -44,20 +44,21 @@ pub async fn unexpanded_soup_by_ids<'a>(
let mut items: Vec<SoupItem> = sqlx::query!(
r#"
- WITH UserAccessibleItems AS (
- SELECT DISTINCT ON ("item_id", "item_type")
- "item_id",
- "item_type"
- FROM "UserItemAccess"
- WHERE "user_id" = $1
- ORDER BY "item_id", "item_type",
- CASE "access_level"
- WHEN 'owner' THEN 4
- WHEN 'edit' THEN 3
- WHEN 'comment' THEN 2
- WHEN 'view' THEN 1
- ELSE 0
- END DESC
+ WITH user_source_ids AS (
+ SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp
+ WHERE cp.user_id = $1 AND cp.left_at IS NULL
+ UNION ALL
+ SELECT t.team_id::text FROM team_user t
+ WHERE t.user_id = $1
+ UNION ALL
+ SELECT $1
+ ),
+ UserAccessibleItems AS (
+ SELECT DISTINCT
+ ea.entity_id::text as item_id,
+ ea.entity_type as item_type
+ FROM entity_access ea
+ WHERE ea.source_id = ANY(SELECT source_id FROM user_source_ids)
),
Combined AS (
SELECT
diff --git a/rust/cloud-storage/target/lambda/delete_chat_handler/bootstrap.zip b/rust/cloud-storage/target/lambda/delete_chat_handler/bootstrap.zip
index 8517f6299f..b305901e9a 100644
Binary files a/rust/cloud-storage/target/lambda/delete_chat_handler/bootstrap.zip and b/rust/cloud-storage/target/lambda/delete_chat_handler/bootstrap.zip differ