File tree Expand file tree Collapse file tree 2 files changed +24
-21
lines changed Expand file tree Collapse file tree 2 files changed +24
-21
lines changed Original file line number Diff line number Diff line change @@ -1413,6 +1413,17 @@ impl<'a> Connection<'a> {
1413
1413
Ok ( ( ) )
1414
1414
}
1415
1415
1416
+ /// The deployment `site` that we marked as unused previously is in fact
1417
+ /// now used again, e.g., because it was redeployed in between recording
1418
+ /// it as unused and now. Remove it from the `unused_deployments` table
1419
+ pub fn unused_deployment_is_used ( & self , site : & Site ) -> Result < ( ) , StoreError > {
1420
+ use unused_deployments as u;
1421
+ delete ( u:: table. filter ( u:: id. eq ( site. id ) ) )
1422
+ . execute ( self . conn . as_ref ( ) )
1423
+ . map ( |_| ( ) )
1424
+ . map_err ( StoreError :: from)
1425
+ }
1426
+
1416
1427
pub fn list_unused_deployments (
1417
1428
& self ,
1418
1429
filter : unused:: Filter ,
Original file line number Diff line number Diff line change @@ -767,36 +767,28 @@ impl SubgraphStoreInner {
767
767
let store = self . for_site ( site. as_ref ( ) ) ?;
768
768
769
769
// Check that deployment is not assigned
770
- match self . mirror . assigned_node ( site. as_ref ( ) ) ? {
771
- Some ( node) => {
772
- return Err ( constraint_violation ! (
773
- "deployment {} can not be removed since it is assigned to node {}" ,
774
- site. deployment. as_str( ) ,
775
- node. as_str( )
776
- ) ) ;
777
- }
778
- None => { /* ok */ }
779
- }
770
+ let mut removable = self . mirror . assigned_node ( site. as_ref ( ) ) ?. is_some ( ) ;
780
771
781
772
// Check that it is not current/pending for any subgraph if it is
782
773
// the active deployment of that subgraph
783
774
if site. active {
784
- let versions = self
775
+ if ! self
785
776
. primary_conn ( ) ?
786
- . subgraphs_using_deployment ( site. as_ref ( ) ) ?;
787
- if versions. len ( ) > 0 {
788
- return Err ( constraint_violation ! (
789
- "deployment {} can not be removed \
790
- since it is the current or pending version for the subgraph(s) {}",
791
- site. deployment. as_str( ) ,
792
- versions. join( ", " ) ,
793
- ) ) ;
777
+ . subgraphs_using_deployment ( site. as_ref ( ) ) ?
778
+ . is_empty ( )
779
+ {
780
+ removable = false ;
794
781
}
795
782
}
796
783
797
- store. drop_deployment ( & site) ?;
784
+ if removable {
785
+ store. drop_deployment ( & site) ?;
798
786
799
- self . primary_conn ( ) ?. drop_site ( site. as_ref ( ) ) ?;
787
+ self . primary_conn ( ) ?. drop_site ( site. as_ref ( ) ) ?;
788
+ } else {
789
+ self . primary_conn ( ) ?
790
+ . unused_deployment_is_used ( site. as_ref ( ) ) ?;
791
+ }
800
792
801
793
Ok ( ( ) )
802
794
}
You can’t perform that action at this time.
0 commit comments