003_zombie_items_german.sql 5.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. -- Migration 003 – German item list for the hidden Zombie apocalypse activity.
  2. -- Run once, after 002, against an existing PackIt database:
  3. -- mysql -u <user> -p <your-database> < migrations/003_zombie_items_german.sql
  4. -- New installs get all of this from schema.sql and can skip it.
  5. --
  6. -- 002 looked item groups and items up by the English sample-data names, so on
  7. -- a database with its own (e.g. German) groups the activity ended up empty.
  8. -- This rebuilds the list without depending on any particular group existing:
  9. -- an item whose group is missing lands in the new "Zombie-Abwehr" group.
  10. -- Safe to run more than once.
  11. -- 1. Activity and its group in German.
  12. SET @zombie = (SELECT activityID FROM activities
  13. WHERE hidden = 1 AND activityName IN ('Zombie apocalypse', 'Zombie-Apokalypse')
  14. ORDER BY activityID LIMIT 1);
  15. UPDATE activities SET activityName = 'Zombie-Apokalypse' WHERE activityID = @zombie;
  16. UPDATE activity_groups ag
  17. JOIN activities a ON a.groupID = ag.groupID AND a.activityID = @zombie
  18. SET ag.groupName = 'Überleben'
  19. WHERE ag.groupName = 'Survival';
  20. -- 2. Start the list over. The English items 002 created are only removed when
  21. -- no other activity uses them.
  22. DELETE FROM activity_item_map WHERE activityID = @zombie;
  23. DELETE FROM items
  24. WHERE itemName IN ('Running shoes (cardio is rule #1)', 'Bite-proof arm guards',
  25. 'Map with safe zones marked', 'Canned beans', 'Manual can opener',
  26. 'Cricket bat', 'Crowbar', 'Duct tape', 'Walkie-talkies')
  27. AND itemID NOT IN (SELECT itemID FROM activity_item_map);
  28. -- 3. Item group for the gear no normal trip needs. The guard sits in HAVING:
  29. -- an aggregate still yields a row when WHERE filters every row out.
  30. INSERT INTO item_groups (groupName, sortOrder)
  31. SELECT 'Zombie-Abwehr', COALESCE(MAX(sortOrder), 0) + 1 FROM item_groups
  32. HAVING SUM(groupName = 'Zombie-Abwehr') = 0;
  33. SET @zgroup = (SELECT groupID FROM item_groups WHERE groupName = 'Zombie-Abwehr'
  34. ORDER BY groupID LIMIT 1);
  35. -- 4. The list. altName is the English sample-data name of an item that may
  36. -- already exist; an item found under either name is reused, not duplicated.
  37. CREATE TEMPORARY TABLE zombie_list (
  38. itemName VARCHAR(150) NOT NULL,
  39. altName VARCHAR(150) NULL,
  40. groupName VARCHAR(100) NOT NULL,
  41. quantity INT NOT NULL
  42. );
  43. INSERT INTO zombie_list (itemName, altName, groupName, quantity) VALUES
  44. ('Laufschuhe (Regel Nr. 1: Cardio)', NULL, 'Kleidung', 1),
  45. ('Bissfeste Armschützer (Paar)', NULL, 'Kleidung', 1),
  46. ('Schlafsack', 'Sleeping bag', 'Kleidung', 1),
  47. ('Dosenbohnen', NULL, 'Essen', 12),
  48. ('Twinkies (letzte Packung der Welt)', NULL, 'Essen', 1),
  49. ('Trinken (1 l)', 'Water bottle', 'Essen', 2),
  50. ('Dosenöffner (manuell)', NULL, 'Küche', 1),
  51. ('Feuerzeug', NULL, 'Küche', 1),
  52. ('Stirnlampe', 'Headlamp + spare batteries', 'Elektronik', 1),
  53. ('Funkgerät', NULL, 'Elektronik', 2),
  54. ('Kurbelradio', NULL, 'Elektronik', 1),
  55. ('EH-Set', 'First aid kit', 'Sicherheit', 1),
  56. ('Multitool', NULL, 'Sicherheit', 1),
  57. ('Karte mit sicheren Zonen', NULL, 'Kleinzeug', 1),
  58. ('Zombie-Wörterbuch (Grrr = Hallo)', NULL, 'Kleinzeug', 1),
  59. ('Glaubwürdige Ausrede für die Bisswunde', NULL, 'Kleinzeug', 1),
  60. ('Cricketschläger', NULL, 'Zombie-Abwehr', 1),
  61. ('Brecheisen', NULL, 'Zombie-Abwehr', 1),
  62. ('Panzertape', NULL, 'Zombie-Abwehr', 1),
  63. ('Bolzenschneider', NULL, 'Zombie-Abwehr', 1),
  64. ('Knoblauch (hilft nicht, beruhigt aber)', NULL, 'Zombie-Abwehr', 1),
  65. ('Gartenzwerg zur Ablenkung', NULL, 'Zombie-Abwehr', 1);
  66. INSERT INTO items (groupID, itemName, sortOrder)
  67. SELECT COALESCE((SELECT ig.groupID FROM item_groups ig
  68. WHERE ig.groupName = z.groupName ORDER BY ig.groupID LIMIT 1), @zgroup),
  69. z.itemName, 0
  70. FROM zombie_list z
  71. WHERE NOT EXISTS (SELECT 1 FROM items i WHERE i.itemName IN (z.itemName, z.altName));
  72. INSERT INTO activity_item_map (activityID, itemID, quantity)
  73. SELECT @zombie, MIN(i.itemID), z.quantity
  74. FROM zombie_list z
  75. JOIN items i ON i.itemName IN (z.itemName, z.altName)
  76. GROUP BY z.itemName, z.quantity;
  77. DROP TEMPORARY TABLE zombie_list;