[12878] | 1 | /* HeuristicLab
|
---|
[14185] | 2 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[12878] | 3 | *
|
---|
| 4 | * This file is part of HeuristicLab.
|
---|
| 5 | *
|
---|
| 6 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 7 | * it under the terms of the GNU General Public License as published by
|
---|
| 8 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 9 | * (at your option) any later version.
|
---|
| 10 | *
|
---|
| 11 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | * GNU General Public License for more details.
|
---|
| 15 | *
|
---|
| 16 | * You should have received a copy of the GNU General Public License
|
---|
| 17 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 18 | */
|
---|
| 19 |
|
---|
| 20 | /* this script is supposed to be executed after the plain DB is generated by the linq-to-sql schema */
|
---|
[16091] | 21 | USE [HeuristicLab.Hive-3.4]
|
---|
[6983] | 22 |
|
---|
[15411] | 23 | ALTER TABLE [dbo].[AssignedProjectResource] DROP CONSTRAINT [Project_AssignedProjectResource]
|
---|
| 24 | ALTER TABLE [dbo].[AssignedProjectResource] WITH CHECK ADD CONSTRAINT [Project_AssignedProjectResource] FOREIGN KEY([ProjectId])
|
---|
[15378] | 25 | REFERENCES [dbo].[Project] ([ProjectId])
|
---|
[6983] | 26 | ON UPDATE CASCADE
|
---|
| 27 | ON DELETE CASCADE
|
---|
| 28 | GO
|
---|
[15411] | 29 | ALTER TABLE [dbo].[AssignedProjectResource] DROP CONSTRAINT [Resource_AssignedProjectResource]
|
---|
| 30 | ALTER TABLE [dbo].[AssignedProjectResource] WITH CHECK ADD CONSTRAINT [Resource_AssignedProjectResource] FOREIGN KEY([ResourceId])
|
---|
[6983] | 31 | REFERENCES [dbo].[Resource] ([ResourceId])
|
---|
| 32 | ON UPDATE CASCADE
|
---|
| 33 | ON DELETE CASCADE
|
---|
| 34 | GO
|
---|
[15552] | 35 | ALTER TABLE [dbo].[AssignedJobResource] DROP CONSTRAINT [Job_AssignedJobResource]
|
---|
| 36 | ALTER TABLE [dbo].[AssignedJobResource] WITH CHECK ADD CONSTRAINT [Job_AssignedJobResource] FOREIGN KEY([JobId])
|
---|
| 37 | REFERENCES [dbo].[Job] ([JobId])
|
---|
| 38 | ON UPDATE CASCADE
|
---|
| 39 | ON DELETE CASCADE
|
---|
| 40 | GO
|
---|
| 41 | ALTER TABLE [dbo].[AssignedJobResource] DROP CONSTRAINT [Resource_AssignedJobResource]
|
---|
| 42 | ALTER TABLE [dbo].[AssignedJobResource] WITH CHECK ADD CONSTRAINT [Resource_AssignedJobResource] FOREIGN KEY([ResourceId])
|
---|
| 43 | REFERENCES [dbo].[Resource] ([ResourceId])
|
---|
| 44 | ON UPDATE CASCADE
|
---|
| 45 | ON DELETE CASCADE
|
---|
| 46 | GO
|
---|
| 47 |
|
---|
[6983] | 48 | ALTER TABLE dbo.Task ALTER COLUMN TaskId ADD ROWGUIDCOL;
|
---|
| 49 | ALTER TABLE dbo.Task WITH NOCHECK ADD CONSTRAINT [DF_Task_TaskId] DEFAULT (NEWSEQUENTIALID()) FOR TaskId;
|
---|
| 50 | GO
|
---|
| 51 |
|
---|
| 52 | ALTER TABLE [dbo].[StateLog] DROP CONSTRAINT [Task_StateLog]
|
---|
| 53 | ALTER TABLE [dbo].[StateLog] WITH CHECK ADD CONSTRAINT [Task_StateLog] FOREIGN KEY([TaskId])
|
---|
| 54 | REFERENCES [dbo].[Task] ([TaskId])
|
---|
| 55 | ON UPDATE CASCADE
|
---|
| 56 | ON DELETE CASCADE
|
---|
| 57 | GO
|
---|
| 58 | ALTER TABLE [dbo].[StateLog] DROP CONSTRAINT [Resource_StateLog]
|
---|
| 59 | ALTER TABLE [dbo].[StateLog] WITH CHECK ADD CONSTRAINT [Resource_StateLog] FOREIGN KEY([SlaveId])
|
---|
| 60 | REFERENCES [dbo].[Resource] ([ResourceId])
|
---|
| 61 | ON UPDATE CASCADE
|
---|
| 62 | ON DELETE SET NULL
|
---|
| 63 | GO
|
---|
| 64 |
|
---|
| 65 | ALTER TABLE dbo.Plugin ALTER COLUMN PluginId ADD ROWGUIDCOL;
|
---|
| 66 | ALTER TABLE dbo.Plugin WITH NOCHECK ADD CONSTRAINT [DF_Plugin_PluginId] DEFAULT (NEWSEQUENTIALID()) FOR PluginId;
|
---|
| 67 |
|
---|
| 68 | ALTER TABLE dbo.PluginData WITH NOCHECK ADD CONSTRAINT [DF_PluginData_PluginDataId] DEFAULT (NEWSEQUENTIALID()) FOR PluginDataId;
|
---|
| 69 |
|
---|
| 70 | ALTER TABLE [dbo].[PluginData] DROP CONSTRAINT [Plugin_PluginData]
|
---|
| 71 | ALTER TABLE [dbo].[PluginData] WITH CHECK ADD CONSTRAINT [Plugin_PluginData] FOREIGN KEY([PluginId])
|
---|
| 72 | REFERENCES [dbo].[Plugin] ([PluginId])
|
---|
| 73 | ON UPDATE CASCADE
|
---|
| 74 | ON DELETE CASCADE
|
---|
| 75 | GO
|
---|
| 76 |
|
---|
| 77 | ALTER TABLE dbo.RequiredPlugins ALTER COLUMN RequiredPluginId ADD ROWGUIDCOL;
|
---|
| 78 | ALTER TABLE dbo.RequiredPlugins WITH NOCHECK ADD CONSTRAINT [DF_RequiredPlugins_RequiredPluginId] DEFAULT (NEWSEQUENTIALID()) FOR RequiredPluginId;
|
---|
| 79 |
|
---|
| 80 | ALTER TABLE [dbo].[RequiredPlugins] DROP CONSTRAINT [Task_RequiredPlugin]
|
---|
| 81 | ALTER TABLE [dbo].[RequiredPlugins] WITH CHECK ADD CONSTRAINT [Task_RequiredPlugin] FOREIGN KEY([TaskId])
|
---|
| 82 | REFERENCES [dbo].[Task] ([TaskId])
|
---|
| 83 | ON UPDATE CASCADE
|
---|
| 84 | ON DELETE CASCADE
|
---|
| 85 | GO
|
---|
| 86 |
|
---|
| 87 | ALTER TABLE [dbo].[RequiredPlugins] DROP CONSTRAINT [Plugin_RequiredPlugin]
|
---|
| 88 | ALTER TABLE [dbo].[RequiredPlugins] WITH CHECK ADD CONSTRAINT [Plugin_RequiredPlugin] FOREIGN KEY([PluginId])
|
---|
| 89 | REFERENCES [dbo].[Plugin] ([PluginId])
|
---|
| 90 | ON UPDATE CASCADE
|
---|
| 91 | ON DELETE CASCADE
|
---|
| 92 | GO
|
---|
| 93 |
|
---|
| 94 | ALTER TABLE dbo.Resource ALTER COLUMN ResourceId ADD ROWGUIDCOL;
|
---|
| 95 | ALTER TABLE dbo.Resource WITH NOCHECK ADD CONSTRAINT [DF_Resource_ResourceId] DEFAULT (NEWSEQUENTIALID()) FOR ResourceId;
|
---|
| 96 |
|
---|
| 97 | ALTER TABLE dbo.Downtime ALTER COLUMN DowntimeId ADD ROWGUIDCOL;
|
---|
| 98 | ALTER TABLE dbo.Downtime WITH NOCHECK ADD CONSTRAINT [DF_Downtime_DowntimeId] DEFAULT (NEWSEQUENTIALID()) FOR DowntimeId;
|
---|
| 99 |
|
---|
| 100 | ALTER TABLE dbo.Job ALTER COLUMN JobId ADD ROWGUIDCOL;
|
---|
| 101 | ALTER TABLE dbo.Job WITH NOCHECK ADD CONSTRAINT [DF_Job_JobId] DEFAULT (NEWSEQUENTIALID()) FOR JobId;
|
---|
[15378] | 102 | ALTER TABLE [dbo].[Job] DROP CONSTRAINT [Project_Job]
|
---|
| 103 | ALTER TABLE [dbo].[Job] WITH CHECK ADD CONSTRAINT [Project_Job] FOREIGN KEY([ProjectId])
|
---|
| 104 | REFERENCES [dbo].[Project] ([ProjectId])
|
---|
| 105 | ON UPDATE CASCADE
|
---|
| 106 | GO
|
---|
[6983] | 107 |
|
---|
| 108 | ALTER TABLE dbo.StateLog ALTER COLUMN StateLogId ADD ROWGUIDCOL;
|
---|
| 109 | ALTER TABLE dbo.StateLog WITH NOCHECK ADD CONSTRAINT [DF_StateLog_StateLogId] DEFAULT (NEWSEQUENTIALID()) FOR StateLogId;
|
---|
| 110 |
|
---|
| 111 | ALTER TABLE [dbo].[JobPermission] DROP CONSTRAINT [Job_JobPermission]
|
---|
| 112 | ALTER TABLE [dbo].[JobPermission] WITH CHECK ADD CONSTRAINT [Job_JobPermission] FOREIGN KEY([JobId])
|
---|
| 113 | REFERENCES [dbo].[Job] ([JobId])
|
---|
| 114 | ON UPDATE CASCADE
|
---|
| 115 | ON DELETE CASCADE
|
---|
| 116 | GO
|
---|
| 117 |
|
---|
[15378] | 118 | ALTER TABLE dbo.Project ALTER COLUMN ProjectId ADD ROWGUIDCOL;
|
---|
| 119 | ALTER TABLE dbo.Project WITH NOCHECK ADD CONSTRAINT [DF_Project_ProjectId] DEFAULT (NEWSEQUENTIALID()) FOR ProjectId;
|
---|
| 120 |
|
---|
| 121 | ALTER TABLE [dbo].[ProjectPermission] DROP CONSTRAINT [Project_ProjectPermission]
|
---|
| 122 | ALTER TABLE [dbo].[ProjectPermission] WITH CHECK ADD CONSTRAINT [Project_ProjectPermission] FOREIGN KEY([ProjectId])
|
---|
| 123 | REFERENCES [dbo].[Project] ([ProjectId])
|
---|
| 124 | ON UPDATE CASCADE
|
---|
| 125 | ON DELETE CASCADE
|
---|
| 126 | GO
|
---|
| 127 |
|
---|
[6983] | 128 | /* create indices */
|
---|
| 129 | CREATE INDEX Index_RequiredPlugins_TaskId ON RequiredPlugins(TaskId);
|
---|
| 130 | GO
|
---|
| 131 |
|
---|
[12878] | 132 | -- speed up joins between Job and Task
|
---|
| 133 | CREATE NONCLUSTERED INDEX [TaskJobIdIndex]
|
---|
| 134 | ON [dbo].[Task] ([JobId])
|
---|
[12926] | 135 | INCLUDE ([TaskId],[TaskState],[ExecutionTimeMs],[LastHeartbeat],[ParentTaskId],[Priority],[CoresNeeded],[MemoryNeeded],[IsParentTask],[FinishWhenChildJobsFinished],[Command])
|
---|
[6983] | 136 | GO
|
---|
| 137 |
|
---|
[12878] | 138 | -- this is an index to speed up the GetWaitingTasks() method
|
---|
| 139 | CREATE NONCLUSTERED INDEX [TaskGetWaitingTasksIndex]
|
---|
| 140 | ON [dbo].[Task] ([TaskState],[IsParentTask],[FinishWhenChildJobsFinished],[CoresNeeded],[MemoryNeeded])
|
---|
[12926] | 141 | INCLUDE ([TaskId],[ExecutionTimeMs],[LastHeartbeat],[ParentTaskId],[Priority],[Command],[JobId])
|
---|
[6983] | 142 | GO
|
---|
| 143 |
|
---|
| 144 |
|
---|
[15630] | 145 |
|
---|
[15737] | 146 | -- OBSOLETE - DO NOT PERFORM (start)
|
---|
[6983] | 147 | /****** Object: Trigger [dbo].[tr_JobDeleteCascade] Script Date: 04/19/2011 16:31:53 ******/
|
---|
| 148 | SET ANSI_NULLS ON
|
---|
| 149 | GO
|
---|
| 150 | SET QUOTED_IDENTIFIER ON
|
---|
| 151 | GO
|
---|
| 152 | -- =============================================
|
---|
| 153 | -- Author: cneumuel
|
---|
| 154 | -- Create date: 19.04.2011
|
---|
| 155 | -- Description: (1) Writes the execution times of deleted jobs into DeletedJobStats to ensure correct statistics
|
---|
| 156 | -- (2) Deletes all associated jobs. This cannot be done with cascading delete,
|
---|
| 157 | -- because the job table defines a INSTEAD OF DELETE trigger itself, which
|
---|
| 158 | -- is not compatible with cascading deletes.
|
---|
| 159 | -- =============================================
|
---|
| 160 | CREATE TRIGGER [dbo].[tr_JobDeleteCascade] ON [dbo].[Job] INSTEAD OF DELETE AS
|
---|
| 161 | BEGIN
|
---|
[12878] | 162 | DELETE Task FROM deleted, Task WHERE deleted.JobId = Task.JobId
|
---|
| 163 | DELETE Job FROM deleted, Job WHERE deleted.JobId = Job.JobId
|
---|
[6983] | 164 | END
|
---|
| 165 | GO
|
---|
| 166 |
|
---|
| 167 | -- =============================================
|
---|
| 168 | -- Author: cneumuel
|
---|
| 169 | -- Create date: 11.11.2010
|
---|
| 170 | -- Description: Recursively deletes all child-jobs of a job when it is deleted. (Source: http://devio.wordpress.com/2008/05/23/recursive-delete-in-sql-server/)
|
---|
[12878] | 171 | -- =============================================DeletedJobStatistics
|
---|
[6983] | 172 | CREATE TRIGGER [dbo].[tr_TaskDeleteCascade] ON [dbo].[Task] INSTEAD OF DELETE AS
|
---|
| 173 | BEGIN
|
---|
[12878] | 174 | -- recursively delete jobs
|
---|
| 175 | CREATE TABLE #Table(
|
---|
| 176 | TaskId uniqueidentifier
|
---|
| 177 | )
|
---|
| 178 | INSERT INTO #Table (TaskId)
|
---|
| 179 | SELECT TaskId FROM deleted
|
---|
| 180 |
|
---|
| 181 | DECLARE @c INT
|
---|
| 182 | SET @c = 0
|
---|
| 183 |
|
---|
| 184 | WHILE @c <> (SELECT COUNT(TaskId) FROM #Table) BEGIN
|
---|
| 185 | SELECT @c = COUNT(TaskId) FROM #Table
|
---|
| 186 |
|
---|
| 187 | INSERT INTO #Table (TaskId)
|
---|
| 188 | SELECT Task.TaskId
|
---|
| 189 | FROM Task
|
---|
| 190 | LEFT OUTER JOIN #Table ON Task.TaskId = #Table.TaskId
|
---|
| 191 | WHERE Task.ParentTaskId IN (SELECT TaskId FROM #Table)
|
---|
| 192 | AND #Table.TaskId IS NULL
|
---|
| 193 | END
|
---|
| 194 |
|
---|
| 195 | DELETE TaskData FROM TaskData INNER JOIN #Table ON TaskData.TaskId = #Table.TaskId
|
---|
| 196 | DELETE Task FROM Task INNER JOIN #Table ON Task.TaskId = #Table.TaskId
|
---|
[6983] | 197 | END
|
---|
| 198 | GO
|
---|
[15630] | 199 | -- OBSOLETE (end)
|
---|
[6983] | 200 |
|
---|