-- Migration 033: email_warmup_pool table for deliverability service.
-- Keeps track of connected email integrations that have opted into the warmup pool.

CREATE TABLE IF NOT EXISTS warmup_pool (
    id              BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    org_id          BIGINT UNSIGNED NOT NULL,
    integration_id  BIGINT UNSIGNED NOT NULL,
    status          ENUM('active','paused') NOT NULL DEFAULT 'active',
    daily_limit     INT UNSIGNED NOT NULL DEFAULT 5,
    created_at      DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,

    PRIMARY KEY (id),
    UNIQUE KEY uq_warmup_pool (org_id, integration_id),
    CONSTRAINT fk_warmup_org FOREIGN KEY (org_id) REFERENCES organizations(id) ON DELETE CASCADE,
    CONSTRAINT fk_warmup_int FOREIGN KEY (integration_id) REFERENCES integrations(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
