-- V3__init_teal.sql (MySQL)
-- TEAL versions and entries

CREATE TABLE teal_versions (
    id              BIGINT AUTO_INCREMENT PRIMARY KEY,
    project_id      BIGINT NOT NULL,
    version_number  INT NOT NULL,
    effective_date  DATE NOT NULL,
    description     VARCHAR(500) CHARACTER SET utf8mb4,
    status          VARCHAR(20) DEFAULT 'DRAFT',
    uploaded_by     BIGINT,
    created_at      DATETIME DEFAULT NOW(),
    UNIQUE (project_id, version_number),
    CONSTRAINT fk_teal_ver_project FOREIGN KEY (project_id) REFERENCES projects(id),
    CONSTRAINT fk_teal_ver_uploader FOREIGN KEY (uploaded_by) REFERENCES users(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE teal_entries (
    id               BIGINT AUTO_INCREMENT PRIMARY KEY,
    teal_version_id  BIGINT NOT NULL,
    canonical_wbs_id BIGINT,
    activity_code    VARCHAR(100) NOT NULL,
    activity_name    VARCHAR(500) CHARACTER SET utf8mb4,
    discipline       VARCHAR(50),
    is_active        TINYINT(1) DEFAULT 1,
    CONSTRAINT fk_teal_entry_version FOREIGN KEY (teal_version_id) REFERENCES teal_versions(id),
    CONSTRAINT fk_teal_entry_cwbs FOREIGN KEY (canonical_wbs_id) REFERENCES canonical_wbs(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
