20260808_stylist_release.sql 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. -- Aitori Stylist release deployment script
  2. -- Target: MySQL 5.7+ / MySQL 8+
  3. -- This script is safe to run once on the production database. It is also
  4. -- idempotent for the schema changes, so a rerun will not add the column or
  5. -- index a second time.
  6. DELIMITER $$
  7. CREATE PROCEDURE `aitori_apply_stylist_release_20260808`()
  8. BEGIN
  9. IF NOT EXISTS (
  10. SELECT 1
  11. FROM information_schema.COLUMNS
  12. WHERE TABLE_SCHEMA = DATABASE()
  13. AND TABLE_NAME = 'hairstylist_user'
  14. AND COLUMN_NAME = 'simulation_invite_code'
  15. ) THEN
  16. ALTER TABLE `hairstylist_user`
  17. ADD COLUMN `simulation_invite_code` VARCHAR(8) NULL AFTER `password`;
  18. END IF;
  19. IF NOT EXISTS (
  20. SELECT 1
  21. FROM information_schema.STATISTICS
  22. WHERE TABLE_SCHEMA = DATABASE()
  23. AND TABLE_NAME = 'hairstylist_user'
  24. AND INDEX_NAME = 'hairstylist_user_simulation_invite_code_key'
  25. ) THEN
  26. CREATE UNIQUE INDEX `hairstylist_user_simulation_invite_code_key`
  27. ON `hairstylist_user` (`simulation_invite_code`);
  28. END IF;
  29. END$$
  30. DELIMITER ;
  31. CALL `aitori_apply_stylist_release_20260808`();
  32. DROP PROCEDURE `aitori_apply_stylist_release_20260808`;
  33. -- Give the standard local/demo stylist the documented code without replacing
  34. -- a code that has already been issued to a production stylist.
  35. UPDATE `hairstylist_user`
  36. SET `simulation_invite_code` = 'K8HUY7SS'
  37. WHERE `email` = 'stylist@aitori.jp'
  38. AND `is_deleted` = 0
  39. AND (`simulation_invite_code` IS NULL OR `simulation_invite_code` = '');
  40. -- Backfill stable 8-character invitation codes for every existing active
  41. -- stylist that does not have one yet. "S" + a zero-padded base-36 id keeps
  42. -- the values in the allowed uppercase alphanumeric format and avoids random
  43. -- collisions for normal account id ranges.
  44. UPDATE `hairstylist_user`
  45. SET `simulation_invite_code` = CONCAT(
  46. 'S',
  47. LPAD(UPPER(CONV(`id`, 10, 36)), 7, '0')
  48. )
  49. WHERE `is_deleted` = 0
  50. AND (`simulation_invite_code` IS NULL OR `simulation_invite_code` = '');
  51. -- The template package is a ZIP file used by the AI service, not a browser
  52. -- image. Set matching system template cover URLs to their display previews.
  53. -- template_url remains unchanged and continues to be sent to the AI service.
  54. UPDATE `hair_template`
  55. SET `cover_url` = CASE `template_name`
  56. WHEN '居家造型' THEN '/images/mvp-simulation-result-10/home-styling.jpg'
  57. WHEN '居家造型30天后造型' THEN '/images/mvp-simulation-result-10/after-30-days.jpg'
  58. WHEN '居家造型60天后造型' THEN '/images/mvp-simulation-result-10/after-60-days.jpg'
  59. ELSE `cover_url`
  60. END
  61. WHERE `is_system_template` = 'YES'
  62. AND `is_deleted` = 0
  63. AND `template_name` IN ('居家造型', '居家造型30天后造型', '居家造型60天后造型')
  64. AND (`cover_url` = '' OR `cover_url` REGEXP '\\.zip(\\?.*)?$');