-- Oracle tables for WMCore.Agent.Database component

-- Create tables
CREATE TABLE wm_init (
    init_param VARCHAR2(100) NOT NULL,
    init_value VARCHAR2(100) NOT NULL,
    CONSTRAINT wm_init_uniq UNIQUE (init_param)
)
/

CREATE TABLE wm_components (
    id               NUMBER(11)     GENERATED BY DEFAULT AS IDENTITY,
    name             VARCHAR2(255)  NOT NULL,
    pid              NUMBER(11)     NOT NULL,
    update_threshold NUMBER(11)     NOT NULL,
    CONSTRAINT wm_components_pk PRIMARY KEY (id),
    CONSTRAINT wm_components_uniq UNIQUE (name)
)
/

CREATE TABLE wm_workers (
    component_id    NUMBER(11)     NOT NULL,
    name           VARCHAR2(255)   NOT NULL,
    last_updated   NUMBER(11)     NOT NULL,
    state          VARCHAR2(255),
    pid            NUMBER(11),
    poll_interval  NUMBER(11)     NOT NULL,
    last_error     NUMBER(11),
    cycle_time     NUMBER(10,4)   DEFAULT 0 NOT NULL,
    outcome        VARCHAR2(1000),
    error_message  VARCHAR2(1000),
    CONSTRAINT wm_workers_uniq UNIQUE (name),
    CONSTRAINT wm_workers_fk_comp FOREIGN KEY (component_id) 
        REFERENCES wm_components(id)
)
/