@@ -444,8 +444,8 @@ mod queries {
444444 use diesel:: dsl:: { exists, sql} ;
445445 use diesel:: pg:: PgConnection ;
446446 use diesel:: prelude:: {
447- ExpressionMethods , JoinOnDsl , NullableExpressionMethods , OptionalExtension , QueryDsl ,
448- RunQueryDsl ,
447+ BoolExpressionMethods , ExpressionMethods , JoinOnDsl , NullableExpressionMethods ,
448+ OptionalExtension , QueryDsl , RunQueryDsl ,
449449 } ;
450450 use diesel:: sql_types:: Text ;
451451 use graph:: prelude:: NodeId ;
@@ -724,6 +724,44 @@ mod queries {
724724 . first :: < ( String , String ) > ( conn)
725725 . optional ( ) ?)
726726 }
727+
728+ pub ( super ) fn versions_for_subgraph_id (
729+ conn : & mut PgConnection ,
730+ subgraph_id : & str ,
731+ ) -> Result < ( Option < String > , Option < String > ) , StoreError > {
732+ Ok ( s:: table
733+ . select ( ( s:: current_version. nullable ( ) , s:: pending_version. nullable ( ) ) )
734+ . filter ( s:: id. eq ( subgraph_id) )
735+ . first :: < ( Option < String > , Option < String > ) > ( conn)
736+ . optional ( ) ?
737+ . unwrap_or ( ( None , None ) ) )
738+ }
739+
740+ /// Returns all (subgraph_name, version) pairs for a given deployment hash.
741+ pub fn subgraphs_by_deployment_hash (
742+ conn : & mut PgConnection ,
743+ deployment_hash : & str ,
744+ ) -> Result < Vec < ( String , String ) > , StoreError > {
745+ v:: table
746+ . inner_join (
747+ s:: table. on ( v:: id
748+ . nullable ( )
749+ . eq ( s:: current_version)
750+ . or ( v:: id. nullable ( ) . eq ( s:: pending_version) ) ) ,
751+ )
752+ . filter ( v:: deployment. eq ( & deployment_hash) )
753+ . select ( (
754+ s:: name,
755+ sql :: < Text > (
756+ "(case when subgraphs.subgraph.pending_version = subgraphs.subgraph_version.id then 'pending'
757+ when subgraphs.subgraph.current_version = subgraphs.subgraph_version.id then 'current'
758+ else 'unused'
759+ end) as version" ,
760+ ) ,
761+ ) )
762+ . get_results ( conn)
763+ . map_err ( Into :: into)
764+ }
727765}
728766
729767/// A wrapper for a database connection that provides access to functionality
@@ -2079,6 +2117,21 @@ impl Mirror {
20792117 self . read ( |conn| queries:: version_info ( conn, version) )
20802118 }
20812119
2120+ pub fn versions_for_subgraph_id (
2121+ & self ,
2122+ subgraph_id : & str ,
2123+ ) -> Result < ( Option < String > , Option < String > ) , StoreError > {
2124+ self . read ( |conn| queries:: versions_for_subgraph_id ( conn, subgraph_id) )
2125+ }
2126+
2127+ /// Returns all (subgraph_name, version) pairs for a given deployment hash.
2128+ pub fn subgraphs_by_deployment_hash (
2129+ & self ,
2130+ deployment_hash : & str ,
2131+ ) -> Result < Vec < ( String , String ) > , StoreError > {
2132+ self . read ( |conn| queries:: subgraphs_by_deployment_hash ( conn, deployment_hash) )
2133+ }
2134+
20822135 pub fn find_site_in_shard (
20832136 & self ,
20842137 subgraph : & DeploymentHash ,
0 commit comments