-- Oracle tables for WMCore.BossAir component

CREATE TABLE bl_status (
    id            NUMBER(11)     GENERATED BY DEFAULT AS IDENTITY,
    name          VARCHAR2(255),
    CONSTRAINT bl_status_pk PRIMARY KEY (id),
    CONSTRAINT bl_status_uk UNIQUE (name)
)
/

CREATE TABLE bl_runjob (
    id            NUMBER(11)     GENERATED BY DEFAULT AS IDENTITY,
    wmbs_id       NUMBER(11),
    grid_id       VARCHAR2(255),
    bulk_id       VARCHAR2(255),
    status        CHAR(1)        DEFAULT '1',
    sched_status  NUMBER(11)     NOT NULL,
    retry_count   NUMBER(11),
    status_time   NUMBER(11),
    location      NUMBER(11),
    user_id       NUMBER(11),
    CONSTRAINT bl_runjob_pk PRIMARY KEY (id),
    CONSTRAINT bl_runjob_fk1 FOREIGN KEY (wmbs_id)
        REFERENCES wmbs_job(id) ON DELETE CASCADE,
    CONSTRAINT bl_runjob_fk2 FOREIGN KEY (sched_status)
        REFERENCES bl_status(id) ON DELETE CASCADE,
    CONSTRAINT bl_runjob_fk3 FOREIGN KEY (user_id)
        REFERENCES wmbs_users(id) ON DELETE CASCADE,
    CONSTRAINT bl_runjob_fk4 FOREIGN KEY (location)
        REFERENCES wmbs_location(id) ON DELETE CASCADE
)
/

-- Indexes
CREATE INDEX idx_bl_runjob_wmbs ON bl_runjob(wmbs_id)
/

CREATE INDEX idx_bl_runjob_status ON bl_runjob(sched_status)
/

CREATE INDEX idx_bl_runjob_users ON bl_runjob(user_id)
/

CREATE INDEX idx_bl_runjob_location ON bl_runjob(location)
/ 