CREATE TABLE NotifyJobQueue
(
    id BIGINT UNSIGNED DEFAULT NULL,
    Launch BIGINT UNSIGNED NOT NULL COMMENT "Launch Id associated to the job entry",
    Zone BIGINT UNSIGNED NOT NULL COMMENT "Zone of the job entry. Could be deduced from Launch, but put here for performance reasons while managing channel limits.",
    Node BIGINT UNSIGNED NOT NULL COMMENT "Node Id of object to be contacted. Typically a Person node.",

    /* FOREIGN KEY(Node) REFERENCES nodes(id), */

    Method BIGINT UNSIGNED NOT NULL COMMENT "Method node ID (SMS node, Email node, Phone node). This represents the one an only communication method used for this job.",

    /* FOREIGN KEY(Method) REFERENCES nodes(id), */

    Priority BIGINT UNSIGNED NOT NULL DEFAULT 32000 COMMENT "Priority of this job.  Higher priority jobs must be processed first by the NM. Priority is set by the NS object.",
    Interface VARCHAR(35) NOT NULL COMMENT "Class name of the NM that shall handle this communication. The class must implement the NotifyMethodInterface.",
    Address VARCHAR(35) NOT NULL COMMENT "Phone number, email address, etc, for detecting duplicates XXX Not sure this is the right place.",
    LastTs BIGINT UNSIGNED DEFAULT NULL COMMENT "Indicates the last time we tried to work this row.",
    LockId CHAR(32) DEFAULT NULL,
    Status ENUM("QUEUE", "WORKING", "PAUSED", "SENT", "LISTEN_BLOCKING", "LISTEN_NONBLOCKING", "ACK", "NOACK", "TEMPFAIL", "PERMFAIL") DEFAULT "QUEUE" COMMENT "Status of the job.",
    ts BIGINT UNSIGNED DEFAULT NULL COMMENT "Timestamp set at job creation.",
    PRIMARY KEY ( id ) AUTO_INCREMENT,
    KEY ( LockId ),
    UNIQUE KEY ( Launch,Node,Method ),
    KEY ( Method,Status,LastTs,LockId ),
    KEY ( Method,Zone,Status,LastTs,LockId ),
    KEY ( Status ),
    KEY ( Interface,Method )

) ENGINE=INNODB CHARSET=UTF8;
