VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/testmanager/db/tmdb-r22-testboxes-3-teststatus-4-testboxinschedgroups-1.pgsql

Last change on this file was 106061, checked in by vboxsync, 3 days ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1-- $Id: tmdb-r22-testboxes-3-teststatus-4-testboxinschedgroups-1.pgsql 106061 2024-09-16 14:03:52Z vboxsync $
2--- @file
3-- VBox Test Manager Database - Turns idSchedGroup column in TestBoxes
4-- into an N:M relationship with a priority via the new table
5-- TestBoxesInSchedGroups. Adds an internal scheduling table index to
6-- TestBoxStatuses to implement testboxes switching between groups.
7--
8
9--
10-- Copyright (C) 2013-2024 Oracle and/or its affiliates.
11--
12-- This file is part of VirtualBox base platform packages, as
13-- available from https://www.virtualbox.org.
14--
15-- This program is free software; you can redistribute it and/or
16-- modify it under the terms of the GNU General Public License
17-- as published by the Free Software Foundation, in version 3 of the
18-- License.
19--
20-- This program is distributed in the hope that it will be useful, but
21-- WITHOUT ANY WARRANTY; without even the implied warranty of
22-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23-- General Public License for more details.
24--
25-- You should have received a copy of the GNU General Public License
26-- along with this program; if not, see <https://www.gnu.org/licenses>.
27--
28-- The contents of this file may alternatively be used under the terms
29-- of the Common Development and Distribution License Version 1.0
30-- (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
31-- in the VirtualBox distribution, in which case the provisions of the
32-- CDDL are applicable instead of those of the GPL.
33--
34-- You may elect to license modified versions of this file under the
35-- terms and conditions of either the GPL or the CDDL or both.
36--
37-- SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
38--
39
40--
41-- Cleanup after failed runs.
42--
43DROP TABLE IF EXISTS OldTestBoxes;
44
45--
46-- Die on error from now on.
47--
48\set ON_ERROR_STOP 1
49\set AUTOCOMMIT 0
50
51
52-- Total grid lock.
53LOCK TABLE TestBoxStatuses IN ACCESS EXCLUSIVE MODE;
54LOCK TABLE TestSets IN ACCESS EXCLUSIVE MODE;
55LOCK TABLE TestBoxes IN ACCESS EXCLUSIVE MODE;
56LOCK TABLE SchedGroups IN ACCESS EXCLUSIVE MODE;
57LOCK TABLE SchedGroupMembers IN ACCESS EXCLUSIVE MODE;
58
59\d+ TestBoxes;
60
61--
62-- We'll only be doing simple alterations so, no need to drop constraints
63-- and stuff like we usually do first.
64--
65
66--
67-- Create the new table and populate it.
68--
69
70CREATE TABLE TestBoxesInSchedGroups (
71 --- TestBox ID.
72 -- Non-unique foreign key: TestBoxes(idTestBox).
73 idTestBox INTEGER NOT NULL,
74 --- Scheduling ID.
75 -- Non-unique foreign key: SchedGroups(idSchedGroup).
76 idSchedGroup INTEGER NOT NULL,
77 --- When this row starts taking effect (inclusive).
78 tsEffective TIMESTAMP WITH TIME ZONE DEFAULT current_timestamp NOT NULL,
79 --- When this row stops being tsEffective (exclusive).
80 tsExpire TIMESTAMP WITH TIME ZONE DEFAULT TIMESTAMP WITH TIME ZONE 'infinity' NOT NULL,
81 --- The user id of the one who created/modified this entry.
82 -- Non-unique foreign key: Users(uid)
83 uidAuthor INTEGER NOT NULL,
84
85 --- The scheduling priority of the scheduling group for the test box.
86 -- Higher number causes the scheduling group to be serviced more frequently.
87 -- @sa TestGroupMembers.iSchedPriority, SchedGroups.iSchedPriority
88 iSchedPriority INTEGER DEFAULT 16 CHECK (iSchedPriority >= 0 AND iSchedPriority < 32) NOT NULL,
89
90 PRIMARY KEY (idTestBox, idSchedGroup, tsExpire)
91);
92
93GRANT ALL PRIVILEGES ON TABLE TestBoxesInSchedGroups TO testmanager;
94
95CREATE OR REPLACE FUNCTION TestBoxesInSchedGroups_ConvertedOneBox(a_idTestBox INTEGER)
96 RETURNS VOID AS $$
97 DECLARE
98 v_Row RECORD;
99 v_idSchedGroup INTEGER;
100 v_uidAuthor INTEGER;
101 v_tsEffective TIMESTAMP WITH TIME ZONE;
102 v_tsExpire TIMESTAMP WITH TIME ZONE;
103 BEGIN
104 FOR v_Row IN
105 SELECT idTestBox,
106 idSchedGroup,
107 tsEffective,
108 tsExpire,
109 uidAuthor
110 FROM TestBoxes
111 WHERE idTestBox = a_idTestBox
112 ORDER BY tsEffective, tsExpire
113 LOOP
114 IF v_idSchedGroup IS NOT NULL THEN
115 IF (v_idSchedGroup != v_Row.idSchedGroup) OR (v_Row.tsEffective <> v_tsExpire) THEN
116 INSERT INTO TestBoxesInSchedGroups (idTestBox, idSchedGroup, tsEffective, tsExpire, uidAuthor)
117 VALUES (a_idTestBox, v_idSchedGroup, v_tsEffective, v_tsExpire, v_uidAuthor);
118 v_idSchedGroup := NULL;
119 END IF;
120 END IF;
121
122 IF v_idSchedGroup IS NULL THEN
123 v_idSchedGroup := v_Row.idSchedGroup;
124 v_tsEffective := v_Row.tsEffective;
125 END IF;
126 IF v_Row.uidAuthor IS NOT NULL THEN
127 v_uidAuthor := v_Row.uidAuthor;
128 END IF;
129 v_tsExpire := v_Row.tsExpire;
130 END LOOP;
131
132 IF v_idSchedGroup != -1 THEN
133 INSERT INTO TestBoxesInSchedGroups (idTestBox, idSchedGroup, tsEffective, tsExpire, uidAuthor)
134 VALUES (a_idTestBox, v_idSchedGroup, v_tsEffective, v_tsExpire, v_uidAuthor);
135 END IF;
136 END;
137$$ LANGUAGE plpgsql;
138
139SELECT TestBoxesInSchedGroups_ConvertedOneBox(TestBoxIDs.idTestBox)
140FROM ( SELECT DISTINCT idTestBox FROM TestBoxes ) AS TestBoxIDs;
141
142DROP FUNCTION TestBoxesInSchedGroups_ConvertedOneBox(INTEGER);
143
144--
145-- Do the other two modifications.
146--
147ALTER TABLE TestBoxStatuses ADD COLUMN iWorkItem INTEGER DEFAULT 0 NOT NULL;
148
149DROP VIEW TestBoxesWithStrings;
150ALTER TABLE TestBoxes DROP COLUMN idSchedGroup;
151CREATE VIEW TestBoxesWithStrings AS
152 SELECT TestBoxes.*,
153 Str1.sValue AS sDescription,
154 Str2.sValue AS sComment,
155 Str3.sValue AS sOs,
156 Str4.sValue AS sOsVersion,
157 Str5.sValue AS sCpuVendor,
158 Str6.sValue AS sCpuArch,
159 Str7.sValue AS sCpuName,
160 Str8.sValue AS sReport
161 FROM TestBoxes
162 LEFT OUTER JOIN TestBoxStrTab Str1 ON idStrDescription = Str1.idStr
163 LEFT OUTER JOIN TestBoxStrTab Str2 ON idStrComment = Str2.idStr
164 LEFT OUTER JOIN TestBoxStrTab Str3 ON idStrOs = Str3.idStr
165 LEFT OUTER JOIN TestBoxStrTab Str4 ON idStrOsVersion = Str4.idStr
166 LEFT OUTER JOIN TestBoxStrTab Str5 ON idStrCpuVendor = Str5.idStr
167 LEFT OUTER JOIN TestBoxStrTab Str6 ON idStrCpuArch = Str6.idStr
168 LEFT OUTER JOIN TestBoxStrTab Str7 ON idStrCpuName = Str7.idStr
169 LEFT OUTER JOIN TestBoxStrTab Str8 ON idStrReport = Str8.idStr;
170
171GRANT ALL PRIVILEGES ON TABLE TestBoxesWithStrings TO testmanager;
172
173\prompt "Update python files while everything is locked. Hurry!" dummy
174
175COMMIT;
176
177\d TestBoxesInSchedGroups;
178\d TestBoxStatuses;
179\d TestBoxes;
180ANALYZE VERBOSE TestBoxesInSchedGroups;
181
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette