0006_bot_teams.sql 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. CREATE TABLE `bot_api_keys` (
  2. `id` text PRIMARY KEY NOT NULL,
  3. `name` text NOT NULL,
  4. `key_hash` text NOT NULL,
  5. `key_prefix` text NOT NULL,
  6. `enabled` integer DEFAULT true NOT NULL,
  7. `allowed_bot_ids` text DEFAULT '[]' NOT NULL,
  8. `created_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL,
  9. `last_used_at` text
  10. );
  11. --> statement-breakpoint
  12. CREATE UNIQUE INDEX `bot_api_keys_key_hash_unique` ON `bot_api_keys` (`key_hash`);--> statement-breakpoint
  13. CREATE TABLE `bots` (
  14. `id` text PRIMARY KEY NOT NULL,
  15. `name` text NOT NULL,
  16. `avatar` text DEFAULT '🤖' NOT NULL,
  17. `kind` text NOT NULL,
  18. `description` text DEFAULT '' NOT NULL,
  19. `profile_id` text NOT NULL,
  20. `enabled` integer DEFAULT true NOT NULL,
  21. `created_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL,
  22. `updated_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL
  23. );
  24. --> statement-breakpoint
  25. CREATE UNIQUE INDEX `bots_name_unique` ON `bots` (`name`);--> statement-breakpoint
  26. CREATE TABLE `team_bot_sessions` (
  27. `team_id` text NOT NULL,
  28. `bot_id` text NOT NULL,
  29. `session_id` text NOT NULL,
  30. `last_read_seq` integer DEFAULT 0 NOT NULL,
  31. PRIMARY KEY(`team_id`, `bot_id`)
  32. );
  33. --> statement-breakpoint
  34. CREATE UNIQUE INDEX `team_bot_sessions_session_id_unique` ON `team_bot_sessions` (`session_id`);--> statement-breakpoint
  35. CREATE TABLE `team_bots` (
  36. `team_id` text NOT NULL,
  37. `bot_id` text NOT NULL,
  38. `role` text NOT NULL,
  39. `joined_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL,
  40. PRIMARY KEY(`team_id`, `bot_id`)
  41. );
  42. --> statement-breakpoint
  43. CREATE INDEX `team_bots_bot_idx` ON `team_bots` (`bot_id`);--> statement-breakpoint
  44. CREATE TABLE `team_events` (
  45. `team_id` text NOT NULL,
  46. `seq` integer NOT NULL,
  47. `type` text NOT NULL,
  48. `payload` text NOT NULL,
  49. `ts` text NOT NULL,
  50. PRIMARY KEY(`team_id`, `seq`)
  51. );
  52. --> statement-breakpoint
  53. CREATE TABLE `teams` (
  54. `id` text PRIMARY KEY NOT NULL,
  55. `source` text NOT NULL,
  56. `title` text DEFAULT '' NOT NULL,
  57. `human` text NOT NULL,
  58. `status` text DEFAULT 'active' NOT NULL,
  59. `workspace_dir` text NOT NULL,
  60. `last_seq` integer DEFAULT 0 NOT NULL,
  61. `created_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL,
  62. `updated_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL
  63. );
  64. --> statement-breakpoint
  65. CREATE INDEX `teams_source_idx` ON `teams` (`source`,`updated_at`);