-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from Media-XI/feat/add-all-media-to-magazine-…
…content 매거진 미디어 URL 전체를 매거진 콘텐츠에 추가하는 SQL 프로시저
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/main/resources/db/migration/V202403051152__application.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |