CREATE OR REPLACE PROCEDURE CREATE_LARGE_TABLE_SPACE
BEGIN
	IF NOT EXISTS (SELECT * FROM SYSCAT.BUFFERPOOLS WHERE BPNAME = 'BP32K')
	THEN
		EXECUTE IMMEDIATE 'CREATE BUFFERPOOL BP32K IMMEDIATE SIZE 250 AUTOMATIC PAGESIZE 32K';
	END IF;
    IF NOT EXISTS (SELECT * FROM SYSIBM.SYSTABLESPACES WHERE TBSPACE = 'TS32K')
    THEN
    	EXECUTE IMMEDIATE 'CREATE LARGE TABLESPACE TS32K PAGESIZE 32K MANAGED by AUTOMATIC STORAGE BUFFERPOOL BP32K';
    END IF;
END
/

CALL CREATE_LARGE_TABLE_SPACE
/

DROP PROCEDURE CREATE_LARGE_TABLE_SPACE
/

CALL SYSPROC.ADMIN_MOVE_TABLE(
(SELECT TABSCHEMA FROM SYSCAT.TABLES where TABNAME = 'IDN_OAUTH2_ACCESS_TOKEN'),
'IDN_OAUTH2_ACCESS_TOKEN',
(SELECT TBSPACE FROM SYSCAT.TABLES where TABNAME = 'IDN_OAUTH2_ACCESS_TOKEN'),
'TS32K',
(SELECT TBSPACE FROM SYSCAT.TABLES where TABNAME = 'IDN_OAUTH2_ACCESS_TOKEN'),
'',
'',
'',
'',
'',
'MOVE')
/

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
/
ALTER TABLE IDN_OAUTH2_ACCESS_TOKEN ALTER COLUMN ACCESS_TOKEN SET DATA TYPE VARCHAR(2048)
/
ALTER TABLE IDN_OAUTH2_ACCESS_TOKEN ALTER COLUMN REFRESH_TOKEN SET DATA TYPE VARCHAR(2048)
/
CREATE TABLE 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)
/
ALTER TABLE IDN_IDENTITY_USER_DATA ALTER COLUMN DATA_VALUE SET DATA TYPE VARCHAR(2048)
/