SET DB_CLOSE_DELAY -1;         
;              
CREATE USER IF NOT EXISTS ZIPCONNECT SALT '791b2ef2581e3748' HASH '40394715a88a697e746b148477d4fb5f05837d47e0d2757fc55c960ef8b39fce' ADMIN;    
CREATE SEQUENCE PUBLIC.SYSTEM_SEQUENCE_05BAF210_F502_4348_B72D_30B4760D1D03 START WITH 1 BELONGS_TO_TABLE;     
CREATE SEQUENCE PUBLIC.SYSTEM_SEQUENCE_B49B1531_1AC3_4339_BF47_BF8C89C85F3B START WITH 1 BELONGS_TO_TABLE;     
CREATE SEQUENCE PUBLIC.SYSTEM_SEQUENCE_69E8117E_547D_4FA0_B4B8_7D61F900115C START WITH 1 BELONGS_TO_TABLE;     
CREATE SEQUENCE PUBLIC.SYSTEM_SEQUENCE_A973D896_49E9_4108_9EB2_04CCBD2E46C1 START WITH 1 BELONGS_TO_TABLE;     
CREATE SEQUENCE PUBLIC.SYSTEM_SEQUENCE_99C30569_781F_4C20_9CE6_F20AA78F4C49 START WITH 5 BELONGS_TO_TABLE;     
CREATE SEQUENCE PUBLIC.SYSTEM_SEQUENCE_B2398558_7506_4144_82D4_6455E324C759 START WITH 1 BELONGS_TO_TABLE;     
CREATE SEQUENCE PUBLIC.SYSTEM_SEQUENCE_FECABC6A_D198_488F_B104_F7AA0724091D START WITH 1 BELONGS_TO_TABLE;     
CREATE MEMORY TABLE PUBLIC.DATABASECHANGELOGLOCK(
    ID INT NOT NULL,
    LOCKED BOOLEAN NOT NULL,
    LOCKGRANTED TIMESTAMP,
    LOCKEDBY VARCHAR(255)
);    
ALTER TABLE PUBLIC.DATABASECHANGELOGLOCK ADD CONSTRAINT PUBLIC.PK_DATABASECHANGELOGLOCK PRIMARY KEY(ID);       
-- 1 +/- SELECT COUNT(*) FROM PUBLIC.DATABASECHANGELOGLOCK;    
INSERT INTO PUBLIC.DATABASECHANGELOGLOCK(ID, LOCKED, LOCKGRANTED, LOCKEDBY) VALUES
(1, FALSE, NULL, NULL);     
CREATE MEMORY TABLE PUBLIC.DATABASECHANGELOG(
    ID VARCHAR(255) NOT NULL,
    AUTHOR VARCHAR(255) NOT NULL,
    FILENAME VARCHAR(255) NOT NULL,
    DATEEXECUTED TIMESTAMP NOT NULL,
    ORDEREXECUTED INT NOT NULL,
    EXECTYPE VARCHAR(10) NOT NULL,
    MD5SUM VARCHAR(35),
    DESCRIPTION VARCHAR(255),
    COMMENTS VARCHAR(255),
    TAG VARCHAR(255),
    LIQUIBASE VARCHAR(20),
    CONTEXTS VARCHAR(255),
    LABELS VARCHAR(255),
    DEPLOYMENT_ID VARCHAR(10)
);               
-- 8 +/- SELECT COUNT(*) FROM PUBLIC.DATABASECHANGELOG;        
INSERT INTO PUBLIC.DATABASECHANGELOG(ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, EXECTYPE, MD5SUM, DESCRIPTION, COMMENTS, TAG, LIQUIBASE, CONTEXTS, LABELS, DEPLOYMENT_ID) VALUES
('00000000000001', 'jhipster', 'config/liquibase/changelog/00000000000000_initial_schema.xml', TIMESTAMP '2018-12-20 15:11:06.045', 1, 'EXECUTED', '7:8eef49fe9846cf127a6c088e3d850cb0', 'createTable tableName=jhi_user; createTable tableName=jhi_authority; createTable tableName=jhi_user_authority; addPrimaryKey tableName=jhi_user_authority; addForeignKeyConstraint baseTableName=jhi_user_authority, constraintName=fk_authority_name, ...', '', NULL, '3.5.4', NULL, NULL, '5336665793'),
('20181217184612-1', 'jhipster', 'config/liquibase/changelog/20181217184612_added_entity_UserProfile.xml', TIMESTAMP '2018-12-20 15:11:06.06', 2, 'EXECUTED', '7:13d806ee806a475cdb828f90479e3da7', 'createTable tableName=user_profile', '', NULL, '3.5.4', NULL, NULL, '5336665793'),
('20181217184613-1', 'jhipster', 'config/liquibase/changelog/20181217184613_added_entity_Cohort.xml', TIMESTAMP '2018-12-20 15:11:06.066', 3, 'EXECUTED', '7:ab6218521729a91a6cf095e1cc219e6b', 'createTable tableName=cohort', '', NULL, '3.5.4', NULL, NULL, '5336665793'),
('20181217184614-1', 'jhipster', 'config/liquibase/changelog/20181217184614_added_entity_Employer.xml', TIMESTAMP '2018-12-20 15:11:06.07', 4, 'EXECUTED', '7:99bb184cef1922b8432114ff5615cd88', 'createTable tableName=employer', '', NULL, '3.5.4', NULL, NULL, '5336665793'),
('20181217184615-1', 'jhipster', 'config/liquibase/changelog/20181217184615_added_entity_Post.xml', TIMESTAMP '2018-12-20 15:11:06.074', 5, 'EXECUTED', '7:68b618230d8b4175f9c3fee15771054a', 'createTable tableName=post', '', NULL, '3.5.4', NULL, NULL, '5336665793'),
('20181217184616-1', 'jhipster', 'config/liquibase/changelog/20181217184616_added_entity_Privacy.xml', TIMESTAMP '2018-12-20 15:11:06.08', 6, 'EXECUTED', '7:2691075ffa5856c7404712dc50f51248', 'createTable tableName=privacy', '', NULL, '3.5.4', NULL, NULL, '5336665793'),
('20181217184612-2', 'jhipster', 'config/liquibase/changelog/20181217184612_added_entity_constraints_UserProfile.xml', TIMESTAMP '2018-12-20 15:11:06.091', 7, 'EXECUTED', '7:4265c77c4003ac55e132296cff70529b', 'addForeignKeyConstraint baseTableName=user_profile, constraintName=fk_user_profile_user_id, referencedTableName=jhi_user; addForeignKeyConstraint baseTableName=user_profile, constraintName=fk_user_profile_employer_id, referencedTableName=employer;...', '', NULL, '3.5.4', NULL, NULL, '5336665793'),
('20181217184615-2', 'jhipster', 'config/liquibase/changelog/20181217184615_added_entity_constraints_Post.xml', TIMESTAMP '2018-12-20 15:11:06.1', 8, 'EXECUTED', '7:7d0aed241b1359d2a465be6011b4109e', 'addForeignKeyConstraint baseTableName=post, constraintName=fk_post_poster_id, referencedTableName=user_profile; addForeignKeyConstraint baseTableName=post, constraintName=fk_post_privacy_setting_id, referencedTableName=privacy', '', NULL, '3.5.4', NULL, NULL, '5336665793');         
CREATE MEMORY TABLE PUBLIC.JHI_USER(
    ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_99C30569_781F_4C20_9CE6_F20AA78F4C49) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_99C30569_781F_4C20_9CE6_F20AA78F4C49,
    LOGIN VARCHAR(50) NOT NULL,
    PASSWORD_HASH VARCHAR(60) NOT NULL,
    FIRST_NAME VARCHAR(50),
    LAST_NAME VARCHAR(50),
    EMAIL VARCHAR(254),
    IMAGE_URL VARCHAR(256),
    ACTIVATED BOOLEAN NOT NULL,
    LANG_KEY VARCHAR(6),
    ACTIVATION_KEY VARCHAR(20),
    RESET_KEY VARCHAR(20),
    CREATED_BY VARCHAR(50) NOT NULL,
    CREATED_DATE TIMESTAMP DEFAULT NULL,
    RESET_DATE TIMESTAMP,
    LAST_MODIFIED_BY VARCHAR(50),
    LAST_MODIFIED_DATE TIMESTAMP
);    
ALTER TABLE PUBLIC.JHI_USER ADD CONSTRAINT PUBLIC.PK_JHI_USER PRIMARY KEY(ID); 
-- 4 +/- SELECT COUNT(*) FROM PUBLIC.JHI_USER; 
INSERT INTO PUBLIC.JHI_USER(ID, LOGIN, PASSWORD_HASH, FIRST_NAME, LAST_NAME, EMAIL, IMAGE_URL, ACTIVATED, LANG_KEY, ACTIVATION_KEY, RESET_KEY, CREATED_BY, CREATED_DATE, RESET_DATE, LAST_MODIFIED_BY, LAST_MODIFIED_DATE) VALUES
(1, 'system', '$2a$10$mE.qmcV0mFU5NcKh73TZx.z4ueI/.bDWbj0T1BYyqP481kGGarKLG', 'System', 'System', 'system@localhost', '', TRUE, 'en', NULL, NULL, 'system', NULL, NULL, 'system', NULL),
(2, 'anonymoususer', '$2a$10$j8S5d7Sr7.8VTOYNviDPOeWX8KcYILUVJBsYV83Y5NtECayypx9lO', 'Anonymous', 'User', 'anonymous@localhost', '', TRUE, 'en', NULL, NULL, 'system', NULL, NULL, 'system', NULL),
(3, 'admin', '$2a$10$gSAhZrxMllrbgj/kkK9UceBPpChGWJA7SYIb1Mqo.n5aNLq1/oRrC', 'Administrator', 'Administrator', 'admin@localhost', '', TRUE, 'en', NULL, NULL, 'system', NULL, NULL, 'system', NULL),
(4, 'user', '$2a$10$VEjxo0jq2YG9Rbk2HmX9S.k1uZBGYUHdUcid3g/vfiEl7lwWgOH/K', 'User', 'User', 'user@localhost', '', TRUE, 'en', NULL, NULL, 'system', NULL, NULL, 'system', NULL);           
CREATE MEMORY TABLE PUBLIC.JHI_AUTHORITY(
    NAME VARCHAR(50) NOT NULL
);     
ALTER TABLE PUBLIC.JHI_AUTHORITY ADD CONSTRAINT PUBLIC.PK_JHI_AUTHORITY PRIMARY KEY(NAME);     
-- 2 +/- SELECT COUNT(*) FROM PUBLIC.JHI_AUTHORITY;            
INSERT INTO PUBLIC.JHI_AUTHORITY(NAME) VALUES
('ROLE_ADMIN'),
('ROLE_USER');   
CREATE MEMORY TABLE PUBLIC.JHI_USER_AUTHORITY(
    USER_ID BIGINT NOT NULL,
    AUTHORITY_NAME VARCHAR(50) NOT NULL
);         
ALTER TABLE PUBLIC.JHI_USER_AUTHORITY ADD CONSTRAINT PUBLIC.CONSTRAINT_E PRIMARY KEY(USER_ID, AUTHORITY_NAME); 
-- 5 +/- SELECT COUNT(*) FROM PUBLIC.JHI_USER_AUTHORITY;       
INSERT INTO PUBLIC.JHI_USER_AUTHORITY(USER_ID, AUTHORITY_NAME) VALUES
(1, 'ROLE_ADMIN'),
(1, 'ROLE_USER'),
(3, 'ROLE_ADMIN'),
(3, 'ROLE_USER'),
(4, 'ROLE_USER');              
CREATE MEMORY TABLE PUBLIC.JHI_PERSISTENT_AUDIT_EVENT(
    EVENT_ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_B2398558_7506_4144_82D4_6455E324C759) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_B2398558_7506_4144_82D4_6455E324C759,
    PRINCIPAL VARCHAR(50) NOT NULL,
    EVENT_DATE TIMESTAMP,
    EVENT_TYPE VARCHAR(255)
);    
ALTER TABLE PUBLIC.JHI_PERSISTENT_AUDIT_EVENT ADD CONSTRAINT PUBLIC.PK_JHI_PERSISTENT_AUDIT_EVENT PRIMARY KEY(EVENT_ID);       
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.JHI_PERSISTENT_AUDIT_EVENT;               
CREATE INDEX PUBLIC.IDX_PERSISTENT_AUDIT_EVENT ON PUBLIC.JHI_PERSISTENT_AUDIT_EVENT(PRINCIPAL, EVENT_DATE);    
CREATE MEMORY TABLE PUBLIC.JHI_PERSISTENT_AUDIT_EVT_DATA(
    EVENT_ID BIGINT NOT NULL,
    NAME VARCHAR(150) NOT NULL,
    VALUE VARCHAR(255)
);              
ALTER TABLE PUBLIC.JHI_PERSISTENT_AUDIT_EVT_DATA ADD CONSTRAINT PUBLIC.CONSTRAINT_F PRIMARY KEY(EVENT_ID, NAME);               
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.JHI_PERSISTENT_AUDIT_EVT_DATA;            
CREATE INDEX PUBLIC.IDX_PERSISTENT_AUDIT_EVT_DATA ON PUBLIC.JHI_PERSISTENT_AUDIT_EVT_DATA(EVENT_ID);           
CREATE MEMORY TABLE PUBLIC.USER_PROFILE(
    ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_A973D896_49E9_4108_9EB2_04CCBD2E46C1) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_A973D896_49E9_4108_9EB2_04CCBD2E46C1,
    FIRST_NAME VARCHAR(255),
    LAST_NAME VARCHAR(255),
    USER_STACK VARCHAR(255),
    USER_ID BIGINT,
    EMPLOYER_ID BIGINT,
    COHORT_ID BIGINT
);           
ALTER TABLE PUBLIC.USER_PROFILE ADD CONSTRAINT PUBLIC.PK_USER_PROFILE PRIMARY KEY(ID);         
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.USER_PROFILE;             
CREATE MEMORY TABLE PUBLIC.COHORT(
    ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_B49B1531_1AC3_4339_BF47_BF8C89C85F3B) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_B49B1531_1AC3_4339_BF47_BF8C89C85F3B,
    GRAD_DATE VARCHAR(255)
);             
ALTER TABLE PUBLIC.COHORT ADD CONSTRAINT PUBLIC.PK_COHORT PRIMARY KEY(ID);     
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.COHORT;   
CREATE MEMORY TABLE PUBLIC.EMPLOYER(
    ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_FECABC6A_D198_488F_B104_F7AA0724091D) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_FECABC6A_D198_488F_B104_F7AA0724091D,
    COMPANY_NAME VARCHAR(255),
    CITY VARCHAR(255),
    STATE VARCHAR(255)
);         
ALTER TABLE PUBLIC.EMPLOYER ADD CONSTRAINT PUBLIC.PK_EMPLOYER PRIMARY KEY(ID); 
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.EMPLOYER; 
CREATE MEMORY TABLE PUBLIC.POST(
    ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_69E8117E_547D_4FA0_B4B8_7D61F900115C) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_69E8117E_547D_4FA0_B4B8_7D61F900115C,
    JHI_TIMESTAMP DATE,
    CONTENT VARCHAR(255),
    LIKES VARCHAR(255),
    POSTER_ID BIGINT,
    PRIVACY_SETTING_ID BIGINT
);            
ALTER TABLE PUBLIC.POST ADD CONSTRAINT PUBLIC.PK_POST PRIMARY KEY(ID);         
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.POST;     
CREATE MEMORY TABLE PUBLIC.PRIVACY(
    ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_05BAF210_F502_4348_B72D_30B4760D1D03) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_05BAF210_F502_4348_B72D_30B4760D1D03,
    PUBLIC_VIEW BOOLEAN,
    COHORT_VIEW BOOLEAN,
    EMPLOYER_VIEW BOOLEAN
);           
ALTER TABLE PUBLIC.PRIVACY ADD CONSTRAINT PUBLIC.PK_PRIVACY PRIMARY KEY(ID);   
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.PRIVACY;  
ALTER TABLE PUBLIC.JHI_USER ADD CONSTRAINT PUBLIC.UX_USER_LOGIN UNIQUE(LOGIN); 
ALTER TABLE PUBLIC.USER_PROFILE ADD CONSTRAINT PUBLIC.UX_USER_PROFILE_USER_ID UNIQUE(USER_ID); 
ALTER TABLE PUBLIC.JHI_USER ADD CONSTRAINT PUBLIC.UX_USER_EMAIL UNIQUE(EMAIL); 
ALTER TABLE PUBLIC.POST ADD CONSTRAINT PUBLIC.FK_POST_POSTER_ID FOREIGN KEY(POSTER_ID) REFERENCES PUBLIC.USER_PROFILE(ID) NOCHECK;             
ALTER TABLE PUBLIC.POST ADD CONSTRAINT PUBLIC.FK_POST_PRIVACY_SETTING_ID FOREIGN KEY(PRIVACY_SETTING_ID) REFERENCES PUBLIC.PRIVACY(ID) NOCHECK;
ALTER TABLE PUBLIC.JHI_USER_AUTHORITY ADD CONSTRAINT PUBLIC.FK_USER_ID FOREIGN KEY(USER_ID) REFERENCES PUBLIC.JHI_USER(ID) NOCHECK;            
ALTER TABLE PUBLIC.JHI_PERSISTENT_AUDIT_EVT_DATA ADD CONSTRAINT PUBLIC.FK_EVT_PERS_AUDIT_EVT_DATA FOREIGN KEY(EVENT_ID) REFERENCES PUBLIC.JHI_PERSISTENT_AUDIT_EVENT(EVENT_ID) NOCHECK;        
ALTER TABLE PUBLIC.USER_PROFILE ADD CONSTRAINT PUBLIC.FK_USER_PROFILE_EMPLOYER_ID FOREIGN KEY(EMPLOYER_ID) REFERENCES PUBLIC.EMPLOYER(ID) NOCHECK;             
ALTER TABLE PUBLIC.USER_PROFILE ADD CONSTRAINT PUBLIC.FK_USER_PROFILE_COHORT_ID FOREIGN KEY(COHORT_ID) REFERENCES PUBLIC.COHORT(ID) NOCHECK;   
ALTER TABLE PUBLIC.USER_PROFILE ADD CONSTRAINT PUBLIC.FK_USER_PROFILE_USER_ID FOREIGN KEY(USER_ID) REFERENCES PUBLIC.JHI_USER(ID) NOCHECK;     
ALTER TABLE PUBLIC.JHI_USER_AUTHORITY ADD CONSTRAINT PUBLIC.FK_AUTHORITY_NAME FOREIGN KEY(AUTHORITY_NAME) REFERENCES PUBLIC.JHI_AUTHORITY(NAME) NOCHECK;       
