CREATE TABLE ohs_alert_rules (
    id SERIAL,
    location varchar(255) DEFAULT NULL,
    type varchar(50) DEFAULT NULL,
    severity varchar(50) DEFAULT NULL,
    tenant_id INTEGER DEFAULT NULL,
    branch_id INTEGER DEFAULT NULL,
    isDeleted BOOLEAN NOT NULL DEFAULT FALSE,
    updatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id)
);


CREATE TABLE alert_recipients (
    id SERIAL,
    user_id INTEGER DEFAULT NULL,
    email varchar(255) DEFAULT NULL,
    phone varchar(50) DEFAULT NULL,
    send_email BOOLEAN DEFAULT FALSE,
    send_sms BOOLEAN DEFAULT FALSE,
    send_push BOOLEAN DEFAULT FALSE,
    tenant_id INTEGER DEFAULT NULL,
    branch_id INTEGER DEFAULT NULL,
    isDeleted BOOLEAN NOT NULL DEFAULT FALSE,
    updatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id)
);


CREATE TABLE ohs_alert_rules2alert_recipients (
    id SERIAL,
    rule_id INTEGER NOT NULL,
    recipient_id INTEGER NOT NULL,
    tenant_id INTEGER DEFAULT NULL,
    branch_id INTEGER DEFAULT NULL,
    isDeleted BOOLEAN NOT NULL DEFAULT FALSE,
    updatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id)
);
CREATE INDEX ohs_alert_rules2alert_recipients_rule_idx ON ohs_alert_rules2alert_recipients(rule_id);
CREATE INDEX ohs_alert_rules2alert_recipients_recipient_idx ON ohs_alert_rules2alert_recipients(recipient_id);

