Skip to content

Commit 3e3dc02

Browse files
committed
store: postgres - add pause_subgraph and resume_subgraph methods
1 parent 1577dd3 commit 3e3dc02

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

store/postgres/src/primary.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,44 @@ impl<'a> Connection<'a> {
981981
}
982982
}
983983

984+
pub fn pause_subgraph(&self, site: &Site) -> Result<(), StoreError> {
985+
use subgraph_deployment_assignment as a;
986+
987+
let conn = self.conn.as_ref();
988+
989+
let updates = update(a::table.filter(a::id.eq(site.id)))
990+
.set(a::paused_at.eq(sql("now()")))
991+
.execute(conn)?;
992+
match updates {
993+
0 => Err(StoreError::DeploymentNotFound(site.deployment.to_string())),
994+
1 => Ok(()),
995+
_ => {
996+
// `id` is the primary key of the subgraph_deployment_assignment table,
997+
// and we can therefore only update no or one entry
998+
unreachable!()
999+
}
1000+
}
1001+
}
1002+
1003+
pub fn resume_subgraph(&self, site: &Site) -> Result<(), StoreError> {
1004+
use subgraph_deployment_assignment as a;
1005+
1006+
let conn = self.conn.as_ref();
1007+
1008+
let updates = update(a::table.filter(a::id.eq(site.id)))
1009+
.set(a::paused_at.eq(sql("null")))
1010+
.execute(conn)?;
1011+
match updates {
1012+
0 => Err(StoreError::DeploymentNotFound(site.deployment.to_string())),
1013+
1 => Ok(()),
1014+
_ => {
1015+
// `id` is the primary key of the subgraph_deployment_assignment table,
1016+
// and we can therefore only update no or one entry
1017+
unreachable!()
1018+
}
1019+
}
1020+
}
1021+
9841022
pub fn reassign_subgraph(
9851023
&self,
9861024
site: &Site,

0 commit comments

Comments
 (0)