-- Migration 059: Ensure ftt_apk_builds exists and add build-metadata columns.
-- These columns are populated by upload_apk.php from the toolkit --build-upload CLI/GUI.

CREATE TABLE IF NOT EXISTS ftt_apk_builds (
  id                  INT AUTO_INCREMENT PRIMARY KEY,
  filename            VARCHAR(255) NOT NULL,
  size                BIGINT       NOT NULL DEFAULT 0,
  changes_summary     TEXT         NULL,
  reason              TEXT         NULL,
  files_touched       TEXT         NULL,
  validation_updates  TEXT         NULL,
  created_at          DATETIME     NOT NULL,
  INDEX idx_ftt_apk_builds_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Add columns to existing table if it was created without them
ALTER TABLE ftt_apk_builds ADD COLUMN IF NOT EXISTS changes_summary    TEXT NULL;
ALTER TABLE ftt_apk_builds ADD COLUMN IF NOT EXISTS reason             TEXT NULL;
ALTER TABLE ftt_apk_builds ADD COLUMN IF NOT EXISTS files_touched      TEXT NULL;
ALTER TABLE ftt_apk_builds ADD COLUMN IF NOT EXISTS validation_updates TEXT NULL;
