002_hidden_activities.sql 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. -- Migration 002 – hidden (easter egg) activities + the Zombie apocalypse list.
  2. -- Run once against an existing PackIt database:
  3. -- mysql -u <user> -p <your-database> < migrations/002_hidden_activities.sql
  4. -- New installs get all of this from schema.sql and can skip it.
  5. -- 1. Hidden activities are left off the selection page until revealed.
  6. ALTER TABLE activities ADD COLUMN hidden TINYINT(1) NOT NULL DEFAULT 0;
  7. -- 2. The Zombie apocalypse activity in its own group.
  8. INSERT INTO activity_groups (groupName, sortOrder)
  9. SELECT 'Survival', COALESCE(MAX(sortOrder), 0) + 1 FROM activity_groups;
  10. SET @survivalGroup = LAST_INSERT_ID();
  11. INSERT INTO activities (groupID, activityName, sortOrder, hidden)
  12. VALUES (@survivalGroup, 'Zombie apocalypse', 1, 1);
  13. SET @zombie = LAST_INSERT_ID();
  14. -- 3. Items only this list needs. Item groups are looked up by their sample-data
  15. -- names; an item whose group was renamed or removed is skipped rather than
  16. -- failing the migration, and can be added through the admin panel instead.
  17. INSERT INTO items (groupID, itemName, sortOrder)
  18. SELECT ig.groupID, n.itemName, n.sortOrder
  19. FROM (
  20. SELECT 'Clothing' AS groupName, 'Running shoes (cardio is rule #1)' AS itemName, 12 AS sortOrder
  21. UNION ALL SELECT 'Clothing', 'Bite-proof arm guards', 13
  22. UNION ALL SELECT 'Navigation', 'Map with safe zones marked', 4
  23. UNION ALL SELECT 'Water & Food', 'Canned beans', 6
  24. UNION ALL SELECT 'Water & Food', 'Manual can opener', 7
  25. UNION ALL SELECT 'Safety Gear', 'Cricket bat', 9
  26. UNION ALL SELECT 'Safety Gear', 'Crowbar', 10
  27. UNION ALL SELECT 'Safety Gear', 'Duct tape', 11
  28. UNION ALL SELECT 'Safety Gear', 'Walkie-talkies', 12
  29. ) n
  30. JOIN item_groups ig ON ig.groupName = n.groupName
  31. WHERE NOT EXISTS (SELECT 1 FROM items i WHERE i.itemName = n.itemName);
  32. -- 4. Map new and existing items to the activity by name. MIN(itemID) guards
  33. -- against an install that happens to hold two items with the same name.
  34. INSERT INTO activity_item_map (activityID, itemID, quantity)
  35. SELECT @zombie, MIN(i.itemID), n.quantity
  36. FROM (
  37. SELECT 'Running shoes (cardio is rule #1)' AS itemName, 1 AS quantity
  38. UNION ALL SELECT 'Bite-proof arm guards', 2
  39. UNION ALL SELECT 'Sleeping bag', 1
  40. UNION ALL SELECT 'Map with safe zones marked', 1
  41. UNION ALL SELECT 'Compass', 1
  42. UNION ALL SELECT 'First aid kit', 1
  43. UNION ALL SELECT 'Water bottle', 2
  44. UNION ALL SELECT 'Water filter', 1
  45. UNION ALL SELECT 'Canned beans', 12
  46. UNION ALL SELECT 'Manual can opener', 1
  47. UNION ALL SELECT 'Headlamp + spare batteries', 1
  48. UNION ALL SELECT 'Rope (30m)', 1
  49. UNION ALL SELECT 'Cricket bat', 1
  50. UNION ALL SELECT 'Crowbar', 1
  51. UNION ALL SELECT 'Duct tape', 1
  52. UNION ALL SELECT 'Walkie-talkies', 2
  53. ) n
  54. JOIN items i ON i.itemName = n.itemName
  55. GROUP BY n.itemName, n.quantity;