(
State(ctx): State<S>,
Path(ResetDatabaseParams { name_or_identity }): Path<ResetDatabaseParams>,
Query(ResetDatabaseQueryParams {
num_replicas,
host_type,
}): Query<R
| 831 | } |
| 832 | |
| 833 | pub async fn reset<S: NodeDelegate + ControlStateDelegate + Authorization>( |
| 834 | State(ctx): State<S>, |
| 835 | Path(ResetDatabaseParams { name_or_identity }): Path<ResetDatabaseParams>, |
| 836 | Query(ResetDatabaseQueryParams { |
| 837 | num_replicas, |
| 838 | host_type, |
| 839 | }): Query<ResetDatabaseQueryParams>, |
| 840 | Extension(auth): Extension<SpacetimeAuth>, |
| 841 | program_bytes: Option<Bytes>, |
| 842 | ) -> axum::response::Result<axum::Json<PublishResult>> { |
| 843 | let database_identity = name_or_identity.resolve(&ctx).await?; |
| 844 | let database = worker_ctx_find_database(&ctx, &database_identity) |
| 845 | .await? |
| 846 | .ok_or(NO_SUCH_DATABASE)?; |
| 847 | |
| 848 | ctx.authorize_action(auth.claims.identity, database.database_identity, Action::ResetDatabase) |
| 849 | .await?; |
| 850 | |
| 851 | if ctx.is_database_locked(&database_identity).await.map_err(log_and_500)? { |
| 852 | return Err(( |
| 853 | StatusCode::FORBIDDEN, |
| 854 | "Database is locked and cannot be reset with --delete-data. Run `spacetime unlock` first.", |
| 855 | ) |
| 856 | .into()); |
| 857 | } |
| 858 | |
| 859 | let num_replicas = num_replicas.map(validate_replication_factor).transpose()?.flatten(); |
| 860 | ctx.reset_database( |
| 861 | &auth.claims.identity, |
| 862 | DatabaseResetDef { |
| 863 | database_identity, |
| 864 | program_bytes, |
| 865 | num_replicas, |
| 866 | host_type: Some(host_type), |
| 867 | }, |
| 868 | ) |
| 869 | .await |
| 870 | .map_err(log_and_500)?; |
| 871 | |
| 872 | Ok(axum::Json(PublishResult::Success { |
| 873 | domain: name_or_identity.name().cloned(), |
| 874 | database_identity, |
| 875 | op: PublishOp::Updated, |
| 876 | })) |
| 877 | } |
| 878 | |
| 879 | #[derive(Deserialize)] |
| 880 | pub struct PublishDatabaseParams { |
no test coverage detected
searching dependent graphs…