-- 20260516 ChatGPT
-- $Header$
--
-- Example:
--   cd /usr/local/src/ble-reticulum/migration
--   sqlite3 ble_migration.sqlite ".read sql/ble_migration_schema.sql"
-- Verify
--   sqlite3 ble_migration.sqlite ".tables"
--   sqlite3 ble_migration.sqlite ".schema symbols"
--
-- Purpose:
--   Track symbol-by-symbol migration status for BLE Reticulum protocol extraction.

CREATE TABLE IF NOT EXISTS symbols (
    symbol_id       INTEGER PRIMARY KEY AUTOINCREMENT,
    source_file     TEXT NOT NULL,
    symbol_name     TEXT NOT NULL,
    symbol_type     TEXT,
    class_name      TEXT,
    line_number     INTEGER,
    tag             TEXT DEFAULT 'UNKNOWN',
    phase           TEXT DEFAULT '0_inventory',
    status          TEXT DEFAULT 'DISCOVERED',
    cpp_candidate   INTEGER DEFAULT 0,
    confidence      TEXT DEFAULT 'unknown',
    rationale       TEXT,
    callers         TEXT,
    callees         TEXT,
    notes           TEXT,
    first_seen_at   TEXT DEFAULT CURRENT_TIMESTAMP,
    updated_at      TEXT DEFAULT CURRENT_TIMESTAMP,

    UNIQUE(source_file, class_name, symbol_name, line_number)
);

CREATE TABLE IF NOT EXISTS reviews (
    review_id       INTEGER PRIMARY KEY AUTOINCREMENT,
    symbol_id       INTEGER NOT NULL REFERENCES symbols(symbol_id),
    reviewed_at     TEXT DEFAULT CURRENT_TIMESTAMP,
    reviewer        TEXT,
    old_tag         TEXT,
    new_tag         TEXT,
    old_status      TEXT,
    new_status      TEXT,
    note            TEXT
);

CREATE INDEX IF NOT EXISTS symbols_tag_idx
    ON symbols(tag);

CREATE INDEX IF NOT EXISTS symbols_status_idx
    ON symbols(status);

CREATE INDEX IF NOT EXISTS symbols_phase_idx
    ON symbols(phase);

CREATE INDEX IF NOT EXISTS symbols_cpp_candidate_idx
    ON symbols(cpp_candidate);