Skip to content

Commit

Permalink
Merge pull request #152 from Media-XI/feat/add-all-media-to-magazine-…
Browse files Browse the repository at this point in the history
…content

매거진 미디어 URL 전체를 매거진 콘텐츠에 추가하는 SQL 프로시저
  • Loading branch information
Hoon9901 authored Mar 18, 2024
2 parents 4e4f57e + e1b239c commit 50d0dd5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/main/resources/db/migration/V202403051152__application.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 매거진 미디어 전체를 매거진 콘텐츠에 추가합니다.
# 작성자 : Hoon9901 (shonn.dev@gmail.com)
# 작성 날짜 : 2024-03-18
# 현재 버전 : V202403051152 (이전 버전 : V202403051151__application.sql)

DELIMITER $$
CREATE PROCEDURE add_all_media_to_content()
BEGIN
DECLARE done BOOLEAN DEFAULT FALSE;
DECLARE p_magazine_id INT;
DECLARE p_url VARCHAR(512);
DECLARE cur CURSOR FOR
SELECT m.magazine_id, mm.url
FROM magazine m
INNER JOIN magazine_media mm ON (m.magazine_id = mm.magazine_id);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; # NOT FOUND -> done true
START TRANSACTION;
OPEN cur;
l:
LOOP
FETCH cur INTO p_magazine_id, p_url;
IF done THEN
LEAVE l;
END IF;
UPDATE magazine m
SET content = CONCAT('![](https://cdn.artscope.kr/', p_url, ')', ' ', content)
WHERE m.magazine_id = p_magazine_id;
END LOOP;
CLOSE cur;
COMMIT;
END$$
DELIMITER ;

CALL add_all_media_to_content();
DROP PROCEDURE add_all_media_to_content;

0 comments on commit 50d0dd5

Please sign in to comment.