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> {
14131413 Ok ( ( ) )
14141414 }
14151415
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+
14161427 pub fn list_unused_deployments (
14171428 & self ,
14181429 filter : unused:: Filter ,
Original file line number Diff line number Diff line change @@ -767,36 +767,28 @@ impl SubgraphStoreInner {
767767 let store = self . for_site ( site. as_ref ( ) ) ?;
768768
769769 // 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 ( ) ;
780771
781772 // Check that it is not current/pending for any subgraph if it is
782773 // the active deployment of that subgraph
783774 if site. active {
784- let versions = self
775+ if ! self
785776 . 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 ;
794781 }
795782 }
796783
797- store. drop_deployment ( & site) ?;
784+ if removable {
785+ store. drop_deployment ( & site) ?;
798786
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+ }
800792
801793 Ok ( ( ) )
802794 }
You can’t perform that action at this time.
0 commit comments