1
-- Non Functional Test Metrics Database Schema.
3
DROP TABLE IF EXISTS data;
4
DROP TABLE IF EXISTS test;
5
DROP TABLE IF EXISTS project;
7
CREATE SEQUENCE project_id_seq;
9
id INTEGER PRIMARY KEY default nextval('project_id_seq'),
10
name varchar(128) NOT NULL,
13
ALTER SEQUENCE project_id_seq owned by project.id;
14
CREATE INDEX project_name_index ON project(name);
16
CREATE SEQUENCE test_id_seq;
18
id INTEGER PRIMARY KEY default nextval('test_id_seq'),
19
name varchar(128) NOT NULL,
21
FOREIGN KEY (project_id) REFERENCES project(id),
22
UNIQUE (project_id, name)
24
ALTER SEQUENCE test_id_seq owned by test.id;
25
CREATE INDEX test_name_index ON test(name);
27
-- The client table stores secret resource owner keys, as well as public
28
-- client and resource owner keys. We also store some information about
30
-- The 'valid' column defaults to true. We only accept connections from
31
-- clients where this is set to 'true' and we set it to 'false' when
32
-- invalidating client keys. We do this rather than deleting the key
33
-- because we still want to retain historical information about which
34
-- data points were inserted by which client.
35
CREATE SEQUENCE client_id_seq;
37
id INTEGER PRIMARY KEY default nextval('client_id_seq'),
38
access_key VARCHAR(30) NOT NULL,
41
point_of_contact TEXT,
42
resource_owner_key VARCHAR(30) NOT NULL,
43
resource_owner_secret VARCHAR(30) NOT NULL,
44
valid BOOLEAN default true,
47
ALTER SEQUENCE client_id_seq owned by client.id;
48
-- we'll often want to look up a specific client access key, so let's index that:
49
CREATE INDEX client_access_key_index ON client(access_key);
50
-- We need to have a dummy client row added so the auth process is constant time:
51
-- Note that the resource owner key and secret need to be valid values, but can
52
-- never be authenticated against.
53
INSERT INTO client (access_key, name, resource_owner_key, resource_owner_secret, valid) VALUES (
54
'dummy-client-access-token',
56
'O9MFI1GUCrzBU6Uv1vshLX5wvhjDji',
57
'{wtgn,V>$#bn1fwqbe&,}/l1STF<@Y',
60
-- We also add a client that's invalid (can never be authenticated) that's used
61
-- for all the pre-populated data in the system.
62
INSERT INTO client (access_key, name, description, resource_owner_key, resource_owner_secret, valid) VALUES (
63
'sys-prepopulated-data-client',
65
'This is not a real client - it is used to link to pre-populated data.',
66
'Bad resource owner key',
67
'Bad resource owner secret',
71
CREATE SEQUENCE data_id_seq;
73
id INTEGER PRIMARY KEY default nextval('data_id_seq'),
74
date_entered timestamp with time zone NOT NULL,
78
FOREIGN KEY (test_id) REFERENCES test(id),
79
FOREIGN KEY (client_id) REFERENCES client(id)
81
ALTER SEQUENCE data_id_seq owned by data.id;
82
-- We will frequently be looking for data between two date ranges. Index the
83
-- date_entered column so this is efficient:
84
CREATE INDEX data_date_entered_index ON data(date_entered);
87
-- We need to store nonce values in the database. The nonce and timestamp are
88
-- stored with the access key and the resource owner key.
90
access_key VARCHAR(30) NOT NULL,
91
timestamp timestamp without time zone NOT NULL,
93
resource_owner_key TEXT
95
-- we'll always be searching for entries in all columns, so index that:
96
CREATE UNIQUE INDEX nonce_all_index ON nonce(access_key, timestamp, nonce, resource_owner_key);
97
-- We'll also be cleaning this table out periodically by sorting on the timestamp column:
98
CREATE INDEX nonce_timestamp_index ON nonce(timestamp);