1*11be35a1SLionel Sambuc-- Copyright 2012 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/schema_v2.sql 30*11be35a1SLionel Sambuc-- Definition of the database schema. 31*11be35a1SLionel Sambuc-- 32*11be35a1SLionel Sambuc-- The whole contents of this file are wrapped in a transaction. We want 33*11be35a1SLionel Sambuc-- to ensure that the initial contents of the database (the table layout as 34*11be35a1SLionel Sambuc-- well as any predefined values) are written atomically to simplify error 35*11be35a1SLionel Sambuc-- handling in our code. 36*11be35a1SLionel Sambuc 37*11be35a1SLionel Sambuc 38*11be35a1SLionel SambucBEGIN TRANSACTION; 39*11be35a1SLionel Sambuc 40*11be35a1SLionel Sambuc 41*11be35a1SLionel Sambuc-- ------------------------------------------------------------------------- 42*11be35a1SLionel Sambuc-- Metadata. 43*11be35a1SLionel Sambuc-- ------------------------------------------------------------------------- 44*11be35a1SLionel Sambuc 45*11be35a1SLionel Sambuc 46*11be35a1SLionel Sambuc-- Database-wide properties. 47*11be35a1SLionel Sambuc-- 48*11be35a1SLionel Sambuc-- Rows in this table are immutable: modifying the metadata implies writing 49*11be35a1SLionel Sambuc-- a new record with a new schema_version greater than all existing 50*11be35a1SLionel Sambuc-- records, and never updating previous records. When extracting data from 51*11be35a1SLionel Sambuc-- this table, the only "valid" row is the one with the highest 52*11be35a1SLionel Sambuc-- scheam_version. All the other rows are meaningless and only exist for 53*11be35a1SLionel Sambuc-- historical purposes. 54*11be35a1SLionel Sambuc-- 55*11be35a1SLionel Sambuc-- In other words, this table keeps the history of the database metadata. 56*11be35a1SLionel Sambuc-- The only reason for doing this is for debugging purposes. It may come 57*11be35a1SLionel Sambuc-- in handy to know when a particular database-wide operation happened if 58*11be35a1SLionel Sambuc-- it turns out that the database got corrupted. 59*11be35a1SLionel SambucCREATE TABLE metadata ( 60*11be35a1SLionel Sambuc schema_version INTEGER PRIMARY KEY CHECK (schema_version >= 1), 61*11be35a1SLionel Sambuc timestamp TIMESTAMP NOT NULL CHECK (timestamp >= 0) 62*11be35a1SLionel Sambuc); 63*11be35a1SLionel Sambuc 64*11be35a1SLionel Sambuc 65*11be35a1SLionel Sambuc-- ------------------------------------------------------------------------- 66*11be35a1SLionel Sambuc-- Contexts. 67*11be35a1SLionel Sambuc-- ------------------------------------------------------------------------- 68*11be35a1SLionel Sambuc 69*11be35a1SLionel Sambuc 70*11be35a1SLionel Sambuc-- Execution contexts. 71*11be35a1SLionel Sambuc-- 72*11be35a1SLionel Sambuc-- A context represents the execution environment of a particular action. 73*11be35a1SLionel Sambuc-- Because every action is invoked by the user, the context may have 74*11be35a1SLionel Sambuc-- changed. We record such information for information and debugging 75*11be35a1SLionel Sambuc-- purposes. 76*11be35a1SLionel SambucCREATE TABLE contexts ( 77*11be35a1SLionel Sambuc context_id INTEGER PRIMARY KEY AUTOINCREMENT, 78*11be35a1SLionel Sambuc cwd TEXT NOT NULL 79*11be35a1SLionel Sambuc 80*11be35a1SLionel Sambuc -- TODO(jmmv): Record the run-time configuration. 81*11be35a1SLionel Sambuc); 82*11be35a1SLionel Sambuc 83*11be35a1SLionel Sambuc 84*11be35a1SLionel Sambuc-- Environment variables of a context. 85*11be35a1SLionel SambucCREATE TABLE env_vars ( 86*11be35a1SLionel Sambuc context_id INTEGER REFERENCES contexts, 87*11be35a1SLionel Sambuc var_name TEXT NOT NULL, 88*11be35a1SLionel Sambuc var_value TEXT NOT NULL, 89*11be35a1SLionel Sambuc 90*11be35a1SLionel Sambuc PRIMARY KEY (context_id, var_name) 91*11be35a1SLionel Sambuc); 92*11be35a1SLionel Sambuc 93*11be35a1SLionel Sambuc 94*11be35a1SLionel Sambuc-- ------------------------------------------------------------------------- 95*11be35a1SLionel Sambuc-- Actions. 96*11be35a1SLionel Sambuc-- ------------------------------------------------------------------------- 97*11be35a1SLionel Sambuc 98*11be35a1SLionel Sambuc 99*11be35a1SLionel Sambuc-- Representation of user-initiated actions. 100*11be35a1SLionel Sambuc-- 101*11be35a1SLionel Sambuc-- An action is an operation initiated by the user. At the moment, the 102*11be35a1SLionel Sambuc-- only operation Kyua supports is the "test" operation (in the future we 103*11be35a1SLionel Sambuc-- should be able to store, e.g. build logs). To keep things simple the 104*11be35a1SLionel Sambuc-- database schema is restricted to represent one single action. 105*11be35a1SLionel SambucCREATE TABLE actions ( 106*11be35a1SLionel Sambuc action_id INTEGER PRIMARY KEY AUTOINCREMENT, 107*11be35a1SLionel Sambuc context_id INTEGER REFERENCES contexts 108*11be35a1SLionel Sambuc); 109*11be35a1SLionel Sambuc 110*11be35a1SLionel Sambuc 111*11be35a1SLionel Sambuc-- ------------------------------------------------------------------------- 112*11be35a1SLionel Sambuc-- Test suites. 113*11be35a1SLionel Sambuc-- 114*11be35a1SLionel Sambuc-- The tables in this section represent all the components that form a test 115*11be35a1SLionel Sambuc-- suite. This includes data about the test suite itself (test programs 116*11be35a1SLionel Sambuc-- and test cases), and also the data about particular runs (test results). 117*11be35a1SLionel Sambuc-- 118*11be35a1SLionel Sambuc-- As you will notice, every object belongs to a particular action, has a 119*11be35a1SLionel Sambuc-- unique identifier and there is no attempt to deduplicate data. This 120*11be35a1SLionel Sambuc-- comes from the fact that a test suite is not "stable" over time: i.e. on 121*11be35a1SLionel Sambuc-- each execution of the test suite, test programs and test cases may have 122*11be35a1SLionel Sambuc-- come and gone. This has the interesting result of making the 123*11be35a1SLionel Sambuc-- distinction of a test case and a test result a pure syntactic 124*11be35a1SLionel Sambuc-- difference, because there is always a 1:1 relation. 125*11be35a1SLionel Sambuc-- 126*11be35a1SLionel Sambuc-- The code that performs the processing of the actions is the component in 127*11be35a1SLionel Sambuc-- charge of finding correlations between test programs and test cases 128*11be35a1SLionel Sambuc-- across different actions. 129*11be35a1SLionel Sambuc-- ------------------------------------------------------------------------- 130*11be35a1SLionel Sambuc 131*11be35a1SLionel Sambuc 132*11be35a1SLionel Sambuc-- Representation of the metadata objects. 133*11be35a1SLionel Sambuc-- 134*11be35a1SLionel Sambuc-- The way this table works is like this: every time we record a metadata 135*11be35a1SLionel Sambuc-- object, we calculate what its identifier should be as the last rowid of 136*11be35a1SLionel Sambuc-- the table. All properties of that metadata object thus receive the same 137*11be35a1SLionel Sambuc-- identifier. 138*11be35a1SLionel SambucCREATE TABLE metadatas ( 139*11be35a1SLionel Sambuc metadata_id INTEGER NOT NULL, 140*11be35a1SLionel Sambuc 141*11be35a1SLionel Sambuc -- The name of the property. 142*11be35a1SLionel Sambuc property_name TEXT NOT NULL, 143*11be35a1SLionel Sambuc 144*11be35a1SLionel Sambuc -- One of the values of the property. 145*11be35a1SLionel Sambuc property_value TEXT, 146*11be35a1SLionel Sambuc 147*11be35a1SLionel Sambuc PRIMARY KEY (metadata_id, property_name) 148*11be35a1SLionel Sambuc); 149*11be35a1SLionel Sambuc 150*11be35a1SLionel Sambuc 151*11be35a1SLionel Sambuc-- Optimize the loading of the metadata of any single entity. 152*11be35a1SLionel Sambuc-- 153*11be35a1SLionel Sambuc-- The metadata_id column of the metadatas table is not enough to act as a 154*11be35a1SLionel Sambuc-- primary key, yet we need to locate entries in the metadatas table solely by 155*11be35a1SLionel Sambuc-- their identifier. 156*11be35a1SLionel Sambuc-- 157*11be35a1SLionel Sambuc-- TODO(jmmv): I think this index is useless given that the primary key in the 158*11be35a1SLionel Sambuc-- metadatas table includes the metadata_id as the first component. Need to 159*11be35a1SLionel Sambuc-- verify this and drop the index or this comment appropriately. 160*11be35a1SLionel SambucCREATE INDEX index_metadatas_by_id 161*11be35a1SLionel Sambuc ON metadatas (metadata_id); 162*11be35a1SLionel Sambuc 163*11be35a1SLionel Sambuc 164*11be35a1SLionel Sambuc-- Representation of a test program. 165*11be35a1SLionel Sambuc-- 166*11be35a1SLionel Sambuc-- At the moment, there are no substantial differences between the 167*11be35a1SLionel Sambuc-- different interfaces, so we can simplify the design by with having a 168*11be35a1SLionel Sambuc-- single table representing all test caes. We may need to revisit this in 169*11be35a1SLionel Sambuc-- the future. 170*11be35a1SLionel SambucCREATE TABLE test_programs ( 171*11be35a1SLionel Sambuc test_program_id INTEGER PRIMARY KEY AUTOINCREMENT, 172*11be35a1SLionel Sambuc action_id INTEGER REFERENCES actions, 173*11be35a1SLionel Sambuc 174*11be35a1SLionel Sambuc -- The absolute path to the test program. This should not be necessary 175*11be35a1SLionel Sambuc -- because it is basically the concatenation of root and relative_path. 176*11be35a1SLionel Sambuc -- However, this allows us to very easily search for test programs 177*11be35a1SLionel Sambuc -- regardless of where they were executed from. (I.e. different 178*11be35a1SLionel Sambuc -- combinations of root + relative_path can map to the same absolute path). 179*11be35a1SLionel Sambuc absolute_path TEXT NOT NULL, 180*11be35a1SLionel Sambuc 181*11be35a1SLionel Sambuc -- The path to the root of the test suite (where the Kyuafile lives). 182*11be35a1SLionel Sambuc root TEXT NOT NULL, 183*11be35a1SLionel Sambuc 184*11be35a1SLionel Sambuc -- The path to the test program, relative to the root. 185*11be35a1SLionel Sambuc relative_path TEXT NOT NULL, 186*11be35a1SLionel Sambuc 187*11be35a1SLionel Sambuc -- Name of the test suite the test program belongs to. 188*11be35a1SLionel Sambuc test_suite_name TEXT NOT NULL, 189*11be35a1SLionel Sambuc 190*11be35a1SLionel Sambuc -- Reference to the various rows of metadatas. 191*11be35a1SLionel Sambuc metadata_id INTEGER, 192*11be35a1SLionel Sambuc 193*11be35a1SLionel Sambuc -- The name of the test program interface. 194*11be35a1SLionel Sambuc -- 195*11be35a1SLionel Sambuc -- Note that this indicates both the interface for the test program and 196*11be35a1SLionel Sambuc -- its test cases. See below for the corresponding detail tables. 197*11be35a1SLionel Sambuc interface TEXT NOT NULL 198*11be35a1SLionel Sambuc); 199*11be35a1SLionel Sambuc 200*11be35a1SLionel Sambuc 201*11be35a1SLionel Sambuc-- Optimize the lookup of test programs by the action they belong to. 202*11be35a1SLionel SambucCREATE INDEX index_test_programs_by_action_id 203*11be35a1SLionel Sambuc ON test_programs (action_id); 204*11be35a1SLionel Sambuc 205*11be35a1SLionel Sambuc 206*11be35a1SLionel Sambuc-- Representation of a test case. 207*11be35a1SLionel Sambuc-- 208*11be35a1SLionel Sambuc-- At the moment, there are no substantial differences between the 209*11be35a1SLionel Sambuc-- different interfaces, so we can simplify the design by with having a 210*11be35a1SLionel Sambuc-- single table representing all test caes. We may need to revisit this in 211*11be35a1SLionel Sambuc-- the future. 212*11be35a1SLionel SambucCREATE TABLE test_cases ( 213*11be35a1SLionel Sambuc test_case_id INTEGER PRIMARY KEY AUTOINCREMENT, 214*11be35a1SLionel Sambuc test_program_id INTEGER REFERENCES test_programs, 215*11be35a1SLionel Sambuc name TEXT NOT NULL, 216*11be35a1SLionel Sambuc 217*11be35a1SLionel Sambuc -- Reference to the various rows of metadatas. 218*11be35a1SLionel Sambuc metadata_id INTEGER 219*11be35a1SLionel Sambuc); 220*11be35a1SLionel Sambuc 221*11be35a1SLionel Sambuc 222*11be35a1SLionel Sambuc-- Optimize the loading of all test cases that are part of a test program. 223*11be35a1SLionel SambucCREATE INDEX index_test_cases_by_test_programs_id 224*11be35a1SLionel Sambuc ON test_cases (test_program_id); 225*11be35a1SLionel Sambuc 226*11be35a1SLionel Sambuc 227*11be35a1SLionel Sambuc-- Representation of test case results. 228*11be35a1SLionel Sambuc-- 229*11be35a1SLionel Sambuc-- Note that there is a 1:1 relation between test cases and their results. 230*11be35a1SLionel Sambuc-- This is a result of storing the information of a test case on every 231*11be35a1SLionel Sambuc-- single action. 232*11be35a1SLionel SambucCREATE TABLE test_results ( 233*11be35a1SLionel Sambuc test_case_id INTEGER PRIMARY KEY REFERENCES test_cases, 234*11be35a1SLionel Sambuc result_type TEXT NOT NULL, 235*11be35a1SLionel Sambuc result_reason TEXT, 236*11be35a1SLionel Sambuc 237*11be35a1SLionel Sambuc start_time TIMESTAMP NOT NULL, 238*11be35a1SLionel Sambuc end_time TIMESTAMP NOT NULL 239*11be35a1SLionel Sambuc); 240*11be35a1SLionel Sambuc 241*11be35a1SLionel Sambuc 242*11be35a1SLionel Sambuc-- Collection of output files of the test case. 243*11be35a1SLionel SambucCREATE TABLE test_case_files ( 244*11be35a1SLionel Sambuc test_case_id INTEGER NOT NULL REFERENCES test_cases, 245*11be35a1SLionel Sambuc 246*11be35a1SLionel Sambuc -- The raw name of the file. 247*11be35a1SLionel Sambuc -- 248*11be35a1SLionel Sambuc -- The special names '__STDOUT__' and '__STDERR__' are reserved to hold 249*11be35a1SLionel Sambuc -- the stdout and stderr of the test case, respectively. If any of 250*11be35a1SLionel Sambuc -- these are empty, there will be no corresponding entry in this table 251*11be35a1SLionel Sambuc -- (hence why we do not allow NULLs in these fields). 252*11be35a1SLionel Sambuc file_name TEXT NOT NULL, 253*11be35a1SLionel Sambuc 254*11be35a1SLionel Sambuc -- Pointer to the file itself. 255*11be35a1SLionel Sambuc file_id INTEGER NOT NULL REFERENCES files, 256*11be35a1SLionel Sambuc 257*11be35a1SLionel Sambuc PRIMARY KEY (test_case_id, file_name) 258*11be35a1SLionel Sambuc); 259*11be35a1SLionel Sambuc 260*11be35a1SLionel Sambuc 261*11be35a1SLionel Sambuc-- ------------------------------------------------------------------------- 262*11be35a1SLionel Sambuc-- Verbatim files. 263*11be35a1SLionel Sambuc-- ------------------------------------------------------------------------- 264*11be35a1SLionel Sambuc 265*11be35a1SLionel Sambuc 266*11be35a1SLionel Sambuc-- Copies of files or logs generated during testing. 267*11be35a1SLionel Sambuc-- 268*11be35a1SLionel Sambuc-- TODO(jmmv): This will probably grow to unmanageable sizes. We should add a 269*11be35a1SLionel Sambuc-- hash to the file contents and use that as the primary key instead. 270*11be35a1SLionel SambucCREATE TABLE files ( 271*11be35a1SLionel Sambuc file_id INTEGER PRIMARY KEY, 272*11be35a1SLionel Sambuc 273*11be35a1SLionel Sambuc contents BLOB NOT NULL 274*11be35a1SLionel Sambuc); 275*11be35a1SLionel Sambuc 276*11be35a1SLionel Sambuc 277*11be35a1SLionel Sambuc-- ------------------------------------------------------------------------- 278*11be35a1SLionel Sambuc-- Initialization of values. 279*11be35a1SLionel Sambuc-- ------------------------------------------------------------------------- 280*11be35a1SLionel Sambuc 281*11be35a1SLionel Sambuc 282*11be35a1SLionel Sambuc-- Create a new metadata record. 283*11be35a1SLionel Sambuc-- 284*11be35a1SLionel Sambuc-- For every new database, we want to ensure that the metadata is valid if 285*11be35a1SLionel Sambuc-- the database creation (i.e. the whole transaction) succeeded. 286*11be35a1SLionel Sambuc-- 287*11be35a1SLionel Sambuc-- If you modify the value of the schema version in this statement, you 288*11be35a1SLionel Sambuc-- will also have to modify the version encoded in the backend module. 289*11be35a1SLionel SambucINSERT INTO metadata (timestamp, schema_version) 290*11be35a1SLionel Sambuc VALUES (strftime('%s', 'now'), 2); 291*11be35a1SLionel Sambuc 292*11be35a1SLionel Sambuc 293*11be35a1SLionel SambucCOMMIT TRANSACTION; 294