-- update script 2003-11-22 by Zapata
-- * added a bunch of fields to webdb_user: is_disabled, email, profile, creation date,
--     last login date
-- This script will terminate with an error the second time it's run,
--   so running this script when it isn't needed can't do any harm.
--

BEGIN TRANSACTION;

ALTER TABLE "webdb_users" RENAME TO "webdb_users_old";
DROP INDEX "webdb_users_pkey";
  
CREATE TABLE "webdb_users" (
	"id" integer DEFAULT nextval('webdb_users_id_seq'::text) NOT NULL,
	"login" character varying(16) NOT NULL,
	"password" character varying(255) NOT NULL,
	"is_admin" boolean DEFAULT '0' NOT NULL,
	"comment" text,
	"is_disabled" boolean DEFAULT '0' NOT NULL,
        "email" character varying(255) DEFAULT '' NOT NULL,
        "profile" text,
        "webdb_create"  timestamp with time zone NOT NULL,
        "lastlogin"  timestamp with time zone,
        CONSTRAINT "webdb_users_pkey" Primary Key ("id")
);

INSERT INTO "webdb_users" (
  "id", 
  "login", 
  "password",
  "is_admin",
  "comment",
  "is_disabled",
  "email",
  "profile",
  "webdb_create",
  "lastlogin"
)
SELECT
  "id", 
  "login", 
  "password",
  "is_admin",
  '',
  'f',
  '',
  '',
  now(),
  null
FROM "webdb_users_old";

UPDATE  pg_class
SET
  relowner = (SELECT relowner FROM pg_class WHERE relname='webdb_users_old'),
  relacl =   (SELECT relacl FROM pg_class WHERE relname='webdb_users_old')
WHERE 
  relname = 'webdb_users';


-- to prevent this script from being run successfully for a second time
INSERT INTO webdb_users_old(login, password, is_admin) values('','','t');

DROP TABLE "webdb_users_old";

-- that's it!
  
COMMIT TRANSACTION;
