Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

SQL schema update script for SQL server from 1.0 to 2.0, changes to r…

…eading to support varying column layout for blobs
  • Loading branch information...
commit fac1ff913ee586c791933700bef894c167191b4a 1 parent c100549
Marko Lahma authored September 11, 2011
153  database/sqlserver_schema_10_to_20_upgrade.sql
... ...
@@ -0,0 +1,153 @@
  1
+--
  2
+-- !! FIRST RUN IN TEST ENVIRONMENT AGAINST COPY OF YOU PRODUCTION !!
  3
+--
  4
+-- Migration script sample for MS SQL Server
  5
+-- You need to modify script for other databases
  6
+--
  7
+-- !! FIRST RUN IN TEST ENVIRONMENT AGAINST COPY OF YOU PRODUCTION !!
  8
+--
  9
+
  10
+-- 
  11
+-- drop tables that are no longer used
  12
+--
  13
+drop table qrtz_job_listeners;
  14
+drop table qrtz_trigger_listeners;
  15
+GO
  16
+
  17
+--
  18
+-- change some varchar(1)s to true bit/booleans
  19
+--
  20
+alter table QRTZ_FIRED_TRIGGERS alter column REQUESTS_RECOVERY bit
  21
+alter table QRTZ_FIRED_TRIGGERS alter column IS_VOLATILE bit
  22
+alter table QRTZ_FIRED_TRIGGERS alter column IS_STATEFUL bit
  23
+alter table QRTZ_JOB_DETAILS alter column REQUESTS_RECOVERY bit
  24
+alter table QRTZ_JOB_DETAILS alter column IS_DURABLE bit
  25
+
  26
+
  27
+--
  28
+-- drop columns that are no longer used
  29
+--
  30
+alter table qrtz_job_details drop column is_volatile;
  31
+alter table qrtz_triggers drop column is_volatile;
  32
+alter table qrtz_fired_triggers drop column is_volatile;
  33
+--
  34
+-- add new columns that replace the 'is_stateful' column
  35
+--
  36
+alter table qrtz_job_details add IS_NONCONCURRENT bit;
  37
+alter table qrtz_job_details add IS_UPDATE_DATA bit;
  38
+GO
  39
+update qrtz_job_details set IS_NONCONCURRENT = is_stateful;
  40
+update qrtz_job_details set IS_UPDATE_DATA = is_stateful;
  41
+GO
  42
+alter table qrtz_job_details drop column is_stateful;
  43
+alter table qrtz_fired_triggers add IS_NONCONCURRENT bit;
  44
+GO
  45
+update qrtz_fired_triggers set IS_NONCONCURRENT = is_stateful;
  46
+GO
  47
+alter table qrtz_fired_triggers drop column is_stateful;
  48
+GO
  49
+--
  50
+-- add new 'sched_name' column to all tables
  51
+--
  52
+alter table qrtz_blob_triggers add SCHED_NAME varchar(120) not null DEFAULT 'TestScheduler';
  53
+alter table qrtz_calendars add SCHED_NAME varchar(120) not null DEFAULT 'TestScheduler';
  54
+alter table qrtz_cron_triggers add SCHED_NAME varchar(120) not null DEFAULT 'TestScheduler';
  55
+alter table qrtz_fired_triggers add SCHED_NAME varchar(120) not null DEFAULT 'TestScheduler';
  56
+alter table qrtz_job_details add SCHED_NAME varchar(120) not null DEFAULT 'TestScheduler';
  57
+alter table qrtz_locks add SCHED_NAME varchar(120) not null DEFAULT 'TestScheduler';
  58
+alter table qrtz_paused_trigger_grps add SCHED_NAME varchar(120) not null DEFAULT 'TestScheduler';
  59
+alter table qrtz_scheduler_state add SCHED_NAME varchar(120) not null DEFAULT 'TestScheduler';
  60
+alter table qrtz_simple_triggers add SCHED_NAME varchar(120) not null DEFAULT 'TestScheduler';
  61
+alter table qrtz_triggers add SCHED_NAME varchar(120) not null DEFAULT 'TestScheduler';
  62
+GO
  63
+
  64
+--
  65
+-- drop all primary and foreign key constraints, so that we can define new ones
  66
+--
  67
+--alter table qrtz_blob_triggers drop constraint qrtz_blob_triggers_pkey;
  68
+--alter table qrtz_blob_triggers drop constraint qrtz_blob_triggers_trigger_name_fkey;
  69
+alter table qrtz_simple_triggers drop constraint PK_QRTZ_SIMPLE_TRIGGERS;
  70
+alter table qrtz_simple_triggers drop constraint FK_QRTZ_SIMPLE_TRIGGERS_QRTZ_TRIGGERS;
  71
+alter table qrtz_cron_triggers drop constraint PK_QRTZ_CRON_TRIGGERS;
  72
