INSERT INTO `ohrm_module` (`name`, `status`) VALUES ('oauth', 1);

CREATE TABLE ohrm_oauth_client (client_id VARCHAR(80) NOT NULL, client_secret VARCHAR(80), redirect_uri VARCHAR(2000) NOT NULL, grant_types VARCHAR(80), scope VARCHAR(255), user_id VARCHAR(80), CONSTRAINT clients_client_id_pk PRIMARY KEY (client_id))engine=innodb default charset=utf8;
CREATE TABLE ohrm_oauth_access_token (access_token VARCHAR(40) NOT NULL, client_id VARCHAR(80) NOT NULL, user_id VARCHAR(255) NOT NULL, expires TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, scope VARCHAR(2000), session_id VARCHAR(255), CONSTRAINT access_token_pk PRIMARY KEY (access_token), INDEX oauth_access_token_session_id_user_id_idx (session_id, user_id))engine=innodb default charset=utf8;
CREATE TABLE ohrm_oauth_authorization_code (authorization_code VARCHAR(40) NOT NULL, client_id VARCHAR(80) NOT NULL, user_id VARCHAR(255), redirect_uri VARCHAR(2000), expires TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, scope VARCHAR(2000), CONSTRAINT auth_code_pk PRIMARY KEY (authorization_code))engine=innodb default charset=utf8;
CREATE TABLE ohrm_oauth_refresh_token (refresh_token VARCHAR(40) NOT NULL, client_id VARCHAR(80) NOT NULL, user_id VARCHAR(255) NOT NULL, expires TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, scope VARCHAR(2000), session_id VARCHAR(255), CONSTRAINT refresh_token_pk PRIMARY KEY (refresh_token), INDEX oauth_refresh_token_session_id_user_id_idx (session_id, user_id))engine=innodb default charset=utf8;
CREATE TABLE ohrm_oauth_user (username VARCHAR(255) NOT NULL, password VARCHAR(2000), first_name VARCHAR(255), last_name VARCHAR(255), CONSTRAINT username_pk PRIMARY KEY (username))engine=innodb default charset=utf8;
CREATE TABLE ohrm_oauth_scope (scope VARCHAR(50), is_default BOOLEAN)engine=innodb default charset=utf8;
CREATE TABLE ohrm_oauth_jwt (client_id VARCHAR(80) NOT NULL, subject VARCHAR(80), public_key VARCHAR(2000), CONSTRAINT jwt_client_id_pk PRIMARY KEY (client_id))engine=innodb default charset=utf8;

INSERT INTO ohrm_oauth_client(client_id, client_secret, grant_types, scope) VALUES
("public_rest_api_client", "","password refresh_token", "public private"),
("mobile_rest_api_client", "","password refresh_token", "public private");

INSERT INTO ohrm_oauth_scope(scope, is_default) VALUES ("public","0"),("private","0");
