'Store the participant\'s national identity information for a given country.
:param int country_id: an ``id`` from the ``countries`` table
:param dict schema_name: the name of the schema of the identity information
:param dict info: a dictionary of identity information
:returns: the ``id`` of the identity info\'s record in the
``participant_identities`` table
:raises ParticipantIdentitySchemaUnknown: if ``schema_name`` doesn\'t
name a known schema
:raises ParticipantIdentityInfoInvalid: if the ``info`` dictionary does
not conform to the schema named by ``schema_name``
The ``info`` dictionary will be serialized to JSON and then encrypted
with :py:class:`~gratipay.security.crypto.EncryptingPacker` before
being sent to the database. We anticipate multiple schemas evolving for
this dictionary, with enforcement in the application layer (since the
field is opaque in the database layer). For now there is only one
available schema: ``nothing-enforced``.
New participant identity information for a given country always starts
out unverified.'

def store_identity_info(self, country_id, schema_name, info):

    _validate_info(schema_name, info)
    info = self.encrypting_packer.pack(info)
    def _add_event(action):
        payload = dict(id=self.id, country_id=country_id, identity_id=identity_id, action=(action + u'    identity'))
        self.app.add_event(cursor, u'participant', payload)
    params = dict(participant_id=self.id, country_id=country_id, info=info, schema_name=schema_name)
    try:
        with self.db.get_cursor() as cursor:
            identity_id = cursor.one(u'\n\n                                                                                INSERT    INTO    participant_identities\n                                                                                                                                (participant_id,    country_id,    schema_name,    info)\n                                                                                                    VALUES    (%(participant_id)s,    %(country_id)s,    %(schema_name)s,    %(info)s)\n                                                                                        RETURNING    id\n\n                                                                ', params)
            _add_event(u'insert')
    except IntegrityError as exc:
        if (exc.pgcode != u'23505'):
            raise
        with self.db.get_cursor() as cursor:
            (identity_id, old_schema_name) = cursor.one(u'\n\n                                                                                UPDATE    participant_identities\n                                                                                            SET    schema_name=%(schema_name)s,    info=%(info)s,    is_verified=false\n                                                                                    WHERE    participant_id=%(participant_id)s\n                                                                                            AND    country_id=%(country_id)s\n                                                                    RETURNING    id,    schema_name\n\n                                                                ', params)
            _add_event(u'update')
    return identity_id
