-- ----------------------------
-- 1¡¢´æ´¢Ã¿Ò»¸öÒÑÅäÖÃµÄ jobDetail µÄÏêÏ¸ÐÅÏ¢
-- ----------------------------
drop table QRTZ_JOB_DETAILS;
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,
    constraint qrtz_job_details_pk primary key (sched_name,job_name,job_group)
);

-- ----------------------------
-- 2¡¢ ´æ´¢ÒÑÅäÖÃµÄ Trigger µÄÐÅÏ¢
-- ----------------------------
drop table  QRTZ_TRIGGERS;
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 number(13) null,
    prev_fire_time number(13) null,
    priority number(13) null,
    trigger_state varchar2(16) not null,
    trigger_type varchar2(8) not null,
    start_time number(13) not null,
    end_time number(13) null,
    calendar_name varchar2(200) null,
    misfire_instr number(2) null,
    job_data blob null,
    constraint qrtz_triggers_pk primary key (sched_name,trigger_name,trigger_group),
    constraint qrtz_trigger_to_jobs_fk foreign key (sched_name,job_name,job_group)
      references qrtz_job_details(sched_name,job_name,job_group)
);

-- ----------------------------
-- 3¡¢ ´æ´¢¼òµ¥µÄ Trigger£¬°üÀ¨ÖØ¸´´ÎÊý£¬¼ä¸ô£¬ÒÔ¼°ÒÑ´¥·¢µÄ´ÎÊý
-- ----------------------------
drop table  QRTZ_SIMPLE_TRIGGERS;
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 number(7) not null,
    repeat_interval number(12) not null,
    times_triggered number(10) not null,
    constraint qrtz_simple_trig_pk primary key (sched_name,trigger_name,trigger_group),
    constraint qrtz_simple_trig_to_trig_fk foreign key (sched_name,trigger_name,trigger_group)
      references qrtz_triggers(sched_name,trigger_name,trigger_group)
);

-- ----------------------------
-- 4¡¢ ´æ´¢ Cron Trigger£¬°üÀ¨ Cron ±í´ïÊ½ºÍÊ±ÇøÐÅÏ¢
-- ---------------------------- 
drop table  QRTZ_CRON_TRIGGERS;
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(120) not null,
    time_zone_id varchar2(80),
    constraint qrtz_cron_trig_pk primary key (sched_name,trigger_name,trigger_group),
    constraint qrtz_cron_trig_to_trig_fk foreign key (sched_name,trigger_name,trigger_group)
      references qrtz_triggers(sched_name,trigger_name,trigger_group)
);

-- ----------------------------
-- 5¡¢ Trigger ×÷Îª Blob ÀàÐÍ´æ´¢(ÓÃÓÚ Quartz ÓÃ»§ÓÃ JDBC ´´½¨ËûÃÇ×Ô¼º¶¨ÖÆµÄ Trigger ÀàÐÍ£¬JobStore ²¢²»ÖªµÀÈçºÎ´æ´¢ÊµÀýµÄÊ±ºò)
-- ---------------------------- 
drop table  QRTZ_BLOB_TRIGGERS;
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,
    constraint qrtz_blob_trig_pk primary key (sched_name,trigger_name,trigger_group),
    constraint qrtz_blob_trig_to_trig_fk foreign key (sched_name,trigger_name,trigger_group)
      references qrtz_triggers(sched_name,trigger_name,trigger_group)
);

-- ----------------------------
-- 6¡¢ ÒÔ Blob ÀàÐÍ´æ´¢´æ·ÅÈÕÀúÐÅÏ¢£¬ quartz¿ÉÅäÖÃÒ»¸öÈÕÀúÀ´Ö¸¶¨Ò»¸öÊ±¼ä·¶Î§
-- ---------------------------- 
drop table  QRTZ_CALENDARS;
create table qrtz_calendars (
    sched_name varchar2(120) not null,
    calendar_name  varchar2(200) not null,
    calendar blob not null,
    constraint qrtz_calendars_pk primary key (sched_name,calendar_name)
);

-- ----------------------------
-- 7¡¢ ´æ´¢ÒÑÔÝÍ£µÄ Trigger ×éµÄÐÅÏ¢
-- ---------------------------- 
drop table  QRTZ_PAUSED_TRIGGER_GRPS;
create table qrtz_paused_trigger_grps (
    sched_name varchar2(120) not null,
    trigger_group  varchar2(200) not null,
    constraint qrtz_paused_trig_grps_pk primary key (sched_name,trigger_group)
);

