feat(mcpedia): Phase 3 — async indexing (BullMQ), git-sync webhook, revisions, MCP Resources

- packages/queue: ioredis singleton + BullMQ Queue/Worker (prefix mcpedia:
  on shared imrnes Redis :6379); apps/worker runs startWorker()
- @mcpedia/core: indexContentFile/runFullIndex (single indexing entry point
  shared by script/worker/hook) + revision.service (list/get/restore)
- document_revisions table (migration 0002) — snapshots only on body change
- apps/api: POST /hooks/reindex + /hooks/index webhooks; tRPC revisions,
  getRevision, restoreRevision, jobStatus, queueStatus
- apps/mcp: register MCP Resources mcpedia://docs{/,+slug/chunks/revisions}
  ({+slug} RFC6570 reserved expansion for slugs containing /)
- apps/mcp zod pinned to ^4 to match MCP SDK 1.30 compiled types
  (resolves registerTool TS2589/ShapeOutput skew)
- scripts/enqueue.ts one-shot job enqueue helper; indexer refactored to runFullIndex
- PHASES.md/README/.env.example/docs updated
This commit is contained in:
asepharyana
2026-08-19 20:18:28 +07:00
parent 9397303f01
commit 8f2229d447
30 changed files with 1233 additions and 78 deletions
@@ -0,0 +1,19 @@
CREATE TABLE "document_revisions" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"document_id" text NOT NULL,
"slug" text NOT NULL,
"revision_no" integer NOT NULL,
"title" text NOT NULL,
"body" text NOT NULL,
"meta" jsonb NOT NULL,
"reason" text DEFAULT 'index' NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE INDEX "document_revisions_document_id_idx" ON "document_revisions" USING btree ("document_id");
--> statement-breakpoint
CREATE INDEX "document_revisions_slug_idx" ON "document_revisions" USING btree ("slug");
--> statement-breakpoint
CREATE INDEX "document_revisions_doc_rev_idx" ON "document_revisions" USING btree ("document_id", "revision_no" DESC);
--> statement-breakpoint
ALTER TABLE "document_revisions" ADD CONSTRAINT "document_revisions_document_id_documents_id_fk" FOREIGN KEY ("document_id") REFERENCES "public"."documents"("id") ON DELETE cascade;
+110
View File
@@ -0,0 +1,110 @@
{
"id": "0002_document_revisions",
"prevId": "0001_document_chunks",
"version": "7",
"dialect": "postgresql",
"tables": {
"document_revisions": {
"name": "document_revisions",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"document_id": {
"name": "document_id",
"type": "text",
"notNull": true
},
"slug": {
"name": "slug",
"type": "text",
"notNull": true
},
"revision_no": {
"name": "revision_no",
"type": "integer",
"notNull": true
},
"title": {
"name": "title",
"type": "text",
"notNull": true
},
"body": {
"name": "body",
"type": "text",
"notNull": true
},
"meta": {
"name": "meta",
"type": "jsonb",
"notNull": true
},
"reason": {
"name": "reason",
"type": "text",
"notNull": true,
"default": "'index'"
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"notNull": true,
"default": "now()"
}
},
"indexes": {
"document_revisions_document_id_idx": {
"name": "document_revisions_document_id_idx",
"columns": [
{ "name": "document_id", "asc": true }
],
"isUnique": false
},
"document_revisions_slug_idx": {
"name": "document_revisions_slug_idx",
"columns": [
{ "name": "slug", "asc": true }
],
"isUnique": false
},
"document_revisions_doc_rev_idx": {
"name": "document_revisions_doc_rev_idx",
"columns": [
{ "name": "document_id", "asc": true },
{ "name": "revision_no", "asc": false }
],
"isUnique": false
}
},
"foreignKeys": {
"document_revisions_document_id_documents_id_fk": {
"name": "document_revisions_document_id_documents_id_fk",
"columns": ["document_id"],
"referenceTable": "documents",
"referenceColumns": ["id"],
"onDelete": "cascade"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {}
}
},
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"extensions": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
+7
View File
@@ -15,6 +15,13 @@
"when": 1787137149735,
"tag": "0001_document_chunks",
"breakpoints": true
},
{
"idx": 2,
"version": "7",
"when": 1787139150000,
"tag": "0002_document_revisions",
"breakpoints": true
}
]
}
+44
View File
@@ -3,6 +3,7 @@ import {
customType,
index,
integer,
jsonb,
pgTable,
real,
text,
@@ -77,5 +78,48 @@ export const documentChunks = pgTable(
export type DocumentChunkRow = typeof documentChunks.$inferSelect;
export type NewDocumentChunkRow = typeof documentChunks.$inferInsert;
// Phase 3: document revision system. Each row is an immutable snapshot of a
// document's body + metadata at a point in time (taken by the indexer whenever
// the body actually changes). revisionNo is per-document and monotonically
// increasing so the latest revision is always max(revision_no).
export const documentRevisions = pgTable(
"document_revisions",
{
id: uuid("id").primaryKey().defaultRandom(),
documentId: text("document_id")
.notNull()
.references(() => documents.id, { onDelete: "cascade" }),
slug: text("slug").notNull(),
revisionNo: integer("revision_no").notNull(),
title: text("title").notNull(),
body: text("body").notNull(),
// Metadata snapshot (type/section/status/author/tags) as JSON so a revision
// is self-describing even if the live document is later restructured.
meta: jsonb("meta").notNull().$type<{
type: string;
section: string;
status: string;
author: string;
tags: string[];
}>(),
// Why this revision was created (e.g. "index", "git-push", "restore").
reason: text("reason").notNull().default("index"),
createdAt: timestamp("created_at", { withTimezone: true })
.notNull()
.defaultNow(),
},
(t) => ({
docIdx: index("document_revisions_document_id_idx").on(t.documentId),
slugIdx: index("document_revisions_slug_idx").on(t.slug),
docRevIdx: index("document_revisions_doc_rev_idx").on(
t.documentId,
sql`${t.revisionNo} desc`,
),
}),
);
export type DocumentRevisionRow = typeof documentRevisions.$inferSelect;
export type NewDocumentRevisionRow = typeof documentRevisions.$inferInsert;
export type DocumentRow = typeof documents.$inferSelect;
export type NewDocumentRow = typeof documents.$inferInsert;