
--------------------------------------------------
-- 10/20/2020
-- Author: Tony Chen 
-- Following changes are made to integrade with 
-- PHOENIX system.
--------------------------------------------------

-- Replace [REPLACE-WITH-REAL-VALUE] with real values. 
-- These values should be provided by Phoenix Bioinformatics.
INSERT INTO `application_preferences` (`NAME`, `PREFERENCE`, `VALUE`) VALUES 
    ('PORTAL2', 'phoenix.module.enabled', '0'),
    ('PORTAL2', 'phoenix.module.start.date', '2021-01-01'),
    ('PORTAL2', 'phoenix.base.api.host.name', '[REPLACE-WITH-REAL-VALUE]'),
    ('PORTAL2', 'phoenix.cipres.credentials.id', '[REPLACE-WITH-REAL-VALUE]'),
    ('PORTAL2', 'phoenix.cipres.partner.id', '[REPLACE-WITH-REAL-VALUE]'),
    ('PORTAL2', 'phoenix.cipres.secret.key', '[REPLACE-WITH-REAL-VALUE]'),
    ('PORTAL2', 'phoenix.cors.origin', '[REPLACE-WITH-REAL-VALUE]'),
    ('PORTAL2', 'phoenix.subscription.host.name', '[REPLACE-WITH-REAL-VALUE]')
;

INSERT INTO `application_preferences` (`NAME`, `PREFERENCE`, `VALUE`) VALUES 
    ('PORTAL2', 'cipres.su.allocations.valid.days', '364'),
    ('PORTAL2', 'cipres.non.us.users.annual.max.su.allocations', '50000')
;
-- --------------------------------------------------

CREATE TABLE `cipres_phoenix_users` 
(
    `ID`                            BIGINT AUTO_INCREMENT,
    `USER_ID`                       BIGINT NOT NULL, 
    `PHOENIX_USER_ID`               BIGINT NOT NULL, 
    `REGISTERED_TIME`               DATETIME NOT NULL,
    `LAST_MODIFIED_TIME`            DATETIME NOT NULL,
    `NOTE`                          VARCHAR(2000) NULL,
    
    CONSTRAINT pk_cipres_phoenix_users_01 PRIMARY KEY (`ID`), 
    CONSTRAINT uq_cipres_phoenix_users_01 UNIQUE (`USER_ID`), 
    CONSTRAINT uq_cipres_phoenix_users_02 UNIQUE (`PHOENIX_USER_ID`), 

    CONSTRAINT fk_cipres_phoenix_users_01 FOREIGN KEY (`USER_ID`) 
        REFERENCES `users` (`USER_ID`) ON DELETE NO ACTION     ON UPDATE NO ACTION 
);
-- --------------------------------------------------

INSERT INTO `version` (`VERSION`, `LAST_MODIFIED_TIME`) VALUES 
    ('2020-10-20', NOW())
;
-- --------------------------------------------------
