-- Phase A10  -  Knowledge Base
-- Hybrid storage: DB-primary articles editable in /admin/kb,
-- markdown seeds under docs/kb/*.md provide initial content if the DB row is missing.

CREATE TABLE IF NOT EXISTS kb_articles (
    id          INT UNSIGNED NOT NULL AUTO_INCREMENT,
    slug        VARCHAR(140) NOT NULL,
    title       VARCHAR(220) NOT NULL,
    category    VARCHAR(60)  NOT NULL DEFAULT 'general',
    body_md     MEDIUMTEXT   NOT NULL,
    is_published TINYINT(1)  NOT NULL DEFAULT 1,
    updated_by  INT UNSIGNED NULL,
    created_at  DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at  DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (id),
    UNIQUE KEY uniq_kb_slug (slug),
    KEY idx_kb_category (category),
    KEY idx_kb_published (is_published)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
