Elevate MiroFish/CrowdSight from single-container dev to a SaaS foundation: - Local memory backend (Zep-compatible): memory services/models, local graph builder + updater, AgentActivity seam, import-boundary isolation; Zep stays default, local is opt-in behind MEMORY_BACKEND. Semantic parity not yet proven. - Durable product persistence: projects/simulations/reports schema (migration 0007) + tenant/owner-scoped ProductRepository + dual-write + scoped_project read-first + ArtifactStore abstraction; durable JobQueue + worker.py. - SaaS hardening: durable RateLimiter (wired to login), UsageService (LLM accounting), redacted AuditService, idempotency, CORS allowlist, safe API errors, single-use PasswordResetService + endpoints (covers invite-pending). - Exactly 3 roles (super_admin/admin/user) with tenant authz policy. - Admin UI: GET/POST/PATCH /api/admin/users + GET/PUT /api/admin/settings (super-admin only, encrypted/masked); AdminView.vue + SettingsView.vue with admin/super-admin route guards, th/en i18n. - Production deploy topology: multi-stage Dockerfile (frontend build + gunicorn wsgi + nginx SPA-proxy + supervisord worker), backend/wsgi.py, gunicorn dep. Backend 197 passed; frontend 10 tests + build green. ruff unavailable (gap). No commit of credentials; secrets handled via env/.env.example. Deferred: Zep semantic A/B parity, object storage cutover, mobile QA, EasyPanel container build of deploy topology.
117 lines
6.6 KiB
Python
117 lines
6.6 KiB
Python
"""Add durable local graph-memory tables."""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
revision = "0003_memory"
|
|
down_revision = "0002_sessions"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"memory_graphs",
|
|
sa.Column("id", sa.String(length=128), nullable=False),
|
|
sa.Column("organization_id", sa.String(length=64), nullable=False),
|
|
sa.Column("project_id", sa.String(length=128), nullable=False),
|
|
sa.Column("ontology", sa.JSON(), server_default=sa.text("'{}'"), nullable=False),
|
|
sa.Column("status", sa.String(length=32), server_default=sa.text("'ready'"), nullable=False),
|
|
sa.Column("version", sa.Integer(), server_default=sa.text("1"), nullable=False),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index("ix_memory_graphs_organization_id", "memory_graphs", ["organization_id"], unique=False)
|
|
op.create_index("ix_memory_graphs_project_id", "memory_graphs", ["project_id"], unique=False)
|
|
|
|
op.create_table(
|
|
"memory_episodes",
|
|
sa.Column("id", sa.String(length=128), nullable=False),
|
|
sa.Column("graph_id", sa.String(length=128), nullable=False),
|
|
sa.Column("source_type", sa.String(length=32), nullable=False),
|
|
sa.Column("source_ref", sa.String(length=256), nullable=False),
|
|
sa.Column("normalized_text", sa.Text(), nullable=False),
|
|
sa.Column("summary", sa.Text(), server_default=sa.text("''"), nullable=False),
|
|
sa.Column("status", sa.String(length=32), server_default=sa.text("'processed'"), nullable=False),
|
|
sa.Column("extractor_version", sa.String(length=64), server_default=sa.text("'v1'"), nullable=False),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
|
sa.ForeignKeyConstraint(["graph_id"], ["memory_graphs.id"], ondelete="CASCADE"),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("graph_id", "source_type", "source_ref", name="uq_memory_episode_source"),
|
|
)
|
|
op.create_index("ix_memory_episodes_graph_id", "memory_episodes", ["graph_id"], unique=False)
|
|
op.create_index("ix_memory_episodes_graph_status", "memory_episodes", ["graph_id", "status"], unique=False)
|
|
|
|
op.create_table(
|
|
"memory_nodes",
|
|
sa.Column("id", sa.String(length=128), nullable=False),
|
|
sa.Column("graph_id", sa.String(length=128), nullable=False),
|
|
sa.Column("canonical_name", sa.String(length=512), nullable=False),
|
|
sa.Column("normalized_name", sa.String(length=512), nullable=False),
|
|
sa.Column("labels", sa.JSON(), server_default=sa.text("'[]'"), nullable=False),
|
|
sa.Column("aliases", sa.JSON(), server_default=sa.text("'[]'"), nullable=False),
|
|
sa.Column("attributes", sa.JSON(), server_default=sa.text("'{}'"), nullable=False),
|
|
sa.Column("summary", sa.Text(), server_default=sa.text("''"), nullable=False),
|
|
sa.Column("confidence", sa.Float(), server_default=sa.text("0"), nullable=False),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
|
sa.ForeignKeyConstraint(["graph_id"], ["memory_graphs.id"], ondelete="CASCADE"),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("graph_id", "normalized_name", name="uq_memory_node_graph_name"),
|
|
)
|
|
op.create_index("ix_memory_nodes_graph_id", "memory_nodes", ["graph_id"], unique=False)
|
|
op.create_index("ix_memory_nodes_graph_name", "memory_nodes", ["graph_id", "normalized_name"], unique=False)
|
|
|
|
op.create_table(
|
|
"memory_edges",
|
|
sa.Column("id", sa.String(length=128), nullable=False),
|
|
sa.Column("graph_id", sa.String(length=128), nullable=False),
|
|
sa.Column("source_node_id", sa.String(length=128), nullable=False),
|
|
sa.Column("target_node_id", sa.String(length=128), nullable=False),
|
|
sa.Column("relation", sa.String(length=128), nullable=False),
|
|
sa.Column("fact", sa.Text(), nullable=False),
|
|
sa.Column("attributes", sa.JSON(), server_default=sa.text("'{}'"), nullable=False),
|
|
sa.Column("confidence", sa.Float(), server_default=sa.text("0"), nullable=False),
|
|
sa.Column("valid_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("invalid_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("expired_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
|
sa.ForeignKeyConstraint(["graph_id"], ["memory_graphs.id"], ondelete="CASCADE"),
|
|
sa.ForeignKeyConstraint(["source_node_id"], ["memory_nodes.id"], ondelete="CASCADE"),
|
|
sa.ForeignKeyConstraint(["target_node_id"], ["memory_nodes.id"], ondelete="CASCADE"),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index("ix_memory_edges_graph_id", "memory_edges", ["graph_id"], unique=False)
|
|
op.create_index("ix_memory_edges_source_node_id", "memory_edges", ["source_node_id"], unique=False)
|
|
op.create_index("ix_memory_edges_target_node_id", "memory_edges", ["target_node_id"], unique=False)
|
|
op.create_index("ix_memory_edges_graph_relation", "memory_edges", ["graph_id", "relation"], unique=False)
|
|
op.create_index(
|
|
"ix_memory_edges_graph_temporal",
|
|
"memory_edges",
|
|
["graph_id", "valid_at", "invalid_at"],
|
|
unique=False,
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_memory_edges_graph_temporal", table_name="memory_edges")
|
|
op.drop_index("ix_memory_edges_graph_relation", table_name="memory_edges")
|
|
op.drop_index("ix_memory_edges_target_node_id", table_name="memory_edges")
|
|
op.drop_index("ix_memory_edges_source_node_id", table_name="memory_edges")
|
|
op.drop_index("ix_memory_edges_graph_id", table_name="memory_edges")
|
|
op.drop_table("memory_edges")
|
|
|
|
op.drop_index("ix_memory_nodes_graph_name", table_name="memory_nodes")
|
|
op.drop_index("ix_memory_nodes_graph_id", table_name="memory_nodes")
|
|
op.drop_table("memory_nodes")
|
|
|
|
op.drop_index("ix_memory_episodes_graph_status", table_name="memory_episodes")
|
|
op.drop_index("ix_memory_episodes_graph_id", table_name="memory_episodes")
|
|
op.drop_table("memory_episodes")
|
|
|
|
op.drop_index("ix_memory_graphs_project_id", table_name="memory_graphs")
|
|
op.drop_index("ix_memory_graphs_organization_id", table_name="memory_graphs")
|
|
op.drop_table("memory_graphs")
|