create table
  public.ak_contents (
    id uuid not null default gen_random_uuid (),
    raw_content_id uuid null,
    title text not null,
    content text not null,
    summary text null,
    author character varying(128) null,
    source_url text null,
    original_language character varying(10) not null,
    category_id uuid null,
    tags text[] null,
    keywords text[] null,
    entities jsonb null,
    sentiment_score double precision null,
    readability_score double precision null,
    credibility_score double precision null,
    quality_score double precision null,
    view_count integer null default 0,
    like_count integer null default 0,
    share_count integer null default 0,
    comment_count integer null default 0,
    published_at timestamp with time zone null,
    featured_until timestamp with time zone null,
    status character varying(32) null default 'published'::character varying,
    ai_processed_at timestamp with time zone null,
    created_at timestamp with time zone null default now(),
    updated_at timestamp with time zone null default now(),
    favorite_count integer null default 0,
    is_featured boolean null default false,
    content_type character varying null default ''::character varying,
    video_url text null,
    video_duration integer null,
    video_poster text null,
    video_width integer null,
    video_height integer null,
    video_size bigint null,
    video_format character varying(10) null,
    video_quality character varying(10) null,
    audio_url text null,
    audio_duration integer null,
    audio_size bigint null,
    audio_format character varying(10) null,
    audio_bitrate integer null,
    audio_sample_rate integer null,
    audio_cover text null,
    image_url text null,
    image_width integer null,
    image_height integer null,
    image_size bigint null,
    image_format character varying(10) null,
    image_quality character varying(10) null,
    image_alt_text text null,
    images jsonb null,
    allow_danmu boolean null default true,
    allow_download boolean null default false,
    media_metadata jsonb null,
    cid bigserial,
    constraint ak_contents_pkey primary key (id),
    constraint ak_contents_cid_key unique (cid),
    constraint ak_contents_category_id_fkey foreign key (category_id) references ak_content_categories (id),
    constraint ak_contents_raw_content_id_fkey foreign key (raw_content_id) references ak_raw_contents (id) on delete cascade
  ) tablespace pg_default;

create index if not exists idx_contents_title_text on public.ak_contents using btree (title) tablespace pg_default;

create index if not exists idx_contents_favorite_count on public.ak_contents using btree (favorite_count desc) tablespace pg_default;

create index if not exists idx_contents_category on public.ak_contents using btree (category_id) tablespace pg_default;

create index if not exists idx_contents_language on public.ak_contents using btree (original_language) tablespace pg_default;

create index if not exists idx_contents_published on public.ak_contents using btree (published_at desc) tablespace pg_default;

create index if not exists idx_contents_quality on public.ak_contents using btree (quality_score desc) tablespace pg_default;

create index if not exists idx_contents_status on public.ak_contents using btree (status) tablespace pg_default;

create index if not exists idx_contents_type on public.ak_contents using btree (content_type) tablespace pg_default;

create index if not exists idx_contents_type_published on public.ak_contents using btree (content_type, published_at desc) tablespace pg_default;

create index if not exists idx_contents_images_gin on public.ak_contents using gin (images) tablespace pg_default;

create index if not exists idx_contents_tags on public.ak_contents using gin (tags) tablespace pg_default;