2a13348843ef20bea7456a9e12ecc2fda2889de9
[odoo/odoo.git] / openerp / addons / base / base.sql
1 -------------------------------------------------------------------------
2 -- Pure SQL
3 -------------------------------------------------------------------------
4
5 -------------------------------------------------------------------------
6 -- IR dictionary
7 -------------------------------------------------------------------------
8
9 create table ir_values
10 (
11     id serial,
12     name varchar(128) not null,
13     key varchar(128) not null,
14     key2 varchar(256) not null,
15     model varchar(128) not null,
16     value text,
17     meta text default NULL,
18     res_id integer default null,
19     primary key (id)
20 );
21
22 -------------------------------------------------------------------------
23 -- Modules Description
24 -------------------------------------------------------------------------
25
26 CREATE TABLE ir_model (
27   id serial,
28   model varchar(64) DEFAULT ''::varchar NOT NULL,
29   name varchar(64),
30   state varchar(16),
31   info text,
32   primary key(id)
33 );
34
35 CREATE TABLE ir_model_fields (
36   id serial,
37   model varchar(64) DEFAULT ''::varchar NOT NULL,
38   model_id int references ir_model on delete cascade,
39   name varchar(64) DEFAULT ''::varchar NOT NULL,
40   relation varchar(64),
41   select_level varchar(4),
42   field_description varchar(256),
43   ttype varchar(64),
44   state varchar(64) default 'base',
45   view_load boolean,
46   relate boolean default False,
47   relation_field varchar(128),
48   translate boolean default False,
49   primary key(id)
50 );
51
52 ALTER TABLE ir_model_fields ADD column serialization_field_id int references ir_model_fields on delete cascade;
53
54
55 -------------------------------------------------------------------------
56 -- Actions
57 -------------------------------------------------------------------------
58
59 CREATE TABLE ir_actions (
60     id serial NOT NULL,
61     name varchar(64) DEFAULT ''::varchar NOT NULL,
62     "type" varchar(32) DEFAULT 'window'::varchar NOT NULL,
63     usage varchar(32) DEFAULT null,
64     primary key(id)
65 );
66
67 CREATE TABLE ir_act_window (
68     view_id integer,
69     res_model varchar(64),
70     view_type varchar(16),
71     "domain" varchar(250),
72     primary key(id)
73 )
74 INHERITS (ir_actions);
75
76 CREATE TABLE ir_act_report_xml (
77     model varchar(64) NOT NULL,
78     report_name varchar(64) NOT NULL,
79     report_xsl varchar(256),
80     report_xml varchar(256),
81     auto boolean default true,
82     primary key(id)
83 )
84 INHERITS (ir_actions);
85
86 create table ir_act_report_custom (
87     report_id int,
88 --  report_id int references ir_report_custom
89     primary key(id)
90 )
91 INHERITS (ir_actions);
92
93 CREATE TABLE ir_act_wizard (
94     wiz_name varchar(64) NOT NULL,
95     primary key(id)
96 )
97 INHERITS (ir_actions);
98
99 CREATE TABLE ir_act_url (
100     url text NOT NULL,
101     target varchar(64) NOT NULL,
102     primary key(id)
103 )
104 INHERITS (ir_actions);
105
106 CREATE TABLE ir_act_server (
107     primary key(id)
108 )
109 INHERITS (ir_actions);
110
111 CREATE TABLE ir_act_client (
112     primary key(id)
113 )
114 INHERITS (ir_actions);
115
116
117 CREATE TABLE ir_ui_view (
118     id serial NOT NULL,
119     name varchar(64) DEFAULT ''::varchar NOT NULL,
120     model varchar(64) DEFAULT ''::varchar NOT NULL,
121     "type" varchar(64) DEFAULT 'form'::varchar NOT NULL,
122     arch text NOT NULL,
123     field_parent varchar(64),
124     priority integer DEFAULT 5 NOT NULL,
125     primary key(id)
126 );
127
128 CREATE TABLE ir_ui_menu (
129     id serial NOT NULL,
130     parent_id int references ir_ui_menu on delete set null,
131     name varchar(64) DEFAULT ''::varchar NOT NULL,
132     icon varchar(64) DEFAULT ''::varchar,
133     primary key (id)
134 );
135
136 select setval('ir_ui_menu_id_seq', 2);
137
138 ---------------------------------
139 -- Res users
140 ---------------------------------
141
142 -- level:
143 --   0  RESTRICT TO USER
144 --   1  RESTRICT TO GROUP
145 --   2  PUBLIC
146
147 CREATE TABLE res_users (
148     id serial NOT NULL,
149     name varchar(64) not null,
150     active boolean default True,
151     login varchar(64) NOT NULL UNIQUE,
152     password varchar(64) default null,
153     email varchar(64) default null,
154     context_tz varchar(64) default null,
155     signature text,
156     context_lang varchar(64) default '',
157     -- No FK references below, will be added later by ORM
158     -- (when the destination rows exist)
159     company_id int,
160     primary key(id)
161 );
162 alter table res_users add constraint res_users_login_uniq unique (login);
163
164 CREATE TABLE res_groups (
165     id serial NOT NULL,
166     name varchar(64) NOT NULL,
167     primary key(id)
168 );
169
170 CREATE TABLE res_groups_users_rel (
171     uid integer NOT NULL references res_users on delete cascade,
172     gid integer NOT NULL references res_groups on delete cascade,
173     UNIQUE("uid","gid")
174 );
175
176 create index res_groups_users_rel_uid_idx on res_groups_users_rel (uid);
177 create index res_groups_users_rel_gid_idx on res_groups_users_rel (gid);
178
179
180 ---------------------------------
181 -- Workflows
182 ---------------------------------
183
184 create table wkf
185 (
186     id serial,
187     name varchar(64),
188     osv varchar(64),
189     on_create bool default False,
190     primary key(id)
191 );
192
193 create table wkf_activity
194 (
195     id serial,
196     wkf_id int references wkf on delete cascade,
197     subflow_id int references wkf on delete set null,
198     split_mode varchar(3) default 'XOR',
199     join_mode varchar(3) default 'XOR',
200     kind varchar(16) not null default 'dummy',
201     name varchar(64),
202     signal_send varchar(32) default null,
203     flow_start boolean default False,
204     flow_stop boolean default False,
205     action text default null,
206     primary key(id)
207 );
208
209 create table wkf_transition
210 (
211     id serial,
212     act_from int references wkf_activity on delete cascade,
213     act_to int references wkf_activity on delete cascade,
214     condition varchar(128) default NULL,
215
216     trigger_type varchar(128) default NULL,
217     trigger_expr_id varchar(128) default NULL,
218
219     signal varchar(64) default null,
220     group_id int references res_groups on delete set null,
221
222     primary key(id)
223 );
224
225 create table wkf_instance
226 (
227     id serial,
228     wkf_id int references wkf on delete restrict,
229     uid int default null,
230     res_id int not null,
231     res_type varchar(64) not null,
232     state varchar(32) not null default 'active',
233     primary key(id)
234 );
235
236 create table wkf_workitem
237 (
238     id serial,
239     act_id int not null references wkf_activity on delete cascade,
240     inst_id int not null references wkf_instance on delete cascade,
241     subflow_id int references wkf_instance on delete cascade,
242     state varchar(64) default 'blocked',
243     primary key(id)
244 );
245
246 create table wkf_witm_trans
247 (
248     trans_id int not null references wkf_transition on delete cascade,
249     inst_id int not null references wkf_instance on delete cascade
250 );
251
252 create index wkf_witm_trans_inst_idx on wkf_witm_trans (inst_id);
253
254 create table wkf_logs
255 (
256     id serial,
257     res_type varchar(128) not null,
258     res_id int not null,
259     uid int references res_users on delete set null,
260     act_id int references wkf_activity on delete set null,
261     time time not null,
262     info varchar(128) default NULL,
263     primary key(id)
264 );
265
266 ---------------------------------
267 -- Modules
268 ---------------------------------
269
270 CREATE TABLE ir_module_category (
271     id serial NOT NULL,
272     create_uid integer references res_users on delete set null,
273     create_date timestamp without time zone,
274     write_date timestamp without time zone,
275     write_uid integer references res_users on delete set null,
276     parent_id integer REFERENCES ir_module_category ON DELETE SET NULL,
277     name character varying(128) NOT NULL,
278     primary key(id)
279 );
280
281
282 CREATE TABLE ir_module_module (
283     id serial NOT NULL,
284     create_uid integer references res_users on delete set null,
285     create_date timestamp without time zone,
286     write_date timestamp without time zone,
287     write_uid integer references res_users on delete set null,
288     website character varying(256),
289     name character varying(128) NOT NULL,
290     author character varying(128),
291     url character varying(128),
292     state character varying(16),
293     latest_version character varying(64),
294     shortdesc character varying(256),
295     category_id integer REFERENCES ir_module_category ON DELETE SET NULL,
296     certificate character varying(64),
297     description text,
298     demo boolean default False,
299     web boolean DEFAULT FALSE,
300     license character varying(32),
301     primary key(id)
302 );
303 ALTER TABLE ir_module_module add constraint name_uniq unique (name);
304
305 CREATE TABLE ir_module_module_dependency (
306     id serial NOT NULL,
307     create_uid integer references res_users on delete set null,
308     create_date timestamp without time zone,
309     write_date timestamp without time zone,
310     write_uid integer references res_users on delete set null,
311     name character varying(128),
312     version_pattern character varying(128) default NULL,
313     module_id integer REFERENCES ir_module_module ON DELETE cascade,
314     primary key(id)
315 );
316
317 CREATE TABLE res_company (
318     id serial NOT NULL,
319     name character varying(64) not null,
320     parent_id integer references res_company on delete set null,
321     primary key(id)
322 );
323
324 CREATE TABLE ir_model_data (
325     id serial NOT NULL,
326     create_uid integer,
327     create_date timestamp without time zone,
328     write_date timestamp without time zone,
329     write_uid integer,
330     noupdate boolean,
331     name character varying(128) NOT NULL,
332     date_init timestamp without time zone,
333     date_update timestamp without time zone,
334     module character varying(64) NOT NULL,
335     model character varying(64) NOT NULL,
336     res_id integer, primary key(id)
337 );
338
339 ---------------------------------
340 -- Users
341 ---------------------------------
342
343 insert into res_users (id,login,password,name,active,company_id,context_lang) values (1,'admin','admin','Administrator',True,1,'en_US');
344 insert into ir_model_data (name,module,model,noupdate,res_id) values ('user_root','base','res.users',True,1);
345
346 -- Compatibility purpose, to remove V6.0
347 insert into ir_model_data (name,module,model,noupdate,res_id) values ('user_admin','base','res.users',True,1);
348
349 select setval('res_users_id_seq', 2);