USE `androidcast_crashes`;
CREATE TABLE IF NOT EXISTS builds (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    build_code VARCHAR(64) NOT NULL,
    status ENUM('queued','running','passed','failed','cancelled') NOT NULL DEFAULT 'queued',
    phase VARCHAR(64) NOT NULL DEFAULT 'init',
    git_ref VARCHAR(256) NULL,
    git_sha VARCHAR(64) NULL,
    branch VARCHAR(128) NULL,
    pipeline_yaml LONGTEXT NULL,
    params_json LONGTEXT NOT NULL,
    dockerfile_version VARCHAR(32) NOT NULL DEFAULT '00.01.00.1000',
    builder_id VARCHAR(128) NOT NULL DEFAULT 'local-docker',
    version_app VARCHAR(32) NULL,
    version_code INT NULL,
    target_os VARCHAR(32) NOT NULL DEFAULT 'android',
    min_api_level INT NOT NULL DEFAULT 24,
    ota_channel VARCHAR(64) NULL,
    auto_ota TINYINT(1) NOT NULL DEFAULT 0,
    auto_deploy TINYINT(1) NOT NULL DEFAULT 0,
    log_path VARCHAR(512) NULL,
    artifacts_json LONGTEXT NULL,
    error_message VARCHAR(512) NULL,
    created_by_user_id INT UNSIGNED NULL,
    started_at TIMESTAMP NULL,
    finished_at TIMESTAMP NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    UNIQUE KEY uq_builds_code (build_code),
    KEY idx_builds_status (status),
    KEY idx_builds_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
