Initial revision
[mir.git] / dbscripts / create_pg.sql
1 \connect - postgres
2 CREATE SEQUENCE "media_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
3 SELECT nextval ('"media_id_seq"');
4 CREATE SEQUENCE "media_folder_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
5 SELECT nextval ('"media_folder_id_seq"');
6 CREATE SEQUENCE "creator_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
7 SELECT nextval ('"creator_id_seq"');
8 CREATE SEQUENCE "feature_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
9 SELECT nextval ('"feature_id_seq"');
10 CREATE SEQUENCE "topic_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
11 SELECT nextval ('"topic_id_seq"');
12 CREATE SEQUENCE "webdb_users_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
13 SELECT nextval ('"webdb_users_id_seq"');
14 CREATE SEQUENCE "comment_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
15 SELECT nextval ('"comment_id_seq"');
16 CREATE SEQUENCE "breaking_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
17 SELECT nextval ('"breaking_id_seq"');
18 CREATE SEQUENCE "messages_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1 ;
19 SELECT nextval ('"messages_id_seq"');
20 CREATE TABLE "media_folder" (
21         "id" int4 DEFAULT nextval('media_folder_id_seq'::text) NOT NULL,
22         "name" character varying(255) NOT NULL,
23         "date" character(8) NOT NULL,
24         "place" character varying(80),
25         "keywords" text,
26         "comment" text,
27         "webdb_create" timestamp NOT NULL,
28         "webdb_lastchange" timestamp
29 );
30 CREATE TABLE "media_type" (
31         "id" int2 NOT NULL,
32         "name" character varying(80) NOT NULL,
33         "classname" character varying(80) NOT NULL,
34         "tablename" character varying(80) NOT NULL,
35         "dcname" character varying(20)
36 );
37 CREATE TABLE "img_format" (
38         "id" int2 NOT NULL,
39         "name" character varying(20) NOT NULL,
40         "extension" character varying(10) NOT NULL,
41         "mimetype" character varying(40) NOT NULL,
42         "commment" character varying(255)
43 );
44 CREATE TABLE "img_layout" (
45         "id" int2 NOT NULL,
46         "name" character varying(20) NOT NULL
47 );
48 CREATE TABLE "img_type" (
49         "id" int2 NOT NULL,
50         "name" character varying(30) NOT NULL
51 );
52 CREATE TABLE "img_color" (
53         "id" int2 NOT NULL,
54         "name" character varying(30) NOT NULL
55 );
56 CREATE TABLE "language" (
57         "id" int4 NOT NULL,
58         "name" character varying(40) NOT NULL,
59         "code" character varying(2) NOT NULL,
60         PRIMARY KEY ("id")
61 );
62 CREATE TABLE "rights" (
63         "id" int4 NOT NULL,
64         "name" character varying(80) NOT NULL,
65         "description" text,
66         PRIMARY KEY ("id")
67 );
68 CREATE TABLE "creator" (
69         "id" int4 DEFAULT nextval('creator_id_seq'::text) NOT NULL,
70         "name" character varying(80) NOT NULL,
71         "main_url" character varying(255),
72         "email" character varying(80),
73         "address" character varying(80),
74         "phone" character varying(20),
75         PRIMARY KEY ("id")
76 );
77 CREATE TABLE "feature" (
78         "id" int4 DEFAULT nextval('feature_id_seq'::text) NOT NULL,
79         "title" character varying(80) NOT NULL,
80         "description" text,
81         "filename" character varying(20) NOT NULL,
82         "main_url" character varying(255),
83         "is_published" bool DEFAULT '0' NOT NULL,
84         PRIMARY KEY ("id")
85 );
86 CREATE TABLE "webdb_users" (
87         "id" int4 DEFAULT nextval('webdb_users_id_seq'::text) NOT NULL,
88         "login" character varying(16) NOT NULL,
89         "password" character varying(16) NOT NULL,
90         "is_admin" bool DEFAULT '0' NOT NULL,
91         PRIMARY KEY ("id")
92 );
93 CREATE TABLE "content_x_topic" (
94         "content_id" int4 NOT NULL,
95         "topic_id" int4 NOT NULL
96 );
97 CREATE TABLE "article_type" (
98         "id" int4 NOT NULL,
99         "name" character varying(20) NOT NULL
100 );
101 CREATE TABLE "topic" (
102         "id" int4 DEFAULT nextval('topic_id_seq'::text) NOT NULL,
103         "parent_id" int4 DEFAULT '0' NOT NULL,
104         "title" character varying(80) NOT NULL,
105         "description" text,
106         "filename" character varying(20) NOT NULL,
107         "main_url" character varying(255),
108         "archiv_url" character varying(255),
109         PRIMARY KEY ("id")
110 );
111 CREATE TABLE "comment" (
112         "id" int4 DEFAULT nextval('comment_id_seq'::text) NOT NULL,
113         "title" character varying(80) NOT NULL,
114         "creator" character varying(80) NOT NULL,
115         "description" text NOT NULL,
116         "main_url" character varying(255),
117         "email" character varying(80),
118         "address" character varying(80),
119         "phone" character varying(20),
120         "webdb_create" timestamp NOT NULL,
121         "is_published" bool DEFAULT '1' NOT NULL,
122         "to_language" int4 DEFAULT '0' NOT NULL,
123         "to_media" int4 NOT NULL,
124         PRIMARY KEY ("id")
125 );
126 CREATE TABLE "media" (
127         "id" int4 DEFAULT nextval('media_id_seq'::text) NOT NULL,
128         "title" character varying(80) NOT NULL,
129         "subtitle" character varying(30),
130         "edittitle" character varying(30),
131         "date" character(8) NOT NULL,
132         "place" character varying(80),
133         "creator" character varying(80),
134         "creator_main_url" character varying(255),
135         "creator_email" character varying(80),
136         "creator_address" character varying(80),
137         "creator_phone" character varying(20),
138         "description" text,
139         "keywords" text,
140         "comment" text,
141         "source" character varying(255),
142         "publish_date" timestamp,
143         "publish_server" character varying(255),
144         "publish_path" character varying(255),
145         "is_published" bool DEFAULT '0' NOT NULL,
146         "to_feature" int4 DEFAULT '0' NOT NULL,
147         "to_media_folder" int4 DEFAULT '0' NOT NULL,
148         "to_media_type" int2 DEFAULT '0' NOT NULL,
149         "to_creator" int4 DEFAULT '0' NOT NULL,
150         "to_publisher" int4 NOT NULL,
151         "to_language" int4 DEFAULT '0',
152         "to_rights" int4 DEFAULT '0',
153         "webdb_create" timestamp NOT NULL,
154         "webdb_lastchange" timestamp,
155         "to_media" int4
156 );
157 CREATE TABLE "images" (
158         "image_data" oid,
159         "icon_data" oid,
160         "icon_path" character varying(255),
161         "icon_is_produced" bool DEFAULT '0' NOT NULL,
162         "year" character varying(40),
163         "img_width" int2,
164         "img_height" int2,
165         "to_img_format" int2 DEFAULT '0' NOT NULL,
166         "to_img_layout" int2 DEFAULT '0' NOT NULL,
167         "to_img_type" int2 DEFAULT '0' NOT NULL,
168         "to_img_color" int2 DEFAULT '0' NOT NULL,
169         "icon_width" int2,
170         "icon_height" int2
171 )
172 inherits ("media");
173 CREATE TABLE "content" (
174         "content_data" text,
175         "link_url" character varying(255),
176         "date_from" character varying(8),
177         "date_to" character varying(8),
178         "date_name" character varying(255),
179         "is_html" bool DEFAULT '0' NOT NULL,
180         "is_produced" bool DEFAULT '0' NOT NULL,
181         "is_stored" bool DEFAULT '0' NOT NULL,
182         "is_mail_sent" bool DEFAULT '1' NOT NULL,
183         "is_digest_sent" bool DEFAULT '1' NOT NULL,
184         "to_article_type" int2 DEFAULT '0' NOT NULL
185 )
186 inherits ("media");
187 CREATE TABLE "breaking" (
188         "id" int4 DEFAULT nextval('breaking_id_seq'::text) NOT NULL,
189         "text" character varying(255) NOT NULL,
190         "webdb_create" timestamp NOT NULL
191 );
192 CREATE TABLE "messages" (
193         "id" int4 DEFAULT nextval('messages_id_seq'::text) NOT NULL,
194         "title" character varying(30),
195         "description" character varying(255) NOT NULL,
196         "creator" character varying(30) NOT NULL,
197         "webdb_create" timestamp NOT NULL
198 );
199 CREATE TABLE "videos" (
200         "video_data" oid,
201         "to_video_type" int2 DEFAULT '0' NOT NULL
202 )
203 inherits ("media");
204 CREATE FUNCTION "plpgsql_call_handler" ( ) RETURNS opaque AS '/usr/lib/postgresql/lib/plpgsql.so' LANGUAGE 'C';
205 CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql' HANDLER "plpgsql_call_handler" LANCOMPILER 'PL/pgSQL';
206 CREATE  INDEX "idx_comment_to_media" on "comment" using btree ( "to_media" "int4_ops" );
207 CREATE  INDEX "idx_content_to_article_type" on "content" using btree ( "to_article_type" "int2_ops" );
208 CREATE  INDEX "idx_content_is_produced" on "content" using btree ( "is_produced" "bool_ops" );
209 CREATE  INDEX "idx_content_is_published__to_ar" on "content" using btree ( "is_published" "bool_ops", "to_article_type" "int2_ops" );
210 CREATE  INDEX "idx_webdb_user_log_pas_is_admin" on "webdb_users" using btree ( "login" "varchar_ops", "password" "varchar_ops", "is_admin" "bool_ops" );
211 CREATE  INDEX "idx_content_is_stored" on "content" using btree ( "is_stored" "bool_ops" );
212 CREATE  INDEX "idx_content_is_published__id" on "content" using btree ( "is_published" "bool_ops", "id" "int4_ops" );
213 CREATE UNIQUE INDEX "idx_content" on "content_x_topic" using btree ( "content_id" "int4_ops", "topic_id" "int4_ops" );
214 CREATE  INDEX "idx_webdb_user_log_pas" on "webdb_users" using btree ( "login" "varchar_ops", "password" "varchar_ops" );
215 CREATE UNIQUE INDEX "idx_topic" on "content_x_topic" using btree ( "topic_id" "int4_ops", "content_id" "int4_ops" );
216 CREATE  INDEX "idx_topic_title" on "topic" using btree ( "title" "varchar_ops" );
217 CREATE  INDEX "idx_images_is_published__icon_i" on "images" using btree ( "is_published" "bool_ops", "icon_is_produced" "bool_ops" );
218 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" );
219 CREATE UNIQUE INDEX "idx_images_id" on "images" using btree ( "id" "int4_ops" );
220 CREATE UNIQUE INDEX "idx_content_id" on "content" using btree ( "id" "int4_ops" );
221 CREATE UNIQUE INDEX "idx_topic_id" on "topic" using btree ( "id" "int4_ops" );