SET NAMES utf8mb4;

ALTER TABLE integration_http_logs ADD COLUMN IF NOT EXISTS duration_ms INT NULL;

ALTER TABLE integrations
  MODIFY COLUMN status ENUM('active','inactive','warning','error') NOT NULL DEFAULT 'inactive';

ALTER TABLE content_components ADD COLUMN IF NOT EXISTS component_type ENUM('headline','body','cta') NULL;
ALTER TABLE content_components ADD COLUMN IF NOT EXISTS tags VARCHAR(500) NULL;
UPDATE content_components SET component_type=type WHERE component_type IS NULL AND type IS NOT NULL;
ALTER TABLE content_components MODIFY COLUMN component_type ENUM('headline','body','cta') NOT NULL;

ALTER TABLE media_library ADD COLUMN IF NOT EXISTS file_path VARCHAR(500) NULL;
ALTER TABLE media_library ADD COLUMN IF NOT EXISTS storage_path VARCHAR(500) NULL;
UPDATE media_library SET file_path=storage_path WHERE file_path IS NULL AND storage_path IS NOT NULL;

ALTER TABLE content_variants ADD COLUMN IF NOT EXISTS name VARCHAR(180) NULL;
ALTER TABLE content_variants ADD COLUMN IF NOT EXISTS fingerprint CHAR(64) NULL;
ALTER TABLE content_variants ADD COLUMN IF NOT EXISTS generated_at DATETIME NULL;

CREATE INDEX idx_ihttp_adapter_time ON integration_http_logs(adapter,created_at);
