CREATE TABLE NotifyScheduler
(
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    Notification BIGINT UNSIGNED DEFAULT NULL COMMENT "Identifier of a specific launch. NotificationLaunch Node id.",
    NotificationPriority SmallINT UNSIGNED DEFAULT 32000 COMMENT "Priority of this notification relative to other notifications",
    Person BIGINT UNSIGNED DEFAULT NULL COMMENT "Identifier of the target to be contacted. Person Node id to be contacted.",
    PersonPriority SmallINT UNSIGNED DEFAULT 32000 COMMENT "Priority of this target relative to the other targets in the scheduler",
    NextRetry BIGINT UNSIGNED DEFAULT 0 COMMENT "Time at which the NS will be allowed to work with this entry.  This can be used to schedule a communications in the future.",
    LockId CHAR(32) DEFAULT NULL COMMENT "Field used to allow multiple process to work on the same queue",
    IsActive INT DEFAULT 0 COMMENT "Whether or not the row is active (0: paused/inactive, 1: active)",
    StartTs BIGINT UNSIGNED DEFAULT NULL COMMENT "When this row was created, this represents when the launch occurred.",
    IsInit TINYINT(1) DEFAULT 0 COMMENT "If = 1, it means we already tried to contact the person once and have been through the NotifyMethodChooser initialization.",
    PRIMARY KEY ( id ),
    UNIQUE KEY Person_2 ( Person,Notification ),
    KEY Person ( Person ),
    KEY LockId ( LockId,NextRetry,NotificationPriority,Notification,PersonPriority,id ),
    KEY Notification ( Notification ),
    FOREIGN KEY ( Person ) REFERENCES Person ( id) ON DELETE RESTRICT ON UPDATE RESTRICT,
    FOREIGN KEY ( Notification ) REFERENCES NotificationLaunch ( id) ON DELETE RESTRICT ON UPDATE RESTRICT

) ENGINE=INNODB CHARSET=UTF8 COMMENT="People we still have to reach for the given notification";
