현재 네이버 뉴스 검색 결과를 실시간으로만 보여주는 구조에서, Supabase를 연동하여 검색 이력과 뉴스 결과를 영구 저장하고 관리하는 기능을 추가한다.
SUPABASE_SCHEMA.md 에 정의된 search_history / search_results 테이블 준수search_results.is_permanent (영구 저장 플래그)search_history 테이블 (변경 없음)create table public.search_history (
id uuid primary key default uuid_generate_v4(),
keyword text not null,
searched_at timestamp with time zone not null default now(),
last_build_date timestamp with time zone,
total_results integer
);
create index idx_search_history_searched_at on public.search_history (searched_at desc);
search_results 테이블 (컬럼 1개 추가)create table public.search_results (
id uuid primary key default uuid_generate_v4(),
search_id uuid not null references public.search_history(id) on delete cascade,
title text not null,
original_link text,
naver_link text,
description text,
pub_date timestamp with time zone,
is_permanent boolean not null default false -- ★ 영구 저장 플래그
);
create index idx_search_results_search_id on public.search_results (search_id);
create index idx_search_results_is_permanent on public.search_results (is_permanent)
where is_permanent = true;
핵심 동작:
search_history행 삭제 시ON DELETE CASCADE로 연결된search_results가 자동 삭제된다. 단,is_permanent = true인 행은 별도 API에서 cascade 전에search_id를 NULL로 해제 하거나, 삭제 전is_permanent행을 미리 걸러 보호하는 로직을 API 레이어에서 처리한다.
is_permanent 보호 전략search_id에 속한 is_permanent = true 기사 수를 조회.is_permanent = true 행의 search_id를 NULL로 업데이트 → 이후 search_history 행 삭제 (cascade).search_id가 NULL인 영구저장 기사는 "저장 기사" 탭에서 별도 표시.search_results.search_id를 nullable로 변경:
alter table public.search_results
alter column search_id drop not null;