Spaces:
Paused
Paused
Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- alembic.ini +37 -0
- alembic/__pycache__/env.cpython-313.pyc +0 -0
- alembic/env.py +82 -0
- alembic/script.py.mako +25 -0
- alembic/versions/001_initial_schema.py +166 -0
- alembic/versions/002_add_is_admin_to_users.py +26 -0
- alembic/versions/003_add_callback_url_to_tasks.py +26 -0
- alembic/versions/004_add_mcp_url_to_agents.py +26 -0
- alembic/versions/005_add_did_keys_to_agents.py +31 -0
- alembic/versions/006_add_api_key_revoked_at.py +26 -0
- alembic/versions/007_add_agent_profile_fields.py +27 -0
- alembic/versions/008_add_status_history_to_tasks.py +23 -0
- alembic/versions/009_create_llm_calls_table.py +38 -0
- alembic/versions/010_add_onboarding_fields_to_users.py +28 -0
- alembic/versions/011_create_org_team_membership_tables.py +58 -0
- alembic/versions/012_fix_boolean_server_defaults.py +28 -0
- alembic/versions/013_add_account_tier_to_users.py +36 -0
- alembic/versions/014_add_creator_user_id_to_tasks.py +26 -0
- alembic/versions/015_add_webhook_logs.py +36 -0
- alembic/versions/016_production_readiness_columns.py +77 -0
- alembic/versions/017_add_eval_subscores.py +31 -0
- alembic/versions/018_simplify_verification_tiers.py +26 -0
- alembic/versions/019_agent_crews.py +40 -0
- alembic/versions/020_pgvector_embeddings.py +58 -0
- alembic/versions/021_fix_embedding_dimension.py +53 -0
- alembic/versions/022_add_stripe_connect_payouts.py +56 -0
- alembic/versions/023_workflows_and_schedules.py +170 -0
- alembic/versions/024_workflow_timeouts_and_step_errors.py +35 -0
- alembic/versions/025_workflow_step_instructions.py +20 -0
- alembic/versions/026_custom_agents.py +113 -0
- alembic/versions/027_agent_submissions.py +45 -0
- alembic/versions/028_orchestration_patterns.py +93 -0
- alembic/versions/029_multi_channel_gateway.py +82 -0
- alembic/versions/030_audit_logs.py +33 -0
- alembic/versions/031_gdpr_compliance.py +27 -0
- alembic/versions/032_admin_roles.py +23 -0
- alembic/versions/033_recover_health_deactivated_agents.py +36 -0
- alembic/versions/034_health_monitor_columns.py +46 -0
- alembic/versions/036_channel_contacts_privacy.py +52 -0
- alembic/versions/037_workflow_channel_integration.py +80 -0
- alembic/versions/038_mcp_server_registry.py +51 -0
- alembic/versions/039_ap2_payment_standard.py +25 -0
- alembic/versions/040_ucp_credit_schedules.py +31 -0
- alembic/versions/041_infrastructure_metrics.py +31 -0
- alembic/versions/__pycache__/001_initial_schema.cpython-313.pyc +0 -0
- alembic/versions/__pycache__/002_add_is_admin_to_users.cpython-313.pyc +0 -0
- alembic/versions/__pycache__/003_add_callback_url_to_tasks.cpython-313.pyc +0 -0
- alembic/versions/__pycache__/004_add_mcp_url_to_agents.cpython-313.pyc +0 -0
- alembic/versions/__pycache__/005_add_did_keys_to_agents.cpython-313.pyc +0 -0
- alembic/versions/__pycache__/006_add_api_key_revoked_at.cpython-313.pyc +0 -0
alembic.ini
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[alembic]
|
| 2 |
+
script_location = alembic
|
| 3 |
+
prepend_sys_path = .
|
| 4 |
+
sqlalchemy.url = postgresql+asyncpg://crewhub:crewhub@localhost:5432/crewhub
|
| 5 |
+
|
| 6 |
+
[loggers]
|
| 7 |
+
keys = root,sqlalchemy,alembic
|
| 8 |
+
|
| 9 |
+
[handlers]
|
| 10 |
+
keys = console
|
| 11 |
+
|
| 12 |
+
[formatters]
|
| 13 |
+
keys = generic
|
| 14 |
+
|
| 15 |
+
[logger_root]
|
| 16 |
+
level = WARN
|
| 17 |
+
handlers = console
|
| 18 |
+
|
| 19 |
+
[logger_sqlalchemy]
|
| 20 |
+
level = WARN
|
| 21 |
+
handlers =
|
| 22 |
+
qualname = sqlalchemy.engine
|
| 23 |
+
|
| 24 |
+
[logger_alembic]
|
| 25 |
+
level = INFO
|
| 26 |
+
handlers =
|
| 27 |
+
qualname = alembic
|
| 28 |
+
|
| 29 |
+
[handler_console]
|
| 30 |
+
class = StreamHandler
|
| 31 |
+
args = (sys.stderr,)
|
| 32 |
+
level = NOTSET
|
| 33 |
+
formatter = generic
|
| 34 |
+
|
| 35 |
+
[formatter_generic]
|
| 36 |
+
format = %(levelname)-5.5s [%(name)s] %(message)s
|
| 37 |
+
datefmt = %H:%M:%S
|
alembic/__pycache__/env.cpython-313.pyc
ADDED
|
Binary file (3.53 kB). View file
|
|
|
alembic/env.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
from logging.config import fileConfig
|
| 3 |
+
|
| 4 |
+
from alembic import context
|
| 5 |
+
from sqlalchemy import pool
|
| 6 |
+
from sqlalchemy.ext.asyncio import async_engine_from_config
|
| 7 |
+
|
| 8 |
+
from src.config import settings
|
| 9 |
+
from src.database import Base
|
| 10 |
+
|
| 11 |
+
# Import all models so they register with Base.metadata
|
| 12 |
+
from src.models import * # noqa: F401, F403
|
| 13 |
+
|
| 14 |
+
config = context.config
|
| 15 |
+
# Escape % for configparser interpolation (e.g. %40 in URL-encoded passwords)
|
| 16 |
+
# Strip sslmode param — asyncpg handles SSL via connect_args
|
| 17 |
+
_url = settings.database_url
|
| 18 |
+
if "asyncpg" in _url and "sslmode=" in _url:
|
| 19 |
+
import re
|
| 20 |
+
_url = re.sub(r'[?&]sslmode=[^&]*', '', _url).replace('?&', '?').rstrip('?')
|
| 21 |
+
config.set_main_option("sqlalchemy.url", _url.replace("%", "%%"))
|
| 22 |
+
|
| 23 |
+
if config.config_file_name is not None:
|
| 24 |
+
fileConfig(config.config_file_name)
|
| 25 |
+
|
| 26 |
+
target_metadata = Base.metadata
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def run_migrations_offline() -> None:
|
| 30 |
+
"""Run migrations in 'offline' mode."""
|
| 31 |
+
url = config.get_main_option("sqlalchemy.url")
|
| 32 |
+
context.configure(
|
| 33 |
+
url=url,
|
| 34 |
+
target_metadata=target_metadata,
|
| 35 |
+
literal_binds=True,
|
| 36 |
+
dialect_opts={"paramstyle": "named"},
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
with context.begin_transaction():
|
| 40 |
+
context.run_migrations()
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def do_run_migrations(connection):
|
| 44 |
+
context.configure(connection=connection, target_metadata=target_metadata)
|
| 45 |
+
with context.begin_transaction():
|
| 46 |
+
context.run_migrations()
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
async def run_async_migrations() -> None:
|
| 50 |
+
"""Run migrations in 'online' mode with async engine."""
|
| 51 |
+
engine_kwargs: dict = {"poolclass": pool.NullPool}
|
| 52 |
+
|
| 53 |
+
# Supabase / PgBouncer: disable prepared statements + enable SSL
|
| 54 |
+
db_url = settings.database_url
|
| 55 |
+
if "asyncpg" in db_url and ("pooler.supabase" in db_url or "pgbouncer" in db_url):
|
| 56 |
+
engine_kwargs["connect_args"] = {
|
| 57 |
+
"prepared_statement_cache_size": 0,
|
| 58 |
+
"statement_cache_size": 0,
|
| 59 |
+
"ssl": "require",
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
connectable = async_engine_from_config(
|
| 63 |
+
config.get_section(config.config_ini_section, {}),
|
| 64 |
+
prefix="sqlalchemy.",
|
| 65 |
+
**engine_kwargs,
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
async with connectable.connect() as connection:
|
| 69 |
+
await connection.run_sync(do_run_migrations)
|
| 70 |
+
|
| 71 |
+
await connectable.dispose()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def run_migrations_online() -> None:
|
| 75 |
+
"""Run migrations in 'online' mode."""
|
| 76 |
+
asyncio.run(run_async_migrations())
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
if context.is_offline_mode():
|
| 80 |
+
run_migrations_offline()
|
| 81 |
+
else:
|
| 82 |
+
run_migrations_online()
|
alembic/script.py.mako
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""${message}
|
| 2 |
+
|
| 3 |
+
Revision ID: ${up_revision}
|
| 4 |
+
Revises: ${down_revision | comma,n}
|
| 5 |
+
Create Date: ${create_date}
|
| 6 |
+
"""
|
| 7 |
+
from typing import Sequence, Union
|
| 8 |
+
|
| 9 |
+
from alembic import op
|
| 10 |
+
import sqlalchemy as sa
|
| 11 |
+
${imports if imports else ""}
|
| 12 |
+
|
| 13 |
+
# revision identifiers, used by Alembic.
|
| 14 |
+
revision: str = ${repr(up_revision)}
|
| 15 |
+
down_revision: Union[str, None] = ${repr(down_revision)}
|
| 16 |
+
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
|
| 17 |
+
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def upgrade() -> None:
|
| 21 |
+
${upgrades if upgrades else "pass"}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def downgrade() -> None:
|
| 25 |
+
${downgrades if downgrades else "pass"}
|
alembic/versions/001_initial_schema.py
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Initial schema - all core tables
|
| 2 |
+
|
| 3 |
+
Revision ID: 001
|
| 4 |
+
Revises: None
|
| 5 |
+
Create Date: 2026-02-23
|
| 6 |
+
"""
|
| 7 |
+
from typing import Sequence, Union
|
| 8 |
+
|
| 9 |
+
import sqlalchemy as sa
|
| 10 |
+
from alembic import op
|
| 11 |
+
|
| 12 |
+
revision: str = "001"
|
| 13 |
+
down_revision: Union[str, None] = None
|
| 14 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 15 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def upgrade() -> None:
|
| 19 |
+
# Users
|
| 20 |
+
op.create_table(
|
| 21 |
+
"users",
|
| 22 |
+
sa.Column("id", sa.Uuid(), nullable=False),
|
| 23 |
+
sa.Column("email", sa.String(255), nullable=False),
|
| 24 |
+
sa.Column("hashed_password", sa.String(255), nullable=False),
|
| 25 |
+
sa.Column("name", sa.String(255), nullable=False),
|
| 26 |
+
sa.Column("firebase_uid", sa.String(128), unique=True, nullable=True),
|
| 27 |
+
sa.Column("api_key_hash", sa.String(64), unique=True, nullable=True),
|
| 28 |
+
sa.Column("llm_api_keys", sa.JSON(), server_default="{}"),
|
| 29 |
+
sa.Column("is_active", sa.Boolean(), server_default="true", nullable=False),
|
| 30 |
+
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
| 31 |
+
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
| 32 |
+
sa.PrimaryKeyConstraint("id"),
|
| 33 |
+
)
|
| 34 |
+
op.create_index("ix_users_email", "users", ["email"], unique=True)
|
| 35 |
+
op.create_index("ix_users_firebase_uid", "users", ["firebase_uid"], unique=True)
|
| 36 |
+
op.create_index("ix_users_api_key_hash", "users", ["api_key_hash"], unique=True)
|
| 37 |
+
|
| 38 |
+
# Agents
|
| 39 |
+
op.create_table(
|
| 40 |
+
"agents",
|
| 41 |
+
sa.Column("id", sa.Uuid(), nullable=False),
|
| 42 |
+
sa.Column("owner_id", sa.Uuid(), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False),
|
| 43 |
+
sa.Column("name", sa.String(255), nullable=False),
|
| 44 |
+
sa.Column("description", sa.Text(), nullable=True),
|
| 45 |
+
sa.Column("version", sa.String(50), server_default="1.0.0"),
|
| 46 |
+
sa.Column("endpoint", sa.String(500), nullable=False),
|
| 47 |
+
sa.Column("status", sa.String(20), server_default="active"),
|
| 48 |
+
sa.Column("capabilities", sa.JSON(), server_default="{}"),
|
| 49 |
+
sa.Column("security_schemes", sa.JSON(), server_default="[]"),
|
| 50 |
+
sa.Column("category", sa.String(100), server_default="general"),
|
| 51 |
+
sa.Column("tags", sa.JSON(), server_default="[]"),
|
| 52 |
+
sa.Column("pricing", sa.JSON(), server_default="{}"),
|
| 53 |
+
sa.Column("license_type", sa.String(20), server_default="commercial"),
|
| 54 |
+
sa.Column("sla", sa.JSON(), server_default="{}"),
|
| 55 |
+
sa.Column("embedding_config", sa.JSON(), server_default="{}"),
|
| 56 |
+
sa.Column("accepted_payment_methods", sa.JSON(), server_default='["credits"]'),
|
| 57 |
+
sa.Column("metadata", sa.JSON(), server_default="{}"),
|
| 58 |
+
sa.Column("verification_level", sa.String(20), server_default="unverified"),
|
| 59 |
+
sa.Column("reputation_score", sa.Float(), server_default="0.0"),
|
| 60 |
+
sa.Column("total_tasks_completed", sa.Integer(), server_default="0"),
|
| 61 |
+
sa.Column("success_rate", sa.Float(), server_default="0.0"),
|
| 62 |
+
sa.Column("avg_latency_ms", sa.Float(), server_default="0.0"),
|
| 63 |
+
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
| 64 |
+
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
| 65 |
+
sa.PrimaryKeyConstraint("id"),
|
| 66 |
+
)
|
| 67 |
+
op.create_index("ix_agents_owner_id", "agents", ["owner_id"])
|
| 68 |
+
op.create_index("ix_agents_category", "agents", ["category"])
|
| 69 |
+
op.create_index("ix_agents_status", "agents", ["status"])
|
| 70 |
+
|
| 71 |
+
# Agent Skills
|
| 72 |
+
op.create_table(
|
| 73 |
+
"agent_skills",
|
| 74 |
+
sa.Column("id", sa.Uuid(), nullable=False),
|
| 75 |
+
sa.Column("agent_id", sa.Uuid(), sa.ForeignKey("agents.id", ondelete="CASCADE"), nullable=False),
|
| 76 |
+
sa.Column("skill_key", sa.String(100), nullable=False),
|
| 77 |
+
sa.Column("name", sa.String(255), nullable=False),
|
| 78 |
+
sa.Column("description", sa.Text(), nullable=True),
|
| 79 |
+
sa.Column("input_modes", sa.JSON(), server_default='["text"]'),
|
| 80 |
+
sa.Column("output_modes", sa.JSON(), server_default='["text"]'),
|
| 81 |
+
sa.Column("examples", sa.JSON(), server_default="[]"),
|
| 82 |
+
sa.Column("avg_credits", sa.Float(), server_default="0.0"),
|
| 83 |
+
sa.Column("avg_latency_ms", sa.Integer(), server_default="0"),
|
| 84 |
+
sa.Column("embedding", sa.JSON(), nullable=True),
|
| 85 |
+
sa.PrimaryKeyConstraint("id"),
|
| 86 |
+
)
|
| 87 |
+
op.create_index("ix_agent_skills_agent_id", "agent_skills", ["agent_id"])
|
| 88 |
+
|
| 89 |
+
# Accounts
|
| 90 |
+
op.create_table(
|
| 91 |
+
"accounts",
|
| 92 |
+
sa.Column("id", sa.Uuid(), nullable=False),
|
| 93 |
+
sa.Column("owner_id", sa.Uuid(), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False, unique=True),
|
| 94 |
+
sa.Column("balance", sa.Numeric(16, 4), server_default="0"),
|
| 95 |
+
sa.Column("reserved", sa.Numeric(16, 4), server_default="0"),
|
| 96 |
+
sa.Column("currency", sa.String(20), server_default="CREDITS"),
|
| 97 |
+
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
| 98 |
+
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
| 99 |
+
sa.PrimaryKeyConstraint("id"),
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
# Tasks
|
| 103 |
+
op.create_table(
|
| 104 |
+
"tasks",
|
| 105 |
+
sa.Column("id", sa.Uuid(), nullable=False),
|
| 106 |
+
sa.Column("client_agent_id", sa.Uuid(), sa.ForeignKey("agents.id", ondelete="SET NULL"), nullable=True),
|
| 107 |
+
sa.Column("provider_agent_id", sa.Uuid(), sa.ForeignKey("agents.id", ondelete="SET NULL"), nullable=True),
|
| 108 |
+
sa.Column("skill_id", sa.Uuid(), sa.ForeignKey("agent_skills.id", ondelete="SET NULL"), nullable=True),
|
| 109 |
+
sa.Column("status", sa.String(20), server_default="submitted"),
|
| 110 |
+
sa.Column("messages", sa.JSON(), server_default="[]"),
|
| 111 |
+
sa.Column("artifacts", sa.JSON(), server_default="[]"),
|
| 112 |
+
sa.Column("credits_quoted", sa.Numeric(12, 4), server_default="0"),
|
| 113 |
+
sa.Column("credits_charged", sa.Numeric(12, 4), server_default="0"),
|
| 114 |
+
sa.Column("latency_ms", sa.Integer(), nullable=True),
|
| 115 |
+
sa.Column("client_rating", sa.Float(), nullable=True),
|
| 116 |
+
sa.Column("quality_score", sa.Float(), nullable=True),
|
| 117 |
+
sa.Column("payment_method", sa.String(20), server_default="credits"),
|
| 118 |
+
sa.Column("x402_receipt", sa.JSON(), nullable=True),
|
| 119 |
+
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
| 120 |
+
sa.Column("completed_at", sa.DateTime(timezone=True), nullable=True),
|
| 121 |
+
sa.PrimaryKeyConstraint("id"),
|
| 122 |
+
)
|
| 123 |
+
op.create_index("ix_tasks_client_agent_id", "tasks", ["client_agent_id"])
|
| 124 |
+
op.create_index("ix_tasks_provider_agent_id", "tasks", ["provider_agent_id"])
|
| 125 |
+
op.create_index("ix_tasks_status", "tasks", ["status"])
|
| 126 |
+
|
| 127 |
+
# Transactions
|
| 128 |
+
op.create_table(
|
| 129 |
+
"transactions",
|
| 130 |
+
sa.Column("id", sa.Uuid(), nullable=False),
|
| 131 |
+
sa.Column("from_account_id", sa.Uuid(), sa.ForeignKey("accounts.id"), nullable=True),
|
| 132 |
+
sa.Column("to_account_id", sa.Uuid(), sa.ForeignKey("accounts.id"), nullable=True),
|
| 133 |
+
sa.Column("amount", sa.Numeric(16, 4), nullable=False),
|
| 134 |
+
sa.Column("type", sa.String(20), nullable=False),
|
| 135 |
+
sa.Column("task_id", sa.Uuid(), sa.ForeignKey("tasks.id", ondelete="SET NULL"), nullable=True),
|
| 136 |
+
sa.Column("description", sa.Text(), server_default=""),
|
| 137 |
+
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
| 138 |
+
sa.PrimaryKeyConstraint("id"),
|
| 139 |
+
)
|
| 140 |
+
op.create_index("ix_transactions_from_account", "transactions", ["from_account_id"])
|
| 141 |
+
op.create_index("ix_transactions_to_account", "transactions", ["to_account_id"])
|
| 142 |
+
|
| 143 |
+
# x402 Verified Receipts
|
| 144 |
+
op.create_table(
|
| 145 |
+
"x402_verified_receipts",
|
| 146 |
+
sa.Column("tx_hash", sa.String(128), nullable=False),
|
| 147 |
+
sa.Column("chain", sa.String(20), nullable=False),
|
| 148 |
+
sa.Column("token", sa.String(20), nullable=False),
|
| 149 |
+
sa.Column("amount", sa.Numeric(16, 4), nullable=False),
|
| 150 |
+
sa.Column("payer", sa.String(128), nullable=False),
|
| 151 |
+
sa.Column("payee", sa.String(128), nullable=False),
|
| 152 |
+
sa.Column("task_id", sa.Uuid(), sa.ForeignKey("tasks.id", ondelete="SET NULL"), nullable=True),
|
| 153 |
+
sa.Column("verified_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
| 154 |
+
sa.PrimaryKeyConstraint("tx_hash"),
|
| 155 |
+
)
|
| 156 |
+
op.create_index("ix_x402_receipts_task_id", "x402_verified_receipts", ["task_id"])
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def downgrade() -> None:
|
| 160 |
+
op.drop_table("x402_verified_receipts")
|
| 161 |
+
op.drop_table("transactions")
|
| 162 |
+
op.drop_table("tasks")
|
| 163 |
+
op.drop_table("accounts")
|
| 164 |
+
op.drop_table("agent_skills")
|
| 165 |
+
op.drop_table("agents")
|
| 166 |
+
op.drop_table("users")
|
alembic/versions/002_add_is_admin_to_users.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add is_admin column to users table
|
| 2 |
+
|
| 3 |
+
Revision ID: 002
|
| 4 |
+
Revises: 001
|
| 5 |
+
Create Date: 2026-02-28
|
| 6 |
+
"""
|
| 7 |
+
from typing import Sequence, Union
|
| 8 |
+
|
| 9 |
+
import sqlalchemy as sa
|
| 10 |
+
from alembic import op
|
| 11 |
+
|
| 12 |
+
revision: str = "002"
|
| 13 |
+
down_revision: Union[str, None] = "001"
|
| 14 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 15 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def upgrade() -> None:
|
| 19 |
+
op.add_column(
|
| 20 |
+
"users",
|
| 21 |
+
sa.Column("is_admin", sa.Boolean(), server_default="false", nullable=False),
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def downgrade() -> None:
|
| 26 |
+
op.drop_column("users", "is_admin")
|
alembic/versions/003_add_callback_url_to_tasks.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add callback_url column to tasks table for A2A push notifications
|
| 2 |
+
|
| 3 |
+
Revision ID: 003
|
| 4 |
+
Revises: 002
|
| 5 |
+
Create Date: 2026-02-28
|
| 6 |
+
"""
|
| 7 |
+
from typing import Sequence, Union
|
| 8 |
+
|
| 9 |
+
import sqlalchemy as sa
|
| 10 |
+
from alembic import op
|
| 11 |
+
|
| 12 |
+
revision: str = "003"
|
| 13 |
+
down_revision: Union[str, None] = "002"
|
| 14 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 15 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def upgrade() -> None:
|
| 19 |
+
op.add_column(
|
| 20 |
+
"tasks",
|
| 21 |
+
sa.Column("callback_url", sa.String(2048), nullable=True),
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def downgrade() -> None:
|
| 26 |
+
op.drop_column("tasks", "callback_url")
|
alembic/versions/004_add_mcp_url_to_agents.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add mcp_server_url column to agents table
|
| 2 |
+
|
| 3 |
+
Revision ID: 004
|
| 4 |
+
Revises: 003
|
| 5 |
+
Create Date: 2026-02-28
|
| 6 |
+
"""
|
| 7 |
+
from typing import Sequence, Union
|
| 8 |
+
|
| 9 |
+
import sqlalchemy as sa
|
| 10 |
+
from alembic import op
|
| 11 |
+
|
| 12 |
+
revision: str = "004"
|
| 13 |
+
down_revision: Union[str, None] = "003"
|
| 14 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 15 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def upgrade() -> None:
|
| 19 |
+
op.add_column(
|
| 20 |
+
"agents",
|
| 21 |
+
sa.Column("mcp_server_url", sa.String(2048), nullable=True),
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def downgrade() -> None:
|
| 26 |
+
op.drop_column("agents", "mcp_server_url")
|
alembic/versions/005_add_did_keys_to_agents.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add DID identity columns to agents table
|
| 2 |
+
|
| 3 |
+
Revision ID: 005
|
| 4 |
+
Revises: 004
|
| 5 |
+
Create Date: 2026-02-28
|
| 6 |
+
"""
|
| 7 |
+
from typing import Sequence, Union
|
| 8 |
+
|
| 9 |
+
import sqlalchemy as sa
|
| 10 |
+
from alembic import op
|
| 11 |
+
|
| 12 |
+
revision: str = "005"
|
| 13 |
+
down_revision: Union[str, None] = "004"
|
| 14 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 15 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def upgrade() -> None:
|
| 19 |
+
op.add_column(
|
| 20 |
+
"agents",
|
| 21 |
+
sa.Column("did_public_key", sa.LargeBinary(), nullable=True),
|
| 22 |
+
)
|
| 23 |
+
op.add_column(
|
| 24 |
+
"agents",
|
| 25 |
+
sa.Column("did_private_key_encrypted", sa.Text(), nullable=True),
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def downgrade() -> None:
|
| 30 |
+
op.drop_column("agents", "did_private_key_encrypted")
|
| 31 |
+
op.drop_column("agents", "did_public_key")
|
alembic/versions/006_add_api_key_revoked_at.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add api_key_revoked_at column to users table
|
| 2 |
+
|
| 3 |
+
Revision ID: 006
|
| 4 |
+
Revises: 005
|
| 5 |
+
Create Date: 2026-02-28
|
| 6 |
+
"""
|
| 7 |
+
from typing import Sequence, Union
|
| 8 |
+
|
| 9 |
+
import sqlalchemy as sa
|
| 10 |
+
from alembic import op
|
| 11 |
+
|
| 12 |
+
revision: str = "006"
|
| 13 |
+
down_revision: Union[str, None] = "005"
|
| 14 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 15 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def upgrade() -> None:
|
| 19 |
+
op.add_column(
|
| 20 |
+
"users",
|
| 21 |
+
sa.Column("api_key_revoked_at", sa.DateTime(timezone=True), nullable=True),
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def downgrade() -> None:
|
| 26 |
+
op.drop_column("users", "api_key_revoked_at")
|
alembic/versions/007_add_agent_profile_fields.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add avatar_url, conversation_starters, test_cases to agents
|
| 2 |
+
|
| 3 |
+
Revision ID: 007
|
| 4 |
+
Revises: 006
|
| 5 |
+
Create Date: 2026-02-28
|
| 6 |
+
"""
|
| 7 |
+
from typing import Sequence, Union
|
| 8 |
+
|
| 9 |
+
import sqlalchemy as sa
|
| 10 |
+
from alembic import op
|
| 11 |
+
|
| 12 |
+
revision: str = "007"
|
| 13 |
+
down_revision: Union[str, None] = "006"
|
| 14 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 15 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def upgrade() -> None:
|
| 19 |
+
op.add_column("agents", sa.Column("avatar_url", sa.String(2048), nullable=True))
|
| 20 |
+
op.add_column("agents", sa.Column("conversation_starters", sa.JSON(), nullable=True))
|
| 21 |
+
op.add_column("agents", sa.Column("test_cases", sa.JSON(), nullable=True))
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def downgrade() -> None:
|
| 25 |
+
op.drop_column("agents", "test_cases")
|
| 26 |
+
op.drop_column("agents", "conversation_starters")
|
| 27 |
+
op.drop_column("agents", "avatar_url")
|
alembic/versions/008_add_status_history_to_tasks.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add status_history column to tasks
|
| 2 |
+
|
| 3 |
+
Revision ID: 008
|
| 4 |
+
Revises: 007
|
| 5 |
+
Create Date: 2026-02-28
|
| 6 |
+
"""
|
| 7 |
+
from typing import Sequence, Union
|
| 8 |
+
|
| 9 |
+
import sqlalchemy as sa
|
| 10 |
+
from alembic import op
|
| 11 |
+
|
| 12 |
+
revision: str = "008"
|
| 13 |
+
down_revision: Union[str, None] = "007"
|
| 14 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 15 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def upgrade() -> None:
|
| 19 |
+
op.add_column("tasks", sa.Column("status_history", sa.JSON(), nullable=True))
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def downgrade() -> None:
|
| 23 |
+
op.drop_column("tasks", "status_history")
|
alembic/versions/009_create_llm_calls_table.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Create llm_calls table
|
| 2 |
+
|
| 3 |
+
Revision ID: 009
|
| 4 |
+
Revises: 008
|
| 5 |
+
Create Date: 2026-02-28
|
| 6 |
+
"""
|
| 7 |
+
from typing import Sequence, Union
|
| 8 |
+
|
| 9 |
+
import sqlalchemy as sa
|
| 10 |
+
from alembic import op
|
| 11 |
+
|
| 12 |
+
revision: str = "009"
|
| 13 |
+
down_revision: Union[str, None] = "008"
|
| 14 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 15 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def upgrade() -> None:
|
| 19 |
+
op.create_table(
|
| 20 |
+
"llm_calls",
|
| 21 |
+
sa.Column("id", sa.Uuid(), primary_key=True),
|
| 22 |
+
sa.Column("agent_id", sa.Uuid(), sa.ForeignKey("agents.id", ondelete="SET NULL"), nullable=True, index=True),
|
| 23 |
+
sa.Column("task_id", sa.Uuid(), sa.ForeignKey("tasks.id", ondelete="SET NULL"), nullable=True, index=True),
|
| 24 |
+
sa.Column("provider", sa.String(50), nullable=False),
|
| 25 |
+
sa.Column("model", sa.String(100), nullable=False),
|
| 26 |
+
sa.Column("request_body", sa.JSON(), nullable=True),
|
| 27 |
+
sa.Column("response_body", sa.JSON(), nullable=True),
|
| 28 |
+
sa.Column("status_code", sa.Integer(), nullable=True),
|
| 29 |
+
sa.Column("latency_ms", sa.Integer(), nullable=True),
|
| 30 |
+
sa.Column("tokens_input", sa.Integer(), nullable=True),
|
| 31 |
+
sa.Column("tokens_output", sa.Integer(), nullable=True),
|
| 32 |
+
sa.Column("error_message", sa.Text(), nullable=True),
|
| 33 |
+
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def downgrade() -> None:
|
| 38 |
+
op.drop_table("llm_calls")
|
alembic/versions/010_add_onboarding_fields_to_users.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add onboarding_completed and interests to users
|
| 2 |
+
|
| 3 |
+
Revision ID: 010
|
| 4 |
+
Revises: 009
|
| 5 |
+
Create Date: 2026-02-28
|
| 6 |
+
"""
|
| 7 |
+
from typing import Sequence, Union
|
| 8 |
+
|
| 9 |
+
import sqlalchemy as sa
|
| 10 |
+
from alembic import op
|
| 11 |
+
|
| 12 |
+
revision: str = "010"
|
| 13 |
+
down_revision: Union[str, None] = "009"
|
| 14 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 15 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def upgrade() -> None:
|
| 19 |
+
op.add_column(
|
| 20 |
+
"users",
|
| 21 |
+
sa.Column("onboarding_completed", sa.Boolean(), server_default="false", nullable=False),
|
| 22 |
+
)
|
| 23 |
+
op.add_column("users", sa.Column("interests", sa.JSON(), nullable=True))
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def downgrade() -> None:
|
| 27 |
+
op.drop_column("users", "interests")
|
| 28 |
+
op.drop_column("users", "onboarding_completed")
|
alembic/versions/011_create_org_team_membership_tables.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Create organizations, teams, memberships tables and add organization_id to agents
|
| 2 |
+
|
| 3 |
+
Revision ID: 011
|
| 4 |
+
Revises: 010
|
| 5 |
+
Create Date: 2026-02-28
|
| 6 |
+
"""
|
| 7 |
+
from typing import Sequence, Union
|
| 8 |
+
|
| 9 |
+
import sqlalchemy as sa
|
| 10 |
+
from alembic import op
|
| 11 |
+
|
| 12 |
+
revision: str = "011"
|
| 13 |
+
down_revision: Union[str, None] = "010"
|
| 14 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 15 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def upgrade() -> None:
|
| 19 |
+
op.create_table(
|
| 20 |
+
"organizations",
|
| 21 |
+
sa.Column("id", sa.Uuid(), primary_key=True),
|
| 22 |
+
sa.Column("name", sa.String(255), nullable=False),
|
| 23 |
+
sa.Column("slug", sa.String(255), unique=True, nullable=False, index=True),
|
| 24 |
+
sa.Column("avatar_url", sa.String(2048), nullable=True),
|
| 25 |
+
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
| 26 |
+
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
op.create_table(
|
| 30 |
+
"teams",
|
| 31 |
+
sa.Column("id", sa.Uuid(), primary_key=True),
|
| 32 |
+
sa.Column("organization_id", sa.Uuid(), sa.ForeignKey("organizations.id", ondelete="CASCADE"), nullable=False, index=True),
|
| 33 |
+
sa.Column("name", sa.String(255), nullable=False),
|
| 34 |
+
sa.Column("description", sa.Text(), nullable=True),
|
| 35 |
+
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
op.create_table(
|
| 39 |
+
"memberships",
|
| 40 |
+
sa.Column("id", sa.Uuid(), primary_key=True),
|
| 41 |
+
sa.Column("user_id", sa.Uuid(), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True),
|
| 42 |
+
sa.Column("organization_id", sa.Uuid(), sa.ForeignKey("organizations.id", ondelete="CASCADE"), nullable=False, index=True),
|
| 43 |
+
sa.Column("team_id", sa.Uuid(), sa.ForeignKey("teams.id", ondelete="SET NULL"), nullable=True, index=True),
|
| 44 |
+
sa.Column("role", sa.String(20), nullable=False, server_default="member"),
|
| 45 |
+
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
op.add_column(
|
| 49 |
+
"agents",
|
| 50 |
+
sa.Column("organization_id", sa.Uuid(), sa.ForeignKey("organizations.id", ondelete="SET NULL"), nullable=True, index=True),
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def downgrade() -> None:
|
| 55 |
+
op.drop_column("agents", "organization_id")
|
| 56 |
+
op.drop_table("memberships")
|
| 57 |
+
op.drop_table("teams")
|
| 58 |
+
op.drop_table("organizations")
|
alembic/versions/012_fix_boolean_server_defaults.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Fix boolean server_defaults for cross-database compatibility.
|
| 2 |
+
|
| 3 |
+
Revision ID: 012
|
| 4 |
+
Revises: 011
|
| 5 |
+
Create Date: 2026-02-28
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import sqlalchemy as sa
|
| 9 |
+
from alembic import op
|
| 10 |
+
|
| 11 |
+
revision = "012"
|
| 12 |
+
down_revision = "011"
|
| 13 |
+
branch_labels = None
|
| 14 |
+
depends_on = None
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def upgrade() -> None:
|
| 18 |
+
with op.batch_alter_table("users") as batch_op:
|
| 19 |
+
batch_op.alter_column("is_active", server_default=sa.true())
|
| 20 |
+
batch_op.alter_column("is_admin", server_default=sa.false())
|
| 21 |
+
batch_op.alter_column("onboarding_completed", server_default=sa.false())
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def downgrade() -> None:
|
| 25 |
+
with op.batch_alter_table("users") as batch_op:
|
| 26 |
+
batch_op.alter_column("is_active", server_default=sa.text("'true'"))
|
| 27 |
+
batch_op.alter_column("is_admin", server_default=sa.text("'false'"))
|
| 28 |
+
batch_op.alter_column("onboarding_completed", server_default=sa.text("'false'"))
|
alembic/versions/013_add_account_tier_to_users.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add account_tier and Stripe billing columns to users table.
|
| 2 |
+
|
| 3 |
+
Revision ID: 013
|
| 4 |
+
Revises: 012
|
| 5 |
+
Create Date: 2026-03-01
|
| 6 |
+
"""
|
| 7 |
+
from alembic import op
|
| 8 |
+
import sqlalchemy as sa
|
| 9 |
+
|
| 10 |
+
revision = "013"
|
| 11 |
+
down_revision = "012"
|
| 12 |
+
branch_labels = None
|
| 13 |
+
depends_on = None
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def upgrade() -> None:
|
| 17 |
+
op.add_column(
|
| 18 |
+
"users",
|
| 19 |
+
sa.Column("account_tier", sa.String(20), nullable=False, server_default="free"),
|
| 20 |
+
)
|
| 21 |
+
op.add_column(
|
| 22 |
+
"users",
|
| 23 |
+
sa.Column("stripe_customer_id", sa.String(255), nullable=True),
|
| 24 |
+
)
|
| 25 |
+
op.add_column(
|
| 26 |
+
"users",
|
| 27 |
+
sa.Column("stripe_subscription_id", sa.String(255), nullable=True),
|
| 28 |
+
)
|
| 29 |
+
op.create_index("ix_users_stripe_customer_id", "users", ["stripe_customer_id"], unique=True)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def downgrade() -> None:
|
| 33 |
+
op.drop_index("ix_users_stripe_customer_id", table_name="users")
|
| 34 |
+
op.drop_column("users", "stripe_subscription_id")
|
| 35 |
+
op.drop_column("users", "stripe_customer_id")
|
| 36 |
+
op.drop_column("users", "account_tier")
|
alembic/versions/014_add_creator_user_id_to_tasks.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add creator_user_id column to tasks
|
| 2 |
+
|
| 3 |
+
Revision ID: 014
|
| 4 |
+
Revises: 013
|
| 5 |
+
Create Date: 2026-03-05
|
| 6 |
+
"""
|
| 7 |
+
from typing import Sequence, Union
|
| 8 |
+
|
| 9 |
+
import sqlalchemy as sa
|
| 10 |
+
from alembic import op
|
| 11 |
+
|
| 12 |
+
revision: str = "014"
|
| 13 |
+
down_revision: Union[str, None] = "013"
|
| 14 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 15 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def upgrade() -> None:
|
| 19 |
+
op.add_column(
|
| 20 |
+
"tasks",
|
| 21 |
+
sa.Column("creator_user_id", sa.Uuid(), sa.ForeignKey("users.id", ondelete="SET NULL"), nullable=True, index=True),
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def downgrade() -> None:
|
| 26 |
+
op.drop_column("tasks", "creator_user_id")
|
alembic/versions/015_add_webhook_logs.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add webhook_logs table.
|
| 2 |
+
|
| 3 |
+
Revision ID: 015
|
| 4 |
+
Revises: 014
|
| 5 |
+
Create Date: 2026-03-07
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from alembic import op
|
| 9 |
+
import sqlalchemy as sa
|
| 10 |
+
|
| 11 |
+
revision = "015"
|
| 12 |
+
down_revision = "014"
|
| 13 |
+
branch_labels = None
|
| 14 |
+
depends_on = None
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def upgrade() -> None:
|
| 18 |
+
op.create_table(
|
| 19 |
+
"webhook_logs",
|
| 20 |
+
sa.Column("id", sa.Uuid(), primary_key=True),
|
| 21 |
+
sa.Column("agent_id", sa.Uuid(), sa.ForeignKey("agents.id", ondelete="CASCADE"), nullable=False, index=True),
|
| 22 |
+
sa.Column("task_id", sa.Uuid(), sa.ForeignKey("tasks.id", ondelete="SET NULL"), nullable=True, index=True),
|
| 23 |
+
sa.Column("direction", sa.String(10), nullable=False, index=True),
|
| 24 |
+
sa.Column("method", sa.String(50), nullable=False),
|
| 25 |
+
sa.Column("request_body", sa.JSON(), nullable=True),
|
| 26 |
+
sa.Column("response_body", sa.JSON(), nullable=True),
|
| 27 |
+
sa.Column("status_code", sa.Integer(), nullable=True),
|
| 28 |
+
sa.Column("success", sa.Boolean(), nullable=False, server_default="true"),
|
| 29 |
+
sa.Column("error_message", sa.Text(), nullable=True),
|
| 30 |
+
sa.Column("latency_ms", sa.Integer(), nullable=True),
|
| 31 |
+
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def downgrade() -> None:
|
| 36 |
+
op.drop_table("webhook_logs")
|
alembic/versions/016_production_readiness_columns.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add production-readiness columns and telemetry table.
|
| 2 |
+
|
| 3 |
+
Sprint 1: daily_spend_limit on users
|
| 4 |
+
Sprint 2: delegation_depth, parent_task_id, suggested_agent_id, suggestion_confidence on tasks
|
| 5 |
+
Sprint 2: telemetry_events table
|
| 6 |
+
|
| 7 |
+
Revision ID: 016
|
| 8 |
+
Revises: 015
|
| 9 |
+
Create Date: 2026-03-08
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
from alembic import op
|
| 13 |
+
import sqlalchemy as sa
|
| 14 |
+
|
| 15 |
+
revision = "016"
|
| 16 |
+
down_revision = "015"
|
| 17 |
+
branch_labels = None
|
| 18 |
+
depends_on = None
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def upgrade() -> None:
|
| 22 |
+
# Sprint 1.2: Per-user spending limits
|
| 23 |
+
op.add_column("users", sa.Column("daily_spend_limit", sa.Float(), nullable=True))
|
| 24 |
+
|
| 25 |
+
# Sprint 2.3: Delegation chain depth tracking
|
| 26 |
+
op.add_column(
|
| 27 |
+
"tasks",
|
| 28 |
+
sa.Column("delegation_depth", sa.Integer(), nullable=False, server_default="0"),
|
| 29 |
+
)
|
| 30 |
+
op.add_column(
|
| 31 |
+
"tasks",
|
| 32 |
+
sa.Column(
|
| 33 |
+
"parent_task_id",
|
| 34 |
+
sa.Uuid(),
|
| 35 |
+
sa.ForeignKey("tasks.id", ondelete="SET NULL"),
|
| 36 |
+
nullable=True,
|
| 37 |
+
),
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
# Sprint 2.4: Delegation accuracy tracking
|
| 41 |
+
op.add_column(
|
| 42 |
+
"tasks",
|
| 43 |
+
sa.Column(
|
| 44 |
+
"suggested_agent_id",
|
| 45 |
+
sa.Uuid(),
|
| 46 |
+
sa.ForeignKey("agents.id", ondelete="SET NULL"),
|
| 47 |
+
nullable=True,
|
| 48 |
+
),
|
| 49 |
+
)
|
| 50 |
+
op.add_column(
|
| 51 |
+
"tasks",
|
| 52 |
+
sa.Column("suggestion_confidence", sa.Float(), nullable=True),
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# Sprint 2.6: Telemetry events table
|
| 56 |
+
op.create_table(
|
| 57 |
+
"telemetry_events",
|
| 58 |
+
sa.Column("id", sa.Uuid(), primary_key=True),
|
| 59 |
+
sa.Column("user_id", sa.Uuid(), nullable=True, index=True),
|
| 60 |
+
sa.Column("event_name", sa.String(100), nullable=False, index=True),
|
| 61 |
+
sa.Column("properties", sa.JSON(), nullable=True),
|
| 62 |
+
sa.Column(
|
| 63 |
+
"created_at",
|
| 64 |
+
sa.DateTime(timezone=True),
|
| 65 |
+
server_default=sa.func.now(),
|
| 66 |
+
nullable=False,
|
| 67 |
+
),
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def downgrade() -> None:
|
| 72 |
+
op.drop_table("telemetry_events")
|
| 73 |
+
op.drop_column("tasks", "suggestion_confidence")
|
| 74 |
+
op.drop_column("tasks", "suggested_agent_id")
|
| 75 |
+
op.drop_column("tasks", "parent_task_id")
|
| 76 |
+
op.drop_column("tasks", "delegation_depth")
|
| 77 |
+
op.drop_column("users", "daily_spend_limit")
|
alembic/versions/017_add_eval_subscores.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add eval subscores and model tracking to tasks.
|
| 2 |
+
|
| 3 |
+
Stores per-dimension quality scores (relevance, completeness, coherence)
|
| 4 |
+
and the eval model used, enabling multi-model benchmarking.
|
| 5 |
+
|
| 6 |
+
Revision ID: 017
|
| 7 |
+
Revises: 016
|
| 8 |
+
Create Date: 2026-03-08
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from alembic import op
|
| 12 |
+
import sqlalchemy as sa
|
| 13 |
+
|
| 14 |
+
revision = "017"
|
| 15 |
+
down_revision = "016"
|
| 16 |
+
branch_labels = None
|
| 17 |
+
depends_on = None
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def upgrade() -> None:
|
| 21 |
+
op.add_column("tasks", sa.Column("eval_model", sa.String(100), nullable=True))
|
| 22 |
+
op.add_column("tasks", sa.Column("eval_relevance", sa.Float, nullable=True))
|
| 23 |
+
op.add_column("tasks", sa.Column("eval_completeness", sa.Float, nullable=True))
|
| 24 |
+
op.add_column("tasks", sa.Column("eval_coherence", sa.Float, nullable=True))
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def downgrade() -> None:
|
| 28 |
+
op.drop_column("tasks", "eval_coherence")
|
| 29 |
+
op.drop_column("tasks", "eval_completeness")
|
| 30 |
+
op.drop_column("tasks", "eval_relevance")
|
| 31 |
+
op.drop_column("tasks", "eval_model")
|
alembic/versions/018_simplify_verification_tiers.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Simplify verification_level from 5 tiers to 3.
|
| 2 |
+
|
| 3 |
+
Revision ID: 018
|
| 4 |
+
Revises: 017
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from alembic import op
|
| 8 |
+
|
| 9 |
+
revision = "018"
|
| 10 |
+
down_revision = "017"
|
| 11 |
+
branch_labels = None
|
| 12 |
+
depends_on = None
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def upgrade() -> None:
|
| 16 |
+
# Map old 5-tier values to new 3-tier system
|
| 17 |
+
op.execute("UPDATE agents SET verification_level = 'new' WHERE verification_level = 'unverified'")
|
| 18 |
+
op.execute("UPDATE agents SET verification_level = 'verified' WHERE verification_level IN ('self_tested', 'namespace_verified')")
|
| 19 |
+
op.execute("UPDATE agents SET verification_level = 'certified' WHERE verification_level IN ('quality_assured', 'audit_passed')")
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def downgrade() -> None:
|
| 23 |
+
# Reverse: map back to original values (lossy — self_tested vs namespace_verified indistinguishable)
|
| 24 |
+
op.execute("UPDATE agents SET verification_level = 'unverified' WHERE verification_level = 'new'")
|
| 25 |
+
op.execute("UPDATE agents SET verification_level = 'self_tested' WHERE verification_level = 'verified'")
|
| 26 |
+
op.execute("UPDATE agents SET verification_level = 'quality_assured' WHERE verification_level = 'certified'")
|
alembic/versions/019_agent_crews.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Create agent_crews and agent_crew_members tables.
|
| 2 |
+
|
| 3 |
+
Revision ID: 019
|
| 4 |
+
Revises: 018
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sqlalchemy as sa
|
| 8 |
+
from alembic import op
|
| 9 |
+
|
| 10 |
+
revision = "019"
|
| 11 |
+
down_revision = "018"
|
| 12 |
+
branch_labels = None
|
| 13 |
+
depends_on = None
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def upgrade() -> None:
|
| 17 |
+
op.create_table(
|
| 18 |
+
"agent_crews",
|
| 19 |
+
sa.Column("id", sa.Uuid(), primary_key=True),
|
| 20 |
+
sa.Column("owner_id", sa.Uuid(), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True),
|
| 21 |
+
sa.Column("name", sa.String(255), nullable=False),
|
| 22 |
+
sa.Column("description", sa.Text(), nullable=True),
|
| 23 |
+
sa.Column("icon", sa.String(10), nullable=False, server_default="🤖"),
|
| 24 |
+
sa.Column("is_public", sa.Boolean(), nullable=False, server_default=sa.false()),
|
| 25 |
+
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
| 26 |
+
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
| 27 |
+
)
|
| 28 |
+
op.create_table(
|
| 29 |
+
"agent_crew_members",
|
| 30 |
+
sa.Column("id", sa.Uuid(), primary_key=True),
|
| 31 |
+
sa.Column("crew_id", sa.Uuid(), sa.ForeignKey("agent_crews.id", ondelete="CASCADE"), nullable=False, index=True),
|
| 32 |
+
sa.Column("agent_id", sa.Uuid(), sa.ForeignKey("agents.id", ondelete="CASCADE"), nullable=False),
|
| 33 |
+
sa.Column("skill_id", sa.Uuid(), sa.ForeignKey("agent_skills.id", ondelete="CASCADE"), nullable=False),
|
| 34 |
+
sa.Column("position", sa.Integer(), nullable=False, server_default="0"),
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def downgrade() -> None:
|
| 39 |
+
op.drop_table("agent_crew_members")
|
| 40 |
+
op.drop_table("agent_crews")
|
alembic/versions/020_pgvector_embeddings.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Convert embedding column from JSON to pgvector vector(N).
|
| 2 |
+
|
| 3 |
+
Reads EMBEDDING_DIMENSION from env (default 1536).
|
| 4 |
+
NULLs existing embeddings first to avoid dimension mismatch during cast.
|
| 5 |
+
Uses HNSW index (supports up to 4096 dims) instead of IVFFlat (max 2000).
|
| 6 |
+
|
| 7 |
+
Revision ID: 020
|
| 8 |
+
Revises: 019
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import os
|
| 12 |
+
|
| 13 |
+
from alembic import op
|
| 14 |
+
|
| 15 |
+
revision = "020"
|
| 16 |
+
down_revision = "019"
|
| 17 |
+
branch_labels = None
|
| 18 |
+
depends_on = None
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def upgrade() -> None:
|
| 22 |
+
conn = op.get_bind()
|
| 23 |
+
if conn.dialect.name != "postgresql":
|
| 24 |
+
return # Skip on SQLite
|
| 25 |
+
|
| 26 |
+
dim = int(os.environ.get("EMBEDDING_DIMENSION", "1536"))
|
| 27 |
+
|
| 28 |
+
# Enable pgvector extension
|
| 29 |
+
op.execute("CREATE EXTENSION IF NOT EXISTS vector")
|
| 30 |
+
|
| 31 |
+
# NULL out existing embeddings — dimension may mismatch the target vector type
|
| 32 |
+
op.execute("UPDATE agent_skills SET embedding = NULL")
|
| 33 |
+
|
| 34 |
+
# Convert JSON → vector(dim)
|
| 35 |
+
op.execute(
|
| 36 |
+
f"ALTER TABLE agent_skills ALTER COLUMN embedding "
|
| 37 |
+
f"TYPE vector({dim}) USING embedding::text::vector({dim})"
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
# Vector index — only for dimensions <= 2000 (pgvector limit on Supabase)
|
| 41 |
+
# For higher dims (e.g. Gemini 3072), sequential scan is fine at <1000 rows
|
| 42 |
+
if dim <= 2000:
|
| 43 |
+
op.execute(
|
| 44 |
+
"CREATE INDEX IF NOT EXISTS ix_agent_skills_embedding_cosine "
|
| 45 |
+
"ON agent_skills USING hnsw (embedding vector_cosine_ops)"
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def downgrade() -> None:
|
| 50 |
+
conn = op.get_bind()
|
| 51 |
+
if conn.dialect.name != "postgresql":
|
| 52 |
+
return
|
| 53 |
+
|
| 54 |
+
op.execute("DROP INDEX IF EXISTS ix_agent_skills_embedding_cosine")
|
| 55 |
+
op.execute(
|
| 56 |
+
"ALTER TABLE agent_skills ALTER COLUMN embedding "
|
| 57 |
+
"TYPE json USING embedding::text::json"
|
| 58 |
+
)
|
alembic/versions/021_fix_embedding_dimension.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Fix embedding column if migration 020 ran with wrong dimension or failed.
|
| 2 |
+
|
| 3 |
+
Safety net — re-types column to vector(N) using HNSW index.
|
| 4 |
+
|
| 5 |
+
Revision ID: 021
|
| 6 |
+
Revises: 020
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
|
| 11 |
+
from alembic import op
|
| 12 |
+
|
| 13 |
+
revision = "021"
|
| 14 |
+
down_revision = "020"
|
| 15 |
+
branch_labels = None
|
| 16 |
+
depends_on = None
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def upgrade() -> None:
|
| 20 |
+
conn = op.get_bind()
|
| 21 |
+
if conn.dialect.name != "postgresql":
|
| 22 |
+
return
|
| 23 |
+
|
| 24 |
+
dim = int(os.environ.get("EMBEDDING_DIMENSION", "1536"))
|
| 25 |
+
|
| 26 |
+
op.execute("CREATE EXTENSION IF NOT EXISTS vector")
|
| 27 |
+
op.execute("DROP INDEX IF EXISTS ix_agent_skills_embedding_cosine")
|
| 28 |
+
op.execute("UPDATE agent_skills SET embedding = NULL")
|
| 29 |
+
|
| 30 |
+
op.execute(
|
| 31 |
+
f"ALTER TABLE agent_skills ALTER COLUMN embedding "
|
| 32 |
+
f"TYPE vector({dim}) USING NULL::vector({dim})"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Vector index — only for dimensions <= 2000 (pgvector limit on Supabase)
|
| 36 |
+
if dim <= 2000:
|
| 37 |
+
op.execute(
|
| 38 |
+
"CREATE INDEX IF NOT EXISTS ix_agent_skills_embedding_cosine "
|
| 39 |
+
"ON agent_skills USING hnsw (embedding vector_cosine_ops)"
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def downgrade() -> None:
|
| 44 |
+
conn = op.get_bind()
|
| 45 |
+
if conn.dialect.name != "postgresql":
|
| 46 |
+
return
|
| 47 |
+
|
| 48 |
+
op.execute("DROP INDEX IF EXISTS ix_agent_skills_embedding_cosine")
|
| 49 |
+
op.execute("UPDATE agent_skills SET embedding = NULL")
|
| 50 |
+
op.execute(
|
| 51 |
+
"ALTER TABLE agent_skills ALTER COLUMN embedding "
|
| 52 |
+
"TYPE json USING NULL::json"
|
| 53 |
+
)
|
alembic/versions/022_add_stripe_connect_payouts.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add Stripe Connect columns to users and create payout_requests table.
|
| 2 |
+
|
| 3 |
+
Revision ID: 022
|
| 4 |
+
Revises: 021
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sqlalchemy as sa
|
| 8 |
+
from alembic import op
|
| 9 |
+
|
| 10 |
+
revision = "022"
|
| 11 |
+
down_revision = "021"
|
| 12 |
+
branch_labels = None
|
| 13 |
+
depends_on = None
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def upgrade() -> None:
|
| 17 |
+
# --- Users: Stripe Connect columns ---
|
| 18 |
+
op.add_column("users", sa.Column(
|
| 19 |
+
"stripe_connect_account_id", sa.String(255), nullable=True, unique=True,
|
| 20 |
+
))
|
| 21 |
+
op.add_column("users", sa.Column(
|
| 22 |
+
"stripe_connect_onboarded", sa.Boolean(), nullable=False, server_default=sa.text("false"),
|
| 23 |
+
))
|
| 24 |
+
op.add_column("users", sa.Column(
|
| 25 |
+
"stripe_connect_payouts_enabled", sa.Boolean(), nullable=False, server_default=sa.text("false"),
|
| 26 |
+
))
|
| 27 |
+
op.create_index("ix_users_stripe_connect_account_id", "users", ["stripe_connect_account_id"], unique=True)
|
| 28 |
+
|
| 29 |
+
# --- Payout requests table ---
|
| 30 |
+
op.create_table(
|
| 31 |
+
"payout_requests",
|
| 32 |
+
sa.Column("id", sa.Uuid(), primary_key=True),
|
| 33 |
+
sa.Column("user_id", sa.Uuid(), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True),
|
| 34 |
+
sa.Column("amount_credits", sa.Numeric(16, 4), nullable=False),
|
| 35 |
+
sa.Column("amount_usd_cents", sa.Integer(), nullable=False),
|
| 36 |
+
sa.Column("stripe_fee_cents", sa.Integer(), nullable=False, server_default="0"),
|
| 37 |
+
sa.Column("status", sa.String(20), nullable=False, server_default="pending", index=True),
|
| 38 |
+
sa.Column("stripe_transfer_id", sa.String(255), nullable=True, unique=True),
|
| 39 |
+
sa.Column("failure_reason", sa.String(500), nullable=True),
|
| 40 |
+
sa.Column("requested_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
| 41 |
+
sa.Column("completed_at", sa.DateTime(timezone=True), nullable=True),
|
| 42 |
+
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
# Note: TransactionType is stored as String(20) in the DB, not a native
|
| 46 |
+
# PostgreSQL enum, so no ALTER TYPE needed. New values like 'payout'
|
| 47 |
+
# are automatically supported by inserting the string directly.
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def downgrade() -> None:
|
| 51 |
+
op.drop_table("payout_requests")
|
| 52 |
+
op.drop_index("ix_users_stripe_connect_account_id", table_name="users")
|
| 53 |
+
op.drop_column("users", "stripe_connect_payouts_enabled")
|
| 54 |
+
op.drop_column("users", "stripe_connect_onboarded")
|
| 55 |
+
op.drop_column("users", "stripe_connect_account_id")
|
| 56 |
+
# Note: PostgreSQL enum values cannot be removed without recreating the type
|
alembic/versions/023_workflows_and_schedules.py
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add workflows, workflow_steps, workflow_step_runs, workflow_runs, and schedules tables.
|
| 2 |
+
|
| 3 |
+
Revision ID: 023
|
| 4 |
+
Revises: 022
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sqlalchemy as sa
|
| 8 |
+
from alembic import op
|
| 9 |
+
|
| 10 |
+
revision = "023"
|
| 11 |
+
down_revision = "022"
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def upgrade() -> None:
|
| 15 |
+
op.create_table(
|
| 16 |
+
"workflows",
|
| 17 |
+
sa.Column("id", sa.Uuid(), primary_key=True),
|
| 18 |
+
sa.Column(
|
| 19 |
+
"owner_id",
|
| 20 |
+
sa.Uuid(),
|
| 21 |
+
sa.ForeignKey("users.id", ondelete="CASCADE"),
|
| 22 |
+
nullable=False,
|
| 23 |
+
index=True,
|
| 24 |
+
),
|
| 25 |
+
sa.Column("name", sa.String(255), nullable=False),
|
| 26 |
+
sa.Column("description", sa.Text(), nullable=True),
|
| 27 |
+
sa.Column("icon", sa.String(10), nullable=False, server_default="🔗"),
|
| 28 |
+
sa.Column("is_public", sa.Boolean(), nullable=False, server_default=sa.false()),
|
| 29 |
+
sa.Column("max_total_credits", sa.Integer(), nullable=True),
|
| 30 |
+
sa.Column(
|
| 31 |
+
"created_at",
|
| 32 |
+
sa.DateTime(timezone=True),
|
| 33 |
+
server_default=sa.func.now(),
|
| 34 |
+
nullable=False,
|
| 35 |
+
),
|
| 36 |
+
sa.Column(
|
| 37 |
+
"updated_at",
|
| 38 |
+
sa.DateTime(timezone=True),
|
| 39 |
+
server_default=sa.func.now(),
|
| 40 |
+
nullable=False,
|
| 41 |
+
),
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
op.create_table(
|
| 45 |
+
"workflow_steps",
|
| 46 |
+
sa.Column("id", sa.Uuid(), primary_key=True),
|
| 47 |
+
sa.Column(
|
| 48 |
+
"workflow_id",
|
| 49 |
+
sa.Uuid(),
|
| 50 |
+
sa.ForeignKey("workflows.id", ondelete="CASCADE"),
|
| 51 |
+
nullable=False,
|
| 52 |
+
index=True,
|
| 53 |
+
),
|
| 54 |
+
sa.Column(
|
| 55 |
+
"agent_id",
|
| 56 |
+
sa.Uuid(),
|
| 57 |
+
sa.ForeignKey("agents.id", ondelete="CASCADE"),
|
| 58 |
+
nullable=False,
|
| 59 |
+
),
|
| 60 |
+
sa.Column(
|
| 61 |
+
"skill_id",
|
| 62 |
+
sa.Uuid(),
|
| 63 |
+
sa.ForeignKey("agent_skills.id", ondelete="CASCADE"),
|
| 64 |
+
nullable=False,
|
| 65 |
+
),
|
| 66 |
+
sa.Column("step_group", sa.Integer(), nullable=False, server_default="0"),
|
| 67 |
+
sa.Column("position", sa.Integer(), nullable=False, server_default="0"),
|
| 68 |
+
sa.Column("input_mode", sa.String(20), nullable=False, server_default="chain"),
|
| 69 |
+
sa.Column("input_template", sa.Text(), nullable=True),
|
| 70 |
+
sa.Column("label", sa.String(255), nullable=True),
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
op.create_table(
|
| 74 |
+
"workflow_runs",
|
| 75 |
+
sa.Column("id", sa.Uuid(), primary_key=True),
|
| 76 |
+
sa.Column(
|
| 77 |
+
"workflow_id",
|
| 78 |
+
sa.Uuid(),
|
| 79 |
+
sa.ForeignKey("workflows.id", ondelete="CASCADE"),
|
| 80 |
+
nullable=False,
|
| 81 |
+
index=True,
|
| 82 |
+
),
|
| 83 |
+
sa.Column(
|
| 84 |
+
"user_id",
|
| 85 |
+
sa.Uuid(),
|
| 86 |
+
sa.ForeignKey("users.id", ondelete="CASCADE"),
|
| 87 |
+
nullable=False,
|
| 88 |
+
index=True,
|
| 89 |
+
),
|
| 90 |
+
sa.Column("schedule_id", sa.Uuid(), nullable=True),
|
| 91 |
+
sa.Column("status", sa.String(20), nullable=False, server_default="running"),
|
| 92 |
+
sa.Column("current_step_group", sa.Integer(), nullable=False, server_default="0"),
|
| 93 |
+
sa.Column("input_message", sa.Text(), nullable=False),
|
| 94 |
+
sa.Column("workflow_snapshot", sa.JSON(), nullable=True),
|
| 95 |
+
sa.Column("total_credits_charged", sa.Numeric(12, 4), nullable=True),
|
| 96 |
+
sa.Column("error", sa.Text(), nullable=True),
|
| 97 |
+
sa.Column(
|
| 98 |
+
"created_at",
|
| 99 |
+
sa.DateTime(timezone=True),
|
| 100 |
+
server_default=sa.func.now(),
|
| 101 |
+
nullable=False,
|
| 102 |
+
),
|
| 103 |
+
sa.Column("completed_at", sa.DateTime(timezone=True), nullable=True),
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
op.create_table(
|
| 107 |
+
"workflow_step_runs",
|
| 108 |
+
sa.Column("id", sa.Uuid(), primary_key=True),
|
| 109 |
+
sa.Column(
|
| 110 |
+
"run_id",
|
| 111 |
+
sa.Uuid(),
|
| 112 |
+
sa.ForeignKey("workflow_runs.id", ondelete="CASCADE"),
|
| 113 |
+
nullable=False,
|
| 114 |
+
index=True,
|
| 115 |
+
),
|
| 116 |
+
sa.Column(
|
| 117 |
+
"step_id",
|
| 118 |
+
sa.Uuid(),
|
| 119 |
+
sa.ForeignKey("workflow_steps.id", ondelete="SET NULL"),
|
| 120 |
+
nullable=True,
|
| 121 |
+
),
|
| 122 |
+
sa.Column("task_id", sa.Uuid(), sa.ForeignKey("tasks.id"), nullable=True),
|
| 123 |
+
sa.Column("step_group", sa.Integer(), nullable=False),
|
| 124 |
+
sa.Column("status", sa.String(20), nullable=False, server_default="pending"),
|
| 125 |
+
sa.Column("output_text", sa.Text(), nullable=True),
|
| 126 |
+
sa.Column("credits_charged", sa.Numeric(12, 4), nullable=True),
|
| 127 |
+
sa.Column("started_at", sa.DateTime(timezone=True), nullable=True),
|
| 128 |
+
sa.Column("completed_at", sa.DateTime(timezone=True), nullable=True),
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
op.create_table(
|
| 132 |
+
"schedules",
|
| 133 |
+
sa.Column("id", sa.Uuid(), primary_key=True),
|
| 134 |
+
sa.Column(
|
| 135 |
+
"owner_id",
|
| 136 |
+
sa.Uuid(),
|
| 137 |
+
sa.ForeignKey("users.id", ondelete="CASCADE"),
|
| 138 |
+
nullable=False,
|
| 139 |
+
index=True,
|
| 140 |
+
),
|
| 141 |
+
sa.Column("name", sa.String(255), nullable=False),
|
| 142 |
+
sa.Column("schedule_type", sa.String(20), nullable=False),
|
| 143 |
+
sa.Column("target_id", sa.Uuid(), nullable=True),
|
| 144 |
+
sa.Column("task_params", sa.JSON(), nullable=True),
|
| 145 |
+
sa.Column("cron_expression", sa.String(100), nullable=False),
|
| 146 |
+
sa.Column("timezone", sa.String(50), nullable=False, server_default="UTC"),
|
| 147 |
+
sa.Column("input_message", sa.Text(), nullable=True),
|
| 148 |
+
sa.Column("is_active", sa.Boolean(), nullable=False, server_default=sa.true()),
|
| 149 |
+
sa.Column("next_run_at", sa.DateTime(timezone=True), nullable=True),
|
| 150 |
+
sa.Column("last_run_at", sa.DateTime(timezone=True), nullable=True),
|
| 151 |
+
sa.Column("run_count", sa.Integer(), nullable=False, server_default="0"),
|
| 152 |
+
sa.Column("max_runs", sa.Integer(), nullable=True),
|
| 153 |
+
sa.Column("consecutive_failures", sa.Integer(), nullable=False, server_default="0"),
|
| 154 |
+
sa.Column("max_consecutive_failures", sa.Integer(), nullable=False, server_default="3"),
|
| 155 |
+
sa.Column("credit_minimum", sa.Integer(), nullable=False, server_default="0"),
|
| 156 |
+
sa.Column(
|
| 157 |
+
"created_at",
|
| 158 |
+
sa.DateTime(timezone=True),
|
| 159 |
+
server_default=sa.func.now(),
|
| 160 |
+
nullable=False,
|
| 161 |
+
),
|
| 162 |
+
)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def downgrade() -> None:
|
| 166 |
+
op.drop_table("workflow_step_runs")
|
| 167 |
+
op.drop_table("workflow_runs")
|
| 168 |
+
op.drop_table("workflow_steps")
|
| 169 |
+
op.drop_table("workflows")
|
| 170 |
+
op.drop_table("schedules")
|
alembic/versions/024_workflow_timeouts_and_step_errors.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add timeout_seconds, step_timeout_seconds to workflows; error to workflow_step_runs.
|
| 2 |
+
|
| 3 |
+
Revision ID: 024
|
| 4 |
+
Revises: 023
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sqlalchemy as sa
|
| 8 |
+
from alembic import op
|
| 9 |
+
|
| 10 |
+
revision = "024"
|
| 11 |
+
down_revision = "023"
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def upgrade() -> None:
|
| 15 |
+
# User-configurable workflow-level timeout (default 1800s = 30 min)
|
| 16 |
+
op.add_column(
|
| 17 |
+
"workflows",
|
| 18 |
+
sa.Column("timeout_seconds", sa.Integer(), nullable=True, server_default="1800"),
|
| 19 |
+
)
|
| 20 |
+
# Per-step timeout (default 120s — matches A2A dispatch timeout)
|
| 21 |
+
op.add_column(
|
| 22 |
+
"workflows",
|
| 23 |
+
sa.Column("step_timeout_seconds", sa.Integer(), nullable=True, server_default="120"),
|
| 24 |
+
)
|
| 25 |
+
# Per-step error detail (why a step failed/timed out)
|
| 26 |
+
op.add_column(
|
| 27 |
+
"workflow_step_runs",
|
| 28 |
+
sa.Column("error", sa.Text(), nullable=True),
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def downgrade() -> None:
|
| 33 |
+
op.drop_column("workflow_step_runs", "error")
|
| 34 |
+
op.drop_column("workflows", "step_timeout_seconds")
|
| 35 |
+
op.drop_column("workflows", "timeout_seconds")
|
alembic/versions/025_workflow_step_instructions.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add instructions column to workflow_steps.
|
| 2 |
+
|
| 3 |
+
Revision ID: 025
|
| 4 |
+
Revises: 024
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sqlalchemy as sa
|
| 8 |
+
from alembic import op
|
| 9 |
+
|
| 10 |
+
revision = "025"
|
| 11 |
+
down_revision = "024"
|
| 12 |
+
|
| 13 |
+
def upgrade() -> None:
|
| 14 |
+
op.add_column(
|
| 15 |
+
"workflow_steps",
|
| 16 |
+
sa.Column("instructions", sa.Text(), nullable=True),
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def downgrade() -> None:
|
| 20 |
+
op.drop_column("workflow_steps", "instructions")
|
alembic/versions/026_custom_agents.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add custom_agents, custom_agent_votes, and agent_requests tables.
|
| 2 |
+
|
| 3 |
+
Revision ID: 026
|
| 4 |
+
Revises: 025
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sqlalchemy as sa
|
| 8 |
+
from alembic import op
|
| 9 |
+
|
| 10 |
+
revision = "026"
|
| 11 |
+
down_revision = "025"
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def upgrade() -> None:
|
| 15 |
+
op.create_table(
|
| 16 |
+
"custom_agents",
|
| 17 |
+
sa.Column("id", sa.Uuid(), primary_key=True),
|
| 18 |
+
sa.Column("name", sa.String(255), nullable=False),
|
| 19 |
+
sa.Column("description", sa.Text(), nullable=False),
|
| 20 |
+
sa.Column("system_prompt", sa.Text(), nullable=False),
|
| 21 |
+
sa.Column("category", sa.String(100), nullable=False, server_default="general"),
|
| 22 |
+
sa.Column("tags", sa.JSON(), nullable=True),
|
| 23 |
+
sa.Column("source_query", sa.Text(), nullable=False),
|
| 24 |
+
sa.Column("status", sa.String(20), nullable=False, server_default="active"),
|
| 25 |
+
sa.Column("try_count", sa.Integer(), nullable=False, server_default="0"),
|
| 26 |
+
sa.Column("completion_count", sa.Integer(), nullable=False, server_default="0"),
|
| 27 |
+
sa.Column("avg_rating", sa.Float(), nullable=False, server_default="0.0"),
|
| 28 |
+
sa.Column("upvote_count", sa.Integer(), nullable=False, server_default="0"),
|
| 29 |
+
sa.Column(
|
| 30 |
+
"promoted_agent_id",
|
| 31 |
+
sa.Uuid(),
|
| 32 |
+
sa.ForeignKey("agents.id", ondelete="SET NULL"),
|
| 33 |
+
nullable=True,
|
| 34 |
+
),
|
| 35 |
+
sa.Column(
|
| 36 |
+
"created_by_user_id",
|
| 37 |
+
sa.Uuid(),
|
| 38 |
+
sa.ForeignKey("users.id", ondelete="SET NULL"),
|
| 39 |
+
nullable=True,
|
| 40 |
+
index=True,
|
| 41 |
+
),
|
| 42 |
+
sa.Column(
|
| 43 |
+
"created_at",
|
| 44 |
+
sa.DateTime(timezone=True),
|
| 45 |
+
server_default=sa.func.now(),
|
| 46 |
+
nullable=False,
|
| 47 |
+
),
|
| 48 |
+
sa.Column(
|
| 49 |
+
"updated_at",
|
| 50 |
+
sa.DateTime(timezone=True),
|
| 51 |
+
server_default=sa.func.now(),
|
| 52 |
+
nullable=False,
|
| 53 |
+
),
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
op.create_table(
|
| 57 |
+
"custom_agent_votes",
|
| 58 |
+
sa.Column("id", sa.Uuid(), primary_key=True),
|
| 59 |
+
sa.Column(
|
| 60 |
+
"custom_agent_id",
|
| 61 |
+
sa.Uuid(),
|
| 62 |
+
sa.ForeignKey("custom_agents.id", ondelete="CASCADE"),
|
| 63 |
+
nullable=False,
|
| 64 |
+
index=True,
|
| 65 |
+
),
|
| 66 |
+
sa.Column(
|
| 67 |
+
"user_id",
|
| 68 |
+
sa.Uuid(),
|
| 69 |
+
sa.ForeignKey("users.id", ondelete="CASCADE"),
|
| 70 |
+
nullable=False,
|
| 71 |
+
index=True,
|
| 72 |
+
),
|
| 73 |
+
sa.Column("vote", sa.Integer(), nullable=False),
|
| 74 |
+
sa.Column(
|
| 75 |
+
"created_at",
|
| 76 |
+
sa.DateTime(timezone=True),
|
| 77 |
+
server_default=sa.func.now(),
|
| 78 |
+
nullable=False,
|
| 79 |
+
),
|
| 80 |
+
sa.UniqueConstraint("custom_agent_id", "user_id", name="uq_custom_agent_vote"),
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
op.create_table(
|
| 84 |
+
"agent_requests",
|
| 85 |
+
sa.Column("id", sa.Uuid(), primary_key=True),
|
| 86 |
+
sa.Column(
|
| 87 |
+
"user_id",
|
| 88 |
+
sa.Uuid(),
|
| 89 |
+
sa.ForeignKey("users.id", ondelete="SET NULL"),
|
| 90 |
+
nullable=True,
|
| 91 |
+
index=True,
|
| 92 |
+
),
|
| 93 |
+
sa.Column("query", sa.Text(), nullable=False),
|
| 94 |
+
sa.Column("best_match_confidence", sa.Float(), nullable=True),
|
| 95 |
+
sa.Column(
|
| 96 |
+
"custom_agent_id",
|
| 97 |
+
sa.Uuid(),
|
| 98 |
+
sa.ForeignKey("custom_agents.id", ondelete="SET NULL"),
|
| 99 |
+
nullable=True,
|
| 100 |
+
),
|
| 101 |
+
sa.Column(
|
| 102 |
+
"created_at",
|
| 103 |
+
sa.DateTime(timezone=True),
|
| 104 |
+
server_default=sa.func.now(),
|
| 105 |
+
nullable=False,
|
| 106 |
+
),
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def downgrade() -> None:
|
| 111 |
+
op.drop_table("agent_requests")
|
| 112 |
+
op.drop_table("custom_agent_votes")
|
| 113 |
+
op.drop_table("custom_agents")
|
alembic/versions/027_agent_submissions.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2026 CrewHub. All rights reserved.
|
| 2 |
+
# Proprietary and confidential. See LICENSE for details.
|
| 3 |
+
"""Add agent_submissions table for no-code builder publish flow.
|
| 4 |
+
|
| 5 |
+
Revision ID: 027
|
| 6 |
+
Revises: 026
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from alembic import op
|
| 10 |
+
import sqlalchemy as sa
|
| 11 |
+
from sqlalchemy.dialects import postgresql
|
| 12 |
+
|
| 13 |
+
revision = "027"
|
| 14 |
+
down_revision = "026"
|
| 15 |
+
branch_labels = None
|
| 16 |
+
depends_on = None
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def upgrade() -> None:
|
| 20 |
+
op.create_table(
|
| 21 |
+
"agent_submissions",
|
| 22 |
+
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
|
| 23 |
+
sa.Column("user_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("users.id"), nullable=False),
|
| 24 |
+
sa.Column("langflow_flow_id", sa.String(200), nullable=False),
|
| 25 |
+
sa.Column("flow_snapshot", postgresql.JSON(), nullable=True),
|
| 26 |
+
sa.Column("name", sa.String(200), nullable=False),
|
| 27 |
+
sa.Column("description", sa.Text(), nullable=True),
|
| 28 |
+
sa.Column("category", sa.String(50), nullable=True),
|
| 29 |
+
sa.Column("credits", sa.Float(), nullable=False, server_default="10"),
|
| 30 |
+
sa.Column("tags", postgresql.JSON(), server_default="[]"),
|
| 31 |
+
sa.Column("status", sa.String(20), nullable=False, server_default="pending_review"),
|
| 32 |
+
sa.Column("reviewer_notes", sa.Text(), nullable=True),
|
| 33 |
+
sa.Column("reviewed_by", postgresql.UUID(as_uuid=True), sa.ForeignKey("users.id"), nullable=True),
|
| 34 |
+
sa.Column("agent_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("agents.id"), nullable=True),
|
| 35 |
+
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()")),
|
| 36 |
+
sa.Column("reviewed_at", sa.DateTime(timezone=True), nullable=True),
|
| 37 |
+
)
|
| 38 |
+
op.create_index("idx_submissions_user", "agent_submissions", ["user_id"])
|
| 39 |
+
op.create_index("idx_submissions_status", "agent_submissions", ["status"])
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def downgrade() -> None:
|
| 43 |
+
op.drop_index("idx_submissions_status")
|
| 44 |
+
op.drop_index("idx_submissions_user")
|
| 45 |
+
op.drop_table("agent_submissions")
|
alembic/versions/028_orchestration_patterns.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2026 CrewHub. All rights reserved.
|
| 2 |
+
# Proprietary and confidential. See LICENSE for details.
|
| 3 |
+
"""Add orchestration pattern columns, supervisor_plans table, and sub-workflow support.
|
| 4 |
+
|
| 5 |
+
Revision ID: 028
|
| 6 |
+
Revises: 027
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from alembic import op
|
| 10 |
+
import sqlalchemy as sa
|
| 11 |
+
from sqlalchemy.dialects import postgresql
|
| 12 |
+
|
| 13 |
+
revision = "028"
|
| 14 |
+
down_revision = "027"
|
| 15 |
+
branch_labels = None
|
| 16 |
+
depends_on = None
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def upgrade() -> None:
|
| 20 |
+
# -- New columns on workflows --
|
| 21 |
+
op.add_column("workflows", sa.Column("pattern_type", sa.String(50), nullable=False, server_default="manual"))
|
| 22 |
+
op.add_column("workflows", sa.Column("supervisor_config", postgresql.JSON(), nullable=True))
|
| 23 |
+
|
| 24 |
+
# -- Alter workflow_steps: make agent_id and skill_id nullable --
|
| 25 |
+
op.alter_column("workflow_steps", "agent_id", existing_type=postgresql.UUID(as_uuid=True), nullable=True)
|
| 26 |
+
op.alter_column("workflow_steps", "skill_id", existing_type=postgresql.UUID(as_uuid=True), nullable=True)
|
| 27 |
+
|
| 28 |
+
# -- New column on workflow_steps --
|
| 29 |
+
op.add_column("workflow_steps", sa.Column("sub_workflow_id", postgresql.UUID(as_uuid=True), nullable=True))
|
| 30 |
+
op.create_foreign_key(
|
| 31 |
+
"fk_workflow_steps_sub_workflow",
|
| 32 |
+
"workflow_steps", "workflows",
|
| 33 |
+
["sub_workflow_id"], ["id"],
|
| 34 |
+
ondelete="SET NULL",
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# -- New columns on workflow_runs --
|
| 38 |
+
op.add_column("workflow_runs", sa.Column("parent_run_id", postgresql.UUID(as_uuid=True), nullable=True))
|
| 39 |
+
op.create_foreign_key(
|
| 40 |
+
"fk_workflow_runs_parent_run",
|
| 41 |
+
"workflow_runs", "workflow_runs",
|
| 42 |
+
["parent_run_id"], ["id"],
|
| 43 |
+
ondelete="SET NULL",
|
| 44 |
+
)
|
| 45 |
+
op.add_column("workflow_runs", sa.Column("depth", sa.Integer(), nullable=False, server_default="0"))
|
| 46 |
+
|
| 47 |
+
# -- New column on workflow_step_runs --
|
| 48 |
+
op.add_column("workflow_step_runs", sa.Column("child_run_id", postgresql.UUID(as_uuid=True), nullable=True))
|
| 49 |
+
op.create_foreign_key(
|
| 50 |
+
"fk_workflow_step_runs_child_run",
|
| 51 |
+
"workflow_step_runs", "workflow_runs",
|
| 52 |
+
["child_run_id"], ["id"],
|
| 53 |
+
ondelete="SET NULL",
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
# -- New table: supervisor_plans --
|
| 57 |
+
op.create_table(
|
| 58 |
+
"supervisor_plans",
|
| 59 |
+
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
|
| 60 |
+
sa.Column("user_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False),
|
| 61 |
+
sa.Column("goal", sa.String(2000), nullable=False),
|
| 62 |
+
sa.Column("plan_data", postgresql.JSON(), nullable=False),
|
| 63 |
+
sa.Column("llm_provider", sa.String(50), nullable=True),
|
| 64 |
+
sa.Column("status", sa.String(20), nullable=False, server_default="draft"),
|
| 65 |
+
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()")),
|
| 66 |
+
sa.Column("expires_at", sa.DateTime(timezone=True), nullable=False),
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def downgrade() -> None:
|
| 71 |
+
# 1. Drop supervisor_plans table
|
| 72 |
+
op.drop_table("supervisor_plans")
|
| 73 |
+
|
| 74 |
+
# 2. Drop FK on workflow_step_runs, then column
|
| 75 |
+
op.drop_constraint("fk_workflow_step_runs_child_run", "workflow_step_runs", type_="foreignkey")
|
| 76 |
+
op.drop_column("workflow_step_runs", "child_run_id")
|
| 77 |
+
|
| 78 |
+
# 3. Drop FK + columns on workflow_runs
|
| 79 |
+
op.drop_constraint("fk_workflow_runs_parent_run", "workflow_runs", type_="foreignkey")
|
| 80 |
+
op.drop_column("workflow_runs", "depth")
|
| 81 |
+
op.drop_column("workflow_runs", "parent_run_id")
|
| 82 |
+
|
| 83 |
+
# 4. Drop FK + column on workflow_steps
|
| 84 |
+
op.drop_constraint("fk_workflow_steps_sub_workflow", "workflow_steps", type_="foreignkey")
|
| 85 |
+
op.drop_column("workflow_steps", "sub_workflow_id")
|
| 86 |
+
|
| 87 |
+
# 5. Alter agent_id/skill_id back to NOT NULL
|
| 88 |
+
op.alter_column("workflow_steps", "skill_id", existing_type=postgresql.UUID(as_uuid=True), nullable=False)
|
| 89 |
+
op.alter_column("workflow_steps", "agent_id", existing_type=postgresql.UUID(as_uuid=True), nullable=False)
|
| 90 |
+
|
| 91 |
+
# 6. Drop columns on workflows
|
| 92 |
+
op.drop_column("workflows", "supervisor_config")
|
| 93 |
+
op.drop_column("workflows", "pattern_type")
|
alembic/versions/029_multi_channel_gateway.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2026 CrewHub. All rights reserved.
|
| 2 |
+
# Proprietary and confidential. See LICENSE for details.
|
| 3 |
+
"""Add channel_connections and channel_messages tables for multi-channel gateway.
|
| 4 |
+
|
| 5 |
+
Revision ID: 029
|
| 6 |
+
Revises: 028
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from alembic import op
|
| 10 |
+
import sqlalchemy as sa
|
| 11 |
+
from sqlalchemy.dialects import postgresql
|
| 12 |
+
|
| 13 |
+
revision = "029"
|
| 14 |
+
down_revision = "028"
|
| 15 |
+
branch_labels = None
|
| 16 |
+
depends_on = None
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def upgrade() -> None:
|
| 20 |
+
# -- channel_connections --
|
| 21 |
+
op.create_table(
|
| 22 |
+
"channel_connections",
|
| 23 |
+
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
|
| 24 |
+
sa.Column("owner_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False),
|
| 25 |
+
sa.Column("platform", sa.String(20), nullable=False),
|
| 26 |
+
sa.Column("platform_bot_id", sa.String(200), nullable=True),
|
| 27 |
+
sa.Column("bot_token", sa.Text(), nullable=False),
|
| 28 |
+
sa.Column("webhook_secret", sa.Text(), nullable=True),
|
| 29 |
+
sa.Column("bot_name", sa.String(200), nullable=False),
|
| 30 |
+
sa.Column("agent_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("agents.id", ondelete="CASCADE"), nullable=False),
|
| 31 |
+
sa.Column("skill_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("agent_skills.id", ondelete="SET NULL"), nullable=True),
|
| 32 |
+
sa.Column("status", sa.String(20), nullable=False, server_default="pending"),
|
| 33 |
+
sa.Column("paused_reason", sa.String(50), nullable=True),
|
| 34 |
+
sa.Column("daily_credit_limit", sa.Integer(), nullable=True),
|
| 35 |
+
sa.Column("low_balance_threshold", sa.Integer(), server_default="20"),
|
| 36 |
+
sa.Column("pause_on_limit", sa.Boolean(), server_default=sa.text("true")),
|
| 37 |
+
sa.Column("webhook_url", sa.String(), nullable=True),
|
| 38 |
+
sa.Column("config", postgresql.JSON(), nullable=True),
|
| 39 |
+
sa.Column("error_message", sa.Text(), nullable=True),
|
| 40 |
+
sa.Column("last_active_at", sa.DateTime(timezone=True), nullable=True),
|
| 41 |
+
sa.Column("gateway_instance_id", sa.String(100), nullable=True),
|
| 42 |
+
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()")),
|
| 43 |
+
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()")),
|
| 44 |
+
)
|
| 45 |
+
op.create_index("ix_channel_connections_owner", "channel_connections", ["owner_id"])
|
| 46 |
+
op.create_index("ix_channel_connections_platform_status", "channel_connections", ["platform", "status"])
|
| 47 |
+
|
| 48 |
+
# -- channel_messages --
|
| 49 |
+
op.create_table(
|
| 50 |
+
"channel_messages",
|
| 51 |
+
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
|
| 52 |
+
sa.Column("connection_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("channel_connections.id", ondelete="CASCADE"), nullable=False),
|
| 53 |
+
sa.Column("platform_user_id", sa.String(200), nullable=False),
|
| 54 |
+
sa.Column("platform_message_id", sa.String(200), nullable=False),
|
| 55 |
+
sa.Column("platform_chat_id", sa.String(200), nullable=True),
|
| 56 |
+
sa.Column("direction", sa.String(10), nullable=False),
|
| 57 |
+
sa.Column("message_text", sa.Text(), nullable=False),
|
| 58 |
+
sa.Column("media_type", sa.String(20), nullable=True),
|
| 59 |
+
sa.Column("task_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("tasks.id", ondelete="SET NULL"), nullable=True),
|
| 60 |
+
sa.Column("credits_charged", sa.Numeric(12, 4), server_default="0"),
|
| 61 |
+
sa.Column("response_time_ms", sa.Integer(), nullable=True),
|
| 62 |
+
sa.Column("error", sa.Text(), nullable=True),
|
| 63 |
+
sa.Column("whatsapp_window_expires_at", sa.DateTime(timezone=True), nullable=True),
|
| 64 |
+
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()")),
|
| 65 |
+
)
|
| 66 |
+
op.create_index("ix_channel_messages_connection_created", "channel_messages", ["connection_id", "created_at"])
|
| 67 |
+
op.create_index(
|
| 68 |
+
"ux_channel_messages_dedup",
|
| 69 |
+
"channel_messages",
|
| 70 |
+
["connection_id", "platform_message_id", "direction"],
|
| 71 |
+
unique=True,
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def downgrade() -> None:
|
| 76 |
+
op.drop_index("ux_channel_messages_dedup", table_name="channel_messages")
|
| 77 |
+
op.drop_index("ix_channel_messages_connection_created", table_name="channel_messages")
|
| 78 |
+
op.drop_table("channel_messages")
|
| 79 |
+
|
| 80 |
+
op.drop_index("ix_channel_connections_platform_status", table_name="channel_connections")
|
| 81 |
+
op.drop_index("ix_channel_connections_owner", table_name="channel_connections")
|
| 82 |
+
op.drop_table("channel_connections")
|
alembic/versions/030_audit_logs.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add audit_logs table for SOC 2 compliance.
|
| 2 |
+
|
| 3 |
+
Revision ID: 030
|
| 4 |
+
Revises: 029
|
| 5 |
+
Create Date: 2026-03-19
|
| 6 |
+
"""
|
| 7 |
+
from alembic import op
|
| 8 |
+
import sqlalchemy as sa
|
| 9 |
+
|
| 10 |
+
revision = "030"
|
| 11 |
+
down_revision = "029"
|
| 12 |
+
branch_labels = None
|
| 13 |
+
depends_on = None
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def upgrade() -> None:
|
| 17 |
+
op.create_table(
|
| 18 |
+
"audit_logs",
|
| 19 |
+
sa.Column("id", sa.Uuid, primary_key=True),
|
| 20 |
+
sa.Column("actor_user_id", sa.Uuid, nullable=True, index=True),
|
| 21 |
+
sa.Column("action", sa.String(100), nullable=False, index=True),
|
| 22 |
+
sa.Column("target_type", sa.String(50), nullable=True),
|
| 23 |
+
sa.Column("target_id", sa.String(255), nullable=True),
|
| 24 |
+
sa.Column("old_value", sa.Text, nullable=True),
|
| 25 |
+
sa.Column("new_value", sa.Text, nullable=True),
|
| 26 |
+
sa.Column("ip_address", sa.String(45), nullable=True),
|
| 27 |
+
sa.Column("user_agent", sa.String(500), nullable=True),
|
| 28 |
+
sa.Column("created_at", sa.DateTime, nullable=False, server_default=sa.func.now(), index=True),
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def downgrade() -> None:
|
| 33 |
+
op.drop_table("audit_logs")
|
alembic/versions/031_gdpr_compliance.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add GDPR compliance columns to users table.
|
| 2 |
+
|
| 3 |
+
Revision ID: 031
|
| 4 |
+
Revises: 030
|
| 5 |
+
Create Date: 2026-03-19
|
| 6 |
+
"""
|
| 7 |
+
from alembic import op
|
| 8 |
+
import sqlalchemy as sa
|
| 9 |
+
|
| 10 |
+
revision = "031"
|
| 11 |
+
down_revision = "030"
|
| 12 |
+
branch_labels = None
|
| 13 |
+
depends_on = None
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def upgrade() -> None:
|
| 17 |
+
op.add_column("users", sa.Column("deletion_requested_at", sa.DateTime(timezone=True), nullable=True))
|
| 18 |
+
op.add_column("users", sa.Column("consent_version", sa.String(20), nullable=True))
|
| 19 |
+
op.add_column("users", sa.Column("consent_given_at", sa.DateTime(timezone=True), nullable=True))
|
| 20 |
+
op.add_column("users", sa.Column("consent_ip", sa.String(45), nullable=True))
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def downgrade() -> None:
|
| 24 |
+
op.drop_column("users", "consent_ip")
|
| 25 |
+
op.drop_column("users", "consent_given_at")
|
| 26 |
+
op.drop_column("users", "consent_version")
|
| 27 |
+
op.drop_column("users", "deletion_requested_at")
|
alembic/versions/032_admin_roles.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add admin_role column for RBAC.
|
| 2 |
+
|
| 3 |
+
Revision ID: 032
|
| 4 |
+
Revises: 031
|
| 5 |
+
Create Date: 2026-03-19
|
| 6 |
+
"""
|
| 7 |
+
from alembic import op
|
| 8 |
+
import sqlalchemy as sa
|
| 9 |
+
|
| 10 |
+
revision = "032"
|
| 11 |
+
down_revision = "031"
|
| 12 |
+
branch_labels = None
|
| 13 |
+
depends_on = None
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def upgrade() -> None:
|
| 17 |
+
op.add_column("users", sa.Column("admin_role", sa.String(20), nullable=True))
|
| 18 |
+
# Backfill: existing admins get super_admin
|
| 19 |
+
op.execute("UPDATE users SET admin_role = 'super_admin' WHERE is_admin = TRUE")
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def downgrade() -> None:
|
| 23 |
+
op.drop_column("users", "admin_role")
|
alembic/versions/033_recover_health_deactivated_agents.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Recover agents mass-deactivated by health monitor.
|
| 2 |
+
|
| 3 |
+
One-time data fix: agents with status='inactive' AND
|
| 4 |
+
capabilities->>'_health_failures' >= '3' were deactivated by the
|
| 5 |
+
health monitor (not by owners). Set them back to 'active' and
|
| 6 |
+
reset the failure counter.
|
| 7 |
+
|
| 8 |
+
Revision ID: 033
|
| 9 |
+
Revises: 032
|
| 10 |
+
"""
|
| 11 |
+
from alembic import op
|
| 12 |
+
|
| 13 |
+
revision = "033"
|
| 14 |
+
down_revision = "032"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def upgrade() -> None:
|
| 18 |
+
# Reactivate agents that were deactivated by the health monitor
|
| 19 |
+
# (owner-deactivated agents have _health_failures = 0 or no key)
|
| 20 |
+
op.execute("""
|
| 21 |
+
UPDATE agents
|
| 22 |
+
SET status = 'active',
|
| 23 |
+
capabilities = jsonb_set(
|
| 24 |
+
COALESCE(capabilities, '{}')::jsonb,
|
| 25 |
+
'{_health_failures}',
|
| 26 |
+
'0'
|
| 27 |
+
)
|
| 28 |
+
WHERE status = 'inactive'
|
| 29 |
+
AND COALESCE(capabilities, '{}')::jsonb->>'_health_failures' IS NOT NULL
|
| 30 |
+
AND (COALESCE(capabilities, '{}')::jsonb->>'_health_failures')::int >= 3
|
| 31 |
+
""")
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def downgrade() -> None:
|
| 35 |
+
# Cannot reliably undo — agents may have been re-deactivated since
|
| 36 |
+
pass
|
alembic/versions/034_health_monitor_columns.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add dedicated health monitor columns to agents table.
|
| 2 |
+
|
| 3 |
+
Moves health state out of the capabilities JSONB field into proper
|
| 4 |
+
columns for indexing, querying, and data integrity.
|
| 5 |
+
|
| 6 |
+
Revision ID: 034
|
| 7 |
+
Revises: 033
|
| 8 |
+
"""
|
| 9 |
+
from alembic import op
|
| 10 |
+
import sqlalchemy as sa
|
| 11 |
+
|
| 12 |
+
revision = "034"
|
| 13 |
+
down_revision = "033"
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def upgrade() -> None:
|
| 17 |
+
op.add_column("agents", sa.Column("health_failures", sa.Integer(), nullable=False, server_default="0"))
|
| 18 |
+
op.add_column("agents", sa.Column("health_reason", sa.String(50), nullable=True))
|
| 19 |
+
op.add_column("agents", sa.Column("last_health_check_at", sa.DateTime(timezone=True), nullable=True))
|
| 20 |
+
op.add_column("agents", sa.Column("last_healthy_at", sa.DateTime(timezone=True), nullable=True))
|
| 21 |
+
op.add_column("agents", sa.Column("last_health_latency_ms", sa.Integer(), nullable=True))
|
| 22 |
+
|
| 23 |
+
# Migrate existing health data from capabilities JSONB
|
| 24 |
+
op.execute("""
|
| 25 |
+
UPDATE agents SET health_failures = COALESCE(
|
| 26 |
+
(capabilities->>'_health_failures')::int, 0
|
| 27 |
+
)
|
| 28 |
+
WHERE capabilities IS NOT NULL
|
| 29 |
+
AND capabilities->>'_health_failures' IS NOT NULL
|
| 30 |
+
""")
|
| 31 |
+
|
| 32 |
+
# Clean up health keys from capabilities JSON
|
| 33 |
+
# Cast to jsonb for the - operator, then back to json for storage
|
| 34 |
+
op.execute("""
|
| 35 |
+
UPDATE agents SET capabilities = (capabilities::jsonb - '_health_failures' - '_last_healthy_ms')::json
|
| 36 |
+
WHERE capabilities IS NOT NULL
|
| 37 |
+
AND (capabilities::text LIKE '%_health_failures%' OR capabilities::text LIKE '%_last_healthy_ms%')
|
| 38 |
+
""")
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def downgrade() -> None:
|
| 42 |
+
op.drop_column("agents", "last_health_latency_ms")
|
| 43 |
+
op.drop_column("agents", "last_healthy_at")
|
| 44 |
+
op.drop_column("agents", "last_health_check_at")
|
| 45 |
+
op.drop_column("agents", "health_reason")
|
| 46 |
+
op.drop_column("agents", "health_failures")
|
alembic/versions/036_channel_contacts_privacy.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Channel contact blocks, privacy notice URL, message retention, and indexes."""
|
| 2 |
+
from alembic import op
|
| 3 |
+
import sqlalchemy as sa
|
| 4 |
+
from sqlalchemy.dialects.postgresql import UUID
|
| 5 |
+
|
| 6 |
+
revision = "036_channel_contacts_privacy"
|
| 7 |
+
down_revision = "034"
|
| 8 |
+
|
| 9 |
+
branch_labels = None
|
| 10 |
+
depends_on = None
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def upgrade():
|
| 14 |
+
# Contact blocks table
|
| 15 |
+
op.create_table(
|
| 16 |
+
"channel_contact_blocks",
|
| 17 |
+
sa.Column("id", UUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
|
| 18 |
+
sa.Column("connection_id", UUID(as_uuid=True), sa.ForeignKey("channel_connections.id", ondelete="CASCADE"), nullable=False),
|
| 19 |
+
sa.Column("platform_user_id_hash", sa.String(200), nullable=False),
|
| 20 |
+
sa.Column("blocked_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
| 21 |
+
sa.Column("blocked_by", UUID(as_uuid=True), sa.ForeignKey("users.id"), nullable=True),
|
| 22 |
+
sa.Column("reason", sa.String(200), nullable=True),
|
| 23 |
+
sa.UniqueConstraint("connection_id", "platform_user_id_hash", name="uq_contact_blocks_conn_user"),
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# Privacy notice URL on channel_connections
|
| 27 |
+
op.add_column("channel_connections", sa.Column("privacy_notice_url", sa.String(500), nullable=True))
|
| 28 |
+
|
| 29 |
+
# Message retention config (per-channel, default 90 days)
|
| 30 |
+
op.add_column("channel_connections", sa.Column("message_retention_days", sa.Integer(), server_default="90", nullable=True))
|
| 31 |
+
|
| 32 |
+
# Fix message_text to be nullable (inbound messages will store NULL)
|
| 33 |
+
op.alter_column("channel_messages", "message_text", nullable=True, existing_type=sa.String(2000))
|
| 34 |
+
|
| 35 |
+
# Rename platform_user_id → platform_user_id_hash for clarity
|
| 36 |
+
op.alter_column("channel_messages", "platform_user_id", new_column_name="platform_user_id_hash")
|
| 37 |
+
|
| 38 |
+
# Performance index for contacts aggregation
|
| 39 |
+
op.create_index(
|
| 40 |
+
"ix_channel_messages_conn_user_created",
|
| 41 |
+
"channel_messages",
|
| 42 |
+
["connection_id", "platform_user_id_hash", sa.text("created_at DESC")],
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def downgrade():
|
| 47 |
+
op.drop_index("ix_channel_messages_conn_user_created")
|
| 48 |
+
op.alter_column("channel_messages", "platform_user_id_hash", new_column_name="platform_user_id")
|
| 49 |
+
op.alter_column("channel_messages", "message_text", nullable=False, existing_type=sa.String(2000))
|
| 50 |
+
op.drop_column("channel_connections", "message_retention_days")
|
| 51 |
+
op.drop_column("channel_connections", "privacy_notice_url")
|
| 52 |
+
op.drop_table("channel_contact_blocks")
|
alembic/versions/037_workflow_channel_integration.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Workflow-channel integration fields.
|
| 2 |
+
|
| 3 |
+
Links channel_connections to workflows, tracks workflow_runs triggered
|
| 4 |
+
by channel messages, and adds failure_mode config to workflows.
|
| 5 |
+
|
| 6 |
+
Revision ID: 037_workflow_channel_integration
|
| 7 |
+
Revises: 036_channel_contacts_privacy
|
| 8 |
+
"""
|
| 9 |
+
from alembic import op
|
| 10 |
+
import sqlalchemy as sa
|
| 11 |
+
from sqlalchemy.dialects.postgresql import UUID
|
| 12 |
+
|
| 13 |
+
revision = "037_workflow_channel_integration"
|
| 14 |
+
down_revision = "036_channel_contacts_privacy"
|
| 15 |
+
|
| 16 |
+
branch_labels = None
|
| 17 |
+
depends_on = None
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def upgrade():
|
| 21 |
+
# channel_connections: link to a workflow + per-connection trigger mappings
|
| 22 |
+
op.add_column(
|
| 23 |
+
"channel_connections",
|
| 24 |
+
sa.Column(
|
| 25 |
+
"workflow_id",
|
| 26 |
+
UUID(as_uuid=True),
|
| 27 |
+
sa.ForeignKey("workflows.id", ondelete="SET NULL"),
|
| 28 |
+
nullable=True,
|
| 29 |
+
),
|
| 30 |
+
)
|
| 31 |
+
op.add_column(
|
| 32 |
+
"channel_connections",
|
| 33 |
+
sa.Column("workflow_mappings", sa.JSON(), nullable=True),
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
# workflow_runs: back-link to the channel connection + specific chat thread
|
| 37 |
+
op.add_column(
|
| 38 |
+
"workflow_runs",
|
| 39 |
+
sa.Column(
|
| 40 |
+
"channel_connection_id",
|
| 41 |
+
UUID(as_uuid=True),
|
| 42 |
+
sa.ForeignKey("channel_connections.id", ondelete="SET NULL"),
|
| 43 |
+
nullable=True,
|
| 44 |
+
),
|
| 45 |
+
)
|
| 46 |
+
op.add_column(
|
| 47 |
+
"workflow_runs",
|
| 48 |
+
sa.Column("channel_chat_id", sa.String(200), nullable=True),
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
# channel_messages: link to the workflow run that was triggered
|
| 52 |
+
op.add_column(
|
| 53 |
+
"channel_messages",
|
| 54 |
+
sa.Column(
|
| 55 |
+
"workflow_run_id",
|
| 56 |
+
UUID(as_uuid=True),
|
| 57 |
+
sa.ForeignKey("workflow_runs.id", ondelete="SET NULL"),
|
| 58 |
+
nullable=True,
|
| 59 |
+
),
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
# workflows: how to handle step failures ("stop" or "continue")
|
| 63 |
+
op.add_column(
|
| 64 |
+
"workflows",
|
| 65 |
+
sa.Column(
|
| 66 |
+
"failure_mode",
|
| 67 |
+
sa.String(20),
|
| 68 |
+
server_default="stop",
|
| 69 |
+
nullable=False,
|
| 70 |
+
),
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def downgrade():
|
| 75 |
+
op.drop_column("workflows", "failure_mode")
|
| 76 |
+
op.drop_column("channel_messages", "workflow_run_id")
|
| 77 |
+
op.drop_column("workflow_runs", "channel_chat_id")
|
| 78 |
+
op.drop_column("workflow_runs", "channel_connection_id")
|
| 79 |
+
op.drop_column("channel_connections", "workflow_mappings")
|
| 80 |
+
op.drop_column("channel_connections", "workflow_id")
|
alembic/versions/038_mcp_server_registry.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""MCP server registry and access grants.
|
| 2 |
+
|
| 3 |
+
Adds tables for registering external MCP servers and granting agents
|
| 4 |
+
scoped access to specific tools on those servers.
|
| 5 |
+
|
| 6 |
+
Revision ID: 038_mcp_server_registry
|
| 7 |
+
Revises: 037_workflow_channel_integration
|
| 8 |
+
"""
|
| 9 |
+
from alembic import op
|
| 10 |
+
import sqlalchemy as sa
|
| 11 |
+
from sqlalchemy.dialects.postgresql import UUID
|
| 12 |
+
|
| 13 |
+
revision = "038_mcp_server_registry"
|
| 14 |
+
down_revision = "037_workflow_channel_integration"
|
| 15 |
+
|
| 16 |
+
branch_labels = None
|
| 17 |
+
depends_on = None
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def upgrade():
|
| 21 |
+
op.create_table(
|
| 22 |
+
"mcp_servers",
|
| 23 |
+
sa.Column("id", UUID(as_uuid=True), primary_key=True),
|
| 24 |
+
sa.Column("owner_id", UUID(as_uuid=True), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True),
|
| 25 |
+
sa.Column("name", sa.String(255), nullable=False),
|
| 26 |
+
sa.Column("url", sa.String(2048), nullable=False),
|
| 27 |
+
sa.Column("description", sa.Text, nullable=True),
|
| 28 |
+
sa.Column("auth_type", sa.String(50), nullable=False, server_default="none"),
|
| 29 |
+
sa.Column("auth_config", sa.JSON, nullable=True),
|
| 30 |
+
sa.Column("tools_cached", sa.JSON, nullable=True),
|
| 31 |
+
sa.Column("is_public", sa.Boolean, nullable=False, server_default=sa.text("false")),
|
| 32 |
+
sa.Column("status", sa.String(50), nullable=False, server_default="active"),
|
| 33 |
+
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
| 34 |
+
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
op.create_table(
|
| 38 |
+
"mcp_grants",
|
| 39 |
+
sa.Column("id", UUID(as_uuid=True), primary_key=True),
|
| 40 |
+
sa.Column("user_id", UUID(as_uuid=True), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True),
|
| 41 |
+
sa.Column("agent_id", UUID(as_uuid=True), sa.ForeignKey("agents.id", ondelete="CASCADE"), nullable=False, index=True),
|
| 42 |
+
sa.Column("mcp_server_id", UUID(as_uuid=True), sa.ForeignKey("mcp_servers.id", ondelete="CASCADE"), nullable=False, index=True),
|
| 43 |
+
sa.Column("scopes", sa.JSON, nullable=False, server_default="[]"),
|
| 44 |
+
sa.Column("expires_at", sa.DateTime(timezone=True), nullable=True),
|
| 45 |
+
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def downgrade():
|
| 50 |
+
op.drop_table("mcp_grants")
|
| 51 |
+
op.drop_table("mcp_servers")
|
alembic/versions/039_ap2_payment_standard.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""AP2 payment standard — add idempotency_key to tasks."""
|
| 2 |
+
|
| 3 |
+
revision = "039"
|
| 4 |
+
down_revision = "038_mcp_server_registry"
|
| 5 |
+
branch_labels = None
|
| 6 |
+
depends_on = None
|
| 7 |
+
|
| 8 |
+
from alembic import op
|
| 9 |
+
import sqlalchemy as sa
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def upgrade() -> None:
|
| 13 |
+
op.add_column("tasks", sa.Column("idempotency_key", sa.String(64), nullable=True))
|
| 14 |
+
op.create_index(
|
| 15 |
+
"uq_task_idempotency",
|
| 16 |
+
"tasks",
|
| 17 |
+
["creator_user_id", "idempotency_key"],
|
| 18 |
+
unique=True,
|
| 19 |
+
postgresql_where=sa.text("idempotency_key IS NOT NULL"),
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def downgrade() -> None:
|
| 24 |
+
op.drop_index("uq_task_idempotency", table_name="tasks")
|
| 25 |
+
op.drop_column("tasks", "idempotency_key")
|
alembic/versions/040_ucp_credit_schedules.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""UCP credit-aware schedules — add billing columns."""
|
| 2 |
+
|
| 3 |
+
revision = "040"
|
| 4 |
+
down_revision = "039"
|
| 5 |
+
branch_labels = None
|
| 6 |
+
depends_on = None
|
| 7 |
+
|
| 8 |
+
from alembic import op
|
| 9 |
+
import sqlalchemy as sa
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def upgrade() -> None:
|
| 13 |
+
op.add_column("schedules", sa.Column("credit_budget_per_run", sa.Numeric(12, 4), nullable=True))
|
| 14 |
+
op.add_column("schedules", sa.Column("pause_reason", sa.String(50), nullable=True))
|
| 15 |
+
op.add_column("schedules", sa.Column("last_notified_at", sa.DateTime(timezone=True), nullable=True))
|
| 16 |
+
op.add_column("schedules", sa.Column("last_run_id", sa.Uuid(), nullable=True))
|
| 17 |
+
op.add_column("schedules", sa.Column("total_runs", sa.Integer(), nullable=False, server_default="0"))
|
| 18 |
+
op.add_column("schedules", sa.Column("successful_runs", sa.Integer(), nullable=False, server_default="0"))
|
| 19 |
+
op.add_column("schedules", sa.Column("failed_runs", sa.Integer(), nullable=False, server_default="0"))
|
| 20 |
+
op.add_column("schedules", sa.Column("total_credits_spent", sa.Numeric(16, 4), nullable=False, server_default="0"))
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def downgrade() -> None:
|
| 24 |
+
op.drop_column("schedules", "total_credits_spent")
|
| 25 |
+
op.drop_column("schedules", "failed_runs")
|
| 26 |
+
op.drop_column("schedules", "successful_runs")
|
| 27 |
+
op.drop_column("schedules", "total_runs")
|
| 28 |
+
op.drop_column("schedules", "last_run_id")
|
| 29 |
+
op.drop_column("schedules", "last_notified_at")
|
| 30 |
+
op.drop_column("schedules", "pause_reason")
|
| 31 |
+
op.drop_column("schedules", "credit_budget_per_run")
|
alembic/versions/041_infrastructure_metrics.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Infrastructure usage metrics table."""
|
| 2 |
+
|
| 3 |
+
revision = "041"
|
| 4 |
+
down_revision = "040"
|
| 5 |
+
branch_labels = None
|
| 6 |
+
depends_on = None
|
| 7 |
+
|
| 8 |
+
from alembic import op
|
| 9 |
+
import sqlalchemy as sa
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def upgrade() -> None:
|
| 13 |
+
op.create_table(
|
| 14 |
+
"infrastructure_metrics",
|
| 15 |
+
sa.Column("id", sa.Uuid(), primary_key=True, server_default=sa.text("gen_random_uuid()")),
|
| 16 |
+
sa.Column("collected_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
| 17 |
+
sa.Column("metric_name", sa.String(64), nullable=False),
|
| 18 |
+
sa.Column("metric_value", sa.Float(), nullable=False),
|
| 19 |
+
sa.Column("metric_limit", sa.Float(), nullable=True),
|
| 20 |
+
sa.Column("metadata_json", sa.JSON(), nullable=True),
|
| 21 |
+
)
|
| 22 |
+
op.create_index(
|
| 23 |
+
"ix_infra_metrics_name_collected",
|
| 24 |
+
"infrastructure_metrics",
|
| 25 |
+
["metric_name", "collected_at"],
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def downgrade() -> None:
|
| 30 |
+
op.drop_index("ix_infra_metrics_name_collected", "infrastructure_metrics")
|
| 31 |
+
op.drop_table("infrastructure_metrics")
|
alembic/versions/__pycache__/001_initial_schema.cpython-313.pyc
ADDED
|
Binary file (14.7 kB). View file
|
|
|
alembic/versions/__pycache__/002_add_is_admin_to_users.cpython-313.pyc
ADDED
|
Binary file (1.25 kB). View file
|
|
|
alembic/versions/__pycache__/003_add_callback_url_to_tasks.cpython-313.pyc
ADDED
|
Binary file (1.27 kB). View file
|
|
|
alembic/versions/__pycache__/004_add_mcp_url_to_agents.cpython-313.pyc
ADDED
|
Binary file (1.25 kB). View file
|
|
|
alembic/versions/__pycache__/005_add_did_keys_to_agents.cpython-313.pyc
ADDED
|
Binary file (1.51 kB). View file
|
|
|
alembic/versions/__pycache__/006_add_api_key_revoked_at.cpython-313.pyc
ADDED
|
Binary file (1.26 kB). View file
|
|
|