symbol-db: Add update_flag to the symbol unique constraint.
[anjuta.git] / plugins / symbol-db / tables.sql
blobe0db171158803bb09d095ee88180ff83a93a79f3
2 -- FIXME: FOREIGN keys are now supported. schema should enforces them.
3 -- Right now the support here is disabled.
5 DROP TABLE IF EXISTS workspace;
6 CREATE TABLE workspace (workspace_id integer PRIMARY KEY AUTOINCREMENT,
7                         workspace_name text not null unique,
8                         analyse_time date
9                         );
11 DROP TABLE IF EXISTS project;
12 CREATE TABLE project (project_id integer PRIMARY KEY AUTOINCREMENT,
13                       project_name text not null,
14                       project_version text not null default '1.0',
15                       wrkspace_id integer REFERENCES workspace (workspace_id),
16                       analyse_time date,
17                       unique (project_name, project_version)
18                       );
20 DROP TABLE IF EXISTS file;
21 CREATE TABLE file (file_id integer PRIMARY KEY AUTOINCREMENT,
22                    file_path text not null unique,
23                    prj_id integer REFERENCES project (projec_id),
24                    lang_id integer REFERENCES language (language_id),
25                    analyse_time date
26                    );
28 DROP TABLE IF EXISTS language;
29 CREATE TABLE language (language_id integer PRIMARY KEY AUTOINCREMENT,
30                        language_name text not null unique);
32 DROP TABLE IF EXISTS symbol;
33 CREATE TABLE symbol (symbol_id integer PRIMARY KEY AUTOINCREMENT,
34                      file_defined_id integer not null REFERENCES file (file_id),
35                      name text not null,
36                      file_position integer,
37                      is_file_scope integer,
38                      signature text,
39                      returntype text,
40                      scope_definition_id integer,
41                      scope_id integer,
42                      type_type text not null,
43                                          type_name text not null,
44                      kind_id integer REFERENCES sym_kind (sym_kind_id),
45                      access_kind_id integer REFERENCES sym_access (sym_access_id),
46                      implementation_kind_id integer REFERENCES sym_implementation (sym_impl_id),
47                      update_flag integer default 0,
48                      unique (name, file_defined_id, file_position, update_flag)
49                      );
51 DROP TABLE IF EXISTS sym_kind;
52 CREATE TABLE sym_kind (sym_kind_id integer PRIMARY KEY AUTOINCREMENT,
53                        kind_name text not null unique,
54                        is_container integer default 0
55                        );
57 DROP TABLE IF EXISTS sym_access;
58 CREATE TABLE sym_access (access_kind_id integer PRIMARY KEY AUTOINCREMENT,
59                          access_name text not null unique
60                          );
62 DROP TABLE IF EXISTS sym_implementation;
63 CREATE TABLE sym_implementation (sym_impl_id integer PRIMARY KEY AUTOINCREMENT,
64                                  implementation_name text not null unique
65                                  );
67 DROP TABLE IF EXISTS heritage;
68 CREATE TABLE heritage (symbol_id_base integer REFERENCES symbol (symbol_id),
69                        symbol_id_derived integer REFERENCES symbol (symbol_id),
70                        PRIMARY KEY (symbol_id_base, symbol_id_derived)
71                        );
73 DROP TABLE IF EXISTS scope;
74 CREATE TABLE scope (scope_id integer PRIMARY KEY AUTOINCREMENT,
75                     scope_name text not null,
76                     unique (scope_name)
77                     );
79 DROP TABLE IF EXISTS version;
80 CREATE TABLE version (sdb_version numeric PRIMARY KEY);
83 DROP TABLE IF EXISTS __tmp_removed;
84 CREATE TABLE __tmp_removed (tmp_removed_id integer PRIMARY KEY AUTOINCREMENT,
85                             symbol_removed_id integer not null
86                             );
89 DROP INDEX IF EXISTS symbol_idx_1;
90 CREATE INDEX symbol_idx_1 ON symbol (name, file_defined_id, type_type, type_name);
92 -- removing this index isn't worth because the performance gain is invisible.
93 DROP INDEX IF EXISTS symbol_idx_2;
94 CREATE INDEX symbol_idx_2 ON symbol (scope_id);
96 -- removing this index isn't worth because the performance gain is invisible.
97 DROP INDEX IF EXISTS symbol_idx_3;
98 CREATE INDEX symbol_idx_3 ON symbol (type_type, type_name);
101 DROP TRIGGER IF EXISTS delete_file_trg;
102 CREATE TRIGGER delete_file_trg BEFORE DELETE ON file
103 FOR EACH ROW
104 BEGIN
105         DELETE FROM symbol WHERE file_defined_id = old.file_id;
106 END;
108 DROP TRIGGER IF EXISTS delete_symbol_trg;
109 CREATE TRIGGER delete_symbol_trg BEFORE DELETE ON symbol
110 FOR EACH ROW
111 BEGIN
112     DELETE FROM scope WHERE scope.scope_id=old.scope_definition_id;
113     UPDATE symbol SET scope_id='-1' WHERE symbol.scope_id=old.scope_definition_id AND symbol.scope_id > 0;
114     INSERT INTO __tmp_removed (symbol_removed_id) VALUES (old.symbol_id);
115 END;
117 PRAGMA page_size = 32768;
118 PRAGMA cache_size = 12288;
119 PRAGMA synchronous = OFF;
120 PRAGMA temp_store = MEMORY;
121 PRAGMA case_sensitive_like = 1;
122 PRAGMA journal_mode = OFF;
123 PRAGMA read_uncommitted = 1;
124 PRAGMA foreign_keys = OFF;
125 PRAGMA auto_vacuum = 0;