pub(crate) fn migrate(
        self,
        logger: &Logger,
        block_ptr: &EthereumBlockPointer,
    ) -> Result<bool, Error> {
        // How many simultaneous subgraph migrations we allow
        const MIGRATION_LIMIT: i32 = 2;
        let subgraph = self.storage.subgraph();

        if !self.should_migrate(subgraph, block_ptr)? {
            return Ok(false);
        }

        let do_migrate = self.conn.transaction(|| -> Result<bool, Error> {
            let lock =
                diesel::sql_query("lock table public.deployment_schemas in exclusive mode nowait")
                    .execute(&self.conn);
            if lock.is_err() {
                return Ok(false);
            }

            let query = "
                UPDATE public.deployment_schemas
                   SET migrating = true
                 WHERE subgraph=$1
                   AND (SELECT count(*) FROM public.deployment_schemas WHERE migrating) < $2";
            let query = diesel::sql_query(query)
                .bind::<Text, _>(subgraph.to_string())
                .bind::<Integer, _>(MIGRATION_LIMIT);
            Ok(query.execute(&self.conn)? > 0)
        })?;

        if do_migrate {
            use self::public::deployment_schemas as dsl;

            let result = loop {
                match self.migration_step(logger, subgraph) {
                    Err(e) => {
                        // An error in a migration should not lead to the
                        // subgraph being marked as failed
                        warn!(logger, "aborted migrating";
                                        "subgraph" => subgraph.to_string(),
                                        "error" => e.to_string(),
                        );
                        break Ok(false);
                    }
                    Ok(again) if !again => break Ok(true),
                    Ok(_) => continue,
                }
            };
            // Relinquish the migrating lock, no matter what happened in
            // the migration
            diesel::update(dsl::table.filter(dsl::subgraph.eq(subgraph.to_string())))
                .set(dsl::migrating.eq(false))
                .execute(&self.conn)?;
            result
        } else {
            Ok(false)
        }
    }
/// Check if the database schema for `subgraph` needs to be migrated, and
/// if so, perform the migration. Return `true` if a migration was
/// performed, and `false` otherwise. A return value of `false` does not
/// indicate that no migration is necessary, just that we currently can
/// not perform it, for example, because too many other subgraphs are
/// migrating.
///
/// Migrating requires performing multiple transactions, and the connection
/// in `self` must therefore not have a transaction open already.
Check if the database schema for `subgraph` needs to be migrated, and
if so, perform the migration. Return `true` if a migration was
performed, and `false` otherwise. A return value of `false` does not
indicate that no migration is necessary, just that we currently can
not perform it, for example, because too many other subgraphs are
migrating.

Migrating requires performing multiple transactions, and the connection
in `self` must therefore not have a transaction open already.
Check if the database schema for ` subgraph ` needs to be migrated and if so perform the migration . Return ` true ` if a migration was performed and ` false ` otherwise . A return value of ` false ` does not indicate that no migration is necessary just that we currently can not perform it for example because too many other subgraphs are migrating . Migrating requires performing multiple transactions and the connection in ` self ` must therefore not have a transaction open already .
pub(crate) fn migrate(
        self,
        logger: &Logger,
        block_ptr: &EthereumBlockPointer,
    ) -> Result<bool, Error> {
        // How many simultaneous subgraph migrations we allow
        const MIGRATION_LIMIT: i32 = 2;
        let subgraph = self.storage.subgraph();
        if !self.should_migrate(subgraph, block_ptr)? {
            return Ok(false);
        }
        let do_migrate = self.conn.transaction(|| -> Result<bool, Error> {
            let lock =
                diesel::sql_query("lock table public.deployment_schemas in exclusive mode nowait")
                    .execute(&self.conn);
            if lock.is_err() {
                return Ok(false);
            }
            let query = "
                UPDATE public.deployment_schemas
                   SET migrating = true
                 WHERE subgraph=$1
                   AND (SELECT count(*) FROM public.deployment_schemas WHERE migrating) < $2";
            let query = diesel::sql_query(query)
                .bind::<Text, _>(subgraph.to_string())
                .bind::<Integer, _>(MIGRATION_LIMIT);
            Ok(query.execute(&self.conn)? > 0)
        })?;
        if do_migrate {
            use self::public::deployment_schemas as dsl;
            let result = loop {
                match self.migration_step(logger, subgraph) {
                    Err(e) => {
                        // An error in a migration should not lead to the
                        // subgraph being marked as failed
                        warn!(logger, "aborted migrating";
                                        "subgraph" => subgraph.to_string(),
                                        "error" => e.to_string(),
                        );
                        break Ok(false);
                    }
                    Ok(again) if !again => break Ok(true),
                    Ok(_) => continue,
                }
            };
            // Relinquish the migrating lock, no matter what happened in
            // the migration
            diesel::update(dsl::table.filter(dsl::subgraph.eq(subgraph.to_string())))
                .set(dsl::migrating.eq(false))
                .execute(&self.conn)?;
            result
        } else {
            Ok(false)
        }
    }
pub ( crate ) fn migrate ( self , logger : & Logger , block_ptr : & EthereumBlockPointer , ) -> Result < bool , Error > { // How many simultaneous subgraph migrations we allow const MIGRATION_LIMIT : i32 = 2 ; let subgraph = self . storage . subgraph ( ) ; if ! self . should_migrate ( subgraph , block_ptr ) ? { return Ok ( false ) ; } let do_migrate = self . conn . transaction ( | | -> Result < bool , Error > { let lock = diesel :: sql_query ( " " ) . execute ( & self . conn ) ; if lock . is_err ( ) { return Ok ( false ) ; } let query = " " ; let query = diesel :: sql_query ( query ) . bind :: < Text , _ > ( subgraph . to_string ( ) ) . bind :: < Integer , _ > ( MIGRATION_LIMIT ) ; Ok ( query . execute ( & self . conn ) ? > 0 ) } ) ? ; if do_migrate { use self :: public :: deployment_schemas as dsl ; let result = loop { match self . migration_step ( logger , subgraph ) { Err ( e ) => { // An error in a migration should not lead to the // subgraph being marked as failed warn ! ( logger " " " " subgraph to_string ( ) " " e to_string ( ) ) ; break Ok ( false ) ; } Ok ( again ) if ! again => break Ok ( true ) , Ok ( _ ) => continue , } } ; // Relinquish the migrating lock, no matter what happened in // the migration diesel :: update ( dsl :: table . filter ( dsl :: subgraph . eq ( subgraph . to_string ( ) ) ) ) . set ( dsl :: migrating . eq ( false ) ) . execute ( & self . conn ) ? ; result } else { Ok ( false ) } }
Check if the database schema for `subgraph` needs to be migrated, and
if so, perform the migration.
Check if the database schema for ` subgraph ` needs to be migrated and if so perform the migration .
self
logger
&Logger
block_ptr
&EthereumBlockPointer
self
logger
&Logger
block_ptr
&EthereumBlockPointer