scripts/mir-setup/README: update with link to new doc on wiki
[mir.git] / dbscripts / create_pg.sql
1 --
2 -- media_folder
3 --
4
5 CREATE SEQUENCE "media_folder_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
6
7 CREATE TABLE "media_folder" (
8         "id" integer DEFAULT nextval('media_folder_id_seq'::text) NOT NULL,
9         "name" character varying(255) NOT NULL,
10         "date" character(8) NOT NULL,
11         "place" character varying(80),
12         "keywords" text,
13         "comment" text,
14         "webdb_create" timestamp with time zone NOT NULL,
15         "webdb_lastchange" timestamp with time zone
16 );
17
18 --
19 -- media_type
20 --
21
22 CREATE SEQUENCE "media_type_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
23
24 CREATE TABLE "media_type" (
25         "id" integer DEFAULT nextval('media_type_id_seq'::text) NOT NULL,
26         "name" character varying(80) NOT NULL,
27         "mime_type" character varying(40) NOT NULL,
28         "classname" character varying(80) NOT NULL,
29         "tablename" character varying(80) NOT NULL,
30         "dcname" character varying(20)
31 );
32
33 --
34 -- language
35 --
36
37 CREATE SEQUENCE "language_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1 ;
38
39 CREATE TABLE "language" (
40         "id" integer DEFAULT nextval('language_id_seq') NOT NULL,
41   "name" character varying(40) NOT NULL,
42   "code" character varying(2) NOT NULL,
43   Constraint "language_pkey" Primary Key ("id")
44 );
45
46 --
47 -- comment_status
48 --
49
50 CREATE SEQUENCE "comment_status_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1 ;
51
52 CREATE TABLE "comment_status" (
53   "id" integer DEFAULT nextval('comment_status_id_seq') NOT NULL,
54   "name" character varying(40) NOT NULL,
55   CONSTRAINT "comment_status_pkey" PRIMARY KEY ("id")
56 );
57
58
59
60 --
61 -- rights
62 --
63
64 CREATE TABLE "rights" (
65         "id" integer NOT NULL,
66         "name" character varying(80) NOT NULL,
67         "description" text,
68         Constraint "rights_pkey" Primary Key ("id")
69 );
70
71 --
72 -- webdb_users
73 --
74
75 CREATE SEQUENCE "webdb_users_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
76
77 CREATE TABLE "webdb_users" (
78         "id" integer DEFAULT nextval('webdb_users_id_seq'::text) NOT NULL,
79         "login" character varying(16) UNIQUE NOT NULL,
80         "password" character varying(255) NOT NULL,
81         "is_admin" boolean DEFAULT '0' NOT NULL,
82         "comment" text,
83         "is_disabled" boolean DEFAULT '0' NOT NULL,
84         "email" character varying(255) DEFAULT '' NOT NULL,
85         "profile" text,
86         "webdb_create"  timestamp with time zone NOT NULL,
87         "lastlogin"  timestamp with time zone,
88         CONSTRAINT "webdb_users_pkey" Primary Key ("id")
89 );
90
91
92 --
93 -- article type
94 --
95
96 CREATE SEQUENCE "article_type_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1 ;
97
98 CREATE TABLE "article_type" (
99         "id" integer DEFAULT nextval('article_type_id_seq') NOT NULL,
100         "name" character varying(40) NOT NULL,
101         CONSTRAINT "article_type_pkey" PRIMARY KEY ("id")
102 );
103
104 --
105 -- topic
106 --
107
108 CREATE SEQUENCE "topic_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
109
110 CREATE TABLE "topic" (
111         "id" integer DEFAULT nextval('topic_id_seq'::text) NOT NULL,
112         "parent_id" integer DEFAULT '0' NOT NULL,
113         "title" character varying(80) NOT NULL,
114         "description" text,
115         "filename" character varying(20) NOT NULL,
116         "main_url" character varying(255),
117         "archiv_url" character varying(255),
118         Constraint "topic_pkey" Primary Key ("id")
119 );
120
121 CREATE        INDEX "idx_topic_title" on "topic"           using btree ( "title" "varchar_ops" );
122
123
124 -- 
125 -- content_x_topics
126 --
127
128 CREATE TABLE "content_x_topic" (
129         "content_id" integer NOT NULL,
130         "topic_id" integer NOT NULL
131 );
132
133 CREATE UNIQUE INDEX "idx_content"     on "content_x_topic" using btree ( "content_id" "int4_ops", "topic_id" "int4_ops" );
134 CREATE UNIQUE INDEX "idx_topic"       on "content_x_topic" using btree ( "topic_id" "int4_ops", "content_id" "int4_ops" );
135
136 --
137 -- comment
138 --
139
140 CREATE SEQUENCE "comment_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
141 CREATE TABLE "comment" (
142   "id" integer DEFAULT nextval('comment_id_seq'::text) NOT NULL,
143   "title" character varying(80) NOT NULL,
144   "creator" character varying(80) NOT NULL,
145   "description" text NOT NULL,
146   "main_url" character varying(255),
147   "email" character varying(80),
148   "address" character varying(80),
149   "phone" character varying(20),
150   "webdb_create" timestamp with time zone NOT NULL,
151   "webdb_lastchange" timestamp with time zone,
152   "is_published" boolean DEFAULT '1' NOT NULL,
153   "to_language" integer DEFAULT '0' NOT NULL,
154   "to_media" integer NOT NULL,
155   "to_comment_status" smallint,
156         "comment" text,
157   "is_html" boolean DEFAULT '0' NOT NULL,
158   Constraint "comment_pkey" Primary Key ("id")
159 );
160
161 CREATE        INDEX "idx_comment_to_media" on "comment" using btree ( "to_media" "int4_ops" );
162 CREATE        INDEX idx_comment_webdb_create on comment(webdb_create);
163 CREATE        INDEX "idx_comment_tomedia_ispublished" on "comment" using btree ( "to_media" "int4_ops", "is_published" "bool_ops" );
164
165
166
167       CREATE TABLE "comment_x_media" (
168          "comment_id" integer,
169          "media_id" integer
170       );
171       
172       CREATE UNIQUE INDEX idx_comment_media on comment_x_media (comment_id, media_id);
173       CREATE UNIQUE INDEX idx_media_comment on comment_x_media (media_id, comment_id);
174
175
176 --
177 -- media
178 --
179
180 CREATE SEQUENCE "media_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
181
182 --
183 -- uploaded_media
184 --
185
186 CREATE TABLE "uploaded_media" (
187         "id" integer DEFAULT nextval('media_id_seq'::text) NOT NULL,
188         "title" character varying(255),
189         "subtitle" character varying(255),
190         "edittitle" character varying(255),
191         "date" character(8) NOT NULL,
192         "creator" character varying(80),
193         "creator_main_url" character varying(255),
194         "creator_email" character varying(80),
195         "creator_address" character varying(80),
196         "creator_phone" character varying(20),
197         "description" text,
198         "comment" text,
199         "source" character varying(255),
200         "publish_server" character varying(255),
201         "publish_path" character varying(255),
202         "is_published" boolean DEFAULT '0' NOT NULL,
203         "is_produced" boolean DEFAULT '0' NOT NULL,
204         "to_media_folder" integer DEFAULT '0' NOT NULL,
205         "to_media_type" smallint DEFAULT '0' NOT NULL,
206         "to_publisher" integer NOT NULL,
207         "to_language" integer DEFAULT '0',
208         "to_rights" integer DEFAULT '0',
209         "webdb_create" timestamp with time zone NOT NULL,
210         "webdb_lastchange" timestamp with time zone,
211         "icon_is_produced" boolean DEFAULT '0' NOT NULL,
212         "icon_path" character varying(255),
213         "size" integer,
214         Constraint "uploaded_media_pkey" Primary Key ("id")
215 );
216
217 CREATE UNIQUE INDEX "idx_uploaded_media_id" on "uploaded_media" using btree ( "id" "int4_ops" );
218 CREATE UNIQUE INDEX "idx_uploaded_media_is_published" on "uploaded_media" using btree ( "id" "int4_ops", "is_published" "bool_ops" );
219
220 --
221 -- images
222 --
223
224 CREATE TABLE "images" (
225         "image_data" bytea,
226         "icon_data" bytea,
227         "year" character varying(40),
228         "img_width" smallint,
229         "img_height" smallint,
230         "to_img_format" smallint DEFAULT '0' NOT NULL,
231         "to_img_layout" smallint DEFAULT '0' NOT NULL,
232         "to_img_type" smallint DEFAULT '0' NOT NULL,
233         "to_img_color" smallint DEFAULT '0' NOT NULL,
234         "icon_width" smallint,
235         "icon_height" smallint
236 )
237 INHERITS ("uploaded_media");
238
239 CREATE        INDEX "idx_images_is_published" on "images" using btree ( "is_published" "bool_ops", "icon_is_produced" "bool_ops" );
240 CREATE UNIQUE INDEX "idx_images_id" on "images" using btree ( "id" "int4_ops" );
241
242         --
243         -- img_format
244         --
245         
246         CREATE TABLE "img_format" (
247           "id" smallint NOT NULL,
248           "name" character varying(20) NOT NULL,
249           "extension" character varying(10) NOT NULL,
250           "mimetype" character varying(40) NOT NULL,
251           "commment" character varying(255)
252         );
253         
254         --
255         -- img_layout
256         --
257         
258         CREATE TABLE "img_layout" (
259           "id" smallint NOT NULL,
260           "name" character varying(20) NOT NULL
261         );
262         
263         --
264         -- img_type
265         --
266         
267         CREATE TABLE "img_type" (
268           "id" smallint NOT NULL,
269           "name" character varying(30) NOT NULL
270         );
271         
272         --
273         -- img_color
274         --
275         
276         CREATE TABLE "img_color" (
277           "id" smallint NOT NULL,
278           "name" character varying(30) NOT NULL
279         );
280
281         
282 --
283 -- audio
284 --
285
286 CREATE TABLE "audio" (
287   "kbits" smallint
288 )
289 INHERITS ("uploaded_media");
290
291 CREATE        INDEX "idx_audio_is_published_produced" on "audio" using btree ( "is_published" "bool_ops", "is_produced" "bool_ops" );
292 CREATE UNIQUE INDEX "idx_audio_id" on "audio" using btree ( "id" "int4_ops" );
293
294 --
295 -- video
296 --
297
298 CREATE TABLE "video" (
299 )
300 INHERITS ("uploaded_media");
301
302 CREATE        INDEX "idx_video_is_published_produced" on "video" using btree ( "is_published" "bool_ops", "is_produced" "bool_ops" );
303 CREATE UNIQUE INDEX "idx_video_id" on "video" using btree ( "id" "int4_ops" );
304
305 --
306 -- other_media
307 --
308
309 CREATE TABLE "other_media" (
310 )
311 INHERITS ("uploaded_media");
312
313 CREATE        INDEX "idx_othermedia_is_published_produced" on "other_media" using btree ( "is_published" "bool_ops", "is_produced" "bool_ops" );
314 CREATE UNIQUE INDEX "idx_othermedia_id" on "other_media" using btree ( "id" "int4_ops" );
315
316 --
317 -- content
318 --
319
320 CREATE TABLE "content" (
321         "id" integer DEFAULT nextval('media_id_seq'::text) NOT NULL,
322         "title" character varying(255),
323         "subtitle" character varying(255),
324         "edittitle" character varying(255),
325         "date" character(8) NOT NULL,
326         "creator" character varying(80),
327         "creator_main_url" character varying(255),
328         "creator_email" character varying(80),
329         "creator_address" character varying(80),
330         "creator_phone" character varying(80),
331         "description" text,
332         "comment" text,
333         "source" character varying(255),
334         "is_published" boolean DEFAULT '0' NOT NULL,
335         "is_produced" boolean DEFAULT '0' NOT NULL,
336         "to_publisher" integer NOT NULL,
337         "to_language" integer DEFAULT '0',
338         "to_rights" integer DEFAULT '0',
339         "webdb_create" timestamp with time zone NOT NULL,
340         "webdb_lastchange" timestamp with time zone,
341         "content_data" text,
342         "is_html" boolean DEFAULT '0' NOT NULL,
343         "to_article_type" smallint DEFAULT '0' NOT NULL,
344         "to_content" integer,
345         "keywords" text,
346         "to_locking_user" integer,
347   Constraint "content_pkey" Primary Key ("id")
348 );
349
350
351 CREATE        INDEX "idx_content_to_article_type" on "content" using btree ( "to_article_type" "int2_ops" );
352 CREATE        INDEX "idx_content_is_produced" on "content" using btree ( "is_produced" "bool_ops" );
353 CREATE        INDEX "idx_content_is_published__to_ar" on "content" using btree ( "is_published" "bool_ops", "to_article_type" "int2_ops" );
354 CREATE        INDEX "idx_content_is_published__id" on "content" using btree ( "is_published" "bool_ops", "id" "int4_ops" );
355 CREATE        INDEX "idx_content_is_pub__to_art__to_" on "content" using btree ( "is_published" "bool_ops", "to_article_type" "int2_ops", "id" "int4_ops" );
356 CREATE        INDEX "idx_content_is_published" on "content" using btree ( "is_published" "bool_ops" );
357 CREATE        INDEX idx_content_webdb_create on content(webdb_create);
358
359
360     -- content_x_media
361
362     CREATE TABLE "content_x_media" (
363       "content_id" integer,
364       "media_id" integer
365     );
366
367     CREATE INDEX "idx_cxm_content" on "content_x_media" using btree ( "content_id" "int4_ops" );
368     CREATE INDEX "idx_cxm_media" on "content_x_media" using btree ( "media_id" "int4_ops" );
369
370 --
371 -- breaking
372 --
373
374 CREATE SEQUENCE "breaking_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
375
376 CREATE TABLE "breaking" (
377   "id" integer DEFAULT nextval('breaking_id_seq'::text) NOT NULL,
378   "text" character varying(255) NOT NULL,
379   "webdb_create" timestamp with time zone NOT NULL
380 );
381
382 --
383 -- messages
384 --
385
386 CREATE SEQUENCE "messages_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
387
388 CREATE TABLE "messages" (
389   "id" integer DEFAULT nextval('messages_id_seq'::text) NOT NULL,
390   "title" character varying(30),
391   "description" character varying(255) NOT NULL,
392   "creator" character varying(30) NOT NULL,
393   "webdb_create" timestamp with time zone NOT NULL
394 );
395
396
397 --
398 -- filter
399 --
400
401 CREATE SEQUENCE "filter_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
402
403 CREATE TABLE "filter" (
404   "id" integer DEFAULT nextval('filter_id_seq'::text) NOT NULL,
405   "priority" integer,
406   "filter_group_id" integer,
407   "type" character varying(255) NOT NULL,
408   "expression" character varying(255) NOT NULL,
409   "tag" character varying(255) NOT NULL,
410         "comment" text,
411   "articleaction" character varying(255) NOT NULL,
412   "commentaction" character varying(255) NOT NULL,
413         "last_hit" timestamp with time zone
414 );
415
416 --
417 -- filter_group
418 --
419
420 CREATE SEQUENCE "filter_group_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
421
422 CREATE TABLE "filter_group" (
423   "id" integer DEFAULT nextval('filter_group_id_seq'::text) NOT NULL,
424   "name" character varying(255),
425   "priority" integer
426 );
427
428 --
429 -- db_patches
430 --
431
432 CREATE SEQUENCE "db_patches_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
433
434 CREATE TABLE "db_patches" (
435   "id" integer DEFAULT nextval('db_patches_id_seq'::text) NOT NULL,
436   "date" date NOT NULL,
437   "description" text
438 );
439
440 --
441 -- model_version
442 --
443
444 CREATE TABLE "model_version" (
445   "description"  character varying(24)
446 );
447