-- ----------------------------
-- 8¡¢ ´æ´¢ÓëÒÑ´¥·¢µÄ Trigger Ïà¹ØµÄ×´Ì¬ÐÅÏ¢£¬ÒÔ¼°ÏàÁª Job µÄÖ´ÐÐÐÅÏ¢
-- ---------------------------- 
drop table  QRTZ_FIRED_TRIGGERS;
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 number(13) not null,
    sched_time number(13) not null,
    priority number(13) 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,
    constraint qrtz_fired_trigger_pk primary key (sched_name,entry_id)
);

-- ----------------------------
-- 9¡¢ ´æ´¢ÉÙÁ¿µÄÓÐ¹Ø Scheduler µÄ×´Ì¬ÐÅÏ¢£¬¼ÙÈçÊÇÓÃÓÚ¼¯ÈºÖÐ£¬¿ÉÒÔ¿´µ½ÆäËûµÄ Scheduler ÊµÀý
-- ---------------------------- 
drop table  QRTZ_SCHEDULER_STATE; 
create table qrtz_scheduler_state (
    sched_name varchar2(120) not null,
    instance_name varchar2(200) not null,
    last_checkin_time number(13) not null,
    checkin_interval number(13) not null,
    constraint qrtz_scheduler_state_pk primary key (sched_name,instance_name)
);

-- ----------------------------
-- 10¡¢ ´æ´¢³ÌÐòµÄ±¯¹ÛËøµÄÐÅÏ¢(¼ÙÈçÊ¹ÓÃÁË±¯¹ÛËø)
-- ---------------------------- 
drop table  QRTZ_LOCKS;
create table qrtz_locks (
    sched_name varchar2(120) not null,
    lock_name  varchar2(40) not null,
    constraint qrtz_locks_pk primary key (sched_name,lock_name)
);
drop table  QRTZ_SIMPROP_TRIGGERS;
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 number(10) null,
    int_prop_2 number(10) null,
    long_prop_1 number(13) null,
    long_prop_2 number(13) null,
    dec_prop_1 numeric(13,4) null,
    dec_prop_2 numeric(13,4) null,
    bool_prop_1 varchar2(1) null,
    bool_prop_2 varchar2(1) null,
    constraint qrtz_simprop_trig_pk primary key (sched_name,trigger_name,trigger_group),
    constraint qrtz_simprop_trig_to_trig_fk foreign key (sched_name,trigger_name,trigger_group)
      references qrtz_triggers(sched_name,trigger_name,trigger_group)
);


create index idx_qrtz_j_req_recovery on qrtz_job_details(sched_name,requests_recovery);
create index idx_qrtz_j_grp on qrtz_job_details(sched_name,job_group);

create index idx_qrtz_t_j on qrtz_triggers(sched_name,job_name,job_group);
create index idx_qrtz_t_jg on qrtz_triggers(sched_name,job_group);
create index idx_qrtz_t_c on qrtz_triggers(sched_name,calendar_name);
create index idx_qrtz_t_g on qrtz_triggers(sched_name,trigger_group);
create index idx_qrtz_t_state on qrtz_triggers(sched_name,trigger_state);
create index idx_qrtz_t_n_state on qrtz_triggers(sched_name,trigger_name,trigger_group,trigger_state);
create index idx_qrtz_t_n_g_state on qrtz_triggers(sched_name,trigger_group,trigger_state);
create index idx_qrtz_t_next_fire_time on qrtz_triggers(sched_name,next_fire_time);
create index idx_qrtz_t_nft_st on qrtz_triggers(sched_name,trigger_state,next_fire_time);
create index idx_qrtz_t_nft_misfire on qrtz_triggers(sched_name,misfire_instr,next_fire_time);
create index idx_qrtz_t_nft_st_misfire on qrtz_triggers(sched_name,misfire_instr,next_fire_time,trigger_state);
create index idx_qrtz_t_nft_st_misfire_grp on qrtz_triggers(sched_name,misfire_instr,next_fire_time,trigger_group,trigger_state);

create index idx_qrtz_ft_trig_inst_name on qrtz_fired_triggers(sched_name,instance_name);
create index idx_qrtz_ft_inst_job_req_rcvry on qrtz_fired_triggers(sched_name,instance_name,requests_recovery);
create index idx_qrtz_ft_j_g on qrtz_fired_triggers(sched_name,job_name,job_group);
create index idx_qrtz_ft_jg on qrtz_fired_triggers(sched_name,job_group);
create index idx_qrtz_ft_t_g on qrtz_fired_triggers(sched_name,trigger_name,trigger_group);

create index idx_qrtz_ft_tg on qrtz_fired_triggers(sched_name,trigger_group);

commit;