0000_init.sql 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. CREATE TABLE `admin_sessions` (
  2. `id` text PRIMARY KEY NOT NULL,
  3. `created_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL,
  4. `expires_at` text NOT NULL
  5. );
  6. --> statement-breakpoint
  7. CREATE TABLE `api_keys` (
  8. `id` text PRIMARY KEY NOT NULL,
  9. `name` text NOT NULL,
  10. `key_hash` text NOT NULL,
  11. `key_prefix` text NOT NULL,
  12. `enabled` integer DEFAULT true NOT NULL,
  13. `created_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL,
  14. `last_used_at` text
  15. );
  16. --> statement-breakpoint
  17. CREATE UNIQUE INDEX `api_keys_key_hash_unique` ON `api_keys` (`key_hash`);--> statement-breakpoint
  18. CREATE TABLE `audit_logs` (
  19. `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
  20. `ts` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL,
  21. `actor` text NOT NULL,
  22. `session_id` text,
  23. `kind` text NOT NULL,
  24. `summary` text NOT NULL,
  25. `detail` text
  26. );
  27. --> statement-breakpoint
  28. CREATE INDEX `audit_ts_idx` ON `audit_logs` (`ts`);--> statement-breakpoint
  29. CREATE TABLE `events` (
  30. `session_id` text NOT NULL,
  31. `seq` integer NOT NULL,
  32. `run_id` text,
  33. `type` text NOT NULL,
  34. `payload` text NOT NULL,
  35. `ts` text NOT NULL,
  36. PRIMARY KEY(`session_id`, `seq`)
  37. );
  38. --> statement-breakpoint
  39. CREATE TABLE `files` (
  40. `id` text PRIMARY KEY NOT NULL,
  41. `session_id` text NOT NULL,
  42. `rel_path` text NOT NULL,
  43. `origin` text NOT NULL,
  44. `mime` text NOT NULL,
  45. `size` integer NOT NULL,
  46. `mtime_ms` real NOT NULL,
  47. `created_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL,
  48. `updated_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL
  49. );
  50. --> statement-breakpoint
  51. CREATE INDEX `files_session_path_idx` ON `files` (`session_id`,`rel_path`);--> statement-breakpoint
  52. CREATE TABLE `interactions` (
  53. `id` text PRIMARY KEY NOT NULL,
  54. `session_id` text NOT NULL,
  55. `run_id` text NOT NULL,
  56. `kind` text NOT NULL,
  57. `request` text NOT NULL,
  58. `response` text,
  59. `status` text NOT NULL,
  60. `created_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL,
  61. `resolved_at` text,
  62. `expires_at` text NOT NULL
  63. );
  64. --> statement-breakpoint
  65. CREATE INDEX `interactions_session_idx` ON `interactions` (`session_id`,`status`);--> statement-breakpoint
  66. CREATE TABLE `knowledge_roots` (
  67. `id` text PRIMARY KEY NOT NULL,
  68. `name` text NOT NULL,
  69. `path` text NOT NULL,
  70. `description` text DEFAULT '' NOT NULL,
  71. `access` text DEFAULT 'read' NOT NULL,
  72. `enabled` integer DEFAULT true NOT NULL,
  73. `created_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL,
  74. `updated_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL
  75. );
  76. --> statement-breakpoint
  77. CREATE TABLE `profiles` (
  78. `id` text PRIMARY KEY NOT NULL,
  79. `name` text NOT NULL,
  80. `description` text DEFAULT '' NOT NULL,
  81. `provider` text NOT NULL,
  82. `model` text NOT NULL,
  83. `system_prompt` text DEFAULT '' NOT NULL,
  84. `permission_mode` text DEFAULT 'ask' NOT NULL,
  85. `allowed_tools` text DEFAULT '[]' NOT NULL,
  86. `disallowed_tools` text DEFAULT '[]' NOT NULL,
  87. `skills` text DEFAULT '"all"' NOT NULL,
  88. `file_access` text NOT NULL,
  89. `knowledge_root_ids` text DEFAULT '[]' NOT NULL,
  90. `is_default` integer DEFAULT false NOT NULL,
  91. `version` integer DEFAULT 1 NOT NULL,
  92. `created_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL,
  93. `updated_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL
  94. );
  95. --> statement-breakpoint
  96. CREATE TABLE `runs` (
  97. `id` text PRIMARY KEY NOT NULL,
  98. `session_id` text NOT NULL,
  99. `status` text NOT NULL,
  100. `started_at` text,
  101. `ended_at` text,
  102. `input_tokens` integer,
  103. `output_tokens` integer,
  104. `cache_read_tokens` integer,
  105. `cache_write_tokens` integer,
  106. `cost_usd` real,
  107. `error` text,
  108. `created_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL
  109. );
  110. --> statement-breakpoint
  111. CREATE INDEX `runs_session_idx` ON `runs` (`session_id`);--> statement-breakpoint
  112. CREATE TABLE `sessions` (
  113. `id` text PRIMARY KEY NOT NULL,
  114. `source` text NOT NULL,
  115. `profile_id` text,
  116. `provider` text NOT NULL,
  117. `model` text NOT NULL,
  118. `permission_mode` text NOT NULL,
  119. `system_prompt_append` text DEFAULT '' NOT NULL,
  120. `provider_session_id` text,
  121. `workspace_dir` text NOT NULL,
  122. `title` text DEFAULT '' NOT NULL,
  123. `last_seq` integer DEFAULT 0 NOT NULL,
  124. `archived` integer DEFAULT false NOT NULL,
  125. `created_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL,
  126. `updated_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL
  127. );
  128. --> statement-breakpoint
  129. CREATE INDEX `sessions_source_idx` ON `sessions` (`source`,`updated_at`);--> statement-breakpoint
  130. CREATE TABLE `settings` (
  131. `key` text PRIMARY KEY NOT NULL,
  132. `value` text NOT NULL,
  133. `updated_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL
  134. );