-- Licensed Materials - Property of IBM
-- BI and PM: Mobile
-- (C) Copyright IBM Corp. 2007, 2012
-- US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

DECLARE
	TABLE_DOES_NOT_EXIST_EXCEPTION EXCEPTION;
	PRAGMA EXCEPTION_INIT(TABLE_DOES_NOT_EXIST_EXCEPTION, -942);
BEGIN
	EXECUTE IMMEDIATE 'ALTER TABLE MOB_USERS ADD LAST_UPDATED timestamp DEFAULT SYSDATE NOT NULL';
EXCEPTION
	WHEN TABLE_DOES_NOT_EXIST_EXCEPTION THEN
		NULL;
END;
/

DECLARE
	TABLE_DOES_NOT_EXIST_EXCEPTION EXCEPTION;
	PRAGMA EXCEPTION_INIT(TABLE_DOES_NOT_EXIST_EXCEPTION, -942);
	CONSTRAINT_DOES_NOT_EXIST_EXC EXCEPTION;
	PRAGMA EXCEPTION_INIT (CONSTRAINT_DOES_NOT_EXIST_EXC, -2443);
BEGIN
	EXECUTE IMMEDIATE 'ALTER TABLE MOB_USER_RESOURCE DROP CONSTRAINT PK_MOB_USERRSRC';
EXCEPTION
	WHEN TABLE_DOES_NOT_EXIST_EXCEPTION THEN
		NULL;
	WHEN CONSTRAINT_DOES_NOT_EXIST_EXC THEN
		NULL;
END;
/

DECLARE
	TABLE_DOES_NOT_EXIST_EXCEPTION EXCEPTION;
	PRAGMA EXCEPTION_INIT(TABLE_DOES_NOT_EXIST_EXCEPTION, -942);
	CONSTRAINT_EXISTS_EXCEPTION EXCEPTION;
	PRAGMA EXCEPTION_INIT (CONSTRAINT_EXISTS_EXCEPTION, -02275);
BEGIN
	EXECUTE IMMEDIATE 'ALTER TABLE MOB_USER_RESOURCE ADD CONSTRAINT PK_MOB_USERRSRC PRIMARY KEY(USER_ID, RESOURCE_ID, USER_RESOURCE_TYPE)';
EXCEPTION
	WHEN TABLE_DOES_NOT_EXIST_EXCEPTION THEN
		NULL;
	WHEN CONSTRAINT_EXISTS_EXCEPTION THEN
		NULL;
END;
/
