-- Copyright 2011 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_v1.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 larger timestamp value, and never updating previous49-- records. When extracting data from this table, the only "valid" row is50-- the one with the highest timestamp. All the other rows are meaningless.51--52-- In other words, this table keeps the history of the database metadata.53-- The only reason for doing this is for debugging purposes. It may come54-- in handy to know when a particular database-wide operation happened if55-- it turns out that the database got corrupted.56CREATE TABLE metadata (57timestamp TIMESTAMP PRIMARY KEY CHECK (timestamp >= 0),58schema_version INTEGER NOT NULL CHECK (schema_version >= 1)59);606162-- -------------------------------------------------------------------------63-- Contexts.64-- -------------------------------------------------------------------------656667-- Execution contexts.68--69-- A context represents the execution environment of a particular action.70-- Because every action is invoked by the user, the context may have71-- changed. We record such information for information and debugging72-- purposes.73CREATE TABLE contexts (74context_id INTEGER PRIMARY KEY AUTOINCREMENT,75cwd TEXT NOT NULL7677-- TODO(jmmv): Record the run-time configuration.78);798081-- Environment variables of a context.82CREATE TABLE env_vars (83context_id INTEGER REFERENCES contexts,84var_name TEXT NOT NULL,85var_value TEXT NOT NULL,8687PRIMARY KEY (context_id, var_name)88);899091-- -------------------------------------------------------------------------92-- Actions.93-- -------------------------------------------------------------------------949596-- Representation of user-initiated actions.97--98-- An action is an operation initiated by the user. At the moment, the99-- only operation Kyua supports is the "test" operation (in the future we100-- should be able to store, e.g. build logs). To keep things simple the101-- database schema is restricted to represent one single action.102CREATE TABLE actions (103action_id INTEGER PRIMARY KEY AUTOINCREMENT,104context_id INTEGER REFERENCES contexts105);106107108-- -------------------------------------------------------------------------109-- Test suites.110--111-- The tables in this section represent all the components that form a test112-- suite. This includes data about the test suite itself (test programs113-- and test cases), and also the data about particular runs (test results).114--115-- As you will notice, every object belongs to a particular action, has a116-- unique identifier and there is no attempt to deduplicate data. This117-- comes from the fact that a test suite is not "stable" over time: i.e. on118-- each execution of the test suite, test programs and test cases may have119-- come and gone. This has the interesting result of making the120-- distinction of a test case and a test result a pure syntactic121-- difference, because there is always a 1:1 relation.122--123-- The code that performs the processing of the actions is the component in124-- charge of finding correlations between test programs and test cases125-- across different actions.126-- -------------------------------------------------------------------------127128129-- Representation of a test program.130--131-- At the moment, there are no substantial differences between the132-- different interfaces, so we can simplify the design by with having a133-- single table representing all test caes. We may need to revisit this in134-- the future.135CREATE TABLE test_programs (136test_program_id INTEGER PRIMARY KEY AUTOINCREMENT,137action_id INTEGER REFERENCES actions,138139-- The absolute path to the test program. This should not be necessary140-- because it is basically the concatenation of root and relative_path.141-- However, this allows us to very easily search for test programs142-- regardless of where they were executed from. (I.e. different143-- combinations of root + relative_path can map to the same absolute path).144absolute_path NOT NULL,145146-- The path to the root of the test suite (where the Kyuafile lives).147root TEXT NOT NULL,148149-- The path to the test program, relative to the root.150relative_path NOT NULL,151152-- Name of the test suite the test program belongs to.153test_suite_name TEXT NOT NULL,154155-- The name of the test program interface.156--157-- Note that this indicates both the interface for the test program and158-- its test cases. See below for the corresponding detail tables.159interface TEXT NOT NULL160);161162163-- Representation of a test case.164--165-- At the moment, there are no substantial differences between the166-- different interfaces, so we can simplify the design by with having a167-- single table representing all test caes. We may need to revisit this in168-- the future.169CREATE TABLE test_cases (170test_case_id INTEGER PRIMARY KEY AUTOINCREMENT,171test_program_id INTEGER REFERENCES test_programs,172name TEXT NOT NULL173);174175176-- Representation of test case results.177--178-- Note that there is a 1:1 relation between test cases and their results.179-- This is a result of storing the information of a test case on every180-- single action.181CREATE TABLE test_results (182test_case_id INTEGER PRIMARY KEY REFERENCES test_cases,183result_type TEXT NOT NULL,184result_reason TEXT,185186start_time TIMESTAMP NOT NULL,187end_time TIMESTAMP NOT NULL188);189190191-- Collection of output files of the test case.192CREATE TABLE test_case_files (193test_case_id INTEGER NOT NULL REFERENCES test_cases,194195-- The raw name of the file.196--197-- The special names '__STDOUT__' and '__STDERR__' are reserved to hold198-- the stdout and stderr of the test case, respectively. If any of199-- these are empty, there will be no corresponding entry in this table200-- (hence why we do not allow NULLs in these fields).201file_name TEXT NOT NULL,202203-- Pointer to the file itself.204file_id INTEGER NOT NULL REFERENCES files,205206PRIMARY KEY (test_case_id, file_name)207);208209210-- -------------------------------------------------------------------------211-- Detail tables for the 'atf' test interface.212-- -------------------------------------------------------------------------213214215-- Properties specific to 'atf' test cases.216--217-- This table contains the representation of singly-valued properties such218-- as 'timeout'. Properties that can have more than one (textual) value219-- are stored in the atf_test_cases_multivalues table.220--221-- Note that all properties can be NULL because test cases are not required222-- to define them.223CREATE TABLE atf_test_cases (224test_case_id INTEGER PRIMARY KEY REFERENCES test_cases,225226-- Free-form description of the text case.227description TEXT,228229-- Either 'true' or 'false', indicating whether the test case has a230-- cleanup routine or not.231has_cleanup TEXT,232233-- The timeout for the test case in microseconds.234timeout INTEGER,235236-- The amount of physical memory required by the test case.237required_memory INTEGER,238239-- Either 'root' or 'unprivileged', indicating the privileges required by240-- the test case.241required_user TEXT242);243244245-- Representation of test case properties that have more than one value.246--247-- While we could store the flattened values of the properties as provided248-- by the test case itself, we choose to store the processed, split249-- representation. This allows us to perform queries about the test cases250-- directly on the database without doing text processing; for example,251-- "get all test cases that require /bin/ls".252CREATE TABLE atf_test_cases_multivalues (253test_case_id INTEGER REFERENCES test_cases,254255-- The name of the property; for example, 'require.progs'.256property_name TEXT NOT NULL,257258-- One of the values of the property.259property_value TEXT NOT NULL260);261262263-- -------------------------------------------------------------------------264-- Detail tables for the 'plain' test interface.265-- -------------------------------------------------------------------------266267268-- Properties specific to 'plain' test programs.269CREATE TABLE plain_test_programs (270test_program_id INTEGER PRIMARY KEY REFERENCES test_programs,271272-- The timeout for the test cases in this test program. While this273-- setting has a default value for test programs, we explicitly record274-- the information here. The "default value" used when the test275-- program was run might change over time, so we want to know what it276-- was exactly when this was run.277timeout INTEGER NOT NULL278);279280281-- -------------------------------------------------------------------------282-- Verbatim files.283-- -------------------------------------------------------------------------284285286-- Copies of files or logs generated during testing.287--288-- TODO(jmmv): This will probably grow to unmanageable sizes. We should add a289-- hash to the file contents and use that as the primary key instead.290CREATE TABLE files (291file_id INTEGER PRIMARY KEY,292293contents BLOB NOT NULL294);295296297-- -------------------------------------------------------------------------298-- Initialization of values.299-- -------------------------------------------------------------------------300301302-- Create a new metadata record.303--304-- For every new database, we want to ensure that the metadata is valid if305-- the database creation (i.e. the whole transaction) succeeded.306--307-- If you modify the value of the schema version in this statement, you308-- will also have to modify the version encoded in the backend module.309INSERT INTO metadata (timestamp, schema_version)310VALUES (strftime('%s', 'now'), 1);311312313COMMIT TRANSACTION;314315316