ALTER TABLE IDN_OAUTH_CONSUMER_APPS
    ADD USER_ACCESS_TOKEN_EXPIRE_TIME BIGINT DEFAULT 3600000;
ALTER TABLE IDN_OAUTH_CONSUMER_APPS
    ADD APP_ACCESS_TOKEN_EXPIRE_TIME BIGINT DEFAULT 3600000;
ALTER TABLE IDN_OAUTH_CONSUMER_APPS
    ADD REFRESH_TOKEN_EXPIRE_TIME BIGINT DEFAULT 84600000;

DROP PROCEDURE IF EXISTS drop_index_idx_at_if_exists;
CREATE PROCEDURE drop_index_idx_at_if_exists()
BEGIN
    IF ((SELECT COUNT(*) AS index_exists
         FROM information_schema.statistics
         WHERE TABLE_SCHEMA = DATABASE()
           and table_name = 'IDN_OAUTH2_ACCESS_TOKEN'
           AND index_name = 'IDX_AT') > 0) THEN
        SET @s = CONCAT('DROP INDEX ', 'IDX_AT', ' ON ', 'IDN_OAUTH2_ACCESS_TOKEN'); PREPARE stmt FROM @s;
        EXECUTE stmt;
    END IF;
END;
CALL drop_index_idx_at_if_exists();
DROP PROCEDURE IF EXISTS drop_index_idx_at_if_exists;

ALTER TABLE IDN_OAUTH2_ACCESS_TOKEN
    MODIFY ACCESS_TOKEN VARCHAR(2048);
ALTER TABLE IDN_OAUTH2_ACCESS_TOKEN
    MODIFY REFRESH_TOKEN VARCHAR(2048);

CREATE TABLE IF NOT EXISTS IDN_OAUTH2_SCOPE_BINDING
(
    SCOPE_ID      INTEGER NOT NULL,
    SCOPE_BINDING VARCHAR(255),
    FOREIGN KEY (SCOPE_ID) REFERENCES IDN_OAUTH2_SCOPE (SCOPE_ID) ON DELETE CASCADE
) ENGINE NDB;

ALTER TABLE IDN_IDENTITY_USER_DATA
    MODIFY DATA_VALUE VARCHAR(2048);

