An unfinished system to manage all your paper documentation in an easy way.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

autodoc.sql 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. ALTER SCHEMA `autodoc` DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci ;
  2. DROP TABLE IF EXISTS `documents_tags`;
  3. DROP TABLE IF EXISTS `documents_pages`;
  4. DROP TABLE IF EXISTS `pages_words`;
  5. DROP TABLE IF EXISTS `words`;
  6. DROP TABLE IF EXISTS `dict`;
  7. DROP TABLE IF EXISTS `languages`;
  8. DROP TABLE IF EXISTS `pages`;
  9. DROP TABLE IF EXISTS `tags`;
  10. DROP TABLE IF EXISTS `users`;
  11. DROP TABLE IF EXISTS `documents`;
  12. DROP PROCEDURE IF EXISTS `create_page_word`;
  13. DROP PROCEDURE IF EXISTS `create_tag`;
  14. DROP PROCEDURE IF EXISTS `create_document`;
  15. DROP PROCEDURE IF EXISTS `create_page`;
  16. DROP PROCEDURE IF EXISTS `delete_tag`;
  17. DROP PROCEDURE IF EXISTS `get_document_filter`;
  18. DROP PROCEDURE IF EXISTS `get_primary_page`;
  19. DROP PROCEDURE IF EXISTS `set_primary_page`;
  20. DROP PROCEDURE IF EXISTS `set_page_status`;
  21. DROP FUNCTION IF EXISTS `SPLIT_STR`;
  22. CREATE TABLE `dict` (
  23. `word` varchar(255) NOT NULL,
  24. `lang` char(2) NOT NULL,
  25. PRIMARY KEY (`word`,`lang`)
  26. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  27. CREATE TABLE `users` (
  28. `username` varchar(255) NOT NULL,
  29. `passwd` varchar(255) DEFAULT NULL,
  30. `groups` varchar(255) DEFAULT NULL,
  31. PRIMARY KEY (`username`)
  32. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  33. CREATE TABLE `documents` (
  34. `id` binary(16) NOT NULL,
  35. `owner` varchar(45) DEFAULT NULL,
  36. `name` varchar(128) CHARACTER SET utf8mb4 DEFAULT NULL,
  37. `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  38. `status` enum('nodata','inprogress','deleted','ok') NOT NULL DEFAULT 'nodata',
  39. PRIMARY KEY (`id`)
  40. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  41. CREATE TABLE `languages` (
  42. `id` binary(16) NOT NULL,
  43. `short` char(2) DEFAULT NULL,
  44. `name` varchar(45) DEFAULT NULL,
  45. PRIMARY KEY (`id`),
  46. UNIQUE KEY `short_UNIQUE` (`short`)
  47. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  48. CREATE TABLE `pages` (
  49. `id` binary(16) NOT NULL,
  50. `owner` varchar(45) DEFAULT NULL,
  51. `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  52. `status` enum('nodata','inprogress','deleted','ok') DEFAULT 'nodata',
  53. `isprimary` tinyint(4) DEFAULT '0',
  54. PRIMARY KEY (`id`)
  55. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  56. CREATE TABLE `tags` (
  57. `id` binary(16) NOT NULL,
  58. `tag` varchar(45) DEFAULT NULL,
  59. `color` enum('primary','secondary','success','danger','warning','info','light','dark') DEFAULT NULL,
  60. PRIMARY KEY (`id`),
  61. UNIQUE KEY `tag_UNIQUE` (`tag`,`color`)
  62. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  63. CREATE TABLE `words` (
  64. `id` binary(16) NOT NULL,
  65. `word` varchar(255) DEFAULT NULL,
  66. `languageId` binary(16) DEFAULT NULL,
  67. PRIMARY KEY (`id`),
  68. UNIQUE KEY `word_UNIQUE` (`word`,`languageId`),
  69. KEY `fk_words_langid_idx` (`languageId`),
  70. CONSTRAINT `fk_words_languageid` FOREIGN KEY (`languageId`) REFERENCES `languages` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
  71. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  72. CREATE TABLE `documents_tags` (
  73. `documentId` binary(16) NOT NULL,
  74. `tagId` binary(16) NOT NULL,
  75. PRIMARY KEY (`documentId`,`tagId`),
  76. KEY `fk_tags_id_idx` (`tagId`),
  77. CONSTRAINT `fk_doctags_docid` FOREIGN KEY (`documentId`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION,
  78. CONSTRAINT `fk_doctags_tagid` FOREIGN KEY (`tagId`) REFERENCES `tags` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
  79. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  80. CREATE TABLE `pages_words` (
  81. `pageId` binary(16) NOT NULL,
  82. `wordId` binary(16) NOT NULL,
  83. `count` int(10) unsigned DEFAULT NULL,
  84. PRIMARY KEY (`pageId`,`wordId`),
  85. KEY `fk_pagword_wordid_idx` (`wordId`),
  86. CONSTRAINT `fk_pagword_pageid` FOREIGN KEY (`pageId`) REFERENCES `pages` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION,
  87. CONSTRAINT `fk_pagword_wordid` FOREIGN KEY (`wordId`) REFERENCES `words` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
  88. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  89. CREATE TABLE `documents_pages` (
  90. `documentId` binary(16) NOT NULL,
  91. `pageId` binary(16) NOT NULL,
  92. PRIMARY KEY (`documentId`,`pageId`),
  93. KEY `fk_docpage_pageid_idx` (`pageId`),
  94. CONSTRAINT `fk_docpage_docid` FOREIGN KEY (`documentId`) REFERENCES `documents` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION,
  95. CONSTRAINT `fk_docpage_pageid` FOREIGN KEY (`pageId`) REFERENCES `pages` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
  96. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  97. DELIMITER ;;
  98. CREATE FUNCTION `SPLIT_STR`(
  99. x VARCHAR(255),
  100. delim VARCHAR(12),
  101. pos INT
  102. ) RETURNS varchar(255) CHARSET utf8mb4
  103. RETURN
  104. CASE WHEN CHAR_LENGTH(SUBSTRING_INDEX(x, delim, pos - 1)) = CHAR_LENGTH(x)
  105. THEN x
  106. ELSE (REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), CHAR_LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), delim, ''))
  107. END ;;
  108. DELIMITER ;
  109. DELIMITER ;;
  110. CREATE PROCEDURE `create_page_word`(
  111. IN IN_pageid BINARY(16),
  112. IN IN_word VARCHAR(255),
  113. IN IN_langid BINARY(16))
  114. BEGIN
  115. DECLARE LOC_wordid BINARY(16) DEFAULT NULL;
  116. INSERT IGNORE INTO words SET id = UUID(), word = IN_word, langId = IN_langid;
  117. SELECT id INTO LOC_wordid FROM words WHERE word = IN_word AND langId = IN_langid;
  118. INSERT INTO pages_words SET pageId = IN_pageid, wordId = LOC_wordid, count = 1
  119. ON DUPLICATE KEY UPDATE count = count + 1;
  120. END ;;
  121. DELIMITER ;
  122. DELIMITER ;;
  123. CREATE PROCEDURE `create_tag`(
  124. IN IN_documentid BINARY(16),
  125. IN IN_tag VARCHAR(45))
  126. BEGIN
  127. DECLARE LOC_tagid BINARY(16) DEFAULT UUID();
  128. INSERT IGNORE INTO tags SET
  129. id = LOC_tagid,
  130. tag = IN_tag;
  131. SELECT id INTO LOC_tagid FROM tags WHERE tag = IN_tag;
  132. INSERT IGNORE INTO documents_tags SET
  133. documentId = IN_documentid,
  134. tagId = LOC_tagid;
  135. END ;;
  136. DELIMITER ;
  137. DELIMITER ;;
  138. CREATE PROCEDURE `create_document`(
  139. IN IN_owner VARCHAR(45))
  140. BEGIN
  141. DECLARE LOC_documentid BINARY(16) DEFAULT UUID();
  142. INSERT INTO documents SET
  143. id = LOC_documentid,
  144. owner = IN_owner,
  145. status = 'nodata';
  146. SELECT LOC_documentid AS documentId;
  147. END ;;
  148. DELIMITER ;
  149. DELIMITER ;;
  150. CREATE PROCEDURE `create_page`(
  151. IN IN_documentId BINARY(16))
  152. BEGIN
  153. DECLARE LOC_pageid BINARY(16) DEFAULT UUID();
  154. INSERT INTO pages SET
  155. id = LOC_pageid,
  156. status = 'nodata';
  157. INSERT INTO documents_pages SET
  158. documentId = IN_documentid,
  159. pageId = LOC_pageid;
  160. SELECT LOC_pageid AS pageId;
  161. END ;;
  162. DELIMITER ;
  163. DELIMITER ;;
  164. CREATE PROCEDURE `delete_tag`(
  165. IN IN_documentid BINARY(16),
  166. IN IN_tag VARCHAR(45))
  167. BEGIN
  168. DECLARE LOC_tagid BINARY(16) DEFAULT UUID();
  169. SELECT id INTO LOC_tagid FROM tags WHERE tag = IN_tag;
  170. DELETE FROM documents_tags
  171. WHERE documentId = IN_documentid
  172. AND tagId = LOC_tagid;
  173. END ;;
  174. DELIMITER ;
  175. DELIMITER ;;
  176. CREATE PROCEDURE `get_document_filter`(
  177. IN IN_words VARCHAR(255),
  178. IN IN_tags VARCHAR(255),
  179. IN IN_lim1 INT,
  180. IN IN_lim2 INT)
  181. BEGIN
  182. DECLARE L_query TEXT default "";
  183. DECLARE L_pos INT UNSIGNED DEFAULT 0;
  184. SELECT BIN_TO_UUID(dp.documentId) AS id, SUM(pw.count) AS wordcount
  185. FROM documents_pages dp
  186. JOIN pages_words pw ON dp.pageId = pw.pageId
  187. JOIN words w ON pw.wordId = w.id
  188. WHERE w.word REGEXP CONCAT("(", IN_words, ")")
  189. GROUP BY dp.documentId
  190. ORDER BY wordcount DESC
  191. LIMIT IN_lim1, IN_lim2;
  192. END ;;
  193. DELIMITER ;
  194. DELIMITER ;;
  195. CREATE PROCEDURE `get_primary_page`(
  196. IN IN_documentid BINARY(16))
  197. BEGIN
  198. DECLARE LOC_pageid BINARY(16) DEFAULT NULL;
  199. SELECT dp.pageId INTO LOC_pageid FROM
  200. documents_pages dp
  201. JOIN pages p ON dp.pageId = p.id
  202. WHERE dp.documentId = IN_documentid
  203. AND p.isprimary = 1;
  204. IF LOC_pageid IS NULL
  205. THEN
  206. SELECT dp.pageId INTO LOC_pageid FROM
  207. documents_pages dp
  208. JOIN pages p ON dp.pageId = p.id
  209. WHERE dp.documentId = IN_documentid
  210. ORDER BY RAND() LIMIT 1;
  211. END IF;
  212. SELECT BIN_TO_UUID(LOC_pageid) AS pageId;
  213. END ;;
  214. DELIMITER ;
  215. DELIMITER ;;
  216. CREATE PROCEDURE `set_primary_page`(
  217. IN IN_pageid BINARY(16))
  218. BEGIN
  219. DECLARE LOC_documentid BINARY(16) DEFAULT NULL;
  220. SELECT documentId INTO LOC_documentid FROM documents_pages WHERE pageId = IN_pageid;
  221. UPDATE
  222. documents_pages dp
  223. JOIN pages p ON dp.pageId = p.id
  224. SET p.isprimary = 0
  225. WHERE dp.documentId = LOC_documentid;
  226. UPDATE
  227. pages
  228. SET isprimary = 1
  229. WHERE id = IN_pageid;
  230. END ;;
  231. DELIMITER ;
  232. DELIMITER ;;
  233. CREATE PROCEDURE `set_page_status`(
  234. IN IN_pageid BINARY(16),
  235. IN IN_status ENUM('nodata', 'inprogress', 'deleted', 'ok')
  236. )
  237. BEGIN
  238. UPDATE pages SET status = IN_status WHERE id = IN_pageid;
  239. END ;;
  240. DELIMITER ;