Get rid off sfinx_compress.sh
[sfinx.git] / scripts / db.sql
blobf6c149c857395bcf7c47abdabd3d7ce22af211ec
2  /*
3   *   Copyright (C) 2007, Rus V. Brushkoff, All rights reserved.
4   */
6 create table info (
7   schema_version INTEGER not null
8 );
10 insert into info (schema_version) values (0);
12 create table objects (
13   id INTEGER not null,
14   name VARCHAR(64) not null,
15   description VARCHAR(256) not null,
16   /* TODO: ÉÍÑ ÔÁÂÌÉÃÙ Ó ÏÐÉÓÁÎÉÅÍ ÐÏÌÅÊ É Ô.Ä. */
17   constraint pkobjects PRIMARY KEY (id),
18   UNIQUE (name)    
21 insert into objects (id, name, description) values (1, 'slice', 'User defined abstraction');
22 insert into objects (id, name, description) values (2, 'file', 'Any file, containing some data');
23 insert into objects (id, name, description) values (3, 'note', 'Note about smth.');
24 insert into objects (id, name, description) values (4, 'event', 'Event');
25 insert into objects (id, name, description) values (5, 'contact', 'Contact');
26 insert into objects (id, name, description) values (6, 'task', 'Task or plan');
27 insert into objects (id, name, description) values (7, 'message', 'Mail or IM');
28 insert into objects (id, name, description) values (8, 'knowledge', 'Knowledge / kh [ know how ]');
30 /*  TODO: rule / intention / aim / dream */
32 create sequence slice_id;
33 set generator slice_id to 0;
35 /* slices - ÔÁÂÌÉÃÁ ËÁÔÅÇÏÒÉÊ/ÓÒÅÚÏ×/ÁÂÓÔÒÁËÃÉÊ. Slice ÏÔÌÉÞÁÅÔÓÑ ÏÔ ÏÓÔÁÌØÎÙÈ
36   ÏÂØÅËÔÏ× ÏÔÓÔÕÔÓÔ×ÉÅÍ ÇÌÁ×ÎÏÊ Ó×ÑÚÉ, Ô.Å. Ñ×ÌÑÅÔÓÑ ÉÚÎÁÞÁÌØÎÙÍ [ Dao ] É
37   ÍÏÖÅÔ ÓÕÝÅÓÔ×Ï×ÁÔØ ÓÁÍ ÐÏ-ÓÅÂÅ. óÌÁÊÓÙ ÉÍÅÀÔ ÄÒÅ×Ï×ÉÄÎÕÀ ÓÔÒÕËÔÕÒÕ, ÐÏËÁ ÂÅÚ
38   ÍÎÏÖÅÓÔ×ÅÎÎÏÇÏ ÎÁÓÌÅÄÏ×ÁÎÉÑ
40  */
42 /* TODO: add cascade delete to all trees */
44 create table slices (
45   id BIGINT not null,
46   parent_id BIGINT not null,
47   name VARCHAR(64) not null,
48   description VARCHAR(256) not null,
49   /* ÄÉÒÅËÔÏÒÉÑ ÄÌÑ ÏÔÓÏÒÔÉÒÏ×ÁÎÎÙÈ ÆÁÊÌÏ× */
50   directory VARCHAR(256),
51   /* ÄÁÔÁ ÓÏÚÄÁÎÉÑ */
52   ctime timestamp default 'now',
53   /* ÄÁÔÁ ÉÚÍÅÎÅÎÉÑ */
54   etime timestamp default 'now',
55   constraint pkslices PRIMARY KEY (id),
56   UNIQUE (parent_id, name)
59 create index slices_etime on slices(etime);
60 create index slices_ctime on slices(ctime);
62 set term ^ ;
64 /* ÕÎÉ×ÅÒÓÁÌØÎÙÊ ÔÒÉÇÇÅÒ: firebird >= 2.x ËÁÖÉÓØ */
66 create trigger slice_trg for slices
67 active before insert or update position 0
69 begin
70   if (new.id is null) then
71     new.id = gen_id(slice_id, 1);
72   select cast('now' as timestamp) from rdb$database into new.etime;
73 end
76 set term ^ ;
78 insert into slices (parent_id, name, description) values (0, 'Root', 'Dao Slice');
79 insert into slices (parent_id, name, description, directory) values (1, 'Texts', 'ôÅËÓÔÙ, äÏËÉ', 'Texts');
80 insert into slices (parent_id, name, description, directory) values (1, 'Images', 'ëÁÒÔÉÎËÉ', 'Images');
81 insert into slices (parent_id, name, description, directory) values (1, 'Music', 'íÕÚÙËÁ, MP3', 'Music');
83 /* module_conf - ÎÁÓÔÒÏÊËÉ ÍÏÄÕÌÅÊ */
85 create table files_module_conf (
86   unsorted_files_path VARCHAR(256),
87   sorted_file_tree VARCHAR(256),
88   desc_file_name VARCHAR(256),
89   desc_file_enable SMALLINT,
90   detect_mime_type SMALLINT
93 insert into files_module_conf (unsorted_files_path, sorted_file_tree, desc_file_name, desc_file_enable) values ('/Arhiv/Unsorted', '/Arhiv/Sfinx', 'description.txt', 1);
95 create sequence file_id;
96 set generator file_id to 0;
98 create table files (
100   id BIGINT not null,
101   /* file name */
102   name VARCHAR(256) not null,
103   title VARCHAR(1024),
104   /* Á×ÔÏÒ/ÉÚÄÁÔÅÌØÓÔ×Ï */
105   authority VARCHAR(512),
106   description VARCHAR(1024),
107   comments VARCHAR(1024),
109   /* TODO : */
110   /* is_directory SMALLINT default 0, */
111   /* ÅÓÌÉ ÆÁÊÌ ÌÅÖÉÔ × ËÁËÏÊ-ÎÉÔØ ÄÉÒÅËÔÏÒÉÉ */
112   /* parent_file_id INTEGER default 0, */
114   /* ÄÁÔÁ ÚÁÎÅÓÅÎÉÑ ÆÁÊÌÁ × ÂÁÚÕ */
115   ctime timestamp default 'now',
116   /* ÄÁÔÁ ÉÚÍÅÎÅÎÉÑ ÉÎÆÙ Ï ÆÁÊÌÅ × ÂÁÚÅ */
117   etime timestamp default 'now',
119   /* ÔÉРÇÌÁ×ÎÏÇÏ ÏÂØÅËÔÁ (main object) Ó ËÏÔÏÒÙÍ ÁÓÓÏÃÉÉÒÏ×ÁΠÆÁÊÌ */
120   mtag_type INTEGER not null,
121   /* ÅÇÏ id */
122   mtag_id BIGINT not null,
123   /* ÌÀÂÁÑ ÉÅÒÁÒÈÉÑ ÏÂØÅËÔÏ× ÉÍÅÅÔ Ó×ÏÊ ÇÌÁ×ÎÙÊ ÓÌÁÊÓ-ÒÏÄÉÔÅÌØ
124      ÉÓÐÏÌØÚÕÅÔÓÑ ÄÌÑ ÂÙÓÔÒÏÊ ×ÙÂÏÒËÉ ×ÎÕÔÒÉ ÓÌÁÊÓÁ
125      ÔÅÏÒÅÔÉÞÅÓËÉ - ÎÅ ÎÕÖÅΠ- ÍÏÖÎÏ ×ÙÞÉÓÌÑÔØ ÎÁ ÈÏÄÕ, ÐÏËÁ ÌÏÍÁÅÔ
126    */
127   mtag_slice_id BIGINT not null,
129   fsize BIGINT default 0,
130   sha256 VARCHAR(64),
131   fsize_compressed BIGINT default 0,
132   sha256_compressed VARCHAR(64),
134   /* ×ÒÅÍÑ ÐÏÓÌÅÄÎÅÊ ÐÒÏ×ÅÒËÉ ËÏÎÔÒ. ÓÕÍÍÙ */
135   csum_last_checked timestamp default '01.01.1900 00:00:00',
136   csum_valid SMALLINT default 0,
138   /* ÔÉРÐÒÏ×ÅÒËÉ ÆÁÊÌÁ :
139     0 ÂÉÔ - ÒÁÚÍÅÒ
140     1 ÂÉÔ - csum
141   */
142   /* check_type SMALLINT default 0, */
144   store_in_sorted_location SMALLINT default 0,
146   /* mimetype INTEGER default 0, */
148   /* mime ÔÉРÄÌÑ ÈÒÁÎÅÎÉÑ × ÕÐÁËÏ×ÁÎÎÏÍ ×ÉÄÅ */
149   /* compress_mimetype INTEGER default 0, */
150   /* full_index SMALLINT default 0, */
151   /* added_by_uid INTEGER not null */
153   constraint pkfiles PRIMARY KEY (id),
154   UNIQUE (mtag_id, mtag_type, name)
157 create index files_etime on files(etime);
158 create index files_ctime on files(ctime);
159 create index files_name on files(name);
160 create index files_title on files(title);
161 create index files_auth on files(authority);
162 create index files_desc on files(description);
163 create index files_comm on files(comments);
165 set term ^ ;
167 create trigger file_trg for files
168 active before insert or update position 0
170 begin
171   if (new.id is null) then
172     new.id = gen_id(file_id, 1);
173   select cast('now' as timestamp) from rdb$database into new.etime;
177 set term ^ ;
179 /* ÄÏÐ-ÔÁÂÌÉÃÁ Ó×ÑÚÉ ÆÁÊÌÏ× É ÏÂØÅËÔÏ× */
181 create table file_tags (
182   file_id BIGINT,
183   obj_id BIGINT,
184   obj_type INTEGER,
185   constraint pkfile_slices PRIMARY KEY (file_id, obj_id, obj_type)
188 create sequence note_id;
189 set generator note_id to 0;
191 create table notes (
193   id BIGINT not null,
194   name VARCHAR(256) not null,
195   url VARCHAR(256),
196   text VARCHAR(4096),
198   /* ÄÁÔÁ ÚÁÎÅÓÅÎÉÑ × ÂÁÚÕ */
199   ctime timestamp default 'now',
200   /* ÄÁÔÁ ÉÚÍÅÎÅÎÉÑ ÉÎÆÙ × ÂÁÚÅ */
201   etime timestamp default 'now',
203   mtag_type INTEGER not null,
204   mtag_id BIGINT not null,
205   mtag_slice_id BIGINT not null,
207   /* text field is crypted */
208   secured SMALLINT default 0,
210   constraint pknotes PRIMARY KEY (id),
211   UNIQUE (mtag_slice_id, mtag_type, mtag_id, name)
214 create index notes_etime on notes(etime);
215 create index notes_ctime on notes(ctime);
216 create index notes_name on notes(name);
217 create index notes_url on notes(url);
219 /* ÅÓÌÉ Ë ÐÒÉÍÅÒÕ text crypted - ÉÎÄÅËÓ ÎÅ ÎÕÖÅÎ: ÉÎÔÅÒÅÓÎÏ ÅÓÔØ ÌÉ ÔÁËÁÑ
220    ÆÉÇÎÑ ËÁË ÕÓÌÏ×ÎÙÊ ÉÎÄÅËÓ - ÉÎÄÅËÓÉÒÏ×ÁÔØ ÔÏÌØËÏ ÞÁÓÔØ ÔÁÂÌÉÃÙ ÐÏ ÕÓÌÏ×ÉÀ
221    ËÁËÉÈ-ÌÉÂÏ ÐÏÌÅÊ × ÔÅËÕÝÅÍ row ? */
222 /* create index notes_text on notes(text); */
224 set term ^ ;
226 create trigger note_trg for notes
227 active before insert or update position 0
229 begin
230   if (new.id is null) then
231     new.id = gen_id(note_id, 1);
232   select cast('now' as timestamp) from rdb$database into new.etime;
236 set term ^ ;
238 insert into notes (name, url, text, mtag_id, mtag_type, mtag_slice_id) values ('sample note', 'some name', 'some url', 3, 1, 3);
240 /* ÄÏÐ-ÔÁÂÌÉÃÁ note-Ó×ÑÚÅÊ */
242 create table note_tags (
243   note_id BIGINT,
244   obj_id BIGINT,
245   obj_type INTEGER,
246   constraint pknote_slices PRIMARY KEY (note_id, obj_id, obj_type)
249 commit;
251 /*  TODO:
253  - ÔÁÂÌÉÃÁ ÀÚÅÒÏ×
254  - ÔÁÂÌÉÃÁ ÒÅÊÔÉÎÇÏ× ÄÌÑ ÏÂØÅËÔÏ× (files/notes/events/contacts/etc.)
255  - ÔÁÂÌÉÃÁ ÓÔÁÔÉÓÔÉËÉ ÄÌÑ ÄÅÍÏÎÁ (ËÏÌ. ËÏÎÎÅËÔÏ×/ÏÂØÅÍÙ ÉÎÆÙ/etc.)