-- ABS-67245 / ABS-67254
CREATE SEQUENCE SEQ_APPPERMOBILEDEVICE
START WITH 1
INCREMENT BY 1;

CREATE TABLE APPPERMOBILEDEVICE
(
APPPERMOBILEDEVICE_ID NUMBER NOT NULL,
DEVICEUID VARCHAR2(50) NOT NULL,
APPLICATIONCODE VARCHAR2(2) NOT NULL,
APPLICATIONVERSION VARCHAR2(10) NOT NULL,
WEBUSER_ID NUMBER NULL,
OSVERSION VARCHAR2(10) NOT NULL,
LASTDATESEEN DATE NOT NULL,
SYSTEMUSER_ID NUMBER NOT NULL,
TIMESTAMP DATE NOT NULL
);

ALTER TABLE APPPERMOBILEDEVICE ADD CONSTRAINT XPKAPPPERMOBILEDEVICE PRIMARY KEY (APPPERMOBILEDEVICE_ID);

CREATE UNIQUE INDEX XAK1APPPERMOBILEDEVICE ON APPPERMOBILEDEVICE (DEVICEUID ASC, APPLICATIONCODE ASC);
CREATE INDEX XIF1APPPERMOBILEDEVICE ON APPPERMOBILEDEVICE (WEBUSER_ID ASC);

ALTER TABLE APPPERMOBILEDEVICE ADD CONSTRAINT APPPERMOBILEDEVICE_WEBID FOREIGN KEY (WEBUSER_ID)
REFERENCES WEBUSER (WEBUSER_ID) ON DELETE SET NULL;

