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