The backend for the AiteStory website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.5 KiB

7 years ago
  1. # DROP TABLE page; DROP TABLE; USER
  2. CREATE TABLE user (
  3. `id` CHAR(32) PRIMARY KEY,
  4. `role` CHAR(16),
  5. INDEX(role)
  6. );
  7. CREATE TABLE page (
  8. `id` CHAR(16) NOT NULL PRIMARY KEY,
  9. `name` VARCHAR(255) NOT NULL,
  10. `author` VARCHAR(64),
  11. `category` VARCHAR(16) NOT NULL,
  12. `fictional_date` DATETIME NOT NULL,
  13. `publish_date` DATETIME NOT NULL,
  14. `edit_date` DATETIME NOT NULL,
  15. `dated` BOOLEAN NOT NULL,
  16. `published` BOOLEAN NOT NULL,
  17. `unlisted` BOOLEAN NOT NULL,
  18. `specific` BOOLEAN NOT NULL,
  19. `indexed` BOOLEAN NOT NULL,
  20. `type` VARCHAR(16) NOT NULL,
  21. `source` MEDIUMTEXT NOT NULL,
  22. `cache` MEDIUMTEXT NOT NULL,
  23. `background_url` VARCHAR(255),
  24. FOREIGN KEY (`author`) REFERENCES user(`id`) ON DELETE SET NULL
  25. );
  26. CREATE TABLE tag (
  27. `id` CHAR(24) NOT NULL PRIMARY KEY,
  28. `type` CHAR(16) NOT NULL,
  29. `disabled` BOOLEAN NOT NULL,
  30. `name` VARCHAR(64) NOT NULL,
  31. UNIQUE(name),
  32. INDEX(disabled)
  33. );
  34. CREATE TABLE page_tag (
  35. `page_id` CHAR(16) NOT NULL,
  36. `tag_id` CHAR(16) NOT NULL,
  37. PRIMARY KEY (`page_id`, `tag_id`),
  38. FOREIGN KEY (`page_id`) REFERENCES page(`id`) ON DELETE CASCADE,
  39. FOREIGN KEY (`tag_id`) REFERENCES tag(`id`) ON DELETE CASCADE
  40. );
  41. CREATE TABLE page_unread (
  42. `page_id` CHAR(16) NOT NULL,
  43. `user_id` CHAR(32) NOT NULL,
  44. PRIMARY KEY (`page_id`, `user_id`),
  45. FOREIGN KEY (`page_id`) REFERENCES page(`id`) ON DELETE CASCADE,
  46. FOREIGN KEY (`user_id`) REFERENCES user(`id`) ON DELETE CASCADE
  47. );