+alter table qrtz_cron_triggers drop constraint FK_QRTZ_CRON_TRIGGERS_QRTZ_TRIGGERS;
  73
+alter table qrtz_triggers drop constraint PK_QRTZ_TRIGGERS;
  74
+alter table qrtz_triggers drop constraint FK_QRTZ_TRIGGERS_QRTZ_JOB_DETAILS;
  75
+alter table qrtz_job_details drop constraint PK_QRTZ_JOB_DETAILS;
  76
+GO
  77
+
  78
+--
  79
+-- add all primary and foreign key constraints, based on new columns
  80
+--
  81
+alter table qrtz_job_details add primary key (sched_name, job_name, job_group);
  82
+alter table qrtz_triggers add primary key (sched_name, trigger_name, trigger_group);
  83
+alter table qrtz_triggers add foreign key (sched_name, job_name, job_group) references qrtz_job_details(sched_name, job_name, job_group);
  84
+alter table qrtz_blob_triggers add primary key (sched_name, trigger_name, trigger_group);
  85
+alter table qrtz_blob_triggers add foreign key (sched_name, trigger_name, trigger_group) references qrtz_triggers(sched_name, trigger_name, trigger_group);
  86
+alter table qrtz_cron_triggers add primary key (sched_name, trigger_name, trigger_group);
  87
+alter table qrtz_cron_triggers add foreign key (sched_name, trigger_name, trigger_group) references qrtz_triggers(sched_name, trigger_name, trigger_group);
  88
+alter table qrtz_simple_triggers add primary key (sched_name, trigger_name, trigger_group);
  89
+alter table qrtz_simple_triggers add foreign key (sched_name, trigger_name, trigger_group) references qrtz_triggers(sched_name, trigger_name, trigger_group);
  90
+alter table qrtz_fired_triggers drop constraint PK_QRTZ_FIRED_TRIGGERS;
  91
+alter table qrtz_fired_triggers add primary key (sched_name, entry_id);
  92
+alter table qrtz_calendars drop constraint PK_QRTZ_CALENDARS;
  93
+alter table qrtz_calendars add primary key (sched_name, calendar_name);
  94
+alter table qrtz_locks drop constraint PK_QRTZ_LOCKS;
  95
+alter table qrtz_locks add primary key (sched_name, lock_name);
  96
+alter table qrtz_paused_trigger_grps drop constraint PK_QRTZ_PAUSED_TRIGGER_GRPS;
  97
+alter table qrtz_paused_trigger_grps add primary key (sched_name, trigger_group);
  98
+alter table qrtz_scheduler_state drop constraint PK_QRTZ_SCHEDULER_STATE;
  99
+alter table qrtz_scheduler_state add primary key (sched_name, instance_name);
  100
+GO
  101
+
  102
+--
  103
+-- add new simprop_triggers table
  104
+--
  105
+CREATE TABLE QRTZ_SIMPROP_TRIGGERS
  106
+ (          
  107
+    SCHED_NAME VARCHAR(120) NOT NULL,
  108
+    TRIGGER_NAME VARCHAR(200) NOT NULL,
  109
+    TRIGGER_GROUP VARCHAR(200) NOT NULL,
  110
+    STR_PROP_1 VARCHAR(512) NULL,
  111
+    STR_PROP_2 VARCHAR(512) NULL,
  112
+    STR_PROP_3 VARCHAR(512) NULL,
  113
+    INT_PROP_1 INT NULL,
  114
+    INT_PROP_2 INT NULL,
  115
+    LONG_PROP_1 BIGINT NULL,
  116
+    LONG_PROP_2 BIGINT NULL,
  117
+    DEC_PROP_1 NUMERIC(13,4) NULL,
  118
+    DEC_PROP_2 NUMERIC(13,4) NULL,
  119
+    BOOL_PROP_1 BIT NULL,
  120
+    BOOL_PROP_2 BIT NULL,
  121
+    PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
  122
+    FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
  123
+    REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
  124
+);
  125
+GO
  126
+
  127
+--
  128
+-- create indexes for faster queries
  129
+--
  130
+create index idx_qrtz_j_req_recovery on qrtz_job_details(SCHED_NAME,REQUESTS_RECOVERY);
  131
+create index idx_qrtz_j_grp on qrtz_job_details(SCHED_NAME,JOB_GROUP);
  132
+create index idx_qrtz_t_j on qrtz_triggers(SCHED_NAME,JOB_NAME,JOB_GROUP);
  133
+create index idx_qrtz_t_jg on qrtz_triggers(SCHED_NAME,JOB_GROUP);
  134
+create index idx_qrtz_t_c on qrtz_triggers(SCHED_NAME,CALENDAR_NAME);
  135
+create index idx_qrtz_t_g on qrtz_triggers(SCHED_NAME,TRIGGER_GROUP);
  136
