schema.sql 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. -- PackIt Database Schema
  2. -- Run this once to set up all required tables.
  3. CREATE DATABASE IF NOT EXISTS packit CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  4. USE packit;
  5. -- Activity groups (categories)
  6. CREATE TABLE IF NOT EXISTS activity_groups (
  7. groupID INT AUTO_INCREMENT PRIMARY KEY,
  8. groupName VARCHAR(100) NOT NULL,
  9. sortOrder INT DEFAULT 0
  10. );
  11. -- Activities
  12. CREATE TABLE IF NOT EXISTS activities (
  13. activityID INT AUTO_INCREMENT PRIMARY KEY,
  14. groupID INT NOT NULL,
  15. activityName VARCHAR(150) NOT NULL,
  16. sortOrder INT DEFAULT 0,
  17. FOREIGN KEY (groupID) REFERENCES activity_groups(groupID) ON DELETE CASCADE
  18. );
  19. -- Item groups
  20. CREATE TABLE IF NOT EXISTS item_groups (
  21. groupID INT AUTO_INCREMENT PRIMARY KEY,
  22. groupName VARCHAR(100) NOT NULL,
  23. sortOrder INT DEFAULT 0
  24. );
  25. -- Items
  26. CREATE TABLE IF NOT EXISTS items (
  27. itemID INT AUTO_INCREMENT PRIMARY KEY,
  28. groupID INT NOT NULL,
  29. itemName VARCHAR(150) NOT NULL,
  30. sortOrder INT DEFAULT 0,
  31. FOREIGN KEY (groupID) REFERENCES item_groups(groupID) ON DELETE CASCADE
  32. );
  33. -- Relation between activities and items
  34. CREATE TABLE IF NOT EXISTS activity_item_map (
  35. activityID INT NOT NULL,
  36. itemID INT NOT NULL,
  37. PRIMARY KEY (activityID, itemID),
  38. FOREIGN KEY (activityID) REFERENCES activities(activityID) ON DELETE CASCADE,
  39. FOREIGN KEY (itemID) REFERENCES items(itemID) ON DELETE CASCADE
  40. );
  41. -- Stored selection hashes (for shareable URLs)
  42. CREATE TABLE IF NOT EXISTS selection_hashes (
  43. hashID INT AUTO_INCREMENT PRIMARY KEY,
  44. hash CHAR(64) NOT NULL UNIQUE,
  45. activity_ids TEXT NOT NULL,
  46. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
  47. );
  48. -- Admin users
  49. CREATE TABLE IF NOT EXISTS admin_users (
  50. adminID INT AUTO_INCREMENT PRIMARY KEY,
  51. username VARCHAR(50) NOT NULL UNIQUE,
  52. password_hash VARCHAR(255) NOT NULL
  53. );
  54. -- -----------------------------------------------
  55. -- Sample data
  56. -- -----------------------------------------------
  57. INSERT INTO activity_groups (groupName, sortOrder) VALUES
  58. ('Overnight', 1), -- groupID 1
  59. ('Rescue & Safety', 2), -- groupID 2
  60. ('Water Activities', 3), -- groupID 3
  61. ('Winter Sports', 4); -- groupID 4
  62. -- activityID 1=Camping 2=Hiking 3=Bivouac 4=First Aid 5=Mountain Rescue
  63. -- activityID 6=Kayaking 7=Swimming 8=Skiing 9=Snowshoeing
  64. INSERT INTO activities (groupID, activityName, sortOrder) VALUES
  65. (1, 'Camping', 1),
  66. (1, 'Hiking', 2),
  67. (1, 'Bivouac', 3),
  68. (2, 'First Aid', 1),
  69. (2, 'Mountain Rescue', 2),
  70. (3, 'Kayaking', 1),
  71. (3, 'Swimming', 2),
  72. (4, 'Skiing', 1),
  73. (4, 'Snowshoeing', 2);
  74. INSERT INTO item_groups (groupName, sortOrder) VALUES
  75. ('Clothing', 1), -- groupID 1
  76. ('Shelter', 2), -- groupID 2
  77. ('Navigation', 3), -- groupID 3
  78. ('Medical', 4), -- groupID 4
  79. ('Water & Food', 5), -- groupID 5
  80. ('Safety Gear', 6); -- groupID 6
  81. -- Items with their resulting auto_increment IDs:
  82. -- 1 Base layer top (Clothing)
  83. -- 2 Base layer bottom (Clothing)
  84. -- 3 Fleece jacket (Clothing)
  85. -- 4 Rain jacket (Clothing)
  86. -- 5 Gloves (Clothing)
  87. -- 6 Warm hat (Clothing)
  88. -- 7 Hiking boots (Clothing)
  89. -- 8 Wetsuit (Clothing)
  90. -- 9 Ski jacket (Clothing)
  91. -- 10 Ski pants (Clothing)
  92. -- 11 Ski boots (Clothing)
  93. -- 12 Tent (Shelter)
  94. -- 13 Sleeping bag (Shelter)
  95. -- 14 Sleeping mat (Shelter)
  96. -- 15 Bivouac bag (Shelter)
  97. -- 16 Topographic map (Navigation)
  98. -- 17 Compass (Navigation)
  99. -- 18 GPS device (Navigation)
  100. -- 19 First aid kit (Medical)
  101. -- 20 Emergency blanket (Medical)
  102. -- 21 Tourniquet (Medical)
  103. -- 22 SAM splint (Medical)
  104. -- 23 Water bottle (Water & Food)
  105. -- 24 Water filter (Water & Food)
  106. -- 25 Trail snacks (Water & Food)
  107. -- 26 Stove & fuel (Water & Food)
  108. -- 27 Cooking pot (Water & Food)
  109. -- 28 Headlamp + batteries (Safety Gear)
  110. -- 29 Whistle (Safety Gear)
  111. -- 30 Rope (30m) (Safety Gear)
  112. -- 31 Avalanche probe (Safety Gear)
  113. -- 32 Avalanche transceiver (Safety Gear)
  114. -- 33 Shovel (Safety Gear)
  115. -- 34 Life jacket (Safety Gear)
  116. -- 35 Paddle float (Safety Gear)
  117. INSERT INTO items (groupID, itemName, sortOrder) VALUES
  118. (1, 'Base layer top', 1),
  119. (1, 'Base layer bottom', 2),
  120. (1, 'Fleece jacket', 3),
  121. (1, 'Rain jacket', 4),
  122. (1, 'Gloves', 5),
  123. (1, 'Warm hat', 6),
  124. (1, 'Hiking boots', 7),
  125. (1, 'Wetsuit', 8),
  126. (1, 'Ski jacket', 9),
  127. (1, 'Ski pants', 10),
  128. (1, 'Ski boots', 11),
  129. (2, 'Tent', 1),
  130. (2, 'Sleeping bag', 2),
  131. (2, 'Sleeping mat', 3),
  132. (2, 'Bivouac bag', 4),
  133. (3, 'Topographic map', 1),
  134. (3, 'Compass', 2),
  135. (3, 'GPS device', 3),
  136. (4, 'First aid kit', 1),
  137. (4, 'Emergency blanket', 2),
  138. (4, 'Tourniquet', 3),
  139. (4, 'SAM splint', 4),
  140. (5, 'Water bottle', 1),
  141. (5, 'Water filter', 2),
  142. (5, 'Trail snacks', 3),
  143. (5, 'Stove & fuel', 4),
  144. (5, 'Cooking pot', 5),
  145. (6, 'Headlamp + spare batteries', 1),
  146. (6, 'Whistle', 2),
  147. (6, 'Rope (30m)', 3),
  148. (6, 'Avalanche probe', 4),
  149. (6, 'Avalanche transceiver', 5),
  150. (6, 'Shovel', 6),
  151. (6, 'Life jacket', 7),
  152. (6, 'Paddle float', 8);
  153. -- -----------------------------------------------
  154. -- Activity -> Item mappings (all IDs verified)
  155. -- -----------------------------------------------
  156. -- activityID 1: Camping
  157. INSERT INTO activity_item_map (activityID, itemID) VALUES
  158. (1, 1),(1, 2),(1, 3),(1, 4),(1, 7),
  159. (1,12),(1,13),(1,14),
  160. (1,16),(1,17),
  161. (1,19),(1,20),
  162. (1,23),(1,24),(1,25),(1,26),(1,27),
  163. (1,28),(1,29);
  164. -- activityID 2: Hiking
  165. INSERT INTO activity_item_map (activityID, itemID) VALUES
  166. (2, 1),(2, 2),(2, 3),(2, 4),(2, 7),
  167. (2,16),(2,17),(2,18),
  168. (2,19),(2,20),
  169. (2,23),(2,24),(2,25),
  170. (2,28),(2,29);
  171. -- activityID 3: Bivouac
  172. INSERT INTO activity_item_map (activityID, itemID) VALUES
  173. (3, 1),(3, 2),(3, 3),(3, 4),(3, 5),(3, 6),(3, 7),
  174. (3,14),(3,15),
  175. (3,16),(3,17),
  176. (3,19),(3,20),
  177. (3,23),(3,25),
  178. (3,28),(3,29);
  179. -- activityID 4: First Aid
  180. INSERT INTO activity_item_map (activityID, itemID) VALUES
  181. (4,19),(4,20),(4,21),(4,22),
  182. (4,28),(4,29);
  183. -- activityID 5: Mountain Rescue
  184. INSERT INTO activity_item_map (activityID, itemID) VALUES
  185. (5, 1),(5, 3),(5, 4),(5, 5),(5, 6),
  186. (5,16),(5,17),(5,18),
  187. (5,19),(5,20),(5,21),(5,22),
  188. (5,28),(5,29),(5,30);
  189. -- activityID 6: Kayaking
  190. INSERT INTO activity_item_map (activityID, itemID) VALUES
  191. (6, 1),(6, 4),(6, 8),
  192. (6,19),(6,20),
  193. (6,23),(6,24),
  194. (6,28),(6,29),
  195. (6,34),(6,35);
  196. -- activityID 7: Swimming
  197. INSERT INTO activity_item_map (activityID, itemID) VALUES
  198. (7, 8),
  199. (7,19),(7,20),
  200. (7,34);
  201. -- activityID 8: Skiing
  202. INSERT INTO activity_item_map (activityID, itemID) VALUES
  203. (8, 1),(8, 2),(8, 5),(8, 6),(8, 9),(8,10),(8,11),
  204. (8,16),(8,17),(8,18),
  205. (8,19),(8,20),
  206. (8,23),(8,25),
  207. (8,28),(8,29),
  208. (8,31),(8,32),(8,33);
  209. -- activityID 9: Snowshoeing
  210. INSERT INTO activity_item_map (activityID, itemID) VALUES
  211. (9, 1),(9, 2),(9, 3),(9, 4),(9, 5),(9, 6),(9, 7),
  212. (9,16),(9,17),
  213. (9,19),(9,20),
  214. (9,23),(9,24),(9,25),
  215. (9,28),(9,29),
  216. (9,31);
  217. -- -----------------------------------------------
  218. -- Default admin user
  219. -- Username: admin Password: packit-admin
  220. -- Change the password after first login!
  221. -- -----------------------------------------------
  222. INSERT INTO admin_users (username, password_hash) VALUES
  223. ('admin', '$2y$12$eTfGi/R5IxHH5NQxrVe9.OijNfyFfpvT/X1i9aYgqZPRF6.Gu72hC');