Skip to content

Commit 777ef9a

Browse files
bchapuisclaude
andcommitted
Unify bot tables into single bots + bot_triggers schema
Replace 8 provider-specific tables (discord_bots, telegram_bots, whatsapp_accounts, slack_bots and their trigger tables) with 2 unified tables using provider discriminator and JSON metadata columns, matching the existing integrations table pattern. - Add bots table with provider, encrypted_token, metadata, encrypted_metadata - Add bot_triggers table with provider, metadata JSON for trigger config - Unified API route at /:orgId/bots with ?provider= filter - Unified trigger endpoint at /:workflowId/bot-trigger - Unified bot-service.ts frontend service with backward-compatible aliases - Webhook handlers updated to parse metadata JSON for provider-specific fields Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c5db664 commit 777ef9a

51 files changed

Lines changed: 1835 additions & 3685 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
-- Drop old bot and trigger tables
2+
DROP TABLE IF EXISTS `discord_triggers`;
3+
DROP TABLE IF EXISTS `telegram_triggers`;
4+
DROP TABLE IF EXISTS `whatsapp_triggers`;
5+
DROP TABLE IF EXISTS `slack_triggers`;
6+
DROP TABLE IF EXISTS `discord_bots`;
7+
DROP TABLE IF EXISTS `telegram_bots`;
8+
DROP TABLE IF EXISTS `whatsapp_accounts`;
9+
DROP TABLE IF EXISTS `slack_bots`;
10+
11+
-- Unified Bots table
12+
CREATE TABLE IF NOT EXISTS `bots` (
13+
`id` text PRIMARY KEY NOT NULL,
14+
`name` text NOT NULL,
15+
`provider` text NOT NULL,
16+
`encrypted_token` text NOT NULL,
17+
`token_last_four` text NOT NULL,
18+
`metadata` text,
19+
`encrypted_metadata` text,
20+
`organization_id` text NOT NULL REFERENCES `organizations`(`id`) ON DELETE CASCADE,
21+
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
22+
`updated_at` integer DEFAULT (unixepoch()) NOT NULL
23+
);
24+
25+
CREATE INDEX IF NOT EXISTS `bots_name_idx` ON `bots` (`name`);
26+
CREATE INDEX IF NOT EXISTS `bots_provider_idx` ON `bots` (`provider`);
27+
CREATE INDEX IF NOT EXISTS `bots_organization_id_idx` ON `bots` (`organization_id`);
28+
CREATE INDEX IF NOT EXISTS `bots_created_at_idx` ON `bots` (`created_at`);
29+
30+
-- Unified Bot Triggers table
31+
CREATE TABLE IF NOT EXISTS `bot_triggers` (
32+
`workflow_id` text PRIMARY KEY NOT NULL REFERENCES `workflows`(`id`) ON DELETE CASCADE,
33+
`organization_id` text NOT NULL REFERENCES `organizations`(`id`) ON DELETE CASCADE,
34+
`bot_id` text REFERENCES `bots`(`id`) ON DELETE SET NULL,
35+
`provider` text NOT NULL,
36+
`metadata` text,
37+
`active` integer NOT NULL DEFAULT 1,
38+
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
39+
`updated_at` integer DEFAULT (unixepoch()) NOT NULL
40+
);
41+
42+
CREATE INDEX IF NOT EXISTS `bot_triggers_organization_id_idx` ON `bot_triggers` (`organization_id`);
43+
CREATE INDEX IF NOT EXISTS `bot_triggers_bot_id_idx` ON `bot_triggers` (`bot_id`);
44+
CREATE INDEX IF NOT EXISTS `bot_triggers_provider_idx` ON `bot_triggers` (`provider`);
45+
CREATE INDEX IF NOT EXISTS `bot_triggers_active_idx` ON `bot_triggers` (`active`);
46+
CREATE INDEX IF NOT EXISTS `bot_triggers_created_at_idx` ON `bot_triggers` (`created_at`);
47+
CREATE INDEX IF NOT EXISTS `bot_triggers_updated_at_idx` ON `bot_triggers` (`updated_at`);

0 commit comments

Comments
 (0)