-- Planning Capacity — default available hours per workstation
-- One row per workstation: the default capacity_hours_per_day for that machine.
-- Per-date overrides live in llx_planning_capacity_override.
-- PHASE 4 — created 2026-03-27

SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS llx_planning_capacity (
    rowid                  INT UNSIGNED NOT NULL AUTO_INCREMENT,
    fk_workstation         INT UNSIGNED NOT NULL,              -- llx_workstation_workstation.rowid
    capacity_hours_per_day DECIMAL(4,1) NOT NULL DEFAULT 12,  -- default shift length (hours)
    entity                 INT NOT NULL DEFAULT 1,
    tms                    TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,

    PRIMARY KEY (rowid),
    UNIQUE KEY uq_cap_ws (fk_workstation, entity),
    KEY idx_cap_entity (entity),
    KEY idx_cap_ws     (entity, fk_workstation)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
