-- ABS-85330 / ABS-88890
--- CUSTOMERCREDITCARDHIST ---
CREATE SEQUENCE SEQ_CUSTOMERCREDITCARDHIST
START WITH 1
INCREMENT BY 1;

CREATE TABLE CUSTOMERCREDITCARDHIST
(
CUSTOMERCREDITCARDHIST_ID NUMBER NOT NULL,
CUSTOMER_ID NUMBER NOT NULL,
MASKEDCARDNUMBER VARCHAR2(100) NOT NULL,
CARDEXPIRYMONTH NUMBER NOT NULL,
CARDEXPIRYYEAR NUMBER NOT NULL,
DELETEDDATE DATE NOT NULL,
SYSTEMUSER_ID NUMBER NOT NULL,
TIMESTAMP DATE NOT NULL
);

COMMENT ON COLUMN CUSTOMERCREDITCARDHIST.MASKEDCARDNUMBER IS 'This is masked data, not full card number';

ALTER TABLE CUSTOMERCREDITCARDHIST ADD CONSTRAINT XPKCUSTOMERCREDITCARDHIST PRIMARY KEY (CUSTOMERCREDITCARDHIST_ID);

CREATE INDEX XIF1CUSTOMERCREDITCARDHIST ON CUSTOMERCREDITCARDHIST (CUSTOMER_ID ASC);

ALTER TABLE CUSTOMERCREDITCARDHIST ADD CONSTRAINT FK_CUSTCREDITCARD_CUST FOREIGN KEY (CUSTOMER_ID)
REFERENCES CUSTOMER (CUSTOMER_ID) ON DELETE CASCADE;
