.
[sfinx.git] / scripts / db.sql
blobe6a308367915ca8afdcee4df1217aeb8d92f16f4
2  /*
3   *   Copyright (C) 2007, Rus V. Brushkoff, All rights reserved.
4   */
6 set sql dialect 3;
7 set names koi8r;
8 create database '/usr/local/sfinx/sfinx.fdb' user 'sysdba' password 'harbour' page_size 16384 default character set koi8r;
10 create table objects (
11   id INTEGER not null,
12   name VARCHAR(64) not null,
13   description VARCHAR(256) not null,
14   /* TODO: ÉÍÑ ÔÁÂÌÉÃÙ Ó ÏÐÉÓÁÎÉÅÍ ÐÏÌÅÊ É Ô.Ä. */
15   constraint pkobjects PRIMARY KEY (id),
16   UNIQUE (name)    
19 insert into objects (id, name, description) values (1, 'slice', 'User defined abstraction');
20 insert into objects (id, name, description) values (2, 'file', 'Any file, containing some data');
21 insert into objects (id, name, description) values (3, 'note', 'Note about smth.');
22 insert into objects (id, name, description) values (4, 'event', 'Event');
23 insert into objects (id, name, description) values (5, 'contact', 'Contact');
24 insert into objects (id, name, description) values (6, 'task', 'Task or plan');
25 insert into objects (id, name, description) values (7, 'message', 'Mail or IM');
26 insert into objects (id, name, description) values (8, 'knowledge', 'Knowledge / kh [ know how ]');
28 /*  TODO: rule / intention / aim / dream */
30 create sequence slice_id;
31 set generator slice_id to 0;
33 /* slices - ÔÁÂÌÉÃÁ ËÁÔÅÇÏÒÉÊ/ÓÒÅÚÏ×/ÁÂÓÔÒÁËÃÉÊ. Slice ÏÔÌÉÞÁÅÔÓÑ ÏÔ ÏÓÔÁÌØÎÙÈ
34   ÏÂØÅËÔÏ× ÏÔÓÔÕÔÓÔ×ÉÅÍ ÇÌÁ×ÎÏÊ Ó×ÑÚÉ, Ô.Å. Ñ×ÌÑÅÔÓÑ ÉÚÎÁÞÁÌØÎÙÍ [ Dao ] É
35   ÍÏÖÅÔ ÓÕÝÅÓÔ×Ï×ÁÔØ ÓÁÍ ÐÏ-ÓÅÂÅ. óÌÁÊÓÙ ÉÍÅÀÔ ÄÒÅ×Ï×ÉÄÎÕÀ ÓÔÒÕËÔÕÒÕ, ÐÏËÁ ÂÅÚ
36   ÍÎÏÖÅÓÔ×ÅÎÎÏÇÏ ÎÁÓÌÅÄÏ×ÁÎÉÑ
38  */
40 create table slices (
41   id BIGINT not null,
42   parent_id BIGINT not null,
43   name VARCHAR(64) not null,
44   description VARCHAR(256) not null,
45   /* ÄÉÒÅËÔÏÒÉÑ ÄÌÑ ÏÔÓÏÒÔÉÒÏ×ÁÎÎÙÈ ÆÁÊÌÏ× */
46   directory VARCHAR(256),
47   /* ÄÁÔÁ ÓÏÚÄÁÎÉÑ */
48   ctime timestamp default 'now',
49   /* ÄÁÔÁ ÉÚÍÅÎÅÎÉÑ */
50   etime timestamp default 'now',
51   constraint pkslices PRIMARY KEY (id),
52   UNIQUE (parent_id, name)
55 create index slices_etime on slices(etime);
56 create index slices_ctime on slices(ctime);
58 set term ^ ;
60 /* ÕÎÉ×ÅÒÓÁÌØÎÙÊ ÔÒÉÇÇÅÒ: firebird >= 2.x ËÁÖÉÓØ */
62 create trigger slice_trg for slices
63 active before insert or update position 0
65 begin
66   if (new.id is null) then
67     new.id = gen_id(slice_id, 1);
68   select cast('now' as timestamp) from rdb$database into new.etime;
69 end
72 set term ^ ;
74 insert into slices (parent_id, name, description) values (0, 'Root', 'Dao Slice');
75 insert into slices (parent_id, name, description, directory) values (1, 'Texts', 'ôÅËÓÔÙ, äÏËÉ', 'Texts');
76 insert into slices (parent_id, name, description, directory) values (1, 'Images', 'ëÁÒÔÉÎËÉ', 'Images');
77 insert into slices (parent_id, name, description, directory) values (1, 'Music', 'íÕÚÙËÁ, MP3', 'Music');
79 /* module_conf - ÎÁÓÔÒÏÊËÉ ÍÏÄÕÌÅÊ */
81 create table files_module_conf (
82   unsorted_files_path VARCHAR(256),
83   sorted_file_tree VARCHAR(256),
84   desc_file_name VARCHAR(256),
85   desc_file_enable SMALLINT,
86   detect_mime_type SMALLINT
89 insert into files_module_conf (unsorted_files_path, sorted_file_tree, desc_file_name, desc_file_enable) values ('/Arhiv/unsorted', '/Arhiv/sorted', 'description.txt', 1);
91 create sequence file_id;
92 set generator file_id to 0;
94 create table files (
96   id BIGINT not null,
97   /* file name */
98   name VARCHAR(256) not null,
99   title VARCHAR(1024),
100   /* Á×ÔÏÒ/ÉÚÄÁÔÅÌØÓÔ×Ï */
101   authority VARCHAR(512),
102   description VARCHAR(1024),
103   comments VARCHAR(1024),
105   /* TODO : */
106   /* is_directory SMALLINT default 0, */
107   /* ÅÓÌÉ ÆÁÊÌ ÌÅÖÉÔ × ËÁËÏÊ-ÎÉÔØ ÄÉÒÅËÔÏÒÉÉ */
108   /* parent_file_id INTEGER default 0, */
110   /* ÄÁÔÁ ÚÁÎÅÓÅÎÉÑ ÆÁÊÌÁ × ÂÁÚÕ */
111   ctime timestamp default 'now',
112   /* ÄÁÔÁ ÉÚÍÅÎÅÎÉÑ ÉÎÆÙ Ï ÆÁÊÌÅ × ÂÁÚÅ */
113   etime timestamp default 'now',
115   /* ÔÉРÇÌÁ×ÎÏÇÏ ÏÂØÅËÔÁ (main object) Ó ËÏÔÏÒÙÍ ÁÓÓÏÃÉÉÒÏ×ÁΠÆÁÊÌ */
116   mtag_type INTEGER not null,
117   /* ÅÇÏ id */
118   mtag_id BIGINT not null,
119   /* ÌÀÂÁÑ ÉÅÒÁÒÈÉÑ ÏÂØÅËÔÏ× ÉÍÅÅÔ Ó×ÏÊ ÇÌÁ×ÎÙÊ ÓÌÁÊÓ-ÒÏÄÉÔÅÌØ
120      ÉÓÐÏÌØÚÕÅÔÓÑ ÄÌÑ ÂÙÓÔÒÏÊ ×ÙÂÏÒËÉ ×ÎÕÔÒÉ ÓÌÁÊÓÁ
121    */
122   mtag_slice_id BIGINT not null,
124   fsize BIGINT default 0,
125   sha256 VARCHAR(64),
126   fsize_compressed BIGINT default 0,
127   sha256_compressed VARCHAR(64),
129   /* ×ÒÅÍÑ ÐÏÓÌÅÄÎÅÊ ÐÒÏ×ÅÒËÉ ËÏÎÔÒ. ÓÕÍÍÙ */
130   csum_last_checked timestamp default '01.01.1900 00:00:00',
131   csum_valid SMALLINT default 0,
133   /* ÔÉРÐÒÏ×ÅÒËÉ ÆÁÊÌÁ :
134     0 ÂÉÔ - ÒÁÚÍÅÒ
135     1 ÂÉÔ - csum
136   */
137   /* check_type SMALLINT default 0, */
139   store_in_sorted_location SMALLINT default 0,
141   /* mimetype INTEGER default 0, */
143   /* mime ÔÉРÄÌÑ ÈÒÁÎÅÎÉÑ × ÕÐÁËÏ×ÁÎÎÏÍ ×ÉÄÅ */
144   /* compress_mimetype INTEGER default 0, */
145   /* full_index SMALLINT default 0, */
146   /* added_by_uid INTEGER not null */
148   constraint pkfiles PRIMARY KEY (id),
149   UNIQUE (mtag_id, mtag_type, name)
152 create index files_etime on files(etime);
153 create index files_ctime on files(ctime);
154 create index files_name on files(name);
155 create index files_title on files(title);
156 create index files_auth on files(authority);
157 create index files_desc on files(description);
158 create index files_comm on files(comments);
160 set term ^ ;
162 create trigger file_trg for files
163 active before insert or update position 0
165 begin
166   if (new.id is null) then
167     new.id = gen_id(file_id, 1);
168   select cast('now' as timestamp) from rdb$database into new.etime;
172 set term ^ ;
174 /* ÄÏÐ-ÔÁÂÌÉÃÁ Ó×ÑÚÉ ÆÁÊÌÏ× É ÏÂØÅËÔÏ× */
176 create table file_tags (
177   file_id BIGINT,
178   obj_id BIGINT,
179   obj_type INTEGER,
180   constraint pkfile_slices PRIMARY KEY (file_id, obj_id, obj_type)
183 create sequence note_id;
184 set generator note_id to 0;
186 create table notes (
188   id BIGINT not null,
189   name VARCHAR(256) not null,
190   url VARCHAR(256),
191   text VARCHAR(4096),
193   /* ÄÁÔÁ ÚÁÎÅÓÅÎÉÑ × ÂÁÚÕ */
194   ctime timestamp default 'now',
195   /* ÄÁÔÁ ÉÚÍÅÎÅÎÉÑ ÉÎÆÙ × ÂÁÚÅ */
196   etime timestamp default 'now',
198   mtag_type INTEGER not null,
199   mtag_id BIGINT not null,
200   mtag_slice_id BIGINT not null,
202   /* text field is crypted */
203   secured SMALLINT default 0,
205   constraint pknotes PRIMARY KEY (id),
206   UNIQUE (mtag_slice_id, mtag_type, mtag_id, name),
207   UNIQUE (url)
210 create index notes_etime on notes(etime);
211 create index notes_ctime on notes(ctime);
212 create index notes_name on notes(name);
213 create index notes_url on notes(url);
215 /* ÅÓÌÉ Ë ÐÒÉÍÅÒÕ text crypted - ÉÎÄÅËÓ ÎÅ ÎÕÖÅÎ: ÉÎÔÅÒÅÓÎÏ ÅÓÔØ ÌÉ ÔÁËÁÑ
216    ÆÉÇÎÑ ËÁË ÕÓÌÏ×ÎÙÊ ÉÎÄÅËÓ - ÉÎÄÅËÓÉÒÏ×ÁÔØ ÔÏÌØËÏ ÞÁÓÔØ ÔÁÂÌÉÃÙ ÐÏ ÕÓÌÏ×ÉÀ
217    ËÁËÉÈ-ÌÉÂÏ ÐÏÌÅÊ × ÔÅËÕÝÅÍ row ? */
218 /* create index notes_text on notes(text); */
220 set term ^ ;
222 create trigger note_trg for notes
223 active before insert or update position 0
225 begin
226   if (new.id is null) then
227     new.id = gen_id(note_id, 1);
228   select cast('now' as timestamp) from rdb$database into new.etime;
232 set term ^ ;
234 insert into notes (id, name, url, text, mtag_id, mtag_type, mtag_slice_id) values (1, 'sample note', 'some name', 'some url', 3, 1, 3);
236 /* ÄÏÐ-ÔÁÂÌÉÃÁ note-Ó×ÑÚÅÊ */
238 create table note_tags (
239   note_id BIGINT,
240   obj_id BIGINT,
241   obj_type INTEGER,
242   constraint pknote_slices PRIMARY KEY (note_id, obj_id, obj_type)
245 commit;
247 /*  TODO:
249  - ÔÁÂÌÉÃÁ ÀÚÅÒÏ×
250  - ÔÁÂÌÉÃÁ ÒÅÊÔÉÎÇÏ× ÄÌÑ ÏÂØÅËÔÏ× (files/notes/events/contacts/etc.)
251  - ÔÁÂÌÉÃÁ ÓÔÁÔÉÓÔÉËÉ ÄÌÑ ÄÅÍÏÎÁ (ËÏÌ. ËÏÎÎÅËÔÏ×/ÏÂØÅÍÙ ÉÎÆÙ/etc.)