From e1b239ce6b4309f2c5d1f32fb0f803ecf24da663 Mon Sep 17 00:00:00 2001 From: Hoon9901 Date: Mon, 18 Mar 2024 23:01:22 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=A7=A4=EA=B1=B0=EC=A7=84=20=EB=AF=B8?= =?UTF-8?q?=EB=94=94=EC=96=B4=20URL=20=EC=A0=84=EC=B2=B4=EB=A5=BC=20?= =?UTF-8?q?=EB=A7=A4=EA=B1=B0=EC=A7=84=20=EC=BD=98=ED=85=90=EC=B8=A0?= =?UTF-8?q?=EC=97=90=20=EC=B6=94=EA=B0=80=ED=95=98=EB=8A=94=20SQL=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=EC=8B=9C=EC=A0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migration/V202403051152__application.sql | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/resources/db/migration/V202403051152__application.sql diff --git a/src/main/resources/db/migration/V202403051152__application.sql b/src/main/resources/db/migration/V202403051152__application.sql new file mode 100644 index 00000000..27a2546c --- /dev/null +++ b/src/main/resources/db/migration/V202403051152__application.sql @@ -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; \ No newline at end of file