-- Planning module — downtime table
-- Stores downtime entries per workstation per day
-- 2026-04-03
-- DROP+CREATE to replace old schema (date_start/date_end) with new schema (downtime_date/duration_minutes/category)

DROP TABLE IF EXISTS llx_planning_downtime;

CREATE TABLE llx_planning_downtime (
    rowid            INT UNSIGNED NOT NULL AUTO_INCREMENT,
    fk_ws            INT UNSIGNED NOT NULL,
    downtime_date    DATE NOT NULL,
    duration_minutes SMALLINT UNSIGNED NOT NULL DEFAULT 0,
    category         VARCHAR(100) NOT NULL DEFAULT '',
    note             VARCHAR(255) NULL,
    fk_user_creat    INT UNSIGNED NULL,
    entity           INT NOT NULL DEFAULT 1,
    tms              TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (rowid),
    KEY idx_dt_ws_date (entity, fk_ws, downtime_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