+create index idx_qrtz_t_state on qrtz_triggers(SCHED_NAME,TRIGGER_STATE);
  137
+create index idx_qrtz_t_n_state on qrtz_triggers(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP,TRIGGER_STATE);
  138
+create index idx_qrtz_t_n_g_state on qrtz_triggers(SCHED_NAME,TRIGGER_GROUP,TRIGGER_STATE);
  139
+create index idx_qrtz_t_next_fire_time on qrtz_triggers(SCHED_NAME,NEXT_FIRE_TIME);
  140
+create index idx_qrtz_t_nft_st on qrtz_triggers(SCHED_NAME,TRIGGER_STATE,NEXT_FIRE_TIME);
  141
+create index idx_qrtz_t_nft_misfire on qrtz_triggers(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME);
  142
+create index idx_qrtz_t_nft_st_misfire on qrtz_triggers(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_STATE);
  143
+create index idx_qrtz_t_nft_st_misfire_grp on qrtz_triggers(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_GROUP,TRIGGER_STATE);
  144
+create index idx_qrtz_ft_trig_inst_name on qrtz_fired_triggers(SCHED_NAME,INSTANCE_NAME);
  145
+create index idx_qrtz_ft_inst_job_req_rcvry on qrtz_fired_triggers(SCHED_NAME,INSTANCE_NAME,REQUESTS_RECOVERY);
  146
+create index idx_qrtz_ft_j_g on qrtz_fired_triggers(SCHED_NAME,JOB_NAME,JOB_GROUP);
  147
+create index idx_qrtz_ft_jg on qrtz_fired_triggers(SCHED_NAME,JOB_GROUP);
  148
+create index idx_qrtz_ft_t_g on qrtz_fired_triggers(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP);
  149
+create index idx_qrtz_ft_tg on qrtz_fired_triggers(SCHED_NAME,TRIGGER_GROUP);
  150
+GO
  151
+--
  152
+-- All done
  153
+--
20  src/Quartz/Impl/AdoJobStore/StdAdoConstants.cs
@@ -163,13 +163,13 @@ public class StdAdoConstants : AdoConstants
163 163
         // SELECT
164 164
 
165 165
         public static readonly string SqlSelectBlobTrigger =
166  
-            string.Format(CultureInfo.InvariantCulture, "SELECT * FROM {0}{1} WHERE {2} = {3} AND {4} = @triggerName AND {5} = @triggerGroup", TablePrefixSubst,
167  
-                          TableBlobTriggers, ColumnSchedulerName, SchedulerNameSubst, ColumnTriggerName,
168  
-                          ColumnTriggerGroup);
  166
+            string.Format(CultureInfo.InvariantCulture, "SELECT {6} FROM {0}{1} WHERE {2} = {3} AND {4} = @triggerName AND {5} = @triggerGroup", TablePrefixSubst,
  167
+                          TableBlobTriggers, ColumnSchedulerName, SchedulerNameSubst, ColumnTriggerName, ColumnTriggerGroup,
  168
+                          ColumnBlob);
169 169
 
170 170
         public static readonly string SqlSelectCalendar =
171  
-            string.Format(CultureInfo.InvariantCulture, "SELECT * FROM {0}{1} WHERE {2} = {3} AND {4} = @calendarName", TablePrefixSubst, TableCalendars,
172  
-                          ColumnSchedulerName, SchedulerNameSubst, ColumnCalendarName);
  171
+            string.Format(CultureInfo.InvariantCulture, "SELECT {5} FROM {0}{1} WHERE {2} = {3} AND {4} = @calendarName", TablePrefixSubst, TableCalendars,
  172
+                          ColumnSchedulerName, SchedulerNameSubst, ColumnCalendarName, ColumnCalendar);
173 173
 
174 174
         public static readonly string SqlSelectCalendarExistence =
175 175
             string.Format(CultureInfo.InvariantCulture, "SELECT {0} FROM {1}{2} WHERE {3} = {4} AND {5} = @calendarName",
@@ -217,8 +217,9 @@ public class StdAdoConstants : AdoConstants
217 217
 
218 218
         public static readonly string SqlSelectJobDetail =
219 219
             string.Format(CultureInfo.InvariantCulture,
220  
-                "SELECT * FROM {0}{1} WHERE {2} = {3} AND {4} = @jobName AND {5} = @jobGroup",
221  
-                TablePrefixSubst, TableJobDetails, ColumnSchedulerName, SchedulerNameSubst, ColumnJobName, ColumnJobGroup);
  220
+                "SELECT {6},{7},{8},{9},{10},{11},{12} FROM {0}{1} WHERE {2} = {3} AND {4} = @jobName AND {5} = @jobGroup",
  221
+                TablePrefixSubst, TableJobDetails, ColumnSchedulerName, SchedulerNameSubst, ColumnJobName, ColumnJobGroup,
  222
+                ColumnJobName, ColumnJobGroup, ColumnDescription, ColumnJobClass, ColumnIsDurable, ColumnRequestsRecovery, ColumnJobDataMap);
222 223
 
