fix: Schema compatibility - emoji → icon column rename

Production Outline DB uses 'icon' column instead of 'emoji' for documents
and revisions. Fixed all affected queries:

- documents.ts: SELECT queries
- advanced-search.ts: Search queries
- analytics.ts: Analytics + GROUP BY
- export-import.ts: Export/import metadata
- templates.ts: Template queries + INSERT
- collections.ts: Collection document listing
- revisions.ts: Revision comparison

reactions.emoji kept unchanged (correct schema)

Tested: 448 documents successfully queried from hub.descomplicar.pt

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-31 17:14:27 +00:00
parent 5f49cb63e8
commit 7d2a014b74
10 changed files with 63 additions and 37 deletions

View File

@@ -220,14 +220,14 @@ const getContentInsights: BaseTool<{ collection_id?: string }> = {
// Most viewed documents
const mostViewed = await pgClient.query(`
SELECT
d.id, d.title, d.emoji, c.name as "collectionName",
d.id, d.title, d.icon, c.name as "collectionName",
COUNT(v.id) as "viewCount",
COUNT(DISTINCT v."userId") as "uniqueViewers"
FROM documents d
LEFT JOIN views v ON v."documentId" = d.id
LEFT JOIN collections c ON d."collectionId" = c.id
WHERE d."deletedAt" IS NULL ${collectionCondition}
GROUP BY d.id, d.title, d.emoji, c.name
GROUP BY d.id, d.title, d.icon, c.name
ORDER BY "viewCount" DESC
LIMIT 10
`, params);
@@ -235,13 +235,13 @@ const getContentInsights: BaseTool<{ collection_id?: string }> = {
// Most starred documents
const mostStarred = await pgClient.query(`
SELECT
d.id, d.title, d.emoji, c.name as "collectionName",
d.id, d.title, d.icon, c.name as "collectionName",
COUNT(s.id) as "starCount"
FROM documents d
LEFT JOIN stars s ON s."documentId" = d.id
LEFT JOIN collections c ON d."collectionId" = c.id
WHERE d."deletedAt" IS NULL ${collectionCondition}
GROUP BY d.id, d.title, d.emoji, c.name
GROUP BY d.id, d.title, d.icon, c.name
HAVING COUNT(s.id) > 0
ORDER BY "starCount" DESC
LIMIT 10
@@ -250,7 +250,7 @@ const getContentInsights: BaseTool<{ collection_id?: string }> = {
// Stale documents (not updated in 90 days)
const staleDocuments = await pgClient.query(`
SELECT
d.id, d.title, d.emoji, c.name as "collectionName",
d.id, d.title, d.icon, c.name as "collectionName",
d."updatedAt",
EXTRACT(DAY FROM NOW() - d."updatedAt") as "daysSinceUpdate"
FROM documents d
@@ -267,7 +267,7 @@ const getContentInsights: BaseTool<{ collection_id?: string }> = {
// Documents without views
const neverViewed = await pgClient.query(`
SELECT
d.id, d.title, d.emoji, c.name as "collectionName",
d.id, d.title, d.icon, c.name as "collectionName",
d."createdAt"
FROM documents d
LEFT JOIN views v ON v."documentId" = d.id