MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / reset

Function reset

crates/client-api/src/routes/database.rs:833–877  ·  view source on GitHub ↗
(
    State(ctx): State<S>,
    Path(ResetDatabaseParams { name_or_identity }): Path<ResetDatabaseParams>,
    Query(ResetDatabaseQueryParams {
        num_replicas,
        host_type,
    }): Query<R

Source from the content-addressed store, hash-verified

831}
832
833pub 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)]
880pub struct PublishDatabaseParams {

Callers 1

publishFunction · 0.85

Calls 10

worker_ctx_find_databaseFunction · 0.85
flattenMethod · 0.80
nameMethod · 0.65
ErrFunction · 0.50
OkFunction · 0.50
resolveMethod · 0.45
authorize_actionMethod · 0.45
is_database_lockedMethod · 0.45
mapMethod · 0.45
reset_databaseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…