@@ -11,14 +11,13 @@ use graph::{
11
11
components:: store:: DeploymentLocator ,
12
12
data:: subgraph:: status,
13
13
prelude:: {
14
- anyhow:: { self , anyhow , bail } ,
15
- lazy_static, DeploymentHash , Error , SubgraphStore as _ ,
14
+ anyhow:: { self } ,
15
+ lazy_static, DeploymentHash ,
16
16
} ,
17
17
} ;
18
+ use graph_store_postgres:: command_support:: catalog as store_catalog;
18
19
use graph_store_postgres:: connection_pool:: ConnectionPool ;
19
- use graph_store_postgres:: { command_support:: catalog as store_catalog, Shard , SubgraphStore } ;
20
20
21
- use crate :: manager:: deployment;
22
21
use crate :: manager:: display:: List ;
23
22
24
23
lazy_static ! {
@@ -156,50 +155,6 @@ pub struct Deployment {
156
155
}
157
156
158
157
impl Deployment {
159
- pub fn lookup ( primary : & ConnectionPool , name : & str ) -> Result < Vec < Self > , anyhow:: Error > {
160
- let conn = primary. get ( ) ?;
161
- Self :: lookup_with_conn ( & conn, name)
162
- }
163
-
164
- pub fn lookup_with_conn ( conn : & PgConnection , name : & str ) -> Result < Vec < Self > , anyhow:: Error > {
165
- use store_catalog:: deployment_schemas as ds;
166
- use store_catalog:: subgraph as s;
167
- use store_catalog:: subgraph_deployment_assignment as a;
168
- use store_catalog:: subgraph_version as v;
169
-
170
- let query = ds:: table
171
- . inner_join ( v:: table. on ( v:: deployment. eq ( ds:: subgraph) ) )
172
- . inner_join ( s:: table. on ( v:: subgraph. eq ( s:: id) ) )
173
- . left_outer_join ( a:: table. on ( a:: id. eq ( ds:: id) ) )
174
- . select ( (
175
- s:: name,
176
- sql :: < Text > (
177
- "(case
178
- when subgraphs.subgraph.pending_version = subgraphs.subgraph_version.id then 'pending'
179
- when subgraphs.subgraph.current_version = subgraphs.subgraph_version.id then 'current'
180
- else 'unused' end) status" ,
181
- ) ,
182
- v:: deployment,
183
- ds:: name,
184
- ds:: id,
185
- a:: node_id. nullable ( ) ,
186
- ds:: shard,
187
- ds:: network,
188
- ds:: active,
189
- ) ) ;
190
-
191
- let deployments: Vec < Deployment > = if name. starts_with ( "sgd" ) {
192
- query. filter ( ds:: name. eq ( & name) ) . load ( conn) ?
193
- } else if name. starts_with ( "Qm" ) {
194
- query. filter ( ds:: subgraph. eq ( & name) ) . load ( conn) ?
195
- } else {
196
- // A subgraph name
197
- let pattern = format ! ( "%{}%" , name) ;
198
- query. filter ( s:: name. ilike ( & pattern) ) . load ( conn) ?
199
- } ;
200
- Ok ( deployments)
201
- }
202
-
203
158
pub fn locator ( & self ) -> DeploymentLocator {
204
159
DeploymentLocator :: new (
205
160
DeploymentId ( self . id ) ,
@@ -262,60 +217,3 @@ impl Deployment {
262
217
list. render ( ) ;
263
218
}
264
219
}
265
-
266
- pub fn locate (
267
- store : & SubgraphStore ,
268
- hash : String ,
269
- shard : Option < String > ,
270
- ) -> Result < DeploymentLocator , Error > {
271
- let hash = deployment:: as_hash ( hash) ?;
272
-
273
- fn locate_unique ( store : & SubgraphStore , hash : String ) -> Result < DeploymentLocator , Error > {
274
- let locators = store. locators ( & hash) ?;
275
-
276
- match locators. len ( ) {
277
- 0 => {
278
- bail ! ( "no matching assignment" ) ;
279
- }
280
- 1 => Ok ( locators[ 0 ] . clone ( ) ) ,
281
- _ => {
282
- bail ! (
283
- "deployment hash `{}` is ambiguous: {} locations found" ,
284
- hash,
285
- locators. len( )
286
- ) ;
287
- }
288
- }
289
- }
290
-
291
- match shard {
292
- Some ( shard) => store
293
- . locate_in_shard ( & hash, Shard :: new ( shard. clone ( ) ) ?) ?
294
- . ok_or_else ( || anyhow ! ( "no deployment with hash `{}` in shard {}" , hash, shard) ) ,
295
- None => locate_unique ( store, hash. to_string ( ) ) ,
296
- }
297
- }
298
-
299
- pub fn as_hash ( hash : String ) -> Result < DeploymentHash , Error > {
300
- DeploymentHash :: new ( hash) . map_err ( |s| anyhow ! ( "illegal deployment hash `{}`" , s) )
301
- }
302
-
303
- /// Finds a single deployment locator for the given deployment identifier.
304
- pub fn find_single_deployment_locator (
305
- pool : & ConnectionPool ,
306
- name : & str ,
307
- ) -> anyhow:: Result < DeploymentLocator > {
308
- let mut locators: Vec < DeploymentLocator > = HashSet :: < DeploymentLocator > :: from_iter (
309
- Deployment :: lookup ( pool, name) ?
310
- . into_iter ( )
311
- . map ( |deployment| deployment. locator ( ) ) ,
312
- )
313
- . into_iter ( )
314
- . collect ( ) ;
315
- let deployment_locator = match locators. len ( ) {
316
- 0 => anyhow:: bail!( "Found no deployment for `{}`" , name) ,
317
- 1 => locators. pop ( ) . unwrap ( ) ,
318
- n => anyhow:: bail!( "Found {} deployments for `{}`" , n, name) ,
319
- } ;
320
- Ok ( deployment_locator)
321
- }
0 commit comments