fn add_entity_history_record(
        &self,
        conn: &PgConnection,
        history_event: Option<&HistoryEvent>,
        key: &EntityKey,
        operation: OperationType,
    ) -> Result<(), Error> {
        // We only need to do work for the subgraph of subgraphs. All other
        // entities tables have triggers that will populate a history record
        // whenever we make a change to an entity
        if !key.subgraph_id.is_meta() {
            return Ok(());
        }
        let history_event = match history_event {
            None => return Ok(()),
            Some(event) => event,
        };
        let event_id = history_event
            .id
            .expect("we always allocate an event_id when we need to record metadata history");
        let schema = self.schema.as_str();

        diesel::sql_query(format!(
            "insert into {}.entity_history(
                   event_id,
                   subgraph, entity, entity_id,
                   data_before, op_id
                 )
                 select
                   $1 as event_id,
                   $2 as subgraph,
                   $3 as entity,
                   $4 as entity_id,
                   (select data
                      from {}.entities
                     where entity = $3
                       and id = $4) as data_before,
                   $5 as op_id",
            schema, schema,
        ))
        .bind::<Integer, _>(event_id)
        .bind::<Text, _>(&*history_event.subgraph)
        .bind::<Text, _>(&key.entity_type)
        .bind::<Text, _>(&key.entity_id)
        .bind::<Integer, i32>(operation.into())
        .execute(conn)?;

        Ok(())
    }
/// This takes a history event, a reversion flag, an entity key to create
/// the history record for and an operation type (e.g. `OperationType::Insert`).
/// It then creates an entry in the subgraph's `entity_history` table.
///
/// Special casing is applied for the `subgraphs.entities` table, as its
/// history records include the subgraph ID in the `subgraph` column.
This takes a history event, a reversion flag, an entity key to create
the history record for and an operation type .
It then creates an entry in the subgraph's `entity_history` table.

Special casing is applied for the `subgraphs.entities` table, as its
history records include the subgraph ID in the `subgraph` column.
This takes a history event a reversion flag an entity key to create the history record for and an operation type . It then creates an entry in the subgraph ' s ` entity_history ` table . Special casing is applied for the ` subgraphs . entities ` table as its history records include the subgraph ID in the ` subgraph ` column .
fn add_entity_history_record(
        &self,
        conn: &PgConnection,
        history_event: Option<&HistoryEvent>,
        key: &EntityKey,
        operation: OperationType,
    ) -> Result<(), Error> {
        // We only need to do work for the subgraph of subgraphs. All other
        // entities tables have triggers that will populate a history record
        // whenever we make a change to an entity
        if !key.subgraph_id.is_meta() {
            return Ok(());
        }
        let history_event = match history_event {
            None => return Ok(()),
            Some(event) => event,
        };
        let event_id = history_event
            .id
            .expect("we always allocate an event_id when we need to record metadata history");
        let schema = self.schema.as_str();
        diesel::sql_query(format!(
            "insert into {}.entity_history(
                   event_id,
                   subgraph, entity, entity_id,
                   data_before, op_id
                 )
                 select
                   $1 as event_id,
                   $2 as subgraph,
                   $3 as entity,
                   $4 as entity_id,
                   (select data
                      from {}.entities
                     where entity = $3
                       and id = $4) as data_before,
                   $5 as op_id",
            schema, schema,
        ))
        .bind::<Integer, _>(event_id)
        .bind::<Text, _>(&*history_event.subgraph)
        .bind::<Text, _>(&key.entity_type)
        .bind::<Text, _>(&key.entity_id)
        .bind::<Integer, i32>(operation.into())
        .execute(conn)?;
        Ok(())
    }
fn add_entity_history_record ( & self , conn : & PgConnection , history_event : Option < & HistoryEvent > , key : & EntityKey , operation : OperationType , ) -> Result < ( ) , Error > { // We only need to do work for the subgraph of subgraphs. All other // entities tables have triggers that will populate a history record // whenever we make a change to an entity if ! key . subgraph_id . is_meta ( ) { return Ok ( ( ) ) ; } let history_event = match history_event { None => return Ok ( ( ) ) , Some ( event ) => event , } ; let event_id = history_event . id . expect ( " " ) ; let schema = self . schema . as_str ( ) ; diesel :: sql_query ( format ! ( " " schema schema ) ) . bind :: < Integer , _ > ( event_id ) . bind :: < Text , _ > ( & * history_event . subgraph ) . bind :: < Text , _ > ( & key . entity_type ) . bind :: < Text , _ > ( & key . entity_id ) . bind :: < Integer , i32 > ( operation . into ( ) ) . execute ( conn ) ? ; Ok ( ( ) ) }
This takes a history event, a reversion flag, an entity key to create
the history record for and an operation type (e.g.
This takes a history event a reversion flag an entity key to create the history record for and an operation type ( e . g .
&self
conn
&PgConnection
history_event
Option<&HistoryEvent>
key
&EntityKey
operation
OperationType
&self
conn
&PgConnection
history_event
Option<&HistoryEvent>
key
&EntityKey
operation
OperationType