SET DEFINE OFF;
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE QRTZ_FIRED_TRIGGERS';
EXCEPTION WHEN OTHERS THEN NULL;
END;
/
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE QRTZ_PAUSED_TRIGGER_GRPS';
EXCEPTION WHEN OTHERS THEN NULL;
END;
/
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE QRTZ_SCHEDULER_STATE';
EXCEPTION WHEN OTHERS THEN NULL;
END;
/
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE QRTZ_LOCKS';
EXCEPTION WHEN OTHERS THEN NULL;
END;
/
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE QRTZ_SIMPLE_TRIGGERS';
EXCEPTION WHEN OTHERS THEN NULL;
END;
/
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE QRTZ_SIMPROP_TRIGGERS';
EXCEPTION WHEN OTHERS THEN NULL;
END;
/
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE QRTZ_CRON_TRIGGERS';
EXCEPTION WHEN OTHERS THEN NULL;
END;
/
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE QRTZ_BLOB_TRIGGERS';
EXCEPTION WHEN OTHERS THEN NULL;
END;
/
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE QRTZ_TRIGGERS';
EXCEPTION WHEN OTHERS THEN NULL;
END;
/
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE QRTZ_JOB_DETAILS';
EXCEPTION WHEN OTHERS THEN NULL;
END;
/
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE QRTZ_CALENDARS';
EXCEPTION WHEN OTHERS THEN NULL;
END;
/

-- ----------------------------
-- 1、存储每一个已配置的 jobDetail 的详细信息
-- ----------------------------
create table QRTZ_JOB_DETAILS (
    sched_name           VARCHAR2(120)    not null           ,
    job_name             VARCHAR2(200)    not null           ,
    job_group            VARCHAR2(200)    not null           ,
    description          VARCHAR2(250)    null               ,
    job_class_name       VARCHAR2(250)    not null           ,
    is_durable           VARCHAR2(1)      not null           ,
    is_nonconcurrent     VARCHAR2(1)      not null           ,
    is_update_data       VARCHAR2(1)      not null           ,
    requests_recovery    VARCHAR2(1)      not null           ,
    job_data             BLOB            null               ,
    primary key (sched_name, job_name, job_group)
);

-- ----------------------------
-- 2、 存储已配置的 Trigger 的信息
-- ----------------------------
create table QRTZ_TRIGGERS (
    sched_name           VARCHAR2(120)    not null           ,
    trigger_name         VARCHAR2(200)    not null           ,
    trigger_group        VARCHAR2(200)    not null           ,
    job_name             VARCHAR2(200)    not null           ,
    job_group            VARCHAR2(200)    not null           ,
    description          VARCHAR2(250)    null               ,
    next_fire_time       BIGINT      null               ,
    prev_fire_time       BIGINT      null               ,
    priority             INT         null               ,
    trigger_state        VARCHAR2(16)     not null           ,
    trigger_type         VARCHAR2(8)      not null           ,
    start_time           BIGINT      not null           ,
    end_time             BIGINT      null               ,
    calendar_name        VARCHAR2(200)    null               ,
    misfire_instr        SMALLINT     null               ,
    job_data             BLOB            null               ,
    primary key (sched_name, trigger_name, trigger_group),
    foreign key (sched_name, job_name, job_group) references QRTZ_JOB_DETAILS(sched_name, job_name, job_group)
);

-- ----------------------------
-- 3、 存储简单的 Trigger，包括重复次数，间隔，以及已触发的次数
-- ----------------------------
create table QRTZ_SIMPLE_TRIGGERS (
    sched_name           VARCHAR2(120)    not null           ,
    trigger_name         VARCHAR2(200)    not null           ,
    trigger_group        VARCHAR2(200)    not null           ,
    repeat_count         BIGINT       not null           ,
    repeat_interval      BIGINT      not null           ,
    times_triggered      BIGINT      not null           ,
    primary key (sched_name, trigger_name, trigger_group),
    foreign key (sched_name, trigger_name, trigger_group) references QRTZ_TRIGGERS(sched_name, trigger_name, trigger_group)
);

-- ----------------------------
-- 4、 存储 Cron Trigger，包括 Cron 表达式和时区信息
-- ---------------------------- 
create table QRTZ_CRON_TRIGGERS (
    sched_name           VARCHAR2(120)    not null           ,
    trigger_name         VARCHAR2(200)    not null           ,
    trigger_group        VARCHAR2(200)    not null           ,
    cron_expression      VARCHAR2(200)    not null           ,
    time_zone_id         VARCHAR2(80)                        ,
    primary key (sched_name, trigger_name, trigger_group),
    foreign key (sched_name, trigger_name, trigger_group) references QRTZ_TRIGGERS(sched_name, trigger_name, trigger_group)
);

