-- Migration: Add hashtag + full-text search support to posts
-- Created: 2026-01-12
-- Purpose: Make category optional while enabling tag storage and search vectors

-- 1) Make category optional to remove posting friction
alter table posts
  alter column category_id drop not null;

-- 2) Store extracted hashtags and full-text search vector
alter table posts
  add column if not exists tags text[] default '{}'::text[],
  add column if not exists fts tsvector
    generated always as (to_tsvector('english', coalesce(body, '')))
    stored;

-- 3) Index for fast full-text search lookups
create index if not exists idx_posts_fts on posts using gin (fts);