223 224
         public static readonly string SqlSelectJobExecutionCount =
224 225
             string.Format(CultureInfo.InvariantCulture, "SELECT COUNT({0}) FROM {1}{2} WHERE {3} = {4} AND {5} = @jobName AND {6} = @jobGroup",
@@ -331,8 +332,9 @@ public class StdAdoConstants : AdoConstants
331 332
                 TablePrefixSubst, TableSimpleTriggers, ColumnSchedulerName, SchedulerNameSubst, ColumnTriggerName, ColumnTriggerGroup);
332 333
 
333 334
         public static readonly string SqlSelectTrigger =
334  
-            string.Format(CultureInfo.InvariantCulture, "SELECT * FROM {0}{1} WHERE {2} = {3} AND {4} = @triggerName AND {5} = @triggerGroup",
335  
-                TablePrefixSubst, TableTriggers, ColumnSchedulerName, SchedulerNameSubst, ColumnTriggerName, ColumnTriggerGroup);
  335
+            string.Format(CultureInfo.InvariantCulture, "SELECT {6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17} FROM {0}{1} WHERE {2} = {3} AND {4} = @triggerName AND {5} = @triggerGroup",
  336
+                TablePrefixSubst, TableTriggers, ColumnSchedulerName, SchedulerNameSubst, ColumnTriggerName, ColumnTriggerGroup,
  337
+                ColumnJobName, ColumnJobGroup, ColumnDescription, ColumnNextFireTime, ColumnPreviousFireTime, ColumnTriggerType, ColumnStartTime, ColumnEndTime, ColumnCalendarName, ColumnMifireInstruction, ColumnPriority, ColumnJobDataMap);
336 338
 
337 339
         public static readonly string SqlSelectTriggerData =
338 340
             string.Format(CultureInfo.InvariantCulture, "SELECT {0} FROM {1}{2} WHERE {3} = {4} AND {5} = @triggerName AND {6} = @triggerGroup",
12  src/Quartz/Impl/AdoJobStore/StdAdoDelegate.cs
@@ -731,11 +731,11 @@ public virtual IJobDetail SelectJobDetail(ConnectionAndTransactionHolder conn, J
731 731
                         IDictionary map;
732 732
                         if (CanUseProperties)
733 733
                         {
734  
-                            map = GetMapFromProperties(rs, 9);
  734
+                            map = GetMapFromProperties(rs, 6);
735 735
                         }
736 736
                         else
737 737
                         {
738  
-                            map = GetObjectFromBlob<IDictionary>(rs, 9);
  738
+                            map = GetObjectFromBlob<IDictionary>(rs, 6);
739 739
                         }
740 740
 
741 741
                         if (null != map)
@@ -1521,11 +1521,11 @@ public virtual IOperableTrigger SelectTrigger(ConnectionAndTransactionHolder con
1521 1521
 
1522 1522
                         if (CanUseProperties)
1523 1523
                         {
1524  
-                            map = GetMapFromProperties(rs, 15);
  1524
+                            map = GetMapFromProperties(rs, 11);
1525 1525
                         }
1526 1526
                         else
1527 1527
                         {
1528  
-                            map = GetObjectFromBlob<IDictionary>(rs, 15);
  1528
+                            map = GetObjectFromBlob<IDictionary>(rs, 11);
1529 1529
                         }
1530 1530
 
1531 1531
 
@@ -1559,7 +1559,7 @@ public virtual IOperableTrigger SelectTrigger(ConnectionAndTransactionHolder con
1559 1559
                                 {
1560 1560
                                     if (rs2.Read())
1561 1561
                                     {
1562  
-                                        trigger = GetObjectFromBlob<IOperableTrigger>(rs2, 3);
  1562
+                                        trigger = GetObjectFromBlob<IOperableTrigger>(rs2, 0);
1563 1563
                                     }
1564 1564
                                 }
1565 1565
                             }
@@ -2013,7 +2013,7 @@ public virtual ICalendar SelectCalendar(ConnectionAndTransactionHolder conn, str
2013 2013
                     ICalendar cal = null;
2014 2014
                     if (rs.Read())
2015 2015
                     {
2016  
-                        cal = GetObjectFromBlob<ICalendar>(rs, 2);
  2016
+                        cal = GetObjectFromBlob<ICalendar>(rs, 0);
2017 2017
                     }
2018 2018
                     if (null == cal)
2019 2019
                     {

0 notes on commit fac1ff9

Please sign in to comment.
Something went wrong with that request. Please try again.