Files
poimen-memory/crates/mem-store/migrations/005_workflows_schema.sql
T
rock 7d49a2aaef
CI / CI (pull_request) Failing after 11m15s
refactor: rename memory_entity→knowledge_node, knowledge graph edge→knowledge_edge
Resolves table name collision between:
- memory_edge (provenance DAG: child_sha/parent_sha) — KEPT
- knowledge_edge (knowledge graph: source_id/target_id) — NEW NAME

Changes:
- memory_entity → knowledge_node (all .rs + migrations 003-009)
- knowledge graph memory_edge → knowledge_edge
- memory_entity_version → knowledge_node_version
- memory_edge_version → knowledge_edge_version
- Added knowledge_node + knowledge_edge to init_schema()
- Converted versioning.rs from sqlx::query_as! to runtime queries
  (avoids stale sqlx offline cache dependency)
- Fixed UUID cast: $1::UUID for String→UUID column binds
- Fixed column names: source_entity_id→source_id, target_entity_id→target_id

Production DB: knowledge_node + knowledge_edge tables created,
memory_entity VIEW points to knowledge_node for backward compat.
2026-09-15 15:22:41 +09:00

73 lines
3.3 KiB
SQL

-- Phase 6: Temporal Workflow Service Integration
--
-- Adds reference/linking table for external Temporal.io workflows.
-- Temporal Service owns execution state; Memory DB owns reasoning traces.
--
-- This is a minimal linking schema - no duplication of workflow logic.
-- ─────────────────────────────────────────────────────────────────────────────
-- Temporal Workflow Links (External Service Reference)
-- ─────────────────────────────────────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS temporal_workflow_links (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
-- Temporal Service Reference (Required)
workflow_id VARCHAR(255) NOT NULL, -- Temporal workflow ID
workflow_type VARCHAR(255), -- e.g., "entity_extraction", "synthesis"
run_id VARCHAR(255), -- Temporal run ID
-- Memory Entity References (Optional - NULL until linked)
entity_id UUID REFERENCES knowledge_node(id) ON DELETE SET NULL,
edge_id UUID REFERENCES knowledge_edge(id) ON DELETE SET NULL,
node_id BIGINT REFERENCES memory_node(id) ON DELETE SET NULL,
-- Sync Status
status VARCHAR(50) NOT NULL DEFAULT 'active'
CHECK (status IN ('active', 'completed', 'failed', 'archived')),
-- Timestamps
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
last_synced_at TIMESTAMPTZ,
-- Metadata (Extra context, error details, etc.)
metadata JSONB
);
-- Indexes for common queries
CREATE INDEX IF NOT EXISTS idx_temporal_workflow_id
ON temporal_workflow_links(workflow_id);
CREATE INDEX IF NOT EXISTS idx_temporal_entity_id
ON temporal_workflow_links(entity_id)
WHERE entity_id IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_temporal_edge_id
ON temporal_workflow_links(edge_id)
WHERE edge_id IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_temporal_node_id
ON temporal_workflow_links(node_id)
WHERE node_id IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_temporal_status
ON temporal_workflow_links(status, created_at DESC);
CREATE INDEX IF NOT EXISTS idx_temporal_workflow_type
ON temporal_workflow_links(workflow_type)
WHERE status = 'active';
-- ─────────────────────────────────────────────────────────────────────────────
-- Rollback Instructions
-- ─────────────────────────────────────────────────────────────────────────────
-- To rollback this migration:
--
-- DROP INDEX IF EXISTS idx_temporal_workflow_type;
-- DROP INDEX IF EXISTS idx_temporal_status;
-- DROP INDEX IF EXISTS idx_temporal_node_id;
-- DROP INDEX IF EXISTS idx_temporal_edge_id;
-- DROP INDEX IF EXISTS idx_temporal_entity_id;
-- DROP INDEX IF EXISTS idx_temporal_workflow_id;
-- DROP TABLE IF EXISTS temporal_workflow_links;