migrate_dimension_unified_rollback.sql 1.2 KB

12345678910111213141516171819202122232425
  1. -- ============================================================
  2. -- 统一维度体系 P0-T5 回滚脚本
  3. -- 作用:将 health_dimension_scores.dimension 由 body.<old> 反向还原为旧 7 维裸名
  4. -- (与主线 forward migrate_dimension_unified.sql 精确成对)
  5. -- 执行方式:由 DBA 手动执行
  6. -- 幂等:UPDATE 仅命中 7 个 body.* 子维,重复执行无副作用(affected rows=0)
  7. -- 备份表:health_dimension_scores_bak_20261105(与 forward 步骤 1 同名同日戳)
  8. -- ============================================================
  9. -- 主回滚(精确逆反 forward 步骤 2):body.{sub} → {sub},仅命中已迁移的 7 行
  10. UPDATE health_dimension_scores
  11. SET dimension = SUBSTRING(dimension, 6)
  12. WHERE dimension IN (
  13. 'body.growth',
  14. 'body.sleep',
  15. 'body.vision',
  16. 'body.immunity',
  17. 'body.nutrition',
  18. 'body.gut',
  19. 'body.exercise'
  20. );
  21. -- 备选整体还原(仅在确认需整体回退时执行;会覆盖当前表,请先确认无新增数据):
  22. -- TRUNCATE health_dimension_scores;
  23. -- INSERT INTO health_dimension_scores SELECT * FROM health_dimension_scores_bak_20261105;