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_v3.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 the test run. 73*b0d29bc4SBrooks Davis-- We record such information for information and debugging purposes. 74*b0d29bc4SBrooks DavisCREATE TABLE contexts ( 75*b0d29bc4SBrooks Davis cwd TEXT NOT NULL 76*b0d29bc4SBrooks Davis 77*b0d29bc4SBrooks Davis -- TODO(jmmv): Record the run-time configuration. 78*b0d29bc4SBrooks Davis); 79*b0d29bc4SBrooks Davis 80*b0d29bc4SBrooks Davis 81*b0d29bc4SBrooks Davis-- Environment variables of a context. 82*b0d29bc4SBrooks DavisCREATE TABLE env_vars ( 83*b0d29bc4SBrooks Davis var_name TEXT PRIMARY KEY, 84*b0d29bc4SBrooks Davis var_value TEXT NOT NULL 85*b0d29bc4SBrooks Davis); 86*b0d29bc4SBrooks Davis 87*b0d29bc4SBrooks Davis 88*b0d29bc4SBrooks Davis-- ------------------------------------------------------------------------- 89*b0d29bc4SBrooks Davis-- Test suites. 90*b0d29bc4SBrooks Davis-- 91*b0d29bc4SBrooks Davis-- The tables in this section represent all the components that form a test 92*b0d29bc4SBrooks Davis-- suite. This includes data about the test suite itself (test programs 93*b0d29bc4SBrooks Davis-- and test cases), and also the data about particular runs (test results). 94*b0d29bc4SBrooks Davis-- 95*b0d29bc4SBrooks Davis-- As you will notice, every object has a unique identifier and there is no 96*b0d29bc4SBrooks Davis-- attempt to deduplicate data. This has the interesting result of making 97*b0d29bc4SBrooks Davis-- the distinction of a test case and a test result a pure syntactic 98*b0d29bc4SBrooks Davis-- difference, because there is always a 1:1 relation. 99*b0d29bc4SBrooks Davis-- ------------------------------------------------------------------------- 100*b0d29bc4SBrooks Davis 101*b0d29bc4SBrooks Davis 102*b0d29bc4SBrooks Davis-- Representation of the metadata objects. 103*b0d29bc4SBrooks Davis-- 104*b0d29bc4SBrooks Davis-- The way this table works is like this: every time we record a metadata 105*b0d29bc4SBrooks Davis-- object, we calculate what its identifier should be as the last rowid of 106*b0d29bc4SBrooks Davis-- the table. All properties of that metadata object thus receive the same 107*b0d29bc4SBrooks Davis-- identifier. 108*b0d29bc4SBrooks DavisCREATE TABLE metadatas ( 109*b0d29bc4SBrooks Davis metadata_id INTEGER NOT NULL, 110*b0d29bc4SBrooks Davis 111*b0d29bc4SBrooks Davis -- The name of the property. 112*b0d29bc4SBrooks Davis property_name TEXT NOT NULL, 113*b0d29bc4SBrooks Davis 114*b0d29bc4SBrooks Davis -- One of the values of the property. 115*b0d29bc4SBrooks Davis property_value TEXT, 116*b0d29bc4SBrooks Davis 117*b0d29bc4SBrooks Davis PRIMARY KEY (metadata_id, property_name) 118*b0d29bc4SBrooks Davis); 119*b0d29bc4SBrooks Davis 120*b0d29bc4SBrooks Davis 121*b0d29bc4SBrooks Davis-- Optimize the loading of the metadata of any single entity. 122*b0d29bc4SBrooks Davis-- 123*b0d29bc4SBrooks Davis-- The metadata_id column of the metadatas table is not enough to act as a 124*b0d29bc4SBrooks Davis-- primary key, yet we need to locate entries in the metadatas table solely by 125*b0d29bc4SBrooks Davis-- their identifier. 126*b0d29bc4SBrooks Davis-- 127*b0d29bc4SBrooks Davis-- TODO(jmmv): I think this index is useless given that the primary key in the 128*b0d29bc4SBrooks Davis-- metadatas table includes the metadata_id as the first component. Need to 129*b0d29bc4SBrooks Davis-- verify this and drop the index or this comment appropriately. 130*b0d29bc4SBrooks DavisCREATE INDEX index_metadatas_by_id 131*b0d29bc4SBrooks Davis ON metadatas (metadata_id); 132*b0d29bc4SBrooks Davis 133*b0d29bc4SBrooks Davis 134*b0d29bc4SBrooks Davis-- Representation of a test program. 135*b0d29bc4SBrooks Davis-- 136*b0d29bc4SBrooks Davis-- At the moment, there are no substantial differences between the 137*b0d29bc4SBrooks Davis-- different interfaces, so we can simplify the design by with having a 138*b0d29bc4SBrooks Davis-- single table representing all test caes. We may need to revisit this in 139*b0d29bc4SBrooks Davis-- the future. 140*b0d29bc4SBrooks DavisCREATE TABLE test_programs ( 141*b0d29bc4SBrooks Davis test_program_id INTEGER PRIMARY KEY AUTOINCREMENT, 142*b0d29bc4SBrooks Davis 143*b0d29bc4SBrooks Davis -- The absolute path to the test program. This should not be necessary 144*b0d29bc4SBrooks Davis -- because it is basically the concatenation of root and relative_path. 145*b0d29bc4SBrooks Davis -- However, this allows us to very easily search for test programs 146*b0d29bc4SBrooks Davis -- regardless of where they were executed from. (I.e. different 147*b0d29bc4SBrooks Davis -- combinations of root + relative_path can map to the same absolute path). 148*b0d29bc4SBrooks Davis absolute_path TEXT NOT NULL, 149*b0d29bc4SBrooks Davis 150*b0d29bc4SBrooks Davis -- The path to the root of the test suite (where the Kyuafile lives). 151*b0d29bc4SBrooks Davis root TEXT NOT NULL, 152*b0d29bc4SBrooks Davis 153*b0d29bc4SBrooks Davis -- The path to the test program, relative to the root. 154*b0d29bc4SBrooks Davis relative_path TEXT NOT NULL, 155*b0d29bc4SBrooks Davis 156*b0d29bc4SBrooks Davis -- Name of the test suite the test program belongs to. 157*b0d29bc4SBrooks Davis test_suite_name TEXT NOT NULL, 158*b0d29bc4SBrooks Davis 159*b0d29bc4SBrooks Davis -- Reference to the various rows of metadatas. 160*b0d29bc4SBrooks Davis metadata_id INTEGER, 161*b0d29bc4SBrooks Davis 162*b0d29bc4SBrooks Davis -- The name of the test program interface. 163*b0d29bc4SBrooks Davis -- 164*b0d29bc4SBrooks Davis -- Note that this indicates both the interface for the test program and 165*b0d29bc4SBrooks Davis -- its test cases. See below for the corresponding detail tables. 166*b0d29bc4SBrooks Davis interface TEXT NOT NULL 167*b0d29bc4SBrooks Davis); 168*b0d29bc4SBrooks Davis 169*b0d29bc4SBrooks Davis 170*b0d29bc4SBrooks Davis-- Representation of a test case. 171*b0d29bc4SBrooks Davis-- 172*b0d29bc4SBrooks Davis-- At the moment, there are no substantial differences between the 173*b0d29bc4SBrooks Davis-- different interfaces, so we can simplify the design by with having a 174*b0d29bc4SBrooks Davis-- single table representing all test caes. We may need to revisit this in 175*b0d29bc4SBrooks Davis-- the future. 176*b0d29bc4SBrooks DavisCREATE TABLE test_cases ( 177*b0d29bc4SBrooks Davis test_case_id INTEGER PRIMARY KEY AUTOINCREMENT, 178*b0d29bc4SBrooks Davis test_program_id INTEGER REFERENCES test_programs, 179*b0d29bc4SBrooks Davis name TEXT NOT NULL, 180*b0d29bc4SBrooks Davis 181*b0d29bc4SBrooks Davis -- Reference to the various rows of metadatas. 182*b0d29bc4SBrooks Davis metadata_id INTEGER 183*b0d29bc4SBrooks Davis); 184*b0d29bc4SBrooks Davis 185*b0d29bc4SBrooks Davis 186*b0d29bc4SBrooks Davis-- Optimize the loading of all test cases that are part of a test program. 187*b0d29bc4SBrooks DavisCREATE INDEX index_test_cases_by_test_programs_id 188*b0d29bc4SBrooks Davis ON test_cases (test_program_id); 189*b0d29bc4SBrooks Davis 190*b0d29bc4SBrooks Davis 191*b0d29bc4SBrooks Davis-- Representation of test case results. 192*b0d29bc4SBrooks Davis-- 193*b0d29bc4SBrooks Davis-- Note that there is a 1:1 relation between test cases and their results. 194*b0d29bc4SBrooks DavisCREATE TABLE test_results ( 195*b0d29bc4SBrooks Davis test_case_id INTEGER PRIMARY KEY REFERENCES test_cases, 196*b0d29bc4SBrooks Davis result_type TEXT NOT NULL, 197*b0d29bc4SBrooks Davis result_reason TEXT, 198*b0d29bc4SBrooks Davis 199*b0d29bc4SBrooks Davis start_time TIMESTAMP NOT NULL, 200*b0d29bc4SBrooks Davis end_time TIMESTAMP NOT NULL 201*b0d29bc4SBrooks Davis); 202*b0d29bc4SBrooks Davis 203*b0d29bc4SBrooks Davis 204*b0d29bc4SBrooks Davis-- Collection of output files of the test case. 205*b0d29bc4SBrooks DavisCREATE TABLE test_case_files ( 206*b0d29bc4SBrooks Davis test_case_id INTEGER NOT NULL REFERENCES test_cases, 207*b0d29bc4SBrooks Davis 208*b0d29bc4SBrooks Davis -- The raw name of the file. 209*b0d29bc4SBrooks Davis -- 210*b0d29bc4SBrooks Davis -- The special names '__STDOUT__' and '__STDERR__' are reserved to hold 211*b0d29bc4SBrooks Davis -- the stdout and stderr of the test case, respectively. If any of 212*b0d29bc4SBrooks Davis -- these are empty, there will be no corresponding entry in this table 213*b0d29bc4SBrooks Davis -- (hence why we do not allow NULLs in these fields). 214*b0d29bc4SBrooks Davis file_name TEXT NOT NULL, 215*b0d29bc4SBrooks Davis 216*b0d29bc4SBrooks Davis -- Pointer to the file itself. 217*b0d29bc4SBrooks Davis file_id INTEGER NOT NULL REFERENCES files, 218*b0d29bc4SBrooks Davis 219*b0d29bc4SBrooks Davis PRIMARY KEY (test_case_id, file_name) 220*b0d29bc4SBrooks Davis); 221*b0d29bc4SBrooks Davis 222*b0d29bc4SBrooks Davis 223*b0d29bc4SBrooks Davis-- ------------------------------------------------------------------------- 224*b0d29bc4SBrooks Davis-- Verbatim files. 225*b0d29bc4SBrooks Davis-- ------------------------------------------------------------------------- 226*b0d29bc4SBrooks Davis 227*b0d29bc4SBrooks Davis 228*b0d29bc4SBrooks Davis-- Copies of files or logs generated during testing. 229*b0d29bc4SBrooks Davis-- 230*b0d29bc4SBrooks Davis-- TODO(jmmv): This will probably grow to unmanageable sizes. We should add a 231*b0d29bc4SBrooks Davis-- hash to the file contents and use that as the primary key instead. 232*b0d29bc4SBrooks DavisCREATE TABLE files ( 233*b0d29bc4SBrooks Davis file_id INTEGER PRIMARY KEY, 234*b0d29bc4SBrooks Davis 235*b0d29bc4SBrooks Davis contents BLOB NOT NULL 236*b0d29bc4SBrooks Davis); 237*b0d29bc4SBrooks Davis 238*b0d29bc4SBrooks Davis 239*b0d29bc4SBrooks Davis-- ------------------------------------------------------------------------- 240*b0d29bc4SBrooks Davis-- Initialization of values. 241*b0d29bc4SBrooks Davis-- ------------------------------------------------------------------------- 242*b0d29bc4SBrooks Davis 243*b0d29bc4SBrooks Davis 244*b0d29bc4SBrooks Davis-- Create a new metadata record. 245*b0d29bc4SBrooks Davis-- 246*b0d29bc4SBrooks Davis-- For every new database, we want to ensure that the metadata is valid if 247*b0d29bc4SBrooks Davis-- the database creation (i.e. the whole transaction) succeeded. 248*b0d29bc4SBrooks Davis-- 249*b0d29bc4SBrooks Davis-- If you modify the value of the schema version in this statement, you 250*b0d29bc4SBrooks Davis-- will also have to modify the version encoded in the backend module. 251*b0d29bc4SBrooks DavisINSERT INTO metadata (timestamp, schema_version) 252*b0d29bc4SBrooks Davis VALUES (strftime('%s', 'now'), 3); 253*b0d29bc4SBrooks Davis 254*b0d29bc4SBrooks Davis 255*b0d29bc4SBrooks DavisCOMMIT TRANSACTION; 256