Advertisement
Guest User

Untitled

a guest
May 25th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.88 KB | None | 0 0
  1. ALTER TABLE `images`
  2.     ADD INDEX `md5_hash` (`md5_hash`);
  3.  
  4. DELETE FROM products_images WHERE products_attributes_id = 0 OR image_name = '';
  5.  
  6. INSERT INTO images (name, md5_hash)
  7. SELECT t.image_name, t.hash
  8. FROM (
  9.     SELECT MIN(pi.image_name) AS image_name, pi.hash
  10.     FROM products_images pi
  11.     LEFT JOIN images i ON i.md5_hash = pi.hash
  12.     WHERE i.images_id IS NULL AND pi.hash IS NOT NULL
  13.     GROUP BY pi.hash
  14. ) t;
  15.  
  16. UPDATE products_images pi
  17. JOIN images i ON i.md5_hash = pi.hash
  18. SET pi.images_id = i.images_id
  19. WHERE pi.images_id IS NULL
  20. ;
  21.  
  22. UPDATE products_images pi
  23. JOIN (
  24.     SELECT pi.products_attributes_id, MAX(COALESCE(pi1.image_nr, 0))+1 AS image_nr, MIN(pi1.images_id) AS min_image
  25.     FROM products_images pi
  26.     JOIN products_images pi1 ON pi1.products_attributes_id = pi.products_attributes_id
  27.     WHERE pi.image_nr IS NULL
  28.     GROUP BY pi.products_attributes_id
  29. ) t ON t.products_attributes_id = pi.products_attributes_id AND pi.images_id = t.min_image
  30. SET pi.image_nr = t.image_nr
  31. WHERE pi.image_nr IS NULL;
  32.  
  33. UPDATE products_images pi
  34. JOIN (
  35.     SELECT pi.products_attributes_id, MAX(COALESCE(pi1.image_nr, 0))+1 AS image_nr
  36.     FROM products_images pi
  37.     JOIN products_images pi1 ON pi1.products_attributes_id = pi.products_attributes_id
  38.     WHERE pi.image_nr IS NULL
  39.     GROUP BY pi.products_attributes_id
  40. ) t ON t.products_attributes_id = pi.products_attributes_id
  41. SET pi.image_nr = t.image_nr
  42. WHERE pi.image_nr IS NULL;
  43.  
  44.  
  45. ALTER TABLE call_rating_criterion ADD call_rating_criterion_prev_id INT NOT NULL DEFAULT 0 COMMENT 'Идентификатор критерия замещённого данным' AFTER call_rating_criterion_id;
  46. CREATE INDEX call_rating_criterion_prev_id_idx ON call_rating_criterion (call_rating_criterion_prev_id);
  47.  
  48. ALTER TABLE call_rating_illegal_events CHANGE COLUMN `events_rating_type` `events_rating_type` enum('CALL','MAIL','CALLBACK','BRAND') NOT NULL DEFAULT 'CALL';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement