1 | -- $Id: tmdb-r21-testsets-4.pgsql 82968 2020-02-04 10:35:17Z vboxsync $
|
---|
2 | --- @file
|
---|
3 | -- VBox Test Manager Database - Adds an idSchedGroup to TestSets in
|
---|
4 | -- preparation for testboxes belonging to multiple scheduling queues.
|
---|
5 | --
|
---|
6 |
|
---|
7 | --
|
---|
8 | -- Copyright (C) 2013-2020 Oracle Corporation
|
---|
9 | --
|
---|
10 | -- This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | -- available from http://www.virtualbox.org. This file is free software;
|
---|
12 | -- you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | -- General Public License (GPL) as published by the Free Software
|
---|
14 | -- Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | -- VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | -- hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | --
|
---|
18 | -- The contents of this file may alternatively be used under the terms
|
---|
19 | -- of the Common Development and Distribution License Version 1.0
|
---|
20 | -- (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
21 | -- VirtualBox OSE distribution, in which case the provisions of the
|
---|
22 | -- CDDL are applicable instead of those of the GPL.
|
---|
23 | --
|
---|
24 | -- You may elect to license modified versions of this file under the
|
---|
25 | -- terms and conditions of either the GPL or the CDDL or both.
|
---|
26 | --
|
---|
27 |
|
---|
28 | --
|
---|
29 | -- Cleanup after failed runs.
|
---|
30 | --
|
---|
31 | DROP TABLE IF EXISTS OldTestSets;
|
---|
32 |
|
---|
33 | --
|
---|
34 | -- Die on error from now on.
|
---|
35 | --
|
---|
36 | \set ON_ERROR_STOP 1
|
---|
37 | \set AUTOCOMMIT 0
|
---|
38 |
|
---|
39 |
|
---|
40 | -- Total grid lock (don't want to deadlock below).
|
---|
41 | LOCK TABLE TestBoxStatuses IN ACCESS EXCLUSIVE MODE;
|
---|
42 | LOCK TABLE TestSets IN ACCESS EXCLUSIVE MODE;
|
---|
43 | LOCK TABLE TestBoxes IN ACCESS EXCLUSIVE MODE;
|
---|
44 | LOCK TABLE TestResults IN ACCESS EXCLUSIVE MODE;
|
---|
45 | LOCK TABLE TestResultFailures IN ACCESS EXCLUSIVE MODE;
|
---|
46 | LOCK TABLE TestResultFiles IN ACCESS EXCLUSIVE MODE;
|
---|
47 | LOCK TABLE TestResultMsgs IN ACCESS EXCLUSIVE MODE;
|
---|
48 | LOCK TABLE TestResultValues IN ACCESS EXCLUSIVE MODE;
|
---|
49 | LOCK TABLE SchedGroups IN ACCESS EXCLUSIVE MODE;
|
---|
50 | LOCK TABLE SchedQueues IN ACCESS EXCLUSIVE MODE;
|
---|
51 | LOCK TABLE SchedGroupMembers IN ACCESS EXCLUSIVE MODE;
|
---|
52 |
|
---|
53 | \d+ TestSets;
|
---|
54 |
|
---|
55 | --
|
---|
56 | -- Rename the table, drop foreign keys refering to it, and drop constrains
|
---|
57 | -- within the table itself. The latter is mostly for naming and we do it
|
---|
58 | -- up front in case the database we're running against has different names
|
---|
59 | -- due to previous conversions.
|
---|
60 | --
|
---|
61 | ALTER TABLE TestSets RENAME TO OldTestSets;
|
---|
62 |
|
---|
63 | ALTER TABLE TestResultFailures DROP CONSTRAINT IF EXISTS idtestsetfk;
|
---|
64 | ALTER TABLE TestResultFailures DROP CONSTRAINT IF EXISTS TestResultFailures_idTestSet_fkey;
|
---|
65 | ALTER TABLE SchedQueues DROP CONSTRAINT IF EXISTS SchedQueues_idTestSetGangLeader_fkey;
|
---|
66 | ALTER TABLE TestBoxStatuses DROP CONSTRAINT IF EXISTS TestBoxStatuses_idTestSet_fkey;
|
---|
67 | ALTER TABLE TestResultFiles DROP CONSTRAINT IF EXISTS TestResultFiles_idTestSet_fkey;
|
---|
68 | ALTER TABLE TestResultMsgs DROP CONSTRAINT IF EXISTS TestResultMsgs_idTestSet_fkey;
|
---|
69 | ALTER TABLE TestResults DROP CONSTRAINT IF EXISTS TestResults_idTestSet_fkey;
|
---|
70 | ALTER TABLE TestResultValues DROP CONSTRAINT IF EXISTS TestResultValues_idTestSet_fkey;
|
---|
71 | ALTER TABLE TestResultValues DROP CONSTRAINT IF EXISTS TestResultValues_idTestSet_fkey1;
|
---|
72 |
|
---|
73 | ALTER TABLE OldTestSets DROP CONSTRAINT testsets_igangmemberno_check;
|
---|
74 |
|
---|
75 | ALTER TABLE OldTestSets DROP CONSTRAINT TestSets_idBuildCategory_fkey;
|
---|
76 | ALTER TABLE OldTestSets DROP CONSTRAINT TestSets_idGenTestBox_fkey;
|
---|
77 | ALTER TABLE OldTestSets DROP CONSTRAINT TestSets_idGenTestCase_fkey;
|
---|
78 | ALTER TABLE OldTestSets DROP CONSTRAINT TestSets_idGenTestCaseArgs_fkey;
|
---|
79 | ALTER TABLE OldTestSets DROP CONSTRAINT TestSets_idTestResult_fkey;
|
---|
80 | ALTER TABLE OldTestSets DROP CONSTRAINT TestSets_idTestSetGangLeader_fkey;
|
---|
81 |
|
---|
82 | ALTER TABLE OldTestSets DROP CONSTRAINT IF EXISTS TestSets_sBaseFilename_key;
|
---|
83 | ALTER TABLE OldTestSets DROP CONSTRAINT IF EXISTS NewTestSets_sBaseFilename_key;
|
---|
84 | ALTER TABLE OldTestSets DROP CONSTRAINT TestSets_pkey;
|
---|
85 |
|
---|
86 | DROP INDEX IF EXISTS TestSetsGangIdx;
|
---|
87 | DROP INDEX IF EXISTS TestSetsBoxIdx;
|
---|
88 | DROP INDEX IF EXISTS TestSetsBuildIdx;
|
---|
89 | DROP INDEX IF EXISTS TestSetsTestCaseIdx;
|
---|
90 | DROP INDEX IF EXISTS TestSetsTestVarIdx;
|
---|
91 | DROP INDEX IF EXISTS TestSetsDoneCreatedBuildCatIdx;
|
---|
92 | DROP INDEX IF EXISTS TestSetsGraphBoxIdx;
|
---|
93 |
|
---|
94 |
|
---|
95 | -- This output should be free of indexes, constraints and references from other tables.
|
---|
96 | \d+ OldTestSets;
|
---|
97 |
|
---|
98 | \prompt "Is the above table completely free of indexes, constraints and references? Ctrl-C if not." dummy
|
---|
99 |
|
---|
100 | --
|
---|
101 | -- Create the new table (no foreign keys).
|
---|
102 | --
|
---|
103 | CREATE TABLE TestSets (
|
---|
104 | --- The ID of this test set.
|
---|
105 | idTestSet INTEGER DEFAULT NEXTVAL('TestSetIdSeq') NOT NULL,
|
---|
106 |
|
---|
107 | --- The test config timestamp, used when reading test config.
|
---|
108 | tsConfig TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
---|
109 | --- When this test set was scheduled.
|
---|
110 | -- idGenTestBox is valid at this point.
|
---|
111 | tsCreated TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
---|
112 | --- When this test completed, i.e. testing stopped. This should only be set once.
|
---|
113 | tsDone TIMESTAMP WITH TIME ZONE DEFAULT NULL,
|
---|
114 | --- The current status.
|
---|
115 | enmStatus TestStatus_T DEFAULT 'running'::TestStatus_T NOT NULL,
|
---|
116 |
|
---|
117 | --- The build we're testing.
|
---|
118 | -- Non-unique foreign key: Builds(idBuild)
|
---|
119 | idBuild INTEGER NOT NULL,
|
---|
120 | --- The build category of idBuild when the test started.
|
---|
121 | -- This is for speeding up graph data collection, i.e. avoid idBuild
|
---|
122 | -- the WHERE part of the selection.
|
---|
123 | idBuildCategory INTEGER NOT NULL,
|
---|
124 | --- The test suite build we're using to do the testing.
|
---|
125 | -- This is NULL if the test suite zip wasn't referred or if a test suite
|
---|
126 | -- build source wasn't configured.
|
---|
127 | -- Non-unique foreign key: Builds(idBuild)
|
---|
128 | idBuildTestSuite INTEGER DEFAULT NULL,
|
---|
129 |
|
---|
130 | --- The exact testbox configuration.
|
---|
131 | idGenTestBox INTEGER NOT NULL,
|
---|
132 | --- The testbox ID for joining with (valid: tsStarted).
|
---|
133 | -- Non-unique foreign key: TestBoxes(idTestBox)
|
---|
134 | idTestBox INTEGER NOT NULL,
|
---|
135 | --- The scheduling group ID the test was scheduled thru (valid: tsStarted).
|
---|
136 | -- Non-unique foreign key: SchedGroups(idSchedGroup)
|
---|
137 | idSchedGroup INTEGER NOT NULL,
|
---|
138 |
|
---|
139 | --- The testgroup (valid: tsConfig).
|
---|
140 | -- Non-unique foreign key: TestBoxes(idTestGroup)
|
---|
141 | -- Note! This also gives the member ship entry, since a testcase can only
|
---|
142 | -- have one membership per test group.
|
---|
143 | idTestGroup INTEGER NOT NULL,
|
---|
144 |
|
---|
145 | --- The exact test case config we executed in this test run.
|
---|
146 | idGenTestCase INTEGER NOT NULL,
|
---|
147 | --- The test case ID for joining with (valid: tsConfig).
|
---|
148 | -- Non-unique foreign key: TestBoxes(idTestCase)
|
---|
149 | idTestCase INTEGER NOT NULL,
|
---|
150 |
|
---|
151 | --- The arguments (and requirements++) we executed this test case with.
|
---|
152 | idGenTestCaseArgs INTEGER NOT NULL,
|
---|
153 | --- The argument variation ID (valid: tsConfig).
|
---|
154 | -- Non-unique foreign key: TestCaseArgs(idTestCaseArgs)
|
---|
155 | idTestCaseArgs INTEGER NOT NULL,
|
---|
156 |
|
---|
157 | --- The root of the test result tree.
|
---|
158 | -- @note This will only be NULL early in the transaction setting up the testset.
|
---|
159 | -- @note If the test reports more than one top level test result, we'll
|
---|
160 | -- fail the whole test run and let the test developer fix it.
|
---|
161 | idTestResult INTEGER DEFAULT NULL,
|
---|
162 |
|
---|
163 | --- The base filename used for storing files related to this test set.
|
---|
164 | -- This is a path relative to wherever TM is dumping log files. In order
|
---|
165 | -- to not become a file system test case, we will try not to put too many
|
---|
166 | -- hundred thousand files in a directory. A simple first approach would
|
---|
167 | -- be to just use the current date (tsCreated) like this:
|
---|
168 | -- TM_FILE_DIR/year/month/day/TestSets.idTestSet
|
---|
169 | --
|
---|
170 | -- The primary log file for the test is this name suffixed by '.log'.
|
---|
171 | --
|
---|
172 | -- The files in the testresultfile table gets their full names like this:
|
---|
173 | -- TM_FILE_DIR/sBaseFilename-testresultfile.id-TestResultStrTab(testresultfile.idStrFilename)
|
---|
174 | --
|
---|
175 | -- @remarks We store this explicitly in case we change the directly layout
|
---|
176 | -- at some later point.
|
---|
177 | sBaseFilename text NOT NULL,
|
---|
178 |
|
---|
179 | --- The gang member number number, 0 is the leader.
|
---|
180 | iGangMemberNo SMALLINT DEFAULT 0 NOT NULL, -- CHECK (iGangMemberNo >= 0 AND iGangMemberNo < 1024),
|
---|
181 | --- The test set of the gang leader, NULL if no gang involved.
|
---|
182 | -- @note This is set by the gang leader as well, so that we can find all
|
---|
183 | -- gang members by WHERE idTestSetGangLeader = :id.
|
---|
184 | idTestSetGangLeader INTEGER DEFAULT NULL
|
---|
185 |
|
---|
186 | );
|
---|
187 |
|
---|
188 | -- Convert the data.
|
---|
189 | INSERT INTO TestSets (
|
---|
190 | idTestSet,
|
---|
191 | tsConfig,
|
---|
192 | tsCreated,
|
---|
193 | tsDone,
|
---|
194 | enmStatus,
|
---|
195 | idBuild,
|
---|
196 | idBuildCategory,
|
---|
197 | idBuildTestSuite,
|
---|
198 | idGenTestBox,
|
---|
199 | idTestBox,
|
---|
200 | idSchedGroup,
|
---|
201 | idTestGroup,
|
---|
202 | idGenTestCase,
|
---|
203 | idTestCase,
|
---|
204 | idGenTestCaseArgs,
|
---|
205 | idTestCaseArgs,
|
---|
206 | idTestResult,
|
---|
207 | sBaseFilename,
|
---|
208 | iGangMemberNo,
|
---|
209 | idTestSetGangLeader
|
---|
210 | )
|
---|
211 | SELECT OldTestSets.idTestSet,
|
---|
212 | OldTestSets.tsConfig,
|
---|
213 | OldTestSets.tsCreated,
|
---|
214 | OldTestSets.tsDone,
|
---|
215 | OldTestSets.enmStatus,
|
---|
216 | OldTestSets.idBuild,
|
---|
217 | OldTestSets.idBuildCategory,
|
---|
218 | OldTestSets.idBuildTestSuite,
|
---|
219 | OldTestSets.idGenTestBox,
|
---|
220 | OldTestSets.idTestBox,
|
---|
221 | TestBoxes.idSchedGroup,
|
---|
222 | OldTestSets.idTestGroup,
|
---|
223 | OldTestSets.idGenTestCase,
|
---|
224 | OldTestSets.idTestCase,
|
---|
225 | OldTestSets.idGenTestCaseArgs,
|
---|
226 | OldTestSets.idTestCaseArgs,
|
---|
227 | OldTestSets.idTestResult,
|
---|
228 | OldTestSets.sBaseFilename,
|
---|
229 | OldTestSets.iGangMemberNo,
|
---|
230 | OldTestSets.idTestSetGangLeader
|
---|
231 | FROM OldTestSets
|
---|
232 | INNER JOIN TestBoxes
|
---|
233 | ON OldTestSets.idGenTestBox = TestBoxes.idGenTestBox;
|
---|
234 |
|
---|
235 | -- Restore the primary key and unique constraints.
|
---|
236 | ALTER TABLE TestSets ADD PRIMARY KEY (idTestSet);
|
---|
237 | ALTER TABLE TestSets ADD UNIQUE (sBaseFilename);
|
---|
238 |
|
---|
239 | -- Restore check constraints.
|
---|
240 | ALTER TABLE TestSets ADD CONSTRAINT TestSets_iGangMemberNo_Check CHECK (iGangMemberNo >= 0 AND iGangMemberNo < 1024);
|
---|
241 |
|
---|
242 | -- Restore foreign keys in the table.
|
---|
243 | ALTER TABLE TestSets ADD FOREIGN KEY (idBuildCategory) REFERENCES BuildCategories(idBuildCategory);
|
---|
244 | ALTER TABLE TestSets ADD FOREIGN KEY (idGenTestBox) REFERENCES TestBoxes(idGenTestBox);
|
---|
245 | ALTER TABLE TestSets ADD FOREIGN KEY (idGenTestCase) REFERENCES TestCases(idGenTestCase);
|
---|
246 | ALTER TABLE TestSets ADD FOREIGN KEY (idGenTestCaseArgs) REFERENCES TestCaseArgs(idGenTestCaseArgs);
|
---|
247 | ALTER TABLE TestSets ADD FOREIGN KEY (idTestResult) REFERENCES TestResults(idTestResult);
|
---|
248 | ALTER TABLE TestSets ADD FOREIGN KEY (idTestSetGangLeader) REFERENCES TestSets(idTestSet);
|
---|
249 |
|
---|
250 | -- Restore indexes.
|
---|
251 | CREATE INDEX TestSetsGangIdx ON TestSets (idTestSetGangLeader);
|
---|
252 | CREATE INDEX TestSetsBoxIdx ON TestSets (idTestBox, idTestResult);
|
---|
253 | CREATE INDEX TestSetsBuildIdx ON TestSets (idBuild, idTestResult);
|
---|
254 | CREATE INDEX TestSetsTestCaseIdx ON TestSets (idTestCase, idTestResult);
|
---|
255 | CREATE INDEX TestSetsTestVarIdx ON TestSets (idTestCaseArgs, idTestResult);
|
---|
256 | CREATE INDEX TestSetsDoneCreatedBuildCatIdx ON TestSets (tsDone DESC NULLS FIRST, tsCreated ASC, idBuildCategory);
|
---|
257 | CREATE INDEX TestSetsGraphBoxIdx ON TestSets (idTestBox, tsCreated DESC, tsDone ASC NULLS LAST, idBuildCategory, idTestCase);
|
---|
258 |
|
---|
259 | -- Restore foreign key references to the table.
|
---|
260 | ALTER TABLE TestResults ADD FOREIGN KEY (idTestSet) REFERENCES TestSets(idTestSet) MATCH FULL;
|
---|
261 | ALTER TABLE TestResultValues ADD FOREIGN KEY (idTestSet) REFERENCES TestSets(idTestSet) MATCH FULL;
|
---|
262 | ALTER TABLE TestResultFiles ADD FOREIGN KEY (idTestSet) REFERENCES TestSets(idTestSet) MATCH FULL;
|
---|
263 | ALTER TABLE TestResultMsgs ADD FOREIGN KEY (idTestSet) REFERENCES TestSets(idTestSet) MATCH FULL;
|
---|
264 | ALTER TABLE TestResultFailures ADD FOREIGN KEY (idTestSet) REFERENCES TestSets(idTestSet) MATCH FULL;
|
---|
265 |
|
---|
266 | ALTER TABLE TestBoxStatuses ADD FOREIGN KEY (idTestSet) REFERENCES TestSets(idTestSet) MATCH FULL;
|
---|
267 | ALTER TABLE SchedQueues ADD FOREIGN KEY (idTestSetGangLeader) REFERENCES TestSets(idTestSet) MATCH FULL;
|
---|
268 |
|
---|
269 | -- Drop the old table.
|
---|
270 | DROP TABLE OldTestSets;
|
---|
271 |
|
---|
272 | \prompt "Update python files while everything is locked. Hurry!" dummy
|
---|
273 |
|
---|
274 | -- Grant access to the new table.
|
---|
275 | GRANT ALL PRIVILEGES ON TABLE TestSets TO testmanager;
|
---|
276 |
|
---|
277 | COMMIT;
|
---|
278 |
|
---|
279 | \d TestSets;
|
---|
280 |
|
---|