USE lesotho_livestock;

CREATE TABLE IF NOT EXISTS sync_error_logs (
  id BIGINT AUTO_INCREMENT PRIMARY KEY,
  user_id INT NULL,
  device_id VARCHAR(120) NULL,
  request_uuid CHAR(36) NULL,
  client_uuid CHAR(36) NULL,
  error_code VARCHAR(80) NULL,
  error_message TEXT NOT NULL,
  record_payload JSON NULL,
  ip_address VARCHAR(64) NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX idx_sync_error_request (request_uuid),
  INDEX idx_sync_error_client (client_uuid),
  INDEX idx_sync_error_created (created_at),
  FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
);
