DROP SEQUENCE IF EXISTS IDN_OAUTH2_ACCESS_TOKEN_AUDIT_PK_SEQ;
CREATE SEQUENCE IDN_OAUTH2_ACCESS_TOKEN_AUDIT_PK_SEQ;
ALTER TABLE IDN_OAUTH2_ACCESS_TOKEN_AUDIT ADD ID INTEGER DEFAULT NEXTVAL('IDN_OAUTH2_ACCESS_TOKEN_AUDIT_PK_SEQ') PRIMARY KEY;

DROP SEQUENCE IF EXISTS IDN_OAUTH2_SCOPE_BINDING_PK_SEQ;
CREATE SEQUENCE IDN_OAUTH2_SCOPE_BINDING_PK_SEQ;
ALTER TABLE IDN_OAUTH2_SCOPE_BINDING ADD ID INTEGER DEFAULT NEXTVAL('IDN_OAUTH2_SCOPE_BINDING_PK_SEQ') PRIMARY KEY;

DROP SEQUENCE IF EXISTS IDN_AUTH_USER_SESSION_MAPPING_PK_SEQ;
CREATE SEQUENCE IDN_AUTH_USER_SESSION_MAPPING_PK_SEQ;
ALTER TABLE IDN_AUTH_USER_SESSION_MAPPING ADD ID INTEGER DEFAULT NEXTVAL('IDN_AUTH_USER_SESSION_MAPPING_PK_SEQ') PRIMARY KEY;

DROP SEQUENCE IF EXISTS IDN_OAUTH2_CIBA_REQUEST_SCOPES_PK_SEQ;
CREATE SEQUENCE IDN_OAUTH2_CIBA_REQUEST_SCOPES_PK_SEQ;
ALTER TABLE IDN_OAUTH2_CIBA_REQUEST_SCOPES ADD ID INTEGER DEFAULT NEXTVAL('IDN_OAUTH2_CIBA_REQUEST_SCOPES_PK_SEQ') PRIMARY KEY;

ALTER TABLE IDN_OAUTH2_ACCESS_TOKEN ADD COLUMN IF NOT EXISTS CONSENTED_TOKEN VARCHAR(6);

DO $$ DECLARE con_name varchar(200); BEGIN SELECT 'ALTER TABLE IDN_FED_AUTH_SESSION_MAPPING DROP CONSTRAINT ' || tc .constraint_name || ';' INTO con_name FROM information_schema.table_constraints AS tc JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name WHERE constraint_type = 'PRIMARY KEY' AND tc.table_name = 'idn_fed_auth_session_mapping'; EXECUTE con_name; END $$;
DROP SEQUENCE IF EXISTS IDN_FED_AUTH_SESSION_MAPPING_PK_SEQ;
CREATE SEQUENCE IDN_FED_AUTH_SESSION_MAPPING_PK_SEQ;
ALTER TABLE IDN_FED_AUTH_SESSION_MAPPING ADD ID INTEGER DEFAULT NEXTVAL('IDN_FED_AUTH_SESSION_MAPPING_PK_SEQ') PRIMARY KEY;
ALTER TABLE IDN_FED_AUTH_SESSION_MAPPING ADD TENANT_ID INTEGER NOT NULL DEFAULT 0;
ALTER TABLE IDN_FED_AUTH_SESSION_MAPPING ADD CONSTRAINT IDN_FED_AUTH_SESSION_MAPPING_UQ_KEY UNIQUE (IDP_SESSION_ID, TENANT_ID);
