added 2 missing indexes to uploaded_media
[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) NOT NULL,
80         "password" character varying(16) NOT NULL,
81         "is_admin" boolean DEFAULT '0' NOT NULL,
82         Constraint "webdb_users_pkey" Primary Key ("id")
83 );
84
85 CREATE  INDEX "idx_webdb_user_log_pas_is_admin" on "webdb_users" using btree ( "login" "varchar_ops", "password" "varchar_ops", "is_admin" "bool_ops" );
86
87 CREATE  INDEX "idx_webdb_user_log_pas" on "webdb_users" using btree ( "login" "varchar_ops", "password" "varchar_ops" );
88
89 --
90 -- article type
91 --
92
93 CREATE SEQUENCE "article_type_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1 ;
94
95 CREATE TABLE "article_type" (
96         "id" integer DEFAULT nextval('article_type_id_seq') NOT NULL,
97         "name" character varying(40) NOT NULL,
98         CONSTRAINT "article_type_pkey" PRIMARY KEY ("id")
99 );
100
101 --
102 -- topic
103 --
104
105 CREATE SEQUENCE "topic_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
106
107 CREATE TABLE "topic" (
108         "id" integer DEFAULT nextval('topic_id_seq'::text) NOT NULL,
109         "parent_id" integer DEFAULT '0' NOT NULL,
110         "title" character varying(80) NOT NULL,
111         "description" text,
112         "filename" character varying(20) NOT NULL,
113         "main_url" character varying(255),
114         "archiv_url" character varying(255),
115         Constraint "topic_pkey" Primary Key ("id")
116 );
117
118 CREATE        INDEX "idx_topic_title" on "topic"           using btree ( "title" "varchar_ops" );
119 CREATE UNIQUE INDEX "idx_topic_id"    on "topic"           using btree ( "id" "int4_ops" );
120
121
122 -- 
123 -- content_x_topics
124 --
125
126 CREATE TABLE "content_x_topic" (
127         "content_id" integer NOT NULL,
128         "topic_id" integer NOT NULL
129 );
130
131 CREATE UNIQUE INDEX "idx_content"     on "content_x_topic" using btree ( "content_id" "int4_ops", "topic_id" "int4_ops" );
132 CREATE UNIQUE INDEX "idx_topic"       on "content_x_topic" using btree ( "topic_id" "int4_ops", "content_id" "int4_ops" );
133
134 --
135 -- comment
136 --
137
138 CREATE SEQUENCE "comment_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
139 CREATE TABLE "comment" (
140   "id" integer DEFAULT nextval('comment_id_seq'::text) NOT NULL,
141   "title" character varying(80) NOT NULL,
142   "creator" character varying(80) NOT NULL,
143   "description" text NOT NULL,
144   "main_url" character varying(255),
145   "email" character varying(80),
146   "address" character varying(80),
147   "phone" character varying(20),
148   "webdb_create" timestamp with time zone NOT NULL,
149   "webdb_lastchange" timestamp with time zone,
150   "is_published" boolean DEFAULT '1' NOT NULL,
151   "to_language" integer DEFAULT '0' NOT NULL,
152   "to_media" integer NOT NULL,
153   "to_comment_status" smallint,
154   "checksum" integer,
155   "is_html" boolean DEFAULT '0' NOT NULL,
156   Constraint "comment_pkey" Primary Key ("id")
157 );
158
159 CREATE        INDEX "comment_checksum_index" on "comment" using btree ( "checksum" "int4_ops" );
160 CREATE        INDEX "idx_comment_to_media" on "comment" using btree ( "to_media" "int4_ops" );
161 CREATE        INDEX idx_comment_webdb_create on comment(webdb_create);
162 CREATE        INDEX "idx_comment_tomedia_ispublished" on "comment" using btree ( "to_media" "int4_ops", "is_published" "bool_ops" );
163 CREATE UNIQUE INDEX "idx_comment_id" on "comment" using btree ( "id" "int4_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 CREATE TABLE "media" (
182         "id" integer DEFAULT nextval('media_id_seq'::text) NOT NULL,
183         "title" character varying(255),
184         "subtitle" character varying(255),
185         "edittitle" character varying(255),
186         "date" character(8) NOT NULL,
187         "creator" character varying(80),
188         "creator_main_url" character varying(255),
189         "creator_email" character varying(80),
190         "creator_address" character varying(80),
191         "creator_phone" character varying(20),
192         "description" text,
193         "comment" text,
194         "source" character varying(255),
195         "publish_date" timestamp with time zone,
196         "publish_server" character varying(255),
197         "publish_path" character varying(255),
198         "is_published" boolean DEFAULT '0' NOT NULL,
199         "is_produced" boolean DEFAULT '0' NOT NULL,
200         "to_feature" integer DEFAULT '0' NOT NULL,
201         "to_media_folder" integer DEFAULT '0' NOT NULL,
202         "to_media_type" smallint DEFAULT '0' NOT NULL,
203         "to_publisher" integer NOT NULL,
204         "to_language" integer DEFAULT '0',
205         "to_rights" integer DEFAULT '0',
206         "webdb_create" timestamp with time zone NOT NULL,
207         "webdb_lastchange" timestamp with time zone,
208         "to_media" integer
209 );
210
211 --
212 -- uploaded_media
213 --
214
215 CREATE TABLE "uploaded_media" (
216         "icon_is_produced" boolean DEFAULT '0' NOT NULL,
217         "icon_path" character varying(255),
218         "size" integer
219 )
220 INHERITS ("media");
221
222 CREATE UNIQUE INDEX "idx_uploaded_media_id" on "uploaded_media" using btree ( "id" "int4_ops" );
223 CREATE UNIQUE INDEX "idx_uploaded_media_is_published" on "uploaded_media" using btree ( "id" "int4_ops", "is_published" "bool_ops" );
224
225 --
226 -- images
227 --
228
229 CREATE TABLE "images" (
230         "image_data" oid,
231         "icon_data" oid,
232         "year" character varying(40),
233         "img_width" smallint,
234         "img_height" smallint,
235         "to_img_format" smallint DEFAULT '0' NOT NULL,
236         "to_img_layout" smallint DEFAULT '0' NOT NULL,
237         "to_img_type" smallint DEFAULT '0' NOT NULL,
238         "to_img_color" smallint DEFAULT '0' NOT NULL,
239         "icon_width" smallint,
240         "icon_height" smallint
241 )
242 INHERITS ("uploaded_media");
243
244 CREATE        INDEX "idx_images_is_published__icon_i" on "images" using btree ( "is_published" "bool_ops", "icon_is_produced" "bool_ops" );
245 CREATE UNIQUE INDEX "idx_images_id" on "images" using btree ( "id" "int4_ops" );
246
247         --
248         -- img_format
249         --
250         
251         CREATE TABLE "img_format" (
252           "id" smallint NOT NULL,
253           "name" character varying(20) NOT NULL,
254           "extension" character varying(10) NOT NULL,
255           "mimetype" character varying(40) NOT NULL,
256           "commment" character varying(255)
257         );
258         
259         --
260         -- img_layout
261         --
262         
263         CREATE TABLE "img_layout" (
264           "id" smallint NOT NULL,
265           "name" character varying(20) NOT NULL
266         );
267         
268         --
269         -- img_type
270         --
271         
272         CREATE TABLE "img_type" (
273           "id" smallint NOT NULL,
274           "name" character varying(30) NOT NULL
275         );
276         
277         --
278         -- img_color
279         --
280         
281         CREATE TABLE "img_color" (
282           "id" smallint NOT NULL,
283           "name" character varying(30) NOT NULL
284         );
285
286         
287 --
288 -- audio
289 --
290
291 CREATE TABLE "audio" (
292   "kbits" smallint
293 )
294 INHERITS ("uploaded_media");
295
296 CREATE        INDEX "idx_audio_is_published_produced" on "audio" using btree ( "is_published" "bool_ops", "is_produced" "bool_ops" );
297 CREATE UNIQUE INDEX "idx_audio_id" on "audio" using btree ( "id" "int4_ops" );
298
299 --
300 -- video
301 --
302
303 CREATE TABLE "video" (
304 )
305 INHERITS ("uploaded_media");
306
307 CREATE        INDEX "idx_video_is_published_produced" on "video" using btree ( "is_published" "bool_ops", "is_produced" "bool_ops" );
308 CREATE UNIQUE INDEX "idx_video_id" on "video" using btree ( "id" "int4_ops" );
309
310 --
311 -- other_media
312 --
313
314 CREATE TABLE "other_media" (
315 )
316 INHERITS ("uploaded_media");
317
318 CREATE        INDEX "idx_othermedia_is_published_produced" on "other_media" using btree ( "is_published" "bool_ops", "is_produced" "bool_ops" );
319 CREATE UNIQUE INDEX "idx_othermedia_id" on "other_media" using btree ( "id" "int4_ops" );
320
321 --
322 -- content
323 --
324
325 CREATE TABLE "content" (
326         "content_data" text,
327         "is_html" boolean DEFAULT '0' NOT NULL,
328         "to_article_type" smallint DEFAULT '0' NOT NULL,
329         "to_content" integer,
330         "checksum" integer
331 )
332 INHERITS ("media");
333
334 CREATE        INDEX "content_checksum_index" on "content" using btree ( "checksum" "int4_ops" );
335 CREATE        INDEX "idx_content_to_article_type" on "content" using btree ( "to_article_type" "int2_ops" );
336 CREATE        INDEX "idx_content_is_produced" on "content" using btree ( "is_produced" "bool_ops" );
337 CREATE        INDEX "idx_content_is_published__to_ar" on "content" using btree ( "is_published" "bool_ops", "to_article_type" "int2_ops" );
338 CREATE        INDEX "idx_content_is_published__id" on "content" using btree ( "is_published" "bool_ops", "id" "int4_ops" );
339 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" );
340 CREATE UNIQUE INDEX "idx_content_id" on "content" using btree ( "id" "int4_ops" );
341 CREATE        INDEX "idx_content_is_published" on "content" using btree ( "is_published" "bool_ops" );
342 CREATE        INDEX idx_content_webdb_create on content(webdb_create);
343
344
345     -- content_x_media
346
347     CREATE TABLE "content_x_media" (
348       "content_id" integer,
349       "media_id" integer
350     );
351
352     CREATE UNIQUE INDEX "idx_content_media" on "content_x_media" using btree ( "content_id" "int4_ops", "media_id" "int4_ops" );
353     CREATE UNIQUE INDEX "idx_media_content" on "content_x_media" using btree ( "media_id" "int4_ops", "content_id" "int4_ops" );
354
355 --
356 -- breaking
357 --
358
359 CREATE SEQUENCE "breaking_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
360
361 CREATE TABLE "breaking" (
362   "id" integer DEFAULT nextval('breaking_id_seq'::text) NOT NULL,
363   "text" character varying(255) NOT NULL,
364   "webdb_create" timestamp with time zone NOT NULL
365 );
366
367 --
368 -- messages
369 --
370
371 CREATE SEQUENCE "messages_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
372
373 CREATE TABLE "messages" (
374   "id" integer DEFAULT nextval('messages_id_seq'::text) NOT NULL,
375   "title" character varying(30),
376   "description" character varying(255) NOT NULL,
377   "creator" character varying(30) NOT NULL,
378   "webdb_create" timestamp with time zone NOT NULL
379 );
380