Files
smart-org/apps/api/alembic/versions/e6f7a8b9c0d1_model_grants.py
T

63 lines
2.2 KiB
Python

"""owner model grants: default grant set + per-org policy
Revision ID: e6f7a8b9c0d1
Revises: d5e6f7a8b9c0
Create Date: 2026-10-14 09:00:00.000000
Owned by Agent 1 (PLAN-v2 §6). Adds the two owner-side tables of the model-grant
workstream: the default set copied into every new organization, and the
per-organization policy (employee cap, monthly budget, automation/MCP switches).
``org_model_grants`` itself is foundation-owned and already exists.
"""
from __future__ import annotations
from collections.abc import Sequence
import sqlalchemy as sa
from alembic import op
revision: str = "e6f7a8b9c0d1"
down_revision: str | None = "d5e6f7a8b9c0"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
def upgrade() -> None:
op.create_table(
"default_model_grants",
sa.Column("id", sa.String(length=32), primary_key=True),
sa.Column(
"ai_model_id",
sa.String(length=32),
sa.ForeignKey("ai_models.id", ondelete="CASCADE"),
nullable=False,
),
sa.Column("daily_credit_cap", sa.Float(), nullable=True),
sa.Column("is_active", sa.Boolean(), nullable=False, server_default=sa.true()),
sa.Column("created_by_user_id", sa.String(length=32), sa.ForeignKey("users.id")),
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
sa.UniqueConstraint("ai_model_id", name="uq_default_model_grant"),
)
op.create_table(
"org_policies",
sa.Column(
"organization_id",
sa.String(length=32),
sa.ForeignKey("organizations.id", ondelete="CASCADE"),
primary_key=True,
),
sa.Column("max_employees", sa.Integer(), nullable=False, server_default="5"),
sa.Column("monthly_credit_budget", sa.Float(), nullable=True),
sa.Column("automation_enabled", sa.Boolean(), nullable=False, server_default=sa.true()),
sa.Column("mcp_enabled", sa.Boolean(), nullable=False, server_default=sa.true()),
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
)
def downgrade() -> None:
op.drop_table("org_policies")
op.drop_table("default_model_grants")