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.
120 lines
7.2 KiB
Python
120 lines
7.2 KiB
Python
"""Add durable product-resource tables: projects, simulations, and reports.
|
|
|
|
These replace the legacy filesystem-backed project/simulation/report payloads
|
|
with tenant- and owner-scoped SQL rows.
|
|
"""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
revision = "0007_product_resources"
|
|
down_revision = "0006_job_metadata"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"projects",
|
|
sa.Column("id", sa.String(length=128), nullable=False),
|
|
sa.Column("organization_id", sa.String(length=64), nullable=False),
|
|
sa.Column("owner_user_id", sa.String(length=64), nullable=True),
|
|
sa.Column("name", sa.String(length=255), server_default=sa.text("''"), nullable=False),
|
|
sa.Column("status", sa.String(length=32), server_default=sa.text("'created'"), nullable=False),
|
|
sa.Column("language", sa.String(length=16), server_default=sa.text("'en'"), nullable=False),
|
|
sa.Column("total_text_length", sa.Integer(), server_default=sa.text("0"), nullable=False),
|
|
sa.Column("source_metadata", sa.JSON(), nullable=True),
|
|
sa.Column("ontology", sa.JSON(), nullable=True),
|
|
sa.Column("analysis_summary", sa.Text(), nullable=True),
|
|
sa.Column("simulation_requirement", sa.Text(), nullable=True),
|
|
sa.Column("graph_id", sa.String(length=128), nullable=True),
|
|
sa.Column("graph_build_task_id", sa.String(length=128), nullable=True),
|
|
sa.Column("error", sa.Text(), nullable=True),
|
|
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(["organization_id"], ["organizations.id"], ondelete="CASCADE"),
|
|
sa.ForeignKeyConstraint(["owner_user_id"], ["users.id"], ondelete="SET NULL"),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index("ix_projects_organization_id", "projects", ["organization_id"])
|
|
op.create_index("ix_projects_owner_user_id", "projects", ["owner_user_id"])
|
|
op.create_index("ix_projects_graph_id", "projects", ["graph_id"])
|
|
op.create_index("ix_projects_org_owner", "projects", ["organization_id", "owner_user_id"])
|
|
op.create_index("ix_projects_org_created", "projects", ["organization_id", "created_at"])
|
|
|
|
op.create_table(
|
|
"simulations",
|
|
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("created_by_user_id", sa.String(length=64), nullable=True),
|
|
sa.Column("status", sa.String(length=32), server_default=sa.text("'created'"), nullable=False),
|
|
sa.Column("platform", sa.String(length=32), server_default=sa.text("'parallel'"), nullable=False),
|
|
sa.Column("config", sa.JSON(), nullable=True),
|
|
sa.Column("current_round", sa.Integer(), server_default=sa.text("0"), nullable=False),
|
|
sa.Column("error", sa.Text(), nullable=True),
|
|
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.Column("finished_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.ForeignKeyConstraint(["organization_id"], ["organizations.id"], ondelete="CASCADE"),
|
|
sa.ForeignKeyConstraint(["project_id"], ["projects.id"], ondelete="CASCADE"),
|
|
sa.ForeignKeyConstraint(["created_by_user_id"], ["users.id"], ondelete="SET NULL"),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index("ix_simulations_organization_id", "simulations", ["organization_id"])
|
|
op.create_index("ix_simulations_project_id", "simulations", ["project_id"])
|
|
op.create_index("ix_simulations_org_project", "simulations", ["organization_id", "project_id"])
|
|
op.create_index("ix_simulations_org_created", "simulations", ["organization_id", "created_at"])
|
|
|
|
op.create_table(
|
|
"reports",
|
|
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("simulation_id", sa.String(length=128), nullable=True),
|
|
sa.Column("created_by_user_id", sa.String(length=64), nullable=True),
|
|
sa.Column("status", sa.String(length=32), server_default=sa.text("'draft'"), nullable=False),
|
|
sa.Column("title", sa.String(length=255), server_default=sa.text("''"), nullable=False),
|
|
sa.Column("outline", sa.JSON(), nullable=True),
|
|
sa.Column("markdown_content", sa.Text(), nullable=True),
|
|
sa.Column("error", sa.Text(), nullable=True),
|
|
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.Column("finished_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.ForeignKeyConstraint(["organization_id"], ["organizations.id"], ondelete="CASCADE"),
|
|
sa.ForeignKeyConstraint(["project_id"], ["projects.id"], ondelete="CASCADE"),
|
|
sa.ForeignKeyConstraint(["simulation_id"], ["simulations.id"], ondelete="SET NULL"),
|
|
sa.ForeignKeyConstraint(["created_by_user_id"], ["users.id"], ondelete="SET NULL"),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("organization_id", "id", name="uq_reports_org_id"),
|
|
)
|
|
op.create_index("ix_reports_organization_id", "reports", ["organization_id"])
|
|
op.create_index("ix_reports_project_id", "reports", ["project_id"])
|
|
op.create_index("ix_reports_simulation_id", "reports", ["simulation_id"])
|
|
op.create_index("ix_reports_org_project", "reports", ["organization_id", "project_id"])
|
|
op.create_index("ix_reports_org_simulation", "reports", ["organization_id", "simulation_id"])
|
|
op.create_index("ix_reports_org_created", "reports", ["organization_id", "created_at"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_reports_org_created", table_name="reports")
|
|
op.drop_index("ix_reports_org_simulation", table_name="reports")
|
|
op.drop_index("ix_reports_org_project", table_name="reports")
|
|
op.drop_index("ix_reports_simulation_id", table_name="reports")
|
|
op.drop_index("ix_reports_project_id", table_name="reports")
|
|
op.drop_index("ix_reports_organization_id", table_name="reports")
|
|
op.drop_table("reports")
|
|
|
|
op.drop_index("ix_simulations_org_created", table_name="simulations")
|
|
op.drop_index("ix_simulations_org_project", table_name="simulations")
|
|
op.drop_index("ix_simulations_project_id", table_name="simulations")
|
|
op.drop_index("ix_simulations_organization_id", table_name="simulations")
|
|
op.drop_table("simulations")
|
|
|
|
op.drop_index("ix_projects_org_created", table_name="projects")
|
|
op.drop_index("ix_projects_org_owner", table_name="projects")
|
|
op.drop_index("ix_projects_graph_id", table_name="projects")
|
|
op.drop_index("ix_projects_owner_user_id", table_name="projects")
|
|
op.drop_index("ix_projects_organization_id", table_name="projects")
|
|
op.drop_table("projects")
|