Upgrades to utility code for new formats, and a few more database tweaks.
[cumulus.git] / schema.sql
1 -- We maintain a local index of data blocks that have been previously stored
2 -- for constructing incremental snapshots.
3 --
4 -- The index is stored in an SQLite3 database.  This is its schema.
5
6 -- List of snapshots which have been created.
7 create table snapshots (
8     snapshotid integer primary key,
9     name text not null,
10     scheme text,
11     timestamp real
12 );
13
14 -- List of segments which have been created.
15 create table segments (
16     segmentid integer primary key,
17     segment text unique not null,
18     path text,
19     checksum text,
20     mtime real,
21     size integer
22 );
23
24 -- Index of all blocks which have been stored, by checksum.
25 create table block_index (
26     blockid integer primary key,
27     segmentid integer not null,
28     object text not null,
29     checksum text,
30     size integer,
31     timestamp real,
32     expired integer
33 );
34 create index block_content_index on block_index(checksum);
35 create unique index block_name_index on block_index(segmentid, object);
36
37 -- Summary of segment utilization for each snapshots.
38 create table segments_used (
39     snapshotid integer not null,
40     segmentid integer not null,
41     utilization real
42 );
43
44 -- Overall estimate of segment utilization, for all snapshots combined.
45 create view segment_info as
46 select segmentid, mtime, size, cast(size * utilization as integer) as used,
47        utilization
48 from segments join
49      (select segmentid, max(utilization) as utilization
50       from segments_used group by segmentid)
51 using (segmentid);