-- ACE2 - Upload ZIP/CSV por streaming y modulo de reseteo
-- Ejecutar sobre la base ACE2 actual antes de subir ZIP grandes.

SET NAMES utf8mb4;

ALTER TABLE ace2_upload_batches
    ADD COLUMN IF NOT EXISTS upload_kind ENUM('csv','zip') NOT NULL DEFAULT 'csv' AFTER id,
    ADD COLUMN IF NOT EXISTS original_archive_filename VARCHAR(255) NULL AFTER original_filename,
    ADD COLUMN IF NOT EXISTS current_byte_offset BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER current_row,
    ADD COLUMN IF NOT EXISTS cleanup_file_on_complete TINYINT(1) NOT NULL DEFAULT 1 AFTER current_byte_offset,
    ADD COLUMN IF NOT EXISTS cleanup_done TINYINT(1) NOT NULL DEFAULT 0 AFTER cleanup_file_on_complete;

CREATE TABLE IF NOT EXISTS ace2_reset_runs (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    status ENUM('completed','failed') NOT NULL DEFAULT 'completed',
    confirmation_text VARCHAR(120) NOT NULL,
    tables_cleared INT UNSIGNED NOT NULL DEFAULT 0,
    error_message VARCHAR(500) NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id),
    KEY idx_ace2_reset_runs_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
