source: branches/samba-3.2.x/source/lib/ldb/ldb_sqlite3/schema@ 234

Last change on this file since 234 was 133, checked in by Paul Smedley, 18 years ago

Update trunk to 3.2.0pre3

File size: 11.6 KB
Line 
1 -- ------------------------------------------------------
2
3 PRAGMA auto_vacuum=1;
4
5 -- ------------------------------------------------------
6
7 BEGIN EXCLUSIVE;
8
9 -- ------------------------------------------------------
10
11 CREATE TABLE ldb_info AS
12 SELECT 'LDB' AS database_type,
13 '1.0' AS version;
14
15 /*
16 * Get the next USN value with:
17 * BEGIN EXCLUSIVE;
18 * UPDATE usn SET value = value + 1;
19 * SELECT value FROM usn;
20 * COMMIT;
21 */
22 CREATE TABLE usn
23 (
24 value INTEGER
25 );
26
27 CREATE TABLE ldb_object
28 (
29 /* tree_key is auto-generated by the insert trigger */
30 tree_key TEXT PRIMARY KEY,
31
32 parent_tree_key TEXT,
33 dn TEXT,
34
35 attr_name TEXT REFERENCES ldb_attributes,
36 attr_value TEXT,
37
38 /*
39 * object_type can take on these values (to date):
40 * 1: object is a node of a DN
41 * 2: object is an attribute/value pair of its parent DN
42 */
43 object_type INTEGER,
44
45 /*
46 * if object_type is 1, the node can have children.
47 * this tracks the maximum previously assigned child
48 * number so we can generate a new unique tree key for
49 * a new child object. note that this is always incremented,
50 * so if children are deleted, this will not represent
51 * the _number_ of children.
52 */
53 max_child_num INTEGER,
54
55 /*
56 * Automatically maintained meta-data (a gift for metze)
57 */
58 object_guid TEXT UNIQUE,
59 timestamp INTEGER, -- originating_time
60 invoke_id TEXT, -- GUID: originating_invocation_id
61 usn INTEGER, -- hyper: originating_usn
62
63 /* do not allow duplicate name/value pairs */
64 UNIQUE (parent_tree_key, attr_name, attr_value, object_type)
65 );
66
67 CREATE TABLE ldb_attributes
68 (
69 attr_name TEXT PRIMARY KEY,
70 parent_tree_key TEXT,
71
72 objectclass_p BOOLEAN DEFAULT 0,
73
74 case_insensitive_p BOOLEAN DEFAULT 0,
75 wildcard_p BOOLEAN DEFAULT 0,
76 hidden_p BOOLEAN DEFAULT 0,
77 integer_p BOOLEAN DEFAULT 0,
78
79 /* tree_key is auto-generated by the insert trigger */
80 tree_key TEXT, -- null if not a object/sub class
81 -- level 1 if an objectclass
82 -- level 1-n if a subclass
83 max_child_num INTEGER
84 );
85
86 -- ------------------------------------------------------
87
88 CREATE INDEX ldb_object_dn_idx
89 ON ldb_object (dn);
90
91 CREATE INDEX ldb_attributes_tree_key_ids
92 ON ldb_attributes (tree_key);
93
94 -- ------------------------------------------------------
95
96 /* Gifts for metze. Automatically updated meta-data */
97 CREATE TRIGGER ldb_object_insert_tr
98 AFTER INSERT
99 ON ldb_object
100 FOR EACH ROW
101 BEGIN
102 UPDATE ldb_object
103 SET max_child_num = max_child_num + 1
104 WHERE tree_key = new.parent_tree_key;
105 UPDATE usn SET value = value + 1;
106 UPDATE ldb_object
107 SET tree_key =
108 (SELECT
109 new.tree_key ||
110 base160(SELECT max_child_num
111 FROM ldb_object
112 WHERE tree_key =
113 new.parent_tree_key));
114 max_child_num = 0,
115 object_guid = random_guid(),
116 timestamp = strftime('%s', 'now'),
117 usn = (SELECT value FROM usn);
118 WHERE tree_key = new.tree_key;
119 END;
120
121 CREATE TRIGGER ldb_object_update_tr
122 AFTER UPDATE
123 ON ldb_object
124 FOR EACH ROW
125 BEGIN
126 UPDATE usn SET value = value + 1;
127 UPDATE ldb_object
128 SET timestamp = strftime('%s', 'now'),
129 usn = (SELECT value FROM usn);
130 WHERE tree_key = new.tree_key;
131 END;
132
133 CREATE TRIGGER ldb_attributes_insert_tr
134 AFTER INSERT
135 ON ldb_attributes
136 FOR EACH ROW
137 BEGIN
138 UPDATE ldb_attributes
139 SET max_child_num = max_child_num + 1
140 WHERE tree_key = new.parent_tree_key;
141 UPDATE ldb_attributes
142 SET tree_key =
143 (SELECT
144 new.tree_key ||
145 base160(SELECT max_child_num
146 FROM ldb_attributes
147 WHERE tree_key =
148 new.parent_tree_key));
149 max_child_num = 0
150 WHERE tree_key = new.tree_key;
151 END;
152
153
154 -- ------------------------------------------------------
155
156 /* Initialize usn */
157 INSERT INTO usn (value) VALUES (0);
158
159 /* Create root object */
160 INSERT INTO ldb_object
161 (tree_key, parent_tree_key,
162 dn,
163 object_type, max_child_num)
164 VALUES ('', NULL,
165 '',
166 1, 0);
167
168 /* We need an implicit "top" level object class */
169 INSERT INTO ldb_attributes (attr_name,
170 parent_tree_key)
171 SELECT 'top', '';
172
173 -- ------------------------------------------------------
174
175 COMMIT;
176
177 -- ------------------------------------------------------
178
179/*
180 * dn: o=University of Michigan,c=US
181 * objectclass: organization
182 * objectclass: domainRelatedObject
183 */
184-- newDN
185BEGIN;
186
187INSERT OR IGNORE INTO ldb_object
188 (parent_tree_key
189 dn,
190 attr_name, attr_value, object_type, max_child_num)
191 VALUES ('',
192 'c=US',
193 'c', 'US', 1, 0);
194
195INSERT INTO ldb_object
196 (parent_tree_key,
197 dn,
198 attr_name, attr_value, object_type, max_child_num)
199 VALUES ('0001',
200 'o=University of Michigan,c=US',
201 'o', 'University of Michigan', 1, 0);
202
203-- newObjectClass
204INSERT OR IGNORE INTO ldb_attributes
205 (attr_name, parent_tree_key, objectclass_p)
206 VALUES
207 ('objectclass', '', 1);
208
209INSERT INTO ldb_object
210 (parent_tree_key,
211 dn,
212 attr_name, attr_value, object_type, max_child_num)
213 VALUES ('00010001',
214 NULL,
215 'objectclass', 'organization', 2, 0);
216
217INSERT OR IGNORE INTO ldb_attributes
218 (attr_name, parent_tree_key, objectclass_p)
219 VALUES
220 ('objectclass', '', 1);
221
222INSERT INTO ldb_object
223 (parent_tree_key,
224 dn,
225 attr_name, attr_value, object_type, max_child_num)
226 VALUES ('00010001',
227 NULL,
228 'objectclass', 'domainRelatedObject', 2, 0);
229
230COMMIT;
231
232
233/*
234 * dn: o=University of Michigan,c=US
235 * l: Ann Arbor, Michigan
236 * st: Michigan
237 * o: University of Michigan
238 * o: UMICH
239 * seeAlso:
240 * telephonenumber: +1 313 764-1817
241 */
242-- addAttrValuePair
243BEGIN;
244
245INSERT INTO ldb_object
246 (parent_tree_key, dn,
247 attr_name, attr_value, object_type, max_child_num)
248 VALUES ('00010001', NULL,
249 'l', 'Ann Arbor, Michigan', 2, 0);
250
251INSERT INTO ldb_object
252 (parent_tree_key, dn,
253 attr_name, attr_value, object_type, max_child_num)
254 VALUES ('00010001', NULL,
255 'st', 'Michigan', 2, 0);
256
257INSERT INTO ldb_object
258 (parent_tree_key, dn,
259 attr_name, attr_value, object_type, max_child_num)
260 VALUES ('00010001', NULL,
261 'o', 'University of Michigan', 2, 0);
262
263INSERT INTO ldb_object
264 (parent_tree_key, dn,
265 attr_name, attr_value, object_type, max_child_num)
266 VALUES ('00010001', NULL,
267 'o', 'UMICH', 2, 0);
268
269INSERT INTO ldb_object
270 (parent_tree_key, dn,
271 attr_name, attr_value, object_type, max_child_num)
272 VALUES ('00010001', NULL,
273 'seeAlso', '', 2, 0);
274
275INSERT INTO ldb_object
276 (parent_tree_key, dn,
277 attr_name, attr_value, object_type, max_child_num)
278 VALUES ('00010001', NULL,
279 'telephonenumber', '+1 313 764-1817', 2, 0);
280
281COMMIT;
282
283-- ----------------------------------------------------------------------
284
285/*
286 * dn: @ATTRIBUTES
287 * uid: CASE_INSENSITIVE WILDCARD
288 * cn: CASE_INSENSITIVE
289 * ou: CASE_INSENSITIVE
290 * dn: CASE_INSENSITIVE
291 */
292-- newAttribute
293
294BEGIN;
295
296INSERT OR IGNORE INTO ldb_attributes
297 (attr_name, parent_tree_key, objectclass_p)
298 VALUES
299 ('uid', '', 0);
300
301UPDATE ldb_attributes
302 SET case_insensitive_p = 1,
303 wildcard_p = 1,
304 hidden_p = 0,
305 integer_p = 0
306 WHERE attr_name = 'uid'
307
308UPDATE ldb_attributes
309 SET case_insensitive_p = 1,
310 wildcard_p = 0,
311 hidden_p = 0,
312 integer_p = 0
313 WHERE attr_name = 'cn'
314
315UPDATE ldb_attributes
316 SET case_insensitive_p = 1,
317 wildcard_p = 0,
318 hidden_p = 0,
319 integer_p = 0
320 WHERE attr_name = 'ou'
321
322UPDATE ldb_attributes
323 SET case_insensitive_p = 1,
324 wildcard_p = 0,
325 hidden_p = 0,
326 integer_p = 0
327 WHERE attr_name = 'dn'
328
329-- ----------------------------------------------------------------------
330
331/*
332 * dn: @SUBCLASSES
333 * top: domain
334 * top: person
335 * domain: domainDNS
336 * person: organizationalPerson
337 * person: fooPerson
338 * organizationalPerson: user
339 * organizationalPerson: OpenLDAPperson
340 * user: computer
341 */
342-- insertSubclass
343
344/* NOT YET UPDATED!!! *
345
346
347INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
348 SELECT 'domain', /* next_tree_key('top') */ '00010001';
349INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
350 SELECT 'person', /* next_tree_key('top') */ '00010002';
351INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
352 SELECT 'domainDNS', /* next_tree_key('domain') */ '000100010001';
353INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
354 SELECT 'organizationalPerson', /* next_tree_key('person') */ '000100020001';
355INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
356 SELECT 'fooPerson', /* next_tree_key('person') */ '000100020002';
357INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
358 SELECT 'user', /* next_tree_key('organizationalPerson') */ '0001000200010001';
359INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
360 SELECT 'OpenLDAPperson', /* next_tree_key('organizationPerson') */ '0001000200010002';
361INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
362 SELECT 'computer', /* next_tree_key('user') */ '0001000200010001';
363
Note: See TracBrowser for help on using the repository browser.