-- RE 메모(요구사항 [4][5]).
--
-- 회신 내용: "별도 양식까진 필요없고, 기관관리 메뉴의 RE 메뉴에서 메모장처럼 등록하는
-- 기능을 만들어 주시면 됩니다. 메모 1개당 RE 1개입니다."
--   예) ooo 계약서 및 제안요청서 송부 요청, 장영익, 2026.07.08
--
-- resolved(해결 여부)는 회신에 없던 항목이다. 대시보드 '미해결 RE' 숫자를 세려면 해결된
-- 건과 아닌 건을 가릴 수단이 있어야 해서 완료 체크 한 칸으로 두었다. 확인 요청해 둔 상태다.

create table re_memo (
    id          bigserial primary key,
    org_id      bigint       not null references organization (id) on delete cascade,
    content     text         not null,
    author      varchar(100) not null,
    memo_date   date         not null,
    resolved    boolean      not null default false,
    resolved_at timestamptz,
    created_at  timestamptz  not null default now(),
    updated_at  timestamptz  not null default now()
);

-- 기관별 최신순 조회와 미해결 건수 집계를 함께 받는 인덱스.
create index ix_re_memo_org on re_memo (org_id, memo_date desc, id desc);
create index ix_re_memo_unresolved on re_memo (org_id) where not resolved;
