2005-05-24 13:31:22 +00:00
-- ------------------------------------------------------
PRAGMA auto_vacuum=1;
-- ------------------------------------------------------
BEGIN EXCLUSIVE;
-- ------------------------------------------------------
CREATE TABLE ldb_info AS
SELECT 'LDB' AS database_type,
'1.0' AS version;
2005-06-04 17:13:43 +00:00
-- ------------------------------------------------------
-- Schema
2005-05-31 03:31:54 +00:00
/*
2005-06-04 17:13:43 +00:00
* The entry table holds the information about an entry. This
* table is used to obtain the EID of the entry and to support
* scope="one" and scope="base". The parent and child table
* is included in the entry table since all the other
2005-06-04 21:16:54 +00:00
* attributes are dependent on EID.
2005-05-31 03:31:54 +00:00
*/
2005-06-04 17:13:43 +00:00
CREATE TABLE ldb_entry
2005-05-24 13:31:22 +00:00
(
2005-06-04 17:13:43 +00:00
-- Unique identifier of this LDB entry
eid INTEGER PRIMARY KEY,
-- Unique identifier of the parent LDB entry
peid INTEGER REFERENCES ldb_entry,
-- Distinguished name of this entry
dn TEXT,
-- Time when the entry was created
create_timestamp INTEGER,
-- Time when the entry was last modified
2005-06-12 03:07:10 +00:00
modify_timestamp INTEGER
2005-05-24 13:31:22 +00:00
);
2005-06-04 17:13:43 +00:00
/*
* The purpose of the descendant table is to support the
* subtree search feature. For each LDB entry with a unique
* ID (AEID), this table contains the unique identifiers
* (DEID) of the descendant entries.
*
* For evern entry in the directory, a row exists in this
* table for each of its ancestors including itself. The size
* of the table depends on the depth of each entry. In the
* worst case, if all the entries were at the same depth, the
* number of rows in the table is O(nm) where n is the number
* of nodes in the directory and m is the depth of the tree.
*/
CREATE TABLE ldb_descendants
2005-05-24 13:31:22 +00:00
(
2005-06-04 17:13:43 +00:00
-- The unique identifier of the ancestor LDB entry
aeid INTEGER REFERENCES ldb_entry,
-- The unique identifier of the descendant LDB entry
deid INTEGER REFERENCES ldb_entry
2005-05-24 13:31:22 +00:00
);
2005-06-04 17:13:43 +00:00
CREATE TABLE ldb_object_classes
(
-- Object classes are inserted into this table to track
-- their class hierarchy. 'top' is the top-level class
-- of which all other classes are subclasses.
class_name TEXT PRIMARY KEY,
-- tree_key tracks the position of the class in
-- the hierarchy
tree_key TEXT UNIQUE
);
2005-05-31 03:31:54 +00:00
2005-06-12 03:07:10 +00:00
/*
* We keep a full listing of attribute/value pairs here
*/
CREATE TABLE ldb_attribute_values
(
eid INTEGER REFERENCES ldb_entry,
attr_name TEXT, -- see ldb_attr_ATTRIBUTE_NAME
attr_value TEXT
);
2005-06-04 17:13:43 +00:00
/*
* There is one attribute table per searchable attribute.
*/
/*
CREATE TABLE ldb_attr_ATTRIBUTE_NAME
(
-- The unique identifier of the LDB entry
eid INTEGER REFERENCES ldb_entry,
2005-05-30 16:46:54 +00:00
2005-06-04 17:13:43 +00:00
-- Normalized attribute value
attr_value TEXT
2005-05-24 13:31:22 +00:00
);
2005-06-04 17:13:43 +00:00
*/
2005-05-24 13:31:22 +00:00
2005-06-04 17:13:43 +00:00
-- ------------------------------------------------------
-- Indexes
2005-05-31 03:31:54 +00:00
-- ------------------------------------------------------
2005-06-04 17:13:43 +00:00
-- Triggers
2005-05-31 03:31:54 +00:00
2005-06-04 17:13:43 +00:00
CREATE TRIGGER ldb_entry_insert_tr
2005-05-31 03:31:54 +00:00
AFTER INSERT
2005-06-04 17:13:43 +00:00
ON ldb_entry
2005-05-24 13:31:22 +00:00
FOR EACH ROW
BEGIN
2005-06-04 17:13:43 +00:00
UPDATE ldb_entry
SET create_timestamp = strftime('%s', 'now'),
modify_timestamp = strftime('%s', 'now')
WHERE eid = new.eid;
2005-05-24 13:31:22 +00:00
END;
2005-06-04 17:13:43 +00:00
CREATE TRIGGER ldb_entry_update_tr
2005-05-31 03:31:54 +00:00
AFTER UPDATE
2005-06-04 17:13:43 +00:00
ON ldb_entry
2005-05-24 13:31:22 +00:00
FOR EACH ROW
BEGIN
2005-06-04 17:13:43 +00:00
UPDATE ldb_entry
SET modify_timestamp = strftime('%s', 'now')
WHERE eid = old.eid;
2005-05-24 13:31:22 +00:00
END;
-- ------------------------------------------------------
2005-06-04 17:13:43 +00:00
-- Table initialization
2005-05-24 13:31:22 +00:00
2005-06-04 21:16:54 +00:00
/* We need an implicit 'top' level object class */
2005-05-31 03:31:54 +00:00
INSERT INTO ldb_attributes (attr_name,
parent_tree_key)
SELECT 'top', '';
2005-05-24 13:31:22 +00:00
-- ------------------------------------------------------
COMMIT;
-- ------------------------------------------------------
2005-06-14 21:52:35 +00:00
/*** TESTS ***/
2005-05-24 13:31:22 +00:00
/*
* dn: o=University of Michigan,c=US
* objectclass: organization
* objectclass: domainRelatedObject
*/
/*
2005-05-31 03:31:54 +00:00
* dn: o=University of Michigan,c=US
2005-05-24 13:31:22 +00:00
* l: Ann Arbor, Michigan
* st: Michigan
* o: University of Michigan
* o: UMICH
* seeAlso:
* telephonenumber: +1 313 764-1817
*/
/*
* dn: @ATTRIBUTES
* uid: CASE_INSENSITIVE WILDCARD
* cn: CASE_INSENSITIVE
* ou: CASE_INSENSITIVE
* dn: CASE_INSENSITIVE
*/
/*
* dn: @SUBCLASSES
* top: domain
* top: person
* domain: domainDNS
* person: organizationalPerson
* person: fooPerson
* organizationalPerson: user
* organizationalPerson: OpenLDAPperson
* user: computer
*/