1 | /* create and initialize hive database tables */
|
---|
2 |
|
---|
3 | SET ARITHABORT ON
|
---|
4 | CREATE TABLE [dbo].[AssignedResources](
|
---|
5 | [ResourceId] UniqueIdentifier NOT NULL,
|
---|
6 | [TaskId] UniqueIdentifier NOT NULL,
|
---|
7 | CONSTRAINT [PK_dbo.ResourceIdTaskId] PRIMARY KEY ([ResourceId], [TaskId])
|
---|
8 | )
|
---|
9 | CREATE TABLE [dbo].[Plugin](
|
---|
10 | [PluginId] UniqueIdentifier NOT NULL,
|
---|
11 | [Name] VarChar(MAX) NOT NULL,
|
---|
12 | [Version] VarChar(MAX) NOT NULL,
|
---|
13 | [UserId] UniqueIdentifier NOT NULL,
|
---|
14 | [DateCreated] DateTime NOT NULL,
|
---|
15 | [Hash] VarBinary(20) NOT NULL,
|
---|
16 | CONSTRAINT [PK_dbo.Plugin] PRIMARY KEY ([PluginId])
|
---|
17 | )
|
---|
18 | CREATE TABLE [dbo].[RequiredPlugins](
|
---|
19 | [RequiredPluginId] UniqueIdentifier NOT NULL,
|
---|
20 | [TaskId] UniqueIdentifier NOT NULL,
|
---|
21 | [PluginId] UniqueIdentifier NOT NULL,
|
---|
22 | CONSTRAINT [PK_dbo.RequiredPlugins] PRIMARY KEY ([RequiredPluginId])
|
---|
23 | )
|
---|
24 | CREATE TABLE [dbo].[Resource](
|
---|
25 | [ResourceId] UniqueIdentifier NOT NULL,
|
---|
26 | [Name] VarChar(MAX) NOT NULL,
|
---|
27 | [ResourceType] NVarChar(4000) NOT NULL,
|
---|
28 | [ParentResourceId] UniqueIdentifier,
|
---|
29 | [CpuSpeed] Int,
|
---|
30 | [Memory] Int,
|
---|
31 | [Login] DateTime,
|
---|
32 | [SlaveState] VarChar(15),
|
---|
33 | [Cores] Int,
|
---|
34 | [FreeCores] Int,
|
---|
35 | [FreeMemory] Int,
|
---|
36 | [IsAllowedToCalculate] Bit,
|
---|
37 | [CpuArchitecture] VarChar(3),
|
---|
38 | [OperatingSystem] VarChar(MAX),
|
---|
39 | [LastHeartbeat] DateTime,
|
---|
40 | [CpuUtilization] float,
|
---|
41 | [HbInterval] int NOT NULL,
|
---|
42 | [IsDisposable] Bit,
|
---|
43 | [OwnerUserId] UniqueIdentifier,
|
---|
44 | CONSTRAINT [PK_dbo.Resource] PRIMARY KEY ([ResourceId])
|
---|
45 | )
|
---|
46 | CREATE TABLE [dbo].[ResourcePermission](
|
---|
47 | [ResourceId] UniqueIdentifier NOT NULL,
|
---|
48 | [GrantedUserId] UniqueIdentifier NOT NULL,
|
---|
49 | [GrantedByUserId] UniqueIdentifier NOT NULL,
|
---|
50 | CONSTRAINT [PK_dbo.ResourcePermission] PRIMARY KEY ([ResourceId], [GrantedUserId])
|
---|
51 | )
|
---|
52 | CREATE TABLE [dbo].[Task](
|
---|
53 | [TaskId] UniqueIdentifier NOT NULL,
|
---|
54 | [TaskState] VarChar(30) NOT NULL,
|
---|
55 | [ExecutionTimeMs] float NOT NULL,
|
---|
56 | [LastHeartbeat] DateTime,
|
---|
57 | [ParentTaskId] UniqueIdentifier,
|
---|
58 | [Priority] Int NOT NULL,
|
---|
59 | [CoresNeeded] Int NOT NULL,
|
---|
60 | [MemoryNeeded] Int NOT NULL,
|
---|
61 | [IsParentTask] Bit NOT NULL,
|
---|
62 | [FinishWhenChildJobsFinished] Bit NOT NULL,
|
---|
63 | [Command] VarChar(30),
|
---|
64 | [JobId] UniqueIdentifier NOT NULL,
|
---|
65 | [IsPrivileged] Bit NOT NULL,
|
---|
66 | CONSTRAINT [PK_dbo.Task] PRIMARY KEY ([TaskId])
|
---|
67 | )
|
---|
68 | CREATE TABLE [dbo].[Downtime](
|
---|
69 | [DowntimeId] UniqueIdentifier NOT NULL,
|
---|
70 | [ResourceId] UniqueIdentifier NOT NULL,
|
---|
71 | [StartDate] DateTime NOT NULL,
|
---|
72 | [EndDate] DateTime NOT NULL,
|
---|
73 | [AllDayEvent] Bit NOT NULL,
|
---|
74 | [Recurring] Bit NOT NULL,
|
---|
75 | [RecurringId] UniqueIdentifier NOT NULL,
|
---|
76 | CONSTRAINT [PK_dbo.Downtime] PRIMARY KEY ([DowntimeId])
|
---|
77 | )
|
---|
78 | CREATE TABLE [dbo].[Job](
|
---|
79 | [JobId] UniqueIdentifier NOT NULL,
|
---|
80 | [Name] VarChar(MAX) NOT NULL,
|
---|
81 | [Description] VarChar(MAX),
|
---|
82 | [ResourceIds] VarChar(MAX),
|
---|
83 | [OwnerUserId] UniqueIdentifier NOT NULL,
|
---|
84 | [DateCreated] DateTime NOT NULL,
|
---|
85 | CONSTRAINT [PK_dbo.Job] PRIMARY KEY ([JobId])
|
---|
86 | )
|
---|
87 | CREATE TABLE [dbo].[TaskData](
|
---|
88 | [TaskId] UniqueIdentifier NOT NULL,
|
---|
89 | [Data] VarBinary(MAX) NOT NULL,
|
---|
90 | [LastUpdate] DateTime NOT NULL,
|
---|
91 | CONSTRAINT [PK_dbo.TaskData] PRIMARY KEY ([TaskId])
|
---|
92 | )
|
---|
93 | CREATE TABLE [dbo].[PluginData](
|
---|
94 | [PluginDataId] UniqueIdentifier NOT NULL,
|
---|
95 | [PluginId] UniqueIdentifier NOT NULL,
|
---|
96 | [Data] VarBinary(MAX) NOT NULL,
|
---|
97 | [FileName] VarChar(MAX) NOT NULL,
|
---|
98 | CONSTRAINT [PK_dbo.PluginData] PRIMARY KEY ([PluginDataId])
|
---|
99 | )
|
---|
100 | CREATE TABLE [dbo].[StateLog](
|
---|
101 | [StateLogId] UniqueIdentifier NOT NULL,
|
---|
102 | [State] VarChar(30) NOT NULL,
|
---|
103 | [DateTime] DateTime NOT NULL,
|
---|
104 | [TaskId] UniqueIdentifier NOT NULL,
|
---|
105 | [UserId] UniqueIdentifier,
|
---|
106 | [SlaveId] UniqueIdentifier,
|
---|
107 | [Exception] VarChar(MAX),
|
---|
108 | CONSTRAINT [PK_dbo.StateLog] PRIMARY KEY ([StateLogId])
|
---|
109 | )
|
---|
110 | CREATE TABLE [dbo].[JobPermission](
|
---|
111 | [JobId] UniqueIdentifier NOT NULL,
|
---|
112 | [GrantedUserId] UniqueIdentifier NOT NULL,
|
---|
113 | [GrantedByUserId] UniqueIdentifier NOT NULL,
|
---|
114 | [Permission] VarChar(15) NOT NULL,
|
---|
115 | CONSTRAINT [PK_dbo.JobPermission] PRIMARY KEY ([JobId], [GrantedUserId])
|
---|
116 | )
|
---|
117 | CREATE TABLE [Lifecycle](
|
---|
118 | [LifecycleId] Int NOT NULL,
|
---|
119 | [LastCleanup] DateTime NOT NULL,
|
---|
120 | CONSTRAINT [PK_Lifecycle] PRIMARY KEY ([LifecycleId])
|
---|
121 | )
|
---|
122 | CREATE TABLE [DeletedJobStatistics](
|
---|
123 | [UserId] UniqueIdentifier NOT NULL,
|
---|
124 | [ExecutionTimeS] float NOT NULL,
|
---|
125 | [ExecutionTimeSFinishedJobs] float NOT NULL,
|
---|
126 | [StartToEndTimeS] float NOT NULL,
|
---|
127 | [DeletedJobStatisticsId] UniqueIdentifier NOT NULL,
|
---|
128 | CONSTRAINT [PK_DeletedJobStatistics] PRIMARY KEY ([DeletedJobStatisticsId])
|
---|
129 | )
|
---|
130 | CREATE TABLE [UserStatistics](
|
---|
131 | [StatisticsId] UniqueIdentifier NOT NULL,
|
---|
132 | [UserId] UniqueIdentifier NOT NULL,
|
---|
133 | [ExecutionTimeMs] float NOT NULL,
|
---|
134 | [UsedCores] Int NOT NULL,
|
---|
135 | [ExecutionTimeMsFinishedJobs] float NOT NULL,
|
---|
136 | [StartToEndTimeMs] float NOT NULL,
|
---|
137 | CONSTRAINT [PK_UserStatistics] PRIMARY KEY ([StatisticsId], [UserId])
|
---|
138 | )
|
---|
139 | CREATE TABLE [SlaveStatistics](
|
---|
140 | [StatisticsId] UniqueIdentifier NOT NULL,
|
---|
141 | [SlaveId] UniqueIdentifier NOT NULL,
|
---|
142 | [Cores] Int NOT NULL,
|
---|
143 | [FreeCores] Int NOT NULL,
|
---|
144 | [CpuUtilization] float NOT NULL,
|
---|
145 | [Memory] Int NOT NULL,
|
---|
146 | [FreeMemory] Int NOT NULL,
|
---|
147 | CONSTRAINT [PK_SlaveStatistics] PRIMARY KEY ([StatisticsId], [SlaveId])
|
---|
148 | )
|
---|
149 | CREATE TABLE [Statistics](
|
---|
150 | [StatisticsId] UniqueIdentifier NOT NULL,
|
---|
151 | [Timestamp] DateTime NOT NULL,
|
---|
152 | CONSTRAINT [PK_Statistics] PRIMARY KEY ([StatisticsId])
|
---|
153 | )
|
---|
154 | ALTER TABLE [dbo].[AssignedResources]
|
---|
155 | ADD CONSTRAINT [Resource_AssignedResource] FOREIGN KEY ([ResourceId]) REFERENCES [dbo].[Resource]([ResourceId])
|
---|
156 | ALTER TABLE [dbo].[AssignedResources]
|
---|
157 | ADD CONSTRAINT [Task_AssignedResource] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[Task]([TaskId])
|
---|
158 | ALTER TABLE [dbo].[RequiredPlugins]
|
---|
159 | ADD CONSTRAINT [Plugin_RequiredPlugin] FOREIGN KEY ([PluginId]) REFERENCES [dbo].[Plugin]([PluginId])
|
---|
160 | ALTER TABLE [dbo].[RequiredPlugins]
|
---|
161 | ADD CONSTRAINT [Task_RequiredPlugin] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[Task]([TaskId])
|
---|
162 | ALTER TABLE [dbo].[Resource]
|
---|
163 | ADD CONSTRAINT [Resource_Resource] FOREIGN KEY ([ParentResourceId]) REFERENCES [dbo].[Resource]([ResourceId])
|
---|
164 | ALTER TABLE [dbo].[ResourcePermission]
|
---|
165 | ADD CONSTRAINT [Resource_ResourcePermission] FOREIGN KEY ([ResourceId]) REFERENCES [dbo].[Resource]([ResourceId])
|
---|
166 | ALTER TABLE [dbo].[Task]
|
---|
167 | ADD CONSTRAINT [Task_Task] FOREIGN KEY ([ParentTaskId]) REFERENCES [dbo].[Task]([TaskId])
|
---|
168 | ALTER TABLE [dbo].[Task]
|
---|
169 | ADD CONSTRAINT [Job_Job] FOREIGN KEY ([JobId]) REFERENCES [dbo].[Job]([JobId])
|
---|
170 | ALTER TABLE [dbo].[Downtime]
|
---|
171 | ADD CONSTRAINT [Resource_Downtime] FOREIGN KEY ([ResourceId]) REFERENCES [dbo].[Resource]([ResourceId])
|
---|
172 | ALTER TABLE [dbo].[TaskData]
|
---|
173 | ADD CONSTRAINT [Task_TaskData] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[Task]([TaskId])
|
---|
174 | ALTER TABLE [dbo].[PluginData]
|
---|
175 | ADD CONSTRAINT [Plugin_PluginData] FOREIGN KEY ([PluginId]) REFERENCES [dbo].[Plugin]([PluginId])
|
---|
176 | ALTER TABLE [dbo].[StateLog]
|
---|
177 | ADD CONSTRAINT [Task_StateLog] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[Task]([TaskId])
|
---|
178 | ALTER TABLE [dbo].[StateLog]
|
---|
179 | ADD CONSTRAINT [Resource_StateLog] FOREIGN KEY ([SlaveId]) REFERENCES [dbo].[Resource]([ResourceId])
|
---|
180 | ALTER TABLE [dbo].[JobPermission]
|
---|
181 | ADD CONSTRAINT [Job_JobPermission] FOREIGN KEY ([JobId]) REFERENCES [dbo].[Job]([JobId])
|
---|
182 | ALTER TABLE [UserStatistics]
|
---|
183 | ADD CONSTRAINT [Statistics_UserStatistics] FOREIGN KEY ([StatisticsId]) REFERENCES [Statistics]([StatisticsId])
|
---|
184 | ALTER TABLE [SlaveStatistics]
|
---|
185 | ADD CONSTRAINT [Statistics_SlaveStatistics] FOREIGN KEY ([StatisticsId]) REFERENCES [Statistics]([StatisticsId])
|
---|