-- $Id: ulog_copy,v 1.1 2005/04/19 21:58:25 bhockney Exp $
--
-- Move ulog data from old schema to new schema
--
BEGIN;
  CREATE TABLE $ULOG_SCHEMA.$ULOG_TABLE AS SELECT * FROM $ULOG_OLD_SCHEMA.$ULOG_OLD_TABLE;
  CREATE SEQUENCE $ULOG_SCHEMA.seq_ulog;
  SELECT setval('$ULOG_SCHEMA.seq_ulog', nextval('$ULOG_OLD_SCHEMA.seq_ulog')-1);
  ALTER TABLE $ULOG_SCHEMA.$ULOG_TABLE ALTER COLUMN id SET DEFAULT nextval('$ULOG_SCHEMA.seq_ulog'::text);
  ALTER TABLE $ULOG_SCHEMA.$ULOG_TABLE ALTER COLUMN id SET NOT NULL;
  GRANT USAGE ON SCHEMA $ULOG_SCHEMA TO $USER;
  GRANT INSERT ON TABLE $ULOG_SCHEMA.$ULOG_TABLE TO $USER;
  GRANT SELECT, UPDATE ON $ULOG_SCHEMA.seq_ulog to $USER;
  DROP TABLE $ULOG_OLD_SCHEMA.$ULOG_OLD_TABLE;
  DROP SEQUENCE $ULOG_OLD_SCHEMA.seq_ulog;
COMMIT;
