insert into secd.oauth_validation (
       oauth_validation_public_id
       , oauth_provider_id
       , access_token
       , raw_response
       , created_at
       , validated_at
) values (
       $1
       , (
         select oauth_provider_id
         from secd.oauth_provider
         where name = $2
         and flow = $3
       )
       , $4
       , $5
       , $6
       , $7
) on conflict (oauth_validation_public_id) do update
  set access_token = excluded.access_token
      , validated_at = excluded.validated_at
      , raw_response = excluded.raw_response;
--
insert into secd.identity_oauth_validation (
       identity_id
       , oauth_validation_id
       , revoked_at
       , deleted_at
) values (
       (
       select identity_id
       from secd.identity
       where identity_public_id = $1
       )
       , (
         select oauth_validation_id
         from secd.oauth_validation
         where oauth_validation_public_id = $2
       )
       , $3
       , $4
) on conflict (identity_id, oauth_validation_id) do update
  set revoked_at = excluded.revoked_at
      , deleted_at = excluded.deleted_at;
