xref: /freebsd/contrib/kyua/store/migrate_v1_v2.sql (revision b0d29bc47dba79f6f38e67eabadfb4b32ffd9390)
1*b0d29bc4SBrooks Davis-- Copyright 2013 The Kyua Authors.
2*b0d29bc4SBrooks Davis-- All rights reserved.
3*b0d29bc4SBrooks Davis--
4*b0d29bc4SBrooks Davis-- Redistribution and use in source and binary forms, with or without
5*b0d29bc4SBrooks Davis-- modification, are permitted provided that the following conditions are
6*b0d29bc4SBrooks Davis-- met:
7*b0d29bc4SBrooks Davis--
8*b0d29bc4SBrooks Davis-- * Redistributions of source code must retain the above copyright
9*b0d29bc4SBrooks Davis--   notice, this list of conditions and the following disclaimer.
10*b0d29bc4SBrooks Davis-- * Redistributions in binary form must reproduce the above copyright
11*b0d29bc4SBrooks Davis--   notice, this list of conditions and the following disclaimer in the
12*b0d29bc4SBrooks Davis--   documentation and/or other materials provided with the distribution.
13*b0d29bc4SBrooks Davis-- * Neither the name of Google Inc. nor the names of its contributors
14*b0d29bc4SBrooks Davis--   may be used to endorse or promote products derived from this software
15*b0d29bc4SBrooks Davis--   without specific prior written permission.
16*b0d29bc4SBrooks Davis--
17*b0d29bc4SBrooks Davis-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18*b0d29bc4SBrooks Davis-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19*b0d29bc4SBrooks Davis-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20*b0d29bc4SBrooks Davis-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21*b0d29bc4SBrooks Davis-- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22*b0d29bc4SBrooks Davis-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23*b0d29bc4SBrooks Davis-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24*b0d29bc4SBrooks Davis-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25*b0d29bc4SBrooks Davis-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26*b0d29bc4SBrooks Davis-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27*b0d29bc4SBrooks Davis-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*b0d29bc4SBrooks Davis
29*b0d29bc4SBrooks Davis-- \file store/v1-to-v2.sql
30*b0d29bc4SBrooks Davis-- Migration of a database with version 1 of the schema to version 2.
31*b0d29bc4SBrooks Davis--
32*b0d29bc4SBrooks Davis-- Version 2 appeared in revision 9a73561a1e3975bba4cbfd19aee6b2365a39519e
33*b0d29bc4SBrooks Davis-- and its changes were:
34*b0d29bc4SBrooks Davis--
35*b0d29bc4SBrooks Davis-- * Changed the primary key of the metadata table to be the
36*b0d29bc4SBrooks Davis--   schema_version, not the timestamp.  Because timestamps only have
37*b0d29bc4SBrooks Davis--   second resolution, the old schema made testing of schema migrations
38*b0d29bc4SBrooks Davis--   difficult.
39*b0d29bc4SBrooks Davis--
40*b0d29bc4SBrooks Davis-- * Introduced the metadatas table, which holds the metadata of all test
41*b0d29bc4SBrooks Davis--   programs and test cases in an abstract manner regardless of their
42*b0d29bc4SBrooks Davis--   interface.
43*b0d29bc4SBrooks Davis--
44*b0d29bc4SBrooks Davis-- * Added the metadata_id field to the test_programs and test_cases
45*b0d29bc4SBrooks Davis--   tables, referencing the new metadatas table.
46*b0d29bc4SBrooks Davis--
47*b0d29bc4SBrooks Davis-- * Changed the precision of the timeout metadata field to be in seconds
48*b0d29bc4SBrooks Davis--   rather than in microseconds.  There is no data loss, and the code that
49*b0d29bc4SBrooks Davis--   writes the metadata is simplified.
50*b0d29bc4SBrooks Davis--
51*b0d29bc4SBrooks Davis-- * Removed the atf_* and plain_* tables.
52*b0d29bc4SBrooks Davis--
53*b0d29bc4SBrooks Davis-- * Added missing indexes to improve the performance of reports.
54*b0d29bc4SBrooks Davis--
55*b0d29bc4SBrooks Davis-- * Added missing column affinities to the absolute_path and relative_path
56*b0d29bc4SBrooks Davis--   columns of the test_programs table.
57*b0d29bc4SBrooks Davis
58*b0d29bc4SBrooks Davis
59*b0d29bc4SBrooks Davis-- TODO(jmmv): Implement addition of missing affinities.
60*b0d29bc4SBrooks Davis
61*b0d29bc4SBrooks Davis
62*b0d29bc4SBrooks Davis--
63*b0d29bc4SBrooks Davis-- Change primary key of the metadata table.
64*b0d29bc4SBrooks Davis--
65*b0d29bc4SBrooks Davis
66*b0d29bc4SBrooks Davis
67*b0d29bc4SBrooks DavisCREATE TABLE new_metadata (
68*b0d29bc4SBrooks Davis    schema_version INTEGER PRIMARY KEY CHECK (schema_version >= 1),
69*b0d29bc4SBrooks Davis    timestamp TIMESTAMP NOT NULL CHECK (timestamp >= 0)
70*b0d29bc4SBrooks Davis);
71*b0d29bc4SBrooks Davis
72*b0d29bc4SBrooks DavisINSERT INTO new_metadata (schema_version, timestamp)
73*b0d29bc4SBrooks Davis    SELECT schema_version, timestamp FROM metadata;
74*b0d29bc4SBrooks Davis
75*b0d29bc4SBrooks DavisDROP TABLE metadata;
76*b0d29bc4SBrooks DavisALTER TABLE new_metadata RENAME TO metadata;
77*b0d29bc4SBrooks Davis
78*b0d29bc4SBrooks Davis
79*b0d29bc4SBrooks Davis--
80*b0d29bc4SBrooks Davis-- Add the new tables, columns and indexes.
81*b0d29bc4SBrooks Davis--
82*b0d29bc4SBrooks Davis
83*b0d29bc4SBrooks Davis
84*b0d29bc4SBrooks DavisCREATE TABLE metadatas (
85*b0d29bc4SBrooks Davis    metadata_id INTEGER NOT NULL,
86*b0d29bc4SBrooks Davis    property_name TEXT NOT NULL,
87*b0d29bc4SBrooks Davis    property_value TEXT,
88*b0d29bc4SBrooks Davis
89*b0d29bc4SBrooks Davis    PRIMARY KEY (metadata_id, property_name)
90*b0d29bc4SBrooks Davis);
91*b0d29bc4SBrooks Davis
92*b0d29bc4SBrooks Davis
93*b0d29bc4SBrooks Davis-- Upgrade the test_programs table by adding missing column affinities and
94*b0d29bc4SBrooks Davis-- the new metadata_id column.
95*b0d29bc4SBrooks DavisCREATE TABLE new_test_programs (
96*b0d29bc4SBrooks Davis    test_program_id INTEGER PRIMARY KEY AUTOINCREMENT,
97*b0d29bc4SBrooks Davis    action_id INTEGER REFERENCES actions,
98*b0d29bc4SBrooks Davis
99*b0d29bc4SBrooks Davis    absolute_path TEXT NOT NULL,
100*b0d29bc4SBrooks Davis    root TEXT NOT NULL,
101*b0d29bc4SBrooks Davis    relative_path TEXT NOT NULL,
102*b0d29bc4SBrooks Davis    test_suite_name TEXT NOT NULL,
103*b0d29bc4SBrooks Davis    metadata_id INTEGER,
104*b0d29bc4SBrooks Davis    interface TEXT NOT NULL
105*b0d29bc4SBrooks Davis);
106*b0d29bc4SBrooks DavisPRAGMA foreign_keys = OFF;
107*b0d29bc4SBrooks DavisINSERT INTO new_test_programs (test_program_id, action_id, absolute_path,
108*b0d29bc4SBrooks Davis                               root, relative_path, test_suite_name,
109*b0d29bc4SBrooks Davis                               interface)
110*b0d29bc4SBrooks Davis    SELECT test_program_id, action_id, absolute_path, root, relative_path,
111*b0d29bc4SBrooks Davis        test_suite_name, interface FROM test_programs;
112*b0d29bc4SBrooks DavisDROP TABLE test_programs;
113*b0d29bc4SBrooks DavisALTER TABLE new_test_programs RENAME TO test_programs;
114*b0d29bc4SBrooks DavisPRAGMA foreign_keys = ON;
115*b0d29bc4SBrooks Davis
116*b0d29bc4SBrooks Davis
117*b0d29bc4SBrooks DavisALTER TABLE test_cases ADD COLUMN metadata_id INTEGER;
118*b0d29bc4SBrooks Davis
119*b0d29bc4SBrooks Davis
120*b0d29bc4SBrooks DavisCREATE INDEX index_metadatas_by_id
121*b0d29bc4SBrooks Davis    ON metadatas (metadata_id);
122*b0d29bc4SBrooks DavisCREATE INDEX index_test_programs_by_action_id
123*b0d29bc4SBrooks Davis    ON test_programs (action_id);
124*b0d29bc4SBrooks DavisCREATE INDEX index_test_cases_by_test_programs_id
125*b0d29bc4SBrooks Davis    ON test_cases (test_program_id);
126*b0d29bc4SBrooks Davis
127*b0d29bc4SBrooks Davis
128*b0d29bc4SBrooks Davis--
129*b0d29bc4SBrooks Davis-- Data migration
130*b0d29bc4SBrooks Davis--
131*b0d29bc4SBrooks Davis-- This is, by far, the trickiest part of the migration.
132*b0d29bc4SBrooks Davis-- TODO(jmmv): Describe the trickiness in here.
133*b0d29bc4SBrooks Davis--
134*b0d29bc4SBrooks Davis
135*b0d29bc4SBrooks Davis
136*b0d29bc4SBrooks Davis-- Auxiliary table to construct the final contents of the metadatas table.
137*b0d29bc4SBrooks Davis--
138*b0d29bc4SBrooks Davis-- We construct the contents by writing a row for every metadata property of
139*b0d29bc4SBrooks Davis-- every test program and test case.  Entries corresponding to a test program
140*b0d29bc4SBrooks Davis-- will have the test_program_id field set to not NULL and entries corresponding
141*b0d29bc4SBrooks Davis-- to test cases will have the test_case_id set to not NULL.
142*b0d29bc4SBrooks Davis--
143*b0d29bc4SBrooks Davis-- The tricky part, however, is to create the individual identifiers for every
144*b0d29bc4SBrooks Davis-- metadata entry.  We do this by picking the minimum ROWID of a particular set
145*b0d29bc4SBrooks Davis-- of properties that map to a single test_program_id or test_case_id.
146*b0d29bc4SBrooks DavisCREATE TABLE tmp_metadatas (
147*b0d29bc4SBrooks Davis    test_program_id INTEGER DEFAULT NULL,
148*b0d29bc4SBrooks Davis    test_case_id INTEGER DEFAULT NULL,
149*b0d29bc4SBrooks Davis    interface TEXT NOT NULL,
150*b0d29bc4SBrooks Davis    property_name TEXT NOT NULL,
151*b0d29bc4SBrooks Davis    property_value TEXT NOT NULL,
152*b0d29bc4SBrooks Davis
153*b0d29bc4SBrooks Davis    UNIQUE (test_program_id, test_case_id, property_name)
154*b0d29bc4SBrooks Davis);
155*b0d29bc4SBrooks DavisCREATE INDEX index_tmp_metadatas_by_test_case_id
156*b0d29bc4SBrooks Davis    ON tmp_metadatas (test_case_id);
157*b0d29bc4SBrooks DavisCREATE INDEX index_tmp_metadatas_by_test_program_id
158*b0d29bc4SBrooks Davis    ON tmp_metadatas (test_program_id);
159*b0d29bc4SBrooks Davis
160*b0d29bc4SBrooks Davis
161*b0d29bc4SBrooks Davis-- Populate default metadata values for all test programs and test cases.
162*b0d29bc4SBrooks Davis--
163*b0d29bc4SBrooks Davis-- We do this first to ensure that all test programs and test cases have
164*b0d29bc4SBrooks Davis-- explicit values for their metadata.  Because we want to keep historical data
165*b0d29bc4SBrooks Davis-- for the tests, we must record these values unconditionally instead of relying
166*b0d29bc4SBrooks Davis-- on the built-in values in the code.
167*b0d29bc4SBrooks Davis--
168*b0d29bc4SBrooks Davis-- Once this is done, we override any values explicity set by the tests.
169*b0d29bc4SBrooks DavisCREATE TABLE tmp_default_metadata (
170*b0d29bc4SBrooks Davis    default_name TEXT PRIMARY KEY,
171*b0d29bc4SBrooks Davis    default_value TEXT NOT NULL
172*b0d29bc4SBrooks Davis);
173*b0d29bc4SBrooks DavisINSERT INTO tmp_default_metadata VALUES ('allowed_architectures', '');
174*b0d29bc4SBrooks DavisINSERT INTO tmp_default_metadata VALUES ('allowed_platforms', '');
175*b0d29bc4SBrooks DavisINSERT INTO tmp_default_metadata VALUES ('description', '');
176*b0d29bc4SBrooks DavisINSERT INTO tmp_default_metadata VALUES ('has_cleanup', 'false');
177*b0d29bc4SBrooks DavisINSERT INTO tmp_default_metadata VALUES ('required_configs', '');
178*b0d29bc4SBrooks DavisINSERT INTO tmp_default_metadata VALUES ('required_files', '');
179*b0d29bc4SBrooks DavisINSERT INTO tmp_default_metadata VALUES ('required_memory', '0');
180*b0d29bc4SBrooks DavisINSERT INTO tmp_default_metadata VALUES ('required_programs', '');
181*b0d29bc4SBrooks DavisINSERT INTO tmp_default_metadata VALUES ('required_user', '');
182*b0d29bc4SBrooks DavisINSERT INTO tmp_default_metadata VALUES ('timeout', '300');
183*b0d29bc4SBrooks DavisINSERT INTO tmp_metadatas
184*b0d29bc4SBrooks Davis    SELECT test_program_id, NULL, interface, default_name, default_value
185*b0d29bc4SBrooks Davis        FROM test_programs JOIN tmp_default_metadata;
186*b0d29bc4SBrooks DavisINSERT INTO tmp_metadatas
187*b0d29bc4SBrooks Davis    SELECT NULL, test_case_id, interface, default_name, default_value
188*b0d29bc4SBrooks Davis        FROM test_programs JOIN test_cases
189*b0d29bc4SBrooks Davis        ON test_cases.test_program_id = test_programs.test_program_id
190*b0d29bc4SBrooks Davis        JOIN tmp_default_metadata;
191*b0d29bc4SBrooks DavisDROP TABLE tmp_default_metadata;
192*b0d29bc4SBrooks Davis
193*b0d29bc4SBrooks Davis
194*b0d29bc4SBrooks Davis-- Populate metadata overrides from plain test programs.
195*b0d29bc4SBrooks DavisUPDATE tmp_metadatas
196*b0d29bc4SBrooks Davis    SET property_value = (
197*b0d29bc4SBrooks Davis        SELECT CAST(timeout / 1000000 AS TEXT) FROM plain_test_programs AS aux
198*b0d29bc4SBrooks Davis            WHERE aux.test_program_id = tmp_metadatas.test_program_id)
199*b0d29bc4SBrooks Davis    WHERE test_program_id IS NOT NULL AND property_name = 'timeout'
200*b0d29bc4SBrooks Davis        AND interface = 'plain';
201*b0d29bc4SBrooks DavisUPDATE tmp_metadatas
202*b0d29bc4SBrooks Davis    SET property_value = (
203*b0d29bc4SBrooks Davis        SELECT DISTINCT CAST(timeout / 1000000 AS TEXT)
204*b0d29bc4SBrooks Davis        FROM test_cases AS aux JOIN plain_test_programs
205*b0d29bc4SBrooks Davis            ON aux.test_program_id == plain_test_programs.test_program_id
206*b0d29bc4SBrooks Davis        WHERE aux.test_case_id = tmp_metadatas.test_case_id)
207*b0d29bc4SBrooks Davis    WHERE test_case_id IS NOT NULL AND property_name = 'timeout'
208*b0d29bc4SBrooks Davis        AND interface = 'plain';
209*b0d29bc4SBrooks Davis
210*b0d29bc4SBrooks Davis
211*b0d29bc4SBrooks DavisCREATE INDEX index_tmp_atf_test_cases_multivalues_by_test_case_id
212*b0d29bc4SBrooks Davis    ON atf_test_cases_multivalues (test_case_id);
213*b0d29bc4SBrooks Davis
214*b0d29bc4SBrooks Davis
215*b0d29bc4SBrooks Davis-- Populate metadata overrides from ATF test cases.
216*b0d29bc4SBrooks DavisUPDATE atf_test_cases SET description = '' WHERE description IS NULL;
217*b0d29bc4SBrooks DavisUPDATE atf_test_cases SET required_user = '' WHERE required_user IS NULL;
218*b0d29bc4SBrooks Davis
219*b0d29bc4SBrooks DavisUPDATE tmp_metadatas
220*b0d29bc4SBrooks Davis    SET property_value = (
221*b0d29bc4SBrooks Davis        SELECT description FROM atf_test_cases AS aux
222*b0d29bc4SBrooks Davis            WHERE aux.test_case_id = tmp_metadatas.test_case_id)
223*b0d29bc4SBrooks Davis    WHERE test_case_id IS NOT NULL AND property_name = 'description'
224*b0d29bc4SBrooks Davis        AND interface = 'atf';
225*b0d29bc4SBrooks DavisUPDATE tmp_metadatas
226*b0d29bc4SBrooks Davis    SET property_value = (
227*b0d29bc4SBrooks Davis        SELECT has_cleanup FROM atf_test_cases AS aux
228*b0d29bc4SBrooks Davis            WHERE aux.test_case_id = tmp_metadatas.test_case_id)
229*b0d29bc4SBrooks Davis    WHERE test_case_id IS NOT NULL AND property_name = 'has_cleanup'
230*b0d29bc4SBrooks Davis        AND interface = 'atf';
231*b0d29bc4SBrooks DavisUPDATE tmp_metadatas
232*b0d29bc4SBrooks Davis    SET property_value = (
233*b0d29bc4SBrooks Davis        SELECT CAST(timeout / 1000000 AS TEXT) FROM atf_test_cases AS aux
234*b0d29bc4SBrooks Davis            WHERE aux.test_case_id = tmp_metadatas.test_case_id)
235*b0d29bc4SBrooks Davis    WHERE test_case_id IS NOT NULL AND property_name = 'timeout'
236*b0d29bc4SBrooks Davis        AND interface = 'atf';
237*b0d29bc4SBrooks DavisUPDATE tmp_metadatas
238*b0d29bc4SBrooks Davis    SET property_value = (
239*b0d29bc4SBrooks Davis        SELECT CAST(required_memory AS TEXT) FROM atf_test_cases AS aux
240*b0d29bc4SBrooks Davis            WHERE aux.test_case_id = tmp_metadatas.test_case_id)
241*b0d29bc4SBrooks Davis    WHERE test_case_id IS NOT NULL AND property_name = 'required_memory'
242*b0d29bc4SBrooks Davis        AND interface = 'atf';
243*b0d29bc4SBrooks DavisUPDATE tmp_metadatas
244*b0d29bc4SBrooks Davis    SET property_value = (
245*b0d29bc4SBrooks Davis        SELECT required_user FROM atf_test_cases AS aux
246*b0d29bc4SBrooks Davis            WHERE aux.test_case_id = tmp_metadatas.test_case_id)
247*b0d29bc4SBrooks Davis    WHERE test_case_id IS NOT NULL AND property_name = 'required_user'
248*b0d29bc4SBrooks Davis        AND interface = 'atf';
249*b0d29bc4SBrooks DavisUPDATE tmp_metadatas
250*b0d29bc4SBrooks Davis    SET property_value = (
251*b0d29bc4SBrooks Davis        SELECT GROUP_CONCAT(aux.property_value, ' ')
252*b0d29bc4SBrooks Davis            FROM atf_test_cases_multivalues AS aux
253*b0d29bc4SBrooks Davis            WHERE aux.test_case_id = tmp_metadatas.test_case_id AND
254*b0d29bc4SBrooks Davis                aux.property_name = 'require.arch')
255*b0d29bc4SBrooks Davis    WHERE test_case_id IS NOT NULL AND property_name = 'allowed_architectures'
256*b0d29bc4SBrooks Davis        AND interface = 'atf'
257*b0d29bc4SBrooks Davis        AND EXISTS(SELECT 1 FROM atf_test_cases_multivalues AS aux
258*b0d29bc4SBrooks Davis                   WHERE aux.test_case_id = tmp_metadatas.test_case_id
259*b0d29bc4SBrooks Davis                   AND property_name = 'require.arch');
260*b0d29bc4SBrooks DavisUPDATE tmp_metadatas
261*b0d29bc4SBrooks Davis    SET property_value = (
262*b0d29bc4SBrooks Davis        SELECT GROUP_CONCAT(aux.property_value, ' ')
263*b0d29bc4SBrooks Davis            FROM atf_test_cases_multivalues AS aux
264*b0d29bc4SBrooks Davis            WHERE aux.test_case_id = tmp_metadatas.test_case_id AND
265*b0d29bc4SBrooks Davis                aux.property_name = 'require.machine')
266*b0d29bc4SBrooks Davis    WHERE test_case_id IS NOT NULL AND property_name = 'allowed_platforms'
267*b0d29bc4SBrooks Davis        AND interface = 'atf'
268*b0d29bc4SBrooks Davis        AND EXISTS(SELECT 1 FROM atf_test_cases_multivalues AS aux
269*b0d29bc4SBrooks Davis                   WHERE aux.test_case_id = tmp_metadatas.test_case_id
270*b0d29bc4SBrooks Davis                   AND property_name = 'require.machine');
271*b0d29bc4SBrooks DavisUPDATE tmp_metadatas
272*b0d29bc4SBrooks Davis    SET property_value = (
273*b0d29bc4SBrooks Davis        SELECT GROUP_CONCAT(aux.property_value, ' ')
274*b0d29bc4SBrooks Davis            FROM atf_test_cases_multivalues AS aux
275*b0d29bc4SBrooks Davis            WHERE aux.test_case_id = tmp_metadatas.test_case_id AND
276*b0d29bc4SBrooks Davis                aux.property_name = 'require.config')
277*b0d29bc4SBrooks Davis    WHERE test_case_id IS NOT NULL AND property_name = 'required_configs'
278*b0d29bc4SBrooks Davis        AND interface = 'atf'
279*b0d29bc4SBrooks Davis        AND EXISTS(SELECT 1 FROM atf_test_cases_multivalues AS aux
280*b0d29bc4SBrooks Davis                   WHERE aux.test_case_id = tmp_metadatas.test_case_id
281*b0d29bc4SBrooks Davis                   AND property_name = 'require.config');
282*b0d29bc4SBrooks DavisUPDATE tmp_metadatas
283*b0d29bc4SBrooks Davis    SET property_value = (
284*b0d29bc4SBrooks Davis        SELECT GROUP_CONCAT(aux.property_value, ' ')
285*b0d29bc4SBrooks Davis            FROM atf_test_cases_multivalues AS aux
286*b0d29bc4SBrooks Davis            WHERE aux.test_case_id = tmp_metadatas.test_case_id AND
287*b0d29bc4SBrooks Davis                aux.property_name = 'require.files')
288*b0d29bc4SBrooks Davis    WHERE test_case_id IS NOT NULL AND property_name = 'required_files'
289*b0d29bc4SBrooks Davis        AND interface = 'atf'
290*b0d29bc4SBrooks Davis        AND EXISTS(SELECT 1 FROM atf_test_cases_multivalues AS aux
291*b0d29bc4SBrooks Davis                   WHERE aux.test_case_id = tmp_metadatas.test_case_id
292*b0d29bc4SBrooks Davis                   AND property_name = 'require.files');
293*b0d29bc4SBrooks DavisUPDATE tmp_metadatas
294*b0d29bc4SBrooks Davis    SET property_value = (
295*b0d29bc4SBrooks Davis        SELECT GROUP_CONCAT(aux.property_value, ' ')
296*b0d29bc4SBrooks Davis            FROM atf_test_cases_multivalues AS aux
297*b0d29bc4SBrooks Davis            WHERE aux.test_case_id = tmp_metadatas.test_case_id AND
298*b0d29bc4SBrooks Davis                aux.property_name = 'require.progs')
299*b0d29bc4SBrooks Davis    WHERE test_case_id IS NOT NULL AND property_name = 'required_programs'
300*b0d29bc4SBrooks Davis        AND interface = 'atf'
301*b0d29bc4SBrooks Davis        AND EXISTS(SELECT 1 FROM atf_test_cases_multivalues AS aux
302*b0d29bc4SBrooks Davis                   WHERE aux.test_case_id = tmp_metadatas.test_case_id
303*b0d29bc4SBrooks Davis                   AND property_name = 'require.progs');
304*b0d29bc4SBrooks Davis
305*b0d29bc4SBrooks Davis
306*b0d29bc4SBrooks Davis-- Fill metadata_id pointers in the test_programs and test_cases tables.
307*b0d29bc4SBrooks DavisUPDATE test_programs
308*b0d29bc4SBrooks Davis    SET metadata_id = (
309*b0d29bc4SBrooks Davis        SELECT MIN(ROWID) FROM tmp_metadatas
310*b0d29bc4SBrooks Davis            WHERE tmp_metadatas.test_program_id = test_programs.test_program_id
311*b0d29bc4SBrooks Davis    );
312*b0d29bc4SBrooks DavisUPDATE test_cases
313*b0d29bc4SBrooks Davis    SET metadata_id = (
314*b0d29bc4SBrooks Davis        SELECT MIN(ROWID) FROM tmp_metadatas
315*b0d29bc4SBrooks Davis            WHERE tmp_metadatas.test_case_id = test_cases.test_case_id
316*b0d29bc4SBrooks Davis    );
317*b0d29bc4SBrooks Davis
318*b0d29bc4SBrooks Davis
319*b0d29bc4SBrooks Davis-- Populate the metadatas table based on tmp_metadatas.
320*b0d29bc4SBrooks DavisINSERT INTO metadatas (metadata_id, property_name, property_value)
321*b0d29bc4SBrooks Davis    SELECT (
322*b0d29bc4SBrooks Davis        SELECT MIN(ROWID) FROM tmp_metadatas AS s
323*b0d29bc4SBrooks Davis        WHERE s.test_program_id = tmp_metadatas.test_program_id
324*b0d29bc4SBrooks Davis    ), property_name, property_value
325*b0d29bc4SBrooks Davis    FROM tmp_metadatas WHERE test_program_id IS NOT NULL;
326*b0d29bc4SBrooks DavisINSERT INTO metadatas (metadata_id, property_name, property_value)
327*b0d29bc4SBrooks Davis    SELECT (
328*b0d29bc4SBrooks Davis        SELECT MIN(ROWID) FROM tmp_metadatas AS s
329*b0d29bc4SBrooks Davis        WHERE s.test_case_id = tmp_metadatas.test_case_id
330*b0d29bc4SBrooks Davis    ), property_name, property_value
331*b0d29bc4SBrooks Davis    FROM tmp_metadatas WHERE test_case_id IS NOT NULL;
332*b0d29bc4SBrooks Davis
333*b0d29bc4SBrooks Davis
334*b0d29bc4SBrooks Davis-- Drop temporary entities used during the migration.
335*b0d29bc4SBrooks DavisDROP INDEX index_tmp_atf_test_cases_multivalues_by_test_case_id;
336*b0d29bc4SBrooks DavisDROP INDEX index_tmp_metadatas_by_test_program_id;
337*b0d29bc4SBrooks DavisDROP INDEX index_tmp_metadatas_by_test_case_id;
338*b0d29bc4SBrooks DavisDROP TABLE tmp_metadatas;
339*b0d29bc4SBrooks Davis
340*b0d29bc4SBrooks Davis
341*b0d29bc4SBrooks Davis--
342*b0d29bc4SBrooks Davis-- Drop obsolete tables.
343*b0d29bc4SBrooks Davis--
344*b0d29bc4SBrooks Davis
345*b0d29bc4SBrooks Davis
346*b0d29bc4SBrooks DavisDROP TABLE atf_test_cases;
347*b0d29bc4SBrooks DavisDROP TABLE atf_test_cases_multivalues;
348*b0d29bc4SBrooks DavisDROP TABLE plain_test_programs;
349*b0d29bc4SBrooks Davis
350*b0d29bc4SBrooks Davis
351*b0d29bc4SBrooks Davis--
352*b0d29bc4SBrooks Davis-- Update the metadata version.
353*b0d29bc4SBrooks Davis--
354*b0d29bc4SBrooks Davis
355*b0d29bc4SBrooks Davis
356*b0d29bc4SBrooks DavisINSERT INTO metadata (timestamp, schema_version)
357*b0d29bc4SBrooks Davis    VALUES (strftime('%s', 'now'), 2);
358