CREATE TABLE COMMUNITY_USER
(
	GATEWAY_NAME VARCHAR(256) NOT NULL,
	COMMUNITY_USER_NAME VARCHAR(256) NOT NULL,
	COMMUNITY_USER_EMAIL VARCHAR(256) NOT NULL,
        PRIMARY KEY (GATEWAY_NAME, COMMUNITY_USER_NAME)
);


CREATE TABLE CREDENTIALS
(
	GATEWAY_NAME VARCHAR(256) NOT NULL,
	COMMUNITY_USER_NAME VARCHAR(256) NOT NULL,
	CREDENTIAL TEXT NOT NULL,
	PRIVATE_KEY TEXT NOT NULL,
	NOT_BEFORE VARCHAR(256) NOT NULL,
	NOT_AFTER VARCHAR(256) NOT NULL,
	LIFETIME MEDIUMINT NOT NULL,
	REQUESTING_PORTAL_USER_NAME VARCHAR(256) NOT NULL,
	REQUESTED_TIME TIMESTAMP DEFAULT '0000-00-00 00:00:00',
        PRIMARY KEY (GATEWAY_NAME, COMMUNITY_USER_NAME)
);

CREATE TABLE MAPPING
(
	GATEWAY_NAME VARCHAR(256) NOT NULL,
	COMMUNITY_USER_NAME VARCHAR(256) NOT NULL,
	PORTAL_USER_NAME VARCHAR(256) NOT NULL,
        PRIMARY KEY (GATEWAY_NAME, COMMUNITY_USER_NAME, PORTAL_USER_NAME)
);
