VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/testmanager/db/tmdb-r18-testresultfiles-1-testresultmsgs-1.pgsql@ 79449

Last change on this file since 79449 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
Line 
1-- $Id: tmdb-r18-testresultfiles-1-testresultmsgs-1.pgsql 76553 2019-01-01 01:45:53Z vboxsync $
2--- @file
3-- VBox Test Manager Database - Adds an idTestSet to TestResultFiles and TestResultMsgs.
4--
5
6--
7-- Copyright (C) 2013-2019 Oracle Corporation
8--
9-- This file is part of VirtualBox Open Source Edition (OSE), as
10-- available from http://www.virtualbox.org. This file is free software;
11-- you can redistribute it and/or modify it under the terms of the GNU
12-- General Public License (GPL) as published by the Free Software
13-- Foundation, in version 2 as it comes in the "COPYING" file of the
14-- VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15-- hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16--
17-- The contents of this file may alternatively be used under the terms
18-- of the Common Development and Distribution License Version 1.0
19-- (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20-- VirtualBox OSE distribution, in which case the provisions of the
21-- CDDL are applicable instead of those of the GPL.
22--
23-- You may elect to license modified versions of this file under the
24-- terms and conditions of either the GPL or the CDDL or both.
25--
26
27--
28-- Cleanup after failed runs.
29--
30DROP TABLE IF EXISTS NewTestResultFiles;
31DROP TABLE IF EXISTS OldTestResultFiles;
32DROP TABLE IF EXISTS NewTestResultMsgs;
33DROP TABLE IF EXISTS OldTestResultMsgs;
34
35-- Die on error from now on.
36\set ON_ERROR_STOP 1
37\set AUTOCOMMIT 0
38
39
40--
41-- Rename the original table, drop constrains and foreign key references so we
42-- get the right name automatic when creating the new one.
43--
44\d+ TestResultFiles;
45ALTER TABLE TestResultFiles RENAME TO OldTestResultFiles;
46
47DROP INDEX IF EXISTS TestResultFilesIdx;
48DROP INDEX IF EXISTS TestResultFilesIdx2;
49
50--
51-- Create the new version of the table and filling with the content of the old.
52--
53CREATE TABLE TestResultFiles (
54 --- The ID of this file.
55 idTestResultFile INTEGER PRIMARY KEY DEFAULT NEXTVAL('TestResultFileId'),
56 --- The test result it was reported within.
57 idTestResult INTEGER NOT NULL,
58 --- The test set this file is a part of (for avoiding joining thru TestResults).
59 idTestSet INTEGER NOT NULL,
60 --- Creation time stamp.
61 tsCreated TIMESTAMP WITH TIME ZONE DEFAULT current_timestamp NOT NULL,
62 --- The filename relative to TestSets(sBaseFilename) + '-'.
63 -- The set of valid filename characters should be very limited so that no
64 -- file system issues can occure either on the TM side or the user when
65 -- loading the files. Tests trying to use other characters will fail.
66 -- Valid character regular expession: '^[a-zA-Z0-9_-(){}#@+,.=]*$'
67 idStrFile INTEGER NOT NULL,
68 --- The description.
69 idStrDescription INTEGER NOT NULL,
70 --- The kind of file.
71 -- For instance: 'log/release/vm',
72 -- 'screenshot/failure',
73 -- 'screencapture/failure',
74 -- 'xmllog/somestuff'
75 idStrKind INTEGER NOT NULL,
76 --- The mime type for the file.
77 -- For instance: 'text/plain',
78 -- 'image/png',
79 -- 'video/webm',
80 -- 'text/xml'
81 idStrMime INTEGER NOT NULL
82);
83
84INSERT INTO TestResultFiles ( idTestResultFile, idTestResult, idTestSet, tsCreated, idStrFile, idStrDescription,
85 idStrKind, idStrMime)
86 SELECT o.idTestResultFile, o.idTestResult, tr.idTestSet, o.tsCreated, o.idStrFile, o.idStrDescription,
87 o.idStrKind, o.idStrMime
88 FROM OldTestResultFiles o,
89 TestResults tr
90 WHERE o.idTestResult = tr.idTestResult;
91
92-- Add new indexes.
93CREATE INDEX TestResultFilesIdx ON TestResultFiles(idTestResult);
94CREATE INDEX TestResultFilesIdx2 ON TestResultFiles(idTestSet, tsCreated DESC);
95
96-- Restore foreign keys.
97ALTER TABLE TestResultFiles ADD CONSTRAINT TestResultFiles_idTestResult_fkey FOREIGN KEY(idTestResult) REFERENCES TestResults(idTestResult);
98ALTER TABLE TestResultFiles ADD CONSTRAINT TestResultFiles_idTestSet_fkey FOREIGN KEY(idTestSet) REFERENCES TestSets(idTestSet);
99ALTER TABLE TestResultFiles ADD CONSTRAINT TestResultFiles_idStrFile_fkey FOREIGN KEY(idStrFile) REFERENCES TestResultStrTab(idStr);
100ALTER TABLE TestResultFiles ADD CONSTRAINT TestResultFiles_idStrDescription_fkey FOREIGN KEY(idStrDescription) REFERENCES TestResultStrTab(idStr);
101ALTER TABLE TestResultFiles ADD CONSTRAINT TestResultFiles_idStrKind_fkey FOREIGN KEY(idStrKind) REFERENCES TestResultStrTab(idStr);
102ALTER TABLE TestResultFiles ADD CONSTRAINT TestResultFiles_idStrMime_fkey FOREIGN KEY(idStrMime) REFERENCES TestResultStrTab(idStr);
103
104\d TestResultFiles;
105
106
107--
108-- Rename the original table, drop constrains and foreign key references so we
109-- get the right name automatic when creating the new one.
110--
111\d+ TestResultMsgs;
112ALTER TABLE TestResultMsgs RENAME TO OldTestResultMsgs;
113
114DROP INDEX IF EXISTS TestResultMsgsIdx;
115DROP INDEX IF EXISTS TestResultMsgsIdx2;
116
117--
118-- Create the new version of the table and filling with the content of the old.
119--
120CREATE TABLE TestResultMsgs (
121 --- The ID of this file.
122 idTestResultMsg INTEGER PRIMARY KEY DEFAULT NEXTVAL('TestResultMsgIdSeq'),
123 --- The test result it was reported within.
124 idTestResult INTEGER NOT NULL,
125 --- The test set this file is a part of (for avoiding joining thru TestResults).
126 idTestSet INTEGER NOT NULL,
127 --- Creation time stamp.
128 tsCreated TIMESTAMP WITH TIME ZONE DEFAULT current_timestamp NOT NULL,
129 --- The message string.
130 idStrMsg INTEGER NOT NULL,
131 --- The message level.
132 enmLevel TestResultMsgLevel_T NOT NULL
133);
134
135INSERT INTO TestResultMsgs ( idTestResultMsg, idTestResult, idTestSet, tsCreated, idStrMsg, enmLevel)
136 SELECT o.idTestResultMsg, o.idTestResult, tr.idTestSet, o.tsCreated, o.idStrMsg, o.enmLevel
137 FROM OldTestResultMsgs o,
138 TestResults tr
139 WHERE o.idTestResult = tr.idTestResult;
140
141-- Add new indexes.
142CREATE INDEX TestResultMsgsIdx ON TestResultMsgs(idTestResult);
143CREATE INDEX TestResultMsgsIdx2 ON TestResultMsgs(idTestSet, tsCreated DESC);
144
145-- Restore foreign keys.
146ALTER TABLE TestResultMsgs ADD CONSTRAINT TestResultMsgs_idTestResult_fkey FOREIGN KEY(idTestResult) REFERENCES TestResults(idTestResult);
147ALTER TABLE TestResultMsgs ADD CONSTRAINT TestResultMsgs_idTestSet_fkey FOREIGN KEY(idTestSet) REFERENCES TestSets(idTestSet);
148ALTER TABLE TestResultMsgs ADD CONSTRAINT TestResultMsgs_idStrMsg_fkey FOREIGN KEY(idStrMsg) REFERENCES TestResultStrTab(idStr);
149
150
151\d TestResultMsgs;
152
153
154--
155-- Drop the old tables and commit.
156--
157DROP TABLE OldTestResultFiles;
158DROP TABLE OldTestResultMsgs;
159
160COMMIT;
161
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