Files
leocrm/alembic/versions/0042_webhooks.py
T
Agent Zero 79ece0fe2e Phase 4: Webhooks, Backup/Restore UI, Onboarding/Tutorial
- Webhooks Backend: model, schema, service (HMAC-SHA256, httpx), routes, event bus dispatcher, migration 0042
- Webhooks Frontend: SettingsWebhooksPage (CRUD, test button, event multi-select), API client
- Backup/Restore Backend: model, schema, service (pg_dump/pg_restore), routes (admin-only), migration 0043
- Backup/Restore Frontend: SettingsBackupPage (create, list, restore dialog with RESTORE confirmation, auto-refresh)
- Onboarding: OnboardingTour (8 steps, custom CSS overlay), WelcomeDialog, onboardingStore (zustand + localStorage)
- Onboarding integrated into AppShell
- Routes: /settings/webhooks, /settings/backup registered
- Settings nav: Webhooks, Backup & Restore entries added
- Migration conflict fixed: 0042_webhooks → 0043_backups chain
2026-07-26 03:17:40 +02:00

70 lines
2.1 KiB
Python

"""Create webhooks table for outgoing webhook subscriptions.
Revision ID: 0042_webhooks
Revises: 0041_custom_field_definitions
Create Date: 2026-07-26
Stores outgoing webhook subscriptions with target URL, event subscriptions,
and delivery settings (retry count, timeout, HMAC secret).
"""
from __future__ import annotations
from typing import Union
import sqlalchemy as sa
from alembic import op
# revision identifiers
revision: str = "0042_webhooks"
down_revision: Union[str, None] = "0041_custom_field_definitions"
branch_labels: Union[str, None] = None
depends_on: Union[str, None] = None
def upgrade() -> None:
conn = op.get_bind()
conn.execute(
sa.text(
"""
CREATE TABLE IF NOT EXISTS webhooks (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
tenant_id UUID NOT NULL,
url VARCHAR(500) NOT NULL,
events JSONB NOT NULL DEFAULT '[]',
secret VARCHAR(255),
is_active BOOLEAN NOT NULL DEFAULT TRUE,
retry_count INTEGER NOT NULL DEFAULT 3,
timeout_seconds INTEGER NOT NULL DEFAULT 30,
created_by UUID,
updated_by UUID,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
deleted_at TIMESTAMPTZ
)
"""
)
)
# Indexes
conn.execute(
sa.text(
"CREATE INDEX IF NOT EXISTS ix_webhooks_tenant "
"ON webhooks (tenant_id)"
)
)
conn.execute(
sa.text(
"CREATE INDEX IF NOT EXISTS ix_webhooks_tenant_active "
"ON webhooks (tenant_id, is_active)"
)
)
def downgrade() -> None:
conn = op.get_bind()
conn.execute(sa.text("DROP INDEX IF EXISTS ix_webhooks_tenant_active"))
conn.execute(sa.text("DROP INDEX IF EXISTS ix_webhooks_tenant"))
conn.execute(sa.text("DROP TABLE IF EXISTS webhooks"))