-- +goose Up
CREATE TABLE IF NOT EXISTS file_processing_outbox_messages (
  id BINARY(16) NOT NULL,
  message_id VARCHAR(64) NOT NULL,
  kind VARCHAR(64) NOT NULL,
  job_type VARCHAR(64) NOT NULL,
  body LONGBLOB NOT NULL,
  attributes LONGBLOB NULL,
  message_group_id VARCHAR(128) NULL,
  deduplication_id VARCHAR(128) NULL,
  status VARCHAR(32) NOT NULL DEFAULT 'pending',
  attempts INT NOT NULL DEFAULT 0,
  available_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
  locked_at DATETIME(6) NULL,
  locked_by VARCHAR(64) NULL,
  published_at DATETIME(6) NULL,
  last_error TEXT NULL,
  correlation_id VARCHAR(64) NULL,
  trace_id VARCHAR(64) NULL,
  created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
  updated_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
  PRIMARY KEY (id),
  UNIQUE KEY uq_file_processing_outbox_message_id (message_id),
  KEY idx_file_processing_outbox_status_available (status, available_at),
  KEY idx_file_processing_outbox_locked_at (locked_at),
  KEY idx_file_processing_outbox_kind (kind),
  KEY idx_file_processing_outbox_job_type (job_type),
  KEY idx_file_processing_outbox_correlation (correlation_id),
  KEY idx_file_processing_outbox_trace (trace_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- +goose Down
DROP TABLE IF EXISTS file_processing_outbox_messages;