-- ----------------------------
-- 5、 Trigger 作为 Blob 类型存储(用于 Quartz 用户用 JDBC 创建他们自己定制的 Trigger 类型，JobStore 并不知道如何存储实例的时候)
-- ---------------------------- 
create table QRTZ_BLOB_TRIGGERS (
    sched_name           VARCHAR2(120)    not null           ,
    trigger_name         VARCHAR2(200)    not null           ,
    trigger_group        VARCHAR2(200)    not null           ,
    blob_data            BLOB            null               ,
    primary key (sched_name, trigger_name, trigger_group),
    foreign key (sched_name, trigger_name, trigger_group) references QRTZ_TRIGGERS(sched_name, trigger_name, trigger_group)
);

-- ----------------------------
-- 6、 以 Blob 类型存储存放日历信息， quartz可配置一个日历来指定一个时间范围
-- ---------------------------- 
create table QRTZ_CALENDARS (
    sched_name           VARCHAR2(120)    not null           ,
    calendar_name        VARCHAR2(200)    not null           ,
    calendar             BLOB            not null           ,
    primary key (sched_name, calendar_name)
);

-- ----------------------------
-- 7、 存储已暂停的 Trigger 组的信息
-- ---------------------------- 
create table QRTZ_PAUSED_TRIGGER_GRPS (
    sched_name           VARCHAR2(120)    not null           ,
    trigger_group        VARCHAR2(200)    not null           ,
    primary key (sched_name, trigger_group)
);

-- ----------------------------
-- 8、 存储与已触发的 Trigger 相关的状态信息，以及相联 Job 的执行信息
-- ---------------------------- 
create table QRTZ_FIRED_TRIGGERS (
    sched_name           VARCHAR2(120)    not null           ,
    entry_id             VARCHAR2(95)     not null           ,
    trigger_name         VARCHAR2(200)    not null           ,
    trigger_group        VARCHAR2(200)    not null           ,
    instance_name        VARCHAR2(200)    not null           ,
    fired_time           BIGINT      not null           ,
    sched_time           BIGINT      not null           ,
    priority             INT         not null           ,
    state                VARCHAR2(16)     not null           ,
    job_name             VARCHAR2(200)    null               ,
    job_group            VARCHAR2(200)    null               ,
    is_nonconcurrent     VARCHAR2(1)      null               ,
    requests_recovery    VARCHAR2(1)      null               ,
    primary key (sched_name, entry_id)
);

-- ----------------------------
-- 9、 存储少量的有关 Scheduler 的状态信息，假如是用于集群中，可以看到其他的 Scheduler 实例
-- ---------------------------- 
create table QRTZ_SCHEDULER_STATE (
    sched_name           VARCHAR2(120)    not null           ,
    instance_name        VARCHAR2(200)    not null           ,
    last_checkin_time    BIGINT      not null           ,
    checkin_interval     BIGINT      not null           ,
    primary key (sched_name, instance_name)
);

-- ----------------------------
-- 10、 存储程序的悲观锁的信息(假如使用了悲观锁)
-- ---------------------------- 
create table QRTZ_LOCKS (
    sched_name           VARCHAR2(120)    not null           ,
    lock_name            VARCHAR2(40)     not null           ,
    primary key (sched_name, lock_name)
);

-- ----------------------------
-- 11、 Quartz集群实现同步机制的行锁表
-- ---------------------------- 
create table QRTZ_SIMPROP_TRIGGERS (
    sched_name           VARCHAR2(120)    not null           ,
    trigger_name         VARCHAR2(200)    not null           ,
    trigger_group        VARCHAR2(200)    not null           ,
    str_prop_1           VARCHAR2(512)    null               ,
    str_prop_2           VARCHAR2(512)    null               ,
    str_prop_3           VARCHAR2(512)    null               ,
    int_prop_1           INT             null               ,
    int_prop_2           INT             null               ,
    long_prop_1          BIGINT          null               ,
    long_prop_2          BIGINT          null               ,
    dec_prop_1           NUMBER(13,4)   null               ,
    dec_prop_2           NUMBER(13,4)   null               ,
    bool_prop_1          VARCHAR2(1)      null               ,
    bool_prop_2          VARCHAR2(1)      null               ,
    primary key (sched_name, trigger_name, trigger_group),
    foreign key (sched_name, trigger_name, trigger_group) references QRTZ_TRIGGERS(sched_name, trigger_name, trigger_group)
);

commit;