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