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