[12962] | 1 | /* HeuristicLab
|
---|
| 2 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 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 */
|
---|
[6983] | 21 | USE [HeuristicLab.Hive-3.3]
|
---|
| 22 |
|
---|
| 23 | ALTER TABLE [dbo].[AssignedResources] DROP CONSTRAINT [Task_AssignedResource]
|
---|
| 24 | ALTER TABLE [dbo].[AssignedResources] WITH CHECK ADD CONSTRAINT [Task_AssignedResource] FOREIGN KEY([TaskId])
|
---|
| 25 | REFERENCES [dbo].[Task] ([TaskId])
|
---|
| 26 | ON UPDATE CASCADE
|
---|
| 27 | ON DELETE CASCADE
|
---|
| 28 | GO
|
---|
| 29 | ALTER TABLE [dbo].[AssignedResources] DROP CONSTRAINT [Resource_AssignedResource]
|
---|
| 30 | ALTER TABLE [dbo].[AssignedResources] WITH CHECK ADD CONSTRAINT [Resource_AssignedResource] FOREIGN KEY([ResourceId])
|
---|
| 31 | REFERENCES [dbo].[Resource] ([ResourceId])
|
---|
| 32 | ON UPDATE CASCADE
|
---|
| 33 | ON DELETE CASCADE
|
---|
| 34 | GO
|
---|
| 35 |
|
---|
| 36 | ALTER TABLE dbo.Task ALTER COLUMN TaskId ADD ROWGUIDCOL;
|
---|
| 37 | ALTER TABLE dbo.Task WITH NOCHECK ADD CONSTRAINT [DF_Task_TaskId] DEFAULT (NEWSEQUENTIALID()) FOR TaskId;
|
---|
| 38 | GO
|
---|
| 39 |
|
---|
| 40 | ALTER TABLE [dbo].[StateLog] DROP CONSTRAINT [Task_StateLog]
|
---|
| 41 | ALTER TABLE [dbo].[StateLog] WITH CHECK ADD CONSTRAINT [Task_StateLog] FOREIGN KEY([TaskId])
|
---|
| 42 | REFERENCES [dbo].[Task] ([TaskId])
|
---|
| 43 | ON UPDATE CASCADE
|
---|
| 44 | ON DELETE CASCADE
|
---|
| 45 | GO
|
---|
| 46 | ALTER TABLE [dbo].[StateLog] DROP CONSTRAINT [Resource_StateLog]
|
---|
| 47 | ALTER TABLE [dbo].[StateLog] WITH CHECK ADD CONSTRAINT [Resource_StateLog] FOREIGN KEY([SlaveId])
|
---|
| 48 | REFERENCES [dbo].[Resource] ([ResourceId])
|
---|
| 49 | ON UPDATE CASCADE
|
---|
| 50 | ON DELETE SET NULL
|
---|
| 51 | GO
|
---|
| 52 |
|
---|
| 53 | ALTER TABLE dbo.Plugin ALTER COLUMN PluginId ADD ROWGUIDCOL;
|
---|
| 54 | ALTER TABLE dbo.Plugin WITH NOCHECK ADD CONSTRAINT [DF_Plugin_PluginId] DEFAULT (NEWSEQUENTIALID()) FOR PluginId;
|
---|
| 55 |
|
---|
| 56 | ALTER TABLE dbo.PluginData WITH NOCHECK ADD CONSTRAINT [DF_PluginData_PluginDataId] DEFAULT (NEWSEQUENTIALID()) FOR PluginDataId;
|
---|
| 57 |
|
---|
| 58 | ALTER TABLE [dbo].[PluginData] DROP CONSTRAINT [Plugin_PluginData]
|
---|
| 59 | ALTER TABLE [dbo].[PluginData] WITH CHECK ADD CONSTRAINT [Plugin_PluginData] FOREIGN KEY([PluginId])
|
---|
| 60 | REFERENCES [dbo].[Plugin] ([PluginId])
|
---|
| 61 | ON UPDATE CASCADE
|
---|
| 62 | ON DELETE CASCADE
|
---|
| 63 | GO
|
---|
| 64 |
|
---|
| 65 | ALTER TABLE dbo.RequiredPlugins ALTER COLUMN RequiredPluginId ADD ROWGUIDCOL;
|
---|
| 66 | ALTER TABLE dbo.RequiredPlugins WITH NOCHECK ADD CONSTRAINT [DF_RequiredPlugins_RequiredPluginId] DEFAULT (NEWSEQUENTIALID()) FOR RequiredPluginId;
|
---|
| 67 |
|
---|
| 68 | ALTER TABLE [dbo].[RequiredPlugins] DROP CONSTRAINT [Task_RequiredPlugin]
|
---|
| 69 | ALTER TABLE [dbo].[RequiredPlugins] WITH CHECK ADD CONSTRAINT [Task_RequiredPlugin] FOREIGN KEY([TaskId])
|
---|
| 70 | REFERENCES [dbo].[Task] ([TaskId])
|
---|
| 71 | ON UPDATE CASCADE
|
---|
| 72 | ON DELETE CASCADE
|
---|
| 73 | GO
|
---|
| 74 |
|
---|
| 75 | ALTER TABLE [dbo].[RequiredPlugins] DROP CONSTRAINT [Plugin_RequiredPlugin]
|
---|
| 76 | ALTER TABLE [dbo].[RequiredPlugins] WITH CHECK ADD CONSTRAINT [Plugin_RequiredPlugin] FOREIGN KEY([PluginId])
|
---|
| 77 | REFERENCES [dbo].[Plugin] ([PluginId])
|
---|
| 78 | ON UPDATE CASCADE
|
---|
| 79 | ON DELETE CASCADE
|
---|
| 80 | GO
|
---|
| 81 |
|
---|
| 82 | ALTER TABLE dbo.Resource ALTER COLUMN ResourceId ADD ROWGUIDCOL;
|
---|
| 83 | ALTER TABLE dbo.Resource WITH NOCHECK ADD CONSTRAINT [DF_Resource_ResourceId] DEFAULT (NEWSEQUENTIALID()) FOR ResourceId;
|
---|
| 84 |
|
---|
| 85 | ALTER TABLE dbo.Downtime ALTER COLUMN DowntimeId ADD ROWGUIDCOL;
|
---|
| 86 | ALTER TABLE dbo.Downtime WITH NOCHECK ADD CONSTRAINT [DF_Downtime_DowntimeId] DEFAULT (NEWSEQUENTIALID()) FOR DowntimeId;
|
---|
| 87 |
|
---|
| 88 | ALTER TABLE dbo.Job ALTER COLUMN JobId ADD ROWGUIDCOL;
|
---|
| 89 | ALTER TABLE dbo.Job WITH NOCHECK ADD CONSTRAINT [DF_Job_JobId] DEFAULT (NEWSEQUENTIALID()) FOR JobId;
|
---|
| 90 |
|
---|
| 91 | ALTER TABLE dbo.StateLog ALTER COLUMN StateLogId ADD ROWGUIDCOL;
|
---|
| 92 | ALTER TABLE dbo.StateLog WITH NOCHECK ADD CONSTRAINT [DF_StateLog_StateLogId] DEFAULT (NEWSEQUENTIALID()) FOR StateLogId;
|
---|
| 93 |
|
---|
| 94 | ALTER TABLE [dbo].[JobPermission] DROP CONSTRAINT [Job_JobPermission]
|
---|
| 95 | ALTER TABLE [dbo].[JobPermission] WITH CHECK ADD CONSTRAINT [Job_JobPermission] FOREIGN KEY([JobId])
|
---|
| 96 | REFERENCES [dbo].[Job] ([JobId])
|
---|
| 97 | ON UPDATE CASCADE
|
---|
| 98 | ON DELETE CASCADE
|
---|
| 99 | GO
|
---|
| 100 |
|
---|
[7916] | 101 | ALTER TABLE [dbo].[ResourcePermission] DROP CONSTRAINT [Resource_ResourcePermission]
|
---|
| 102 | ALTER TABLE [dbo].[ResourcePermission] WITH CHECK ADD CONSTRAINT [Resource_ResourcePermission] FOREIGN KEY([ResourceId])
|
---|
| 103 | REFERENCES [dbo].[Resource] ([ResourceId])
|
---|
| 104 | ON UPDATE CASCADE
|
---|
| 105 | ON DELETE CASCADE
|
---|
| 106 | GO
|
---|
| 107 |
|
---|
[6983] | 108 | /* create indices */
|
---|
| 109 | CREATE INDEX Index_RequiredPlugins_TaskId ON RequiredPlugins(TaskId);
|
---|
| 110 | GO
|
---|
| 111 |
|
---|
[12962] | 112 | -- speed up joins between Job and Task
|
---|
| 113 | CREATE NONCLUSTERED INDEX [TaskJobIdIndex]
|
---|
| 114 | ON [dbo].[Task] ([JobId])
|
---|
[12963] | 115 | INCLUDE ([TaskId],[TaskState],[ExecutionTimeMs],[LastHeartbeat],[ParentTaskId],[Priority],[CoresNeeded],[MemoryNeeded],[IsParentTask],[FinishWhenChildJobsFinished],[Command])
|
---|
[6983] | 116 | GO
|
---|
| 117 |
|
---|
[12962] | 118 | -- this is an index to speed up the GetWaitingTasks() method
|
---|
| 119 | CREATE NONCLUSTERED INDEX [TaskGetWaitingTasksIndex]
|
---|
| 120 | ON [dbo].[Task] ([TaskState],[IsParentTask],[FinishWhenChildJobsFinished],[CoresNeeded],[MemoryNeeded])
|
---|
[12963] | 121 | INCLUDE ([TaskId],[ExecutionTimeMs],[LastHeartbeat],[ParentTaskId],[Priority],[Command],[JobId])
|
---|
[6983] | 122 | GO
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | /****** Object: Trigger [dbo].[tr_JobDeleteCascade] Script Date: 04/19/2011 16:31:53 ******/
|
---|
| 126 | SET ANSI_NULLS ON
|
---|
| 127 | GO
|
---|
| 128 | SET QUOTED_IDENTIFIER ON
|
---|
| 129 | GO
|
---|
| 130 | -- =============================================
|
---|
| 131 | -- Author: cneumuel
|
---|
| 132 | -- Create date: 19.04.2011
|
---|
| 133 | -- Description: (1) Writes the execution times of deleted jobs into DeletedJobStats to ensure correct statistics
|
---|
| 134 | -- (2) Deletes all associated jobs. This cannot be done with cascading delete,
|
---|
| 135 | -- because the job table defines a INSTEAD OF DELETE trigger itself, which
|
---|
| 136 | -- is not compatible with cascading deletes.
|
---|
| 137 | -- =============================================
|
---|
| 138 | CREATE TRIGGER [dbo].[tr_JobDeleteCascade] ON [dbo].[Job] INSTEAD OF DELETE AS
|
---|
| 139 | BEGIN
|
---|
[12962] | 140 | DELETE Task FROM deleted, Task WHERE deleted.JobId = Task.JobId
|
---|
| 141 | DELETE Job FROM deleted, Job WHERE deleted.JobId = Job.JobId
|
---|
[6983] | 142 | END
|
---|
| 143 | GO
|
---|
| 144 |
|
---|
| 145 | -- =============================================
|
---|
| 146 | -- Author: cneumuel
|
---|
| 147 | -- Create date: 11.11.2010
|
---|
| 148 | -- 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/)
|
---|
[12962] | 149 | -- =============================================DeletedJobStatistics
|
---|
[6983] | 150 | CREATE TRIGGER [dbo].[tr_TaskDeleteCascade] ON [dbo].[Task] INSTEAD OF DELETE AS
|
---|
| 151 | BEGIN
|
---|
[12962] | 152 | -- recursively delete jobs
|
---|
| 153 | CREATE TABLE #Table(
|
---|
| 154 | TaskId uniqueidentifier
|
---|
| 155 | )
|
---|
| 156 | INSERT INTO #Table (TaskId)
|
---|
| 157 | SELECT TaskId FROM deleted
|
---|
| 158 |
|
---|
| 159 | DECLARE @c INT
|
---|
| 160 | SET @c = 0
|
---|
| 161 |
|
---|
| 162 | WHILE @c <> (SELECT COUNT(TaskId) FROM #Table) BEGIN
|
---|
| 163 | SELECT @c = COUNT(TaskId) FROM #Table
|
---|
| 164 |
|
---|
| 165 | INSERT INTO #Table (TaskId)
|
---|
| 166 | SELECT Task.TaskId
|
---|
| 167 | FROM Task
|
---|
| 168 | LEFT OUTER JOIN #Table ON Task.TaskId = #Table.TaskId
|
---|
| 169 | WHERE Task.ParentTaskId IN (SELECT TaskId FROM #Table)
|
---|
| 170 | AND #Table.TaskId IS NULL
|
---|
| 171 | END
|
---|
| 172 |
|
---|
| 173 | DELETE TaskData FROM TaskData INNER JOIN #Table ON TaskData.TaskId = #Table.TaskId
|
---|
| 174 | DELETE Task FROM Task INNER JOIN #Table ON Task.TaskId = #Table.TaskId
|
---|
[6983] | 175 | END
|
---|
| 176 | GO
|
---|
| 177 |
|
---|
[7185] | 178 |
|
---|