BEGIN;


ALTER TABLE oauth_tokens
	ADD COLUMN id_token_custom_claims_name TEXT,
	ADD COLUMN id_token_custom_claims_picture TEXT,
	ADD COLUMN id_token_custom_claims_nickname TEXT,
	ADD COLUMN id_token_custom_claims_given_name TEXT,
	ADD COLUMN id_token_custom_claims_updated_at TEXT,
	ADD COLUMN id_token_custom_claims_family_name TEXT;

UPDATE oauth_tokens
	SET id_token_custom_claims_name = claims ->> 'name',
		id_token_custom_claims_picture = claims ->> 'picture',
		id_token_custom_claims_nickname = claims ->> 'nickname',
		id_token_custom_claims_given_name = claims ->> 'given_name',
		id_token_custom_claims_updated_at = (claims ->> 'updated_at')::TIMESTAMPTZ,
		id_token_custom_claims_family_name = claims ->> 'family_name';

ALTER TABLE oauth_tokens
	ALTER COLUMN id_token_custom_claims_name SET NOT NULL,
	ALTER COLUMN id_token_custom_claims_picture SET NOT NULL,
	ALTER COLUMN id_token_custom_claims_nickname SET NOT NULL,
	ALTER COLUMN id_token_custom_claims_given_name SET NOT NULL,
	ALTER COLUMN id_token_custom_claims_updated_at SET NOT NULL,
	ALTER COLUMN id_token_custom_claims_family_name SET NOT NULL;


COMMIT;
