Below is the file 'init.sql' from this revision. You can also download the file.


--
-- this SQL file initialises an SQLite database
-- so that it is in a state suitable to host a
-- GConf database.
--

-- just for checking. the SQLite backend looks
-- for this table and checks the version matches
-- that in this file
CREATE TABLE gconf (
	version integer
);
INSERT INTO gconf (version) VALUES (1);

-- this table represents directories. one row
-- per directory.
CREATE TABLE directories (
	id integer primary key,
	name text not null,
	parent_id integer not null,
	UNIQUE (name, parent_id)
);

-- a key is an entry. it must be in a given directory.
-- there can only be one key with a given name in a given
-- directory
--
-- value_type indicates the type. in the case of scalar types,
-- value is the actual value. in the case of a list, 'value'
-- indicates the type of all values in the list. in all other
-- cases, value has no meaning.
CREATE TABLE keys (
	id integer primary key,
	name text,
	directory_id integer not null,
	mod_user text,
	mod_time text,
	value_type text,
	value,
	UNIQUE (name, directory_id)
);

-- the schema associated with a key
-- (not necessarily set for a given key)
CREATE TABLE keys_to_schema(
	key_id integer primary key,
	schematext
);

-- represents lists. a list value for a given key has key_id to match
-- the keys table, and is ordered by increasing values of list_idx
--
-- nb: special case; could be a schema default value, iff the type of
-- key_id in keys is schema and it has a default value which is a list
CREATE TABLE lists (
	key_id integer,
	list_idx integer,
	value,
	UNIQUE (key_id, list_idx)
);

-- represents a pair. a pair has two values, which may be of different
-- types. these values must be scalar.
--
-- nb: special case; could be a schema default value, iff the type of
-- key_id in keys is schema and it has a default value which is a pair
CREATE TABLE pairs (
	key_id integer primary key,
	car_value_type text,
	car_value,
	cdr_value_type text,
	cdr_value
);

-- represents a schema. match on key_id.
-- schema_type indicates the type of value required
-- in the case that this is list or pair, schema_list_type
-- and schema_car_type,schema_cdr_type apply.
-- owner, short_desc, long_desc are just text values to be stored.
--
-- locale indicates the locale for which this schema is valid
-- this is the only localised type
--
-- default_value_id is an index into schema_defaults, indicating
-- the value which an entry to which this schema applies should default
-- to
CREATE TABLE schemas (
	key_id integer primary key,
	schema_type text,
	schema_list_type text,
	schema_car_type text,
	schema_cdr_type text,
	locale text,
	owner text,
	short_desc text,
	long_desc text,
	default_value_id integer
);

-- the default value for a given schema
-- for schema with matching key_id
CREATE TABLE schemas_defaults (
	key_id integer primary key,
	value_type text,
	value
);