migration.sql 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. CREATE TABLE `project` (
  2. `id` text PRIMARY KEY,
  3. `worktree` text NOT NULL,
  4. `vcs` text,
  5. `name` text,
  6. `icon_url` text,
  7. `icon_color` text,
  8. `time_created` integer NOT NULL,
  9. `time_updated` integer NOT NULL,
  10. `time_initialized` integer,
  11. `sandboxes` text NOT NULL
  12. );
  13. --> statement-breakpoint
  14. CREATE TABLE `message` (
  15. `id` text PRIMARY KEY,
  16. `session_id` text NOT NULL,
  17. `time_created` integer NOT NULL,
  18. `time_updated` integer NOT NULL,
  19. `data` text NOT NULL,
  20. CONSTRAINT `fk_message_session_id_session_id_fk` FOREIGN KEY (`session_id`) REFERENCES `session`(`id`) ON DELETE CASCADE
  21. );
  22. --> statement-breakpoint
  23. CREATE TABLE `part` (
  24. `id` text PRIMARY KEY,
  25. `message_id` text NOT NULL,
  26. `session_id` text NOT NULL,
  27. `time_created` integer NOT NULL,
  28. `time_updated` integer NOT NULL,
  29. `data` text NOT NULL,
  30. CONSTRAINT `fk_part_message_id_message_id_fk` FOREIGN KEY (`message_id`) REFERENCES `message`(`id`) ON DELETE CASCADE
  31. );
  32. --> statement-breakpoint
  33. CREATE TABLE `permission` (
  34. `project_id` text PRIMARY KEY,
  35. `time_created` integer NOT NULL,
  36. `time_updated` integer NOT NULL,
  37. `data` text NOT NULL,
  38. CONSTRAINT `fk_permission_project_id_project_id_fk` FOREIGN KEY (`project_id`) REFERENCES `project`(`id`) ON DELETE CASCADE
  39. );
  40. --> statement-breakpoint
  41. CREATE TABLE `session` (
  42. `id` text PRIMARY KEY,
  43. `project_id` text NOT NULL,
  44. `parent_id` text,
  45. `slug` text NOT NULL,
  46. `directory` text NOT NULL,
  47. `title` text NOT NULL,
  48. `version` text NOT NULL,
  49. `share_url` text,
  50. `summary_additions` integer,
  51. `summary_deletions` integer,
  52. `summary_files` integer,
  53. `summary_diffs` text,
  54. `revert` text,
  55. `permission` text,
  56. `time_created` integer NOT NULL,
  57. `time_updated` integer NOT NULL,
  58. `time_compacting` integer,
  59. `time_archived` integer,
  60. CONSTRAINT `fk_session_project_id_project_id_fk` FOREIGN KEY (`project_id`) REFERENCES `project`(`id`) ON DELETE CASCADE
  61. );
  62. --> statement-breakpoint
  63. CREATE TABLE `todo` (
  64. `session_id` text NOT NULL,
  65. `content` text NOT NULL,
  66. `status` text NOT NULL,
  67. `priority` text NOT NULL,
  68. `position` integer NOT NULL,
  69. `time_created` integer NOT NULL,
  70. `time_updated` integer NOT NULL,
  71. CONSTRAINT `todo_pk` PRIMARY KEY(`session_id`, `position`),
  72. CONSTRAINT `fk_todo_session_id_session_id_fk` FOREIGN KEY (`session_id`) REFERENCES `session`(`id`) ON DELETE CASCADE
  73. );
  74. --> statement-breakpoint
  75. CREATE TABLE `session_share` (
  76. `session_id` text PRIMARY KEY,
  77. `id` text NOT NULL,
  78. `secret` text NOT NULL,
  79. `url` text NOT NULL,
  80. `time_created` integer NOT NULL,
  81. `time_updated` integer NOT NULL,
  82. CONSTRAINT `fk_session_share_session_id_session_id_fk` FOREIGN KEY (`session_id`) REFERENCES `session`(`id`) ON DELETE CASCADE
  83. );
  84. --> statement-breakpoint
  85. CREATE INDEX `message_session_idx` ON `message` (`session_id`);--> statement-breakpoint
  86. CREATE INDEX `part_message_idx` ON `part` (`message_id`);--> statement-breakpoint
  87. CREATE INDEX `part_session_idx` ON `part` (`session_id`);--> statement-breakpoint
  88. CREATE INDEX `session_project_idx` ON `session` (`project_id`);--> statement-breakpoint
  89. CREATE INDEX `session_parent_idx` ON `session` (`parent_id`);--> statement-breakpoint
  90. CREATE INDEX `todo_session_idx` ON `todo` (`session_id`);