back to latest head
[mir.git] / dbscripts / updates / update20031124.sql
1 -- update script 2003-11-25 by Zapata
2 -- * Clean up comments 
3 -- * added a comment field for internal comments
4 -- This script will terminate with an error the second time it's run,
5 --   so running this script when it isn't needed is prevented from doing do any harm.
6
7 BEGIN TRANSACTION;
8
9 ----------------------
10 -- COMMENT changes
11 ----------------------
12
13 ALTER TABLE "comment" RENAME TO "comment_old";
14 DROP INDEX comment_pkey;
15 DROP INDEX comment_checksum_index;
16 DROP INDEX idx_comment_to_media;
17 DROP INDEX idx_comment_webdb_create;
18 DROP INDEX idx_comment_tomedia_ispublished;
19 DROP INDEX idx_comment_id;
20   
21 CREATE TABLE "comment" (
22   "id" integer DEFAULT nextval('comment_id_seq'::text) NOT NULL,
23   "title" character varying(80) NOT NULL,
24   "creator" character varying(80) NOT NULL,
25   "description" text NOT NULL,
26   "main_url" character varying(255),
27   "email" character varying(80),
28   "address" character varying(80),
29   "phone" character varying(20),
30   "webdb_create" timestamp with time zone NOT NULL,
31   "webdb_lastchange" timestamp with time zone,
32   "is_published" boolean DEFAULT '1' NOT NULL,
33   "to_language" integer DEFAULT '0' NOT NULL,
34   "to_media" integer NOT NULL,
35   "to_comment_status" smallint,
36         "comment" text,
37   "is_html" boolean DEFAULT '0' NOT NULL,
38   Constraint "comment_pkey" Primary Key ("id")
39 );
40
41 CREATE        INDEX "idx_comment_to_media"            on "comment" using btree ( "to_media" "int4_ops" );
42 CREATE        INDEX idx_comment_webdb_create          on  comment(webdb_create);
43 CREATE        INDEX "idx_comment_tomedia_ispublished" on "comment" using btree ( "to_media" "int4_ops", "is_published" "bool_ops" );
44 CREATE UNIQUE INDEX "idx_comment_id"                  on "comment" using btree ( "id" "int4_ops" );
45
46 INSERT INTO "comment" (
47   "id",
48   "title",
49   "creator",
50   "description",
51   "main_url",
52   "email",
53   "address",
54   "phone",
55   "webdb_create",
56   "webdb_lastchange",
57   "is_published",
58   "to_language",
59   "to_media",
60   "to_comment_status",
61   "is_html",
62         "comment")
63 select
64   "id",
65   "title",
66   "creator",
67   "description",
68   "main_url",
69   "email",
70   "address",
71   "phone",
72   "webdb_create",
73   "webdb_lastchange",
74   "is_published",
75   "to_language",
76   "to_media",
77   "to_comment_status",
78   "is_html",
79         ''
80 from comment_old;       
81
82
83 UPDATE  pg_class
84 SET
85   relowner = (SELECT relowner FROM pg_class WHERE relname='comment_old'),
86   relacl =   (SELECT relacl FROM pg_class WHERE relname='comment_old')
87 WHERE 
88   relname = 'comment';
89   
90 -- to prevent this script from being run successfully for a second time
91 INSERT INTO comment_old(to_media, description, checksum, title, creator, webdb_create) values(1, '', 1, '', '', now());
92
93 DROP TABLE comment_old;
94
95 -- thats it!
96   
97 COMMIT TRANSACTION;