234 lines
11 KiB
SQL
234 lines
11 KiB
SQL
-- ═══════════════════════════════════════════════════════════════════════
|
|
-- DB 전체 정리 + 데이터 보강 스크립트
|
|
-- 실행 위치: Supabase SQL Editor
|
|
-- 작성일: 2026-04-07
|
|
--
|
|
-- 처리 내용:
|
|
-- 1. 중복/테스트/미완성 레코드 삭제 (53건)
|
|
-- 2. 병원당 최신 complete 1건만 유지 (5건)
|
|
-- 3. 모든 레코드에 lead_doctor + gangnamUnni 데이터 보강
|
|
-- 4. 영문 clinic_name 한글로 정규화
|
|
-- 5. 추적 파라미터가 붙은 URL 클린 URL로 정규화
|
|
-- ═══════════════════════════════════════════════════════════════════════
|
|
|
|
|
|
-- ── STEP 0: 실행 전 현황 확인 ──────────────────────────────────────────
|
|
SELECT
|
|
id, clinic_name, status,
|
|
channel_data->'gangnamUnni'->>'rating' AS gu_rating,
|
|
report->'clinicInfo'->'leadDoctor'->>'name' AS lead_doctor,
|
|
created_at::date AS date
|
|
FROM marketing_reports
|
|
ORDER BY created_at DESC;
|
|
|
|
|
|
-- ── STEP 1: 불필요한 레코드 삭제 ───────────────────────────────────────
|
|
-- 유지할 레코드 5건 (병원당 최신 complete 1건):
|
|
-- 1b838500 → 뷰성형외과 (viewclinic.com) ✅ 이미 완비
|
|
-- 89595bef → 바노바기성형외과 (banobagi.com)
|
|
-- 6c9e8bcb → 아이디병원 (idhospital.com)
|
|
-- 9edb276c → 그랜드성형외과 (grandsurgery.com)
|
|
-- 478d9128 → 디에이성형외과 (daprs.com)
|
|
|
|
DELETE FROM marketing_reports
|
|
WHERE id NOT IN (
|
|
'1b838500-0bca-404c-97e6-2efbd17a2e21',
|
|
'89595bef-a1bf-489e-aba9-348a08bd4d06',
|
|
'6c9e8bcb-153e-4e1f-b7b2-a48acd4d7917',
|
|
'9edb276c-b99b-4326-82fe-e6f5ed1f592b',
|
|
'478d9128-c1d0-45a2-b852-c211ece73270'
|
|
);
|
|
|
|
-- 삭제 확인
|
|
SELECT COUNT(*) AS remaining_count FROM marketing_reports;
|
|
|
|
|
|
-- ── STEP 2: 바노바기성형외과 (89595bef) ────────────────────────────────
|
|
-- 강남언니: 평점 9.2 / 리뷰 6,843 / 대표원장 반재상·오창현 (공동)
|
|
UPDATE marketing_reports SET
|
|
clinic_name = '바노바기성형외과',
|
|
url = 'https://www.banobagi.com/',
|
|
channel_data = channel_data || jsonb_build_object(
|
|
'gangnamUnni', jsonb_build_object(
|
|
'name', '바노바기성형외과의원',
|
|
'rating', 9.2,
|
|
'rawRating', 9.2,
|
|
'ratingScale', '/10',
|
|
'totalReviews', 6843,
|
|
'doctors', jsonb_build_array(
|
|
jsonb_build_object('name','반재상','specialty','성형외과 대표원장','rating',9.7,'reviews',678),
|
|
jsonb_build_object('name','오창현','specialty','성형외과 대표원장','rating',9.7,'reviews',543),
|
|
jsonb_build_object('name','권희연','specialty','성형외과','rating',9.6,'reviews',687),
|
|
jsonb_build_object('name','박선재','specialty','성형외과','rating',8.9,'reviews',92)
|
|
),
|
|
'procedures', jsonb_build_array('눈성형','코성형','안면윤곽/양악','가슴성형','지방성형','필러','보톡스','리프팅','모발이식'),
|
|
'address', '서울 강남구 논현로 517',
|
|
'badges', jsonb_build_array('마취과 전문의 상주','수술실 CCTV','여성 의사 진료','분야별 공동 진료','시술 후 관리','의료진 실명 공개','입원 시설','응급 대응 체계','야간진료'),
|
|
'sourceUrl', 'https://www.gangnamunni.com/hospitals/23'
|
|
)
|
|
),
|
|
report = jsonb_set(
|
|
jsonb_set(
|
|
report,
|
|
'{clinicInfo,leadDoctor}',
|
|
'{"name":"반재상","specialty":"성형외과 대표원장 (공동대표)","rating":9.7,"reviewCount":678}'::jsonb
|
|
),
|
|
'{clinicInfo,staffCount}', '20'::jsonb
|
|
),
|
|
scrape_data = COALESCE(scrape_data, '{}'::jsonb) || jsonb_build_object(
|
|
'source', 'registry',
|
|
'registryData', jsonb_build_object(
|
|
'district','강남',
|
|
'brandGroup','프리미엄/하이타깃',
|
|
'naverPlaceUrl','https://m.place.naver.com/hospital/21033469',
|
|
'gangnamUnniUrl','https://www.gangnamunni.com/hospitals/23'
|
|
)
|
|
)
|
|
WHERE id = '89595bef-a1bf-489e-aba9-348a08bd4d06';
|
|
|
|
|
|
-- ── STEP 3: 아이디병원 (6c9e8bcb) ────────────────────────────────────
|
|
-- 강남언니: 평점 9.5 / 리뷰 14,933 / 대표원장 박상훈 (리뷰 9,058건)
|
|
UPDATE marketing_reports SET
|
|
clinic_name = '아이디병원',
|
|
url = 'https://www.idhospital.com/',
|
|
channel_data = channel_data || jsonb_build_object(
|
|
'gangnamUnni', jsonb_build_object(
|
|
'name', '아이디병원-본원',
|
|
'rating', 9.5,
|
|
'rawRating', 9.5,
|
|
'ratingScale', '/10',
|
|
'totalReviews', 14933,
|
|
'doctors', jsonb_build_array(
|
|
jsonb_build_object('name','박상훈','specialty','성형외과 대표원장 (안면윤곽/양악)','rating',9.8,'reviews',9058),
|
|
jsonb_build_object('name','이지혁','specialty','성형외과','rating',9.2,'reviews',225),
|
|
jsonb_build_object('name','황인석','specialty','성형외과','rating',9.5,'reviews',215),
|
|
jsonb_build_object('name','이근석','specialty','이비인후과','rating',9.1,'reviews',87)
|
|
),
|
|
'procedures', jsonb_build_array('양악수술','안면윤곽','눈성형','코성형','가슴성형','리프팅','피부클리닉','치과'),
|
|
'address', '서울 강남구 도산대로 142',
|
|
'badges', jsonb_build_array('수술실 CCTV','마취과 전문의 상주','시술 후 관리','의료진 실명 공개','여성 의사 진료','입원 시설','전용 휴식 공간','야간진료','응급 대응 체계'),
|
|
'sourceUrl', 'https://www.gangnamunni.com/hospitals/257'
|
|
)
|
|
),
|
|
report = jsonb_set(
|
|
jsonb_set(
|
|
report,
|
|
'{clinicInfo,leadDoctor}',
|
|
'{"name":"박상훈","specialty":"성형외과 대표원장 (안면윤곽/양악 특화)","rating":9.8,"reviewCount":9058}'::jsonb
|
|
),
|
|
'{clinicInfo,staffCount}', '35'::jsonb
|
|
),
|
|
scrape_data = COALESCE(scrape_data, '{}'::jsonb) || jsonb_build_object(
|
|
'source', 'registry',
|
|
'registryData', jsonb_build_object(
|
|
'district','강남',
|
|
'branches','아이디병원 별관(역삼)',
|
|
'brandGroup','프리미엄/하이타깃',
|
|
'naverPlaceUrl','https://m.place.naver.com/hospital/11548359',
|
|
'gangnamUnniUrl','https://www.gangnamunni.com/hospitals/257'
|
|
)
|
|
)
|
|
WHERE id = '6c9e8bcb-153e-4e1f-b7b2-a48acd4d7917';
|
|
|
|
|
|
-- ── STEP 4: 그랜드성형외과 (9edb276c) ────────────────────────────────
|
|
-- 강남언니: 평점 9.8 / 리뷰 1,531 / 대표원장 이세환 (압구정)
|
|
UPDATE marketing_reports SET
|
|
clinic_name = '그랜드성형외과',
|
|
url = 'https://www.grandsurgery.com/',
|
|
channel_data = channel_data || jsonb_build_object(
|
|
'gangnamUnni', jsonb_build_object(
|
|
'name', '그랜드성형외과의원',
|
|
'rating', 9.8,
|
|
'rawRating', 9.8,
|
|
'ratingScale', '/10',
|
|
'totalReviews', 1531,
|
|
'doctors', jsonb_build_array(
|
|
jsonb_build_object('name','이세환','specialty','성형외과 대표원장','rating',9.7,'reviews',562),
|
|
jsonb_build_object('name','김주희','specialty','성형외과','rating',9.6,'reviews',108),
|
|
jsonb_build_object('name','이승현','specialty','마취통증의학과','rating',9.0,'reviews',3)
|
|
),
|
|
'procedures', jsonb_build_array('피부','코성형','눈성형','보톡스','필러','리프팅','가슴성형','지방성형'),
|
|
'address', '서울 강남구 논현로 841 (신사동) 6층',
|
|
'badges', jsonb_build_array('분야별 공동 진료','응급 대응 체계','시술 후 관리','전용 휴식 공간','입원 시설','마취과 전문의 상주','의료진 실명 공개','성형외과 전문의 진료','여성 의사 진료'),
|
|
'sourceUrl', 'https://www.gangnamunni.com/hospitals/62'
|
|
)
|
|
),
|
|
report = jsonb_set(
|
|
jsonb_set(
|
|
report,
|
|
'{clinicInfo,leadDoctor}',
|
|
'{"name":"이세환","specialty":"성형외과 대표원장 (압구정 그랜드)","rating":9.7,"reviewCount":562}'::jsonb
|
|
),
|
|
'{clinicInfo,staffCount}', '12'::jsonb
|
|
),
|
|
scrape_data = COALESCE(scrape_data, '{}'::jsonb) || jsonb_build_object(
|
|
'source', 'registry',
|
|
'registryData', jsonb_build_object(
|
|
'district','압구정/신사',
|
|
'brandGroup','부티크/전문클리닉',
|
|
'gangnamUnniUrl','https://www.gangnamunni.com/hospitals/62'
|
|
)
|
|
)
|
|
WHERE id = '9edb276c-b99b-4326-82fe-e6f5ed1f592b';
|
|
|
|
|
|
-- ── STEP 5: 디에이성형외과 (478d9128) ────────────────────────────────
|
|
-- 강남언니: 평점 9.6 / 리뷰 69,859 (최대!) / 대표원장 이상우
|
|
UPDATE marketing_reports SET
|
|
clinic_name = '디에이성형외과',
|
|
url = 'https://www.daprs.com/',
|
|
channel_data = channel_data || jsonb_build_object(
|
|
'gangnamUnni', jsonb_build_object(
|
|
'name', '디에이성형외과의원',
|
|
'rating', 9.6,
|
|
'rawRating', 9.6,
|
|
'ratingScale', '/10',
|
|
'totalReviews', 69859,
|
|
'doctors', jsonb_build_array(
|
|
jsonb_build_object('name','이상우','specialty','성형외과 대표원장','rating',9.5,'reviews',1115),
|
|
jsonb_build_object('name','양희재','specialty','성형외과','rating',9.4,'reviews',3632),
|
|
jsonb_build_object('name','구현국','specialty','성형외과','rating',9.5,'reviews',2264),
|
|
jsonb_build_object('name','김경회','specialty','성형외과','rating',9.7,'reviews',312)
|
|
),
|
|
'procedures', jsonb_build_array('눈성형','코성형','안면윤곽','가슴성형','지방성형','필러','보톡스','리프팅','피부'),
|
|
'address', '서울 강남구 역삼동',
|
|
'badges', jsonb_build_array('수술실 CCTV','마취과 전문의 상주','분야별 공동 진료','시술 후 관리','의료진 실명 공개','입원 시설','응급 대응 체계'),
|
|
'sourceUrl', 'https://www.gangnamunni.com/hospitals/250'
|
|
)
|
|
),
|
|
report = jsonb_set(
|
|
jsonb_set(
|
|
report,
|
|
'{clinicInfo,leadDoctor}',
|
|
'{"name":"이상우","specialty":"성형외과 대표원장","rating":9.5,"reviewCount":1115}'::jsonb
|
|
),
|
|
'{clinicInfo,staffCount}', '18'::jsonb
|
|
),
|
|
scrape_data = COALESCE(scrape_data, '{}'::jsonb) || jsonb_build_object(
|
|
'source', 'registry',
|
|
'registryData', jsonb_build_object(
|
|
'district','강남/역삼',
|
|
'brandGroup','볼륨/대중브랜드',
|
|
'gangnamUnniUrl','https://www.gangnamunni.com/hospitals/250'
|
|
)
|
|
)
|
|
WHERE id = '478d9128-c1d0-45a2-b852-c211ece73270';
|
|
|
|
|
|
-- ── STEP 6: 최종 검증 ────────────────────────────────────────────────
|
|
SELECT
|
|
id,
|
|
clinic_name,
|
|
url,
|
|
status,
|
|
channel_data->'gangnamUnni'->>'rating' AS gu_rating,
|
|
channel_data->'gangnamUnni'->>'totalReviews' AS gu_reviews,
|
|
report->'clinicInfo'->'leadDoctor'->>'name' AS lead_doctor,
|
|
report->'clinicInfo'->>'staffCount' AS staff_count,
|
|
scrape_data->>'source' AS source,
|
|
scrape_data->'registryData'->>'district' AS district
|
|
FROM marketing_reports
|
|
ORDER BY created_at DESC;
|