feat: Phase H knowledge plugin — models, services (extract/ask/review), routes, plugin with event hooks, migration 0131, builds on graph_rag + llm_client + unified_search
Check Cross-Plugin Imports / check (push) Has been cancelled
Check Cross-Plugin Imports / check (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
"""knowledge extractions table
|
||||
|
||||
Revision ID: 0131
|
||||
Revises: 0130
|
||||
Create Date: 2026-08-20
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects.postgresql import UUID, JSONB
|
||||
|
||||
revision = "0131"
|
||||
down_revision = "0130"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"knowledge_extractions",
|
||||
sa.Column("id", UUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
|
||||
sa.Column("tenant_id", UUID(as_uuid=True), sa.ForeignKey("tenants.id", ondelete="CASCADE"), nullable=False),
|
||||
sa.Column("source_type", sa.String(50), nullable=False),
|
||||
sa.Column("source_id", UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("source_title", sa.String(500), nullable=True),
|
||||
sa.Column("extracted_entities", JSONB, nullable=False, server_default=sa.text("'[]'::jsonb")),
|
||||
sa.Column("extracted_relationships", JSONB, nullable=False, server_default=sa.text("'[]'::jsonb")),
|
||||
sa.Column("confidence", sa.Float, nullable=False, server_default=sa.text("0.0")),
|
||||
sa.Column("status", sa.String(30), nullable=False, server_default=sa.text("'pending'")),
|
||||
sa.Column("review_notes", sa.Text, nullable=True),
|
||||
sa.Column("llm_model", sa.String(100), nullable=True),
|
||||
sa.Column("llm_cost_usd", sa.Float, nullable=False, server_default=sa.text("0.0")),
|
||||
sa.Column("created_by", UUID(as_uuid=True), sa.ForeignKey("users.id", ondelete="SET NULL"), nullable=True),
|
||||
sa.Column("reviewed_by", UUID(as_uuid=True), sa.ForeignKey("users.id", ondelete="SET NULL"), nullable=True),
|
||||
sa.Column("reviewed_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
||||
)
|
||||
op.create_index("ix_knowledge_ext_tenant_status", "knowledge_extractions", ["tenant_id", "status"])
|
||||
op.create_index("ix_knowledge_ext_source", "knowledge_extractions", ["tenant_id", "source_type", "source_id"])
|
||||
# RLS
|
||||
op.execute("ALTER TABLE knowledge_extractions ENABLE ROW LEVEL SECURITY;")
|
||||
op.execute("CREATE POLICY knowledge_extractions_tenant_isolation ON knowledge_extractions USING (tenant_id::text = current_setting('app.current_tenant_id', true));")
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("knowledge_extractions")
|
||||
Reference in New Issue
Block a user