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.

6.7 KB
Raw Blame
{
  "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",
                "snippet",
                "skill",
                "initiative_description"
              ]
            }
          }
        }
      },
      {
        "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"
}