-- Copyright 2012 The Kyua Authors.1-- All rights reserved.2--3-- Redistribution and use in source and binary forms, with or without4-- modification, are permitted provided that the following conditions are5-- met:6--7-- * Redistributions of source code must retain the above copyright8-- notice, this list of conditions and the following disclaimer.9-- * Redistributions in binary form must reproduce the above copyright10-- notice, this list of conditions and the following disclaimer in the11-- documentation and/or other materials provided with the distribution.12-- * Neither the name of Google Inc. nor the names of its contributors13-- may be used to endorse or promote products derived from this software14-- without specific prior written permission.15--16-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT20-- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2728-- \file store/schema_v3.sql29-- Definition of the database schema.30--31-- The whole contents of this file are wrapped in a transaction. We want32-- to ensure that the initial contents of the database (the table layout as33-- well as any predefined values) are written atomically to simplify error34-- handling in our code.353637BEGIN TRANSACTION;383940-- -------------------------------------------------------------------------41-- Metadata.42-- -------------------------------------------------------------------------434445-- Database-wide properties.46--47-- Rows in this table are immutable: modifying the metadata implies writing48-- a new record with a new schema_version greater than all existing49-- records, and never updating previous records. When extracting data from50-- this table, the only "valid" row is the one with the highest51-- scheam_version. All the other rows are meaningless and only exist for52-- historical purposes.53--54-- In other words, this table keeps the history of the database metadata.55-- The only reason for doing this is for debugging purposes. It may come56-- in handy to know when a particular database-wide operation happened if57-- it turns out that the database got corrupted.58CREATE TABLE metadata (59schema_version INTEGER PRIMARY KEY CHECK (schema_version >= 1),60timestamp TIMESTAMP NOT NULL CHECK (timestamp >= 0)61);626364-- -------------------------------------------------------------------------65-- Contexts.66-- -------------------------------------------------------------------------676869-- Execution contexts.70--71-- A context represents the execution environment of the test run.72-- We record such information for information and debugging purposes.73CREATE TABLE contexts (74cwd TEXT NOT NULL7576-- TODO(jmmv): Record the run-time configuration.77);787980-- Environment variables of a context.81CREATE TABLE env_vars (82var_name TEXT PRIMARY KEY,83var_value TEXT NOT NULL84);858687-- -------------------------------------------------------------------------88-- Test suites.89--90-- The tables in this section represent all the components that form a test91-- suite. This includes data about the test suite itself (test programs92-- and test cases), and also the data about particular runs (test results).93--94-- As you will notice, every object has a unique identifier and there is no95-- attempt to deduplicate data. This has the interesting result of making96-- the distinction of a test case and a test result a pure syntactic97-- difference, because there is always a 1:1 relation.98-- -------------------------------------------------------------------------99100101-- Representation of the metadata objects.102--103-- The way this table works is like this: every time we record a metadata104-- object, we calculate what its identifier should be as the last rowid of105-- the table. All properties of that metadata object thus receive the same106-- identifier.107CREATE TABLE metadatas (108metadata_id INTEGER NOT NULL,109110-- The name of the property.111property_name TEXT NOT NULL,112113-- One of the values of the property.114property_value TEXT,115116PRIMARY KEY (metadata_id, property_name)117);118119120-- Optimize the loading of the metadata of any single entity.121--122-- The metadata_id column of the metadatas table is not enough to act as a123-- primary key, yet we need to locate entries in the metadatas table solely by124-- their identifier.125--126-- TODO(jmmv): I think this index is useless given that the primary key in the127-- metadatas table includes the metadata_id as the first component. Need to128-- verify this and drop the index or this comment appropriately.129CREATE INDEX index_metadatas_by_id130ON metadatas (metadata_id);131132133-- Representation of a test program.134--135-- At the moment, there are no substantial differences between the136-- different interfaces, so we can simplify the design by with having a137-- single table representing all test caes. We may need to revisit this in138-- the future.139CREATE TABLE test_programs (140test_program_id INTEGER PRIMARY KEY AUTOINCREMENT,141142-- The absolute path to the test program. This should not be necessary143-- because it is basically the concatenation of root and relative_path.144-- However, this allows us to very easily search for test programs145-- regardless of where they were executed from. (I.e. different146-- combinations of root + relative_path can map to the same absolute path).147absolute_path TEXT NOT NULL,148149-- The path to the root of the test suite (where the Kyuafile lives).150root TEXT NOT NULL,151152-- The path to the test program, relative to the root.153relative_path TEXT NOT NULL,154155-- Name of the test suite the test program belongs to.156test_suite_name TEXT NOT NULL,157158-- Reference to the various rows of metadatas.159metadata_id INTEGER,160161-- The name of the test program interface.162--163-- Note that this indicates both the interface for the test program and164-- its test cases. See below for the corresponding detail tables.165interface TEXT NOT NULL166);167168169-- Representation of a test case.170--171-- At the moment, there are no substantial differences between the172-- different interfaces, so we can simplify the design by with having a173-- single table representing all test caes. We may need to revisit this in174-- the future.175CREATE TABLE test_cases (176test_case_id INTEGER PRIMARY KEY AUTOINCREMENT,177test_program_id INTEGER REFERENCES test_programs,178name TEXT NOT NULL,179180-- Reference to the various rows of metadatas.181metadata_id INTEGER182);183184185-- Optimize the loading of all test cases that are part of a test program.186CREATE INDEX index_test_cases_by_test_programs_id187ON test_cases (test_program_id);188189190-- Representation of test case results.191--192-- Note that there is a 1:1 relation between test cases and their results.193CREATE TABLE test_results (194test_case_id INTEGER PRIMARY KEY REFERENCES test_cases,195result_type TEXT NOT NULL,196result_reason TEXT,197198start_time TIMESTAMP NOT NULL,199end_time TIMESTAMP NOT NULL200);201202203-- Collection of output files of the test case.204CREATE TABLE test_case_files (205test_case_id INTEGER NOT NULL REFERENCES test_cases,206207-- The raw name of the file.208--209-- The special names '__STDOUT__' and '__STDERR__' are reserved to hold210-- the stdout and stderr of the test case, respectively. If any of211-- these are empty, there will be no corresponding entry in this table212-- (hence why we do not allow NULLs in these fields).213file_name TEXT NOT NULL,214215-- Pointer to the file itself.216file_id INTEGER NOT NULL REFERENCES files,217218PRIMARY KEY (test_case_id, file_name)219);220221222-- -------------------------------------------------------------------------223-- Verbatim files.224-- -------------------------------------------------------------------------225226227-- Copies of files or logs generated during testing.228--229-- TODO(jmmv): This will probably grow to unmanageable sizes. We should add a230-- hash to the file contents and use that as the primary key instead.231CREATE TABLE files (232file_id INTEGER PRIMARY KEY,233234contents BLOB NOT NULL235);236237238-- -------------------------------------------------------------------------239-- Initialization of values.240-- -------------------------------------------------------------------------241242243-- Create a new metadata record.244--245-- For every new database, we want to ensure that the metadata is valid if246-- the database creation (i.e. the whole transaction) succeeded.247--248-- If you modify the value of the schema version in this statement, you249-- will also have to modify the version encoded in the backend module.250INSERT INTO metadata (timestamp, schema_version)251VALUES (strftime('%s', 'now'), 3);252253254COMMIT TRANSACTION;255256257