CREATE DATABASE IF NOT EXISTS process_monitor
  CHARACTER SET utf8mb4
  COLLATE utf8mb4_unicode_ci;

USE process_monitor;

CREATE TABLE IF NOT EXISTS process_heartbeat (
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    machine_name VARCHAR(128) NOT NULL,
    status VARCHAR(32) NOT NULL,
    detected_at DATETIME(3) NOT NULL,
    process_name VARCHAR(255) NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id),
    KEY idx_process_heartbeat_machine_detected (machine_name, detected_at),
    KEY idx_process_heartbeat_process_detected (process_name, detected_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
