ddd1e2ca43dc564e4f4b4b01c782ad18df584ae2
[mir.git] / dbscripts / updates / update20030704.sql
1 -- update script 2003-07-04 by Zapata
2 -- * makes the password field longer in webdb_users
3 -- * adds a comments field to webdb_users;
4 -- This script will terminate with an error the second time it's run,
5 --   so running this script when it isn't needed can't do any harm.
6 --
7
8 BEGIN TRANSACTION;
9
10 ALTER TABLE "webdb_users" RENAME TO "webdb_users_old";
11 DROP INDEX "webdb_users_pkey";
12 DROP INDEX "idx_webdb_user_log_pas";
13   
14 CREATE TABLE "webdb_users" (
15         "id" integer DEFAULT nextval('webdb_users_id_seq'::text) NOT NULL,
16         "login" character varying(16) NOT NULL,
17         "password" character varying(255) NOT NULL,
18         "is_admin" boolean DEFAULT '0' NOT NULL,
19         "comment" text,
20         Constraint "webdb_users_pkey" Primary Key ("id")
21 );
22
23 INSERT INTO "webdb_users" (
24   "id", 
25   "login", 
26   "password",
27   "is_admin"
28 )
29 SELECT
30   "id", 
31   "login", 
32   "password",
33   "is_admin"
34 FROM "webdb_users_old";
35
36 UPDATE  pg_class
37 SET
38   relowner = (SELECT relowner FROM pg_class WHERE relname='webdb_users_old'),
39   relacl =   (SELECT relacl FROM pg_class WHERE relname='webdb_users_old')
40 WHERE 
41   relname = 'webdb_users';
42
43 DROP TABLE "webdb_users_old";
44
45 DROP INDEX "idx_webdb_user_log_pas_is_admin" on "webdb_users" using btree ( "login" "varchar_ops", "password" "varchar_ops", "is_admin" "bool_ops" );
46   
47 -- that's it!
48   
49 COMMIT TRANSACTION;