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

Function publish

crates/client-api/src/routes/database.rs:928–1095  ·  view source on GitHub ↗
(
    State(ctx): State<S>,
    Path(PublishDatabaseParams { name_or_identity }): Path<PublishDatabaseParams>,
    Query(PublishDatabaseQueryParams {
        clear,
        num_replicas,
        token

Source from the content-addressed store, hash-verified

926const MAX_UPDATE_CONFIRMATION_TIMEOUT: Duration = Duration::from_secs(5 * 60);
927
928pub async fn publish<S: NodeDelegate + ControlStateDelegate + Authorization>(
929 State(ctx): State<S>,
930 Path(PublishDatabaseParams { name_or_identity }): Path<PublishDatabaseParams>,
931 Query(PublishDatabaseQueryParams {
932 clear,
933 num_replicas,
934 token,
935 policy,
936 host_type,
937 parent,
938 organization,
939 update_confirmation_timeout: confirmation_timeout,
940 }): Query<PublishDatabaseQueryParams>,
941 Extension(auth): Extension<SpacetimeAuth>,
942 program_bytes: Bytes,
943) -> axum::response::Result<axum::Json<PublishResult>> {
944 // If `clear`, check that the database exists and delegate to `reset`.
945 // If it doesn't exist, ignore the `clear` parameter.
946 // TODO: Replace with actual redirect at the next possible version bump.
947 if clear {
948 let name_or_identity = name_or_identity
949 .as_ref()
950 .ok_or_else(|| bad_request("Clear database requires database name or identity".into()))?;
951 let database_identity = name_or_identity.try_resolve(&ctx).await.map_err(log_and_500)?;
952 if let Ok(identity) = database_identity {
953 let exists = ctx
954 .get_database_by_identity(&identity)
955 .await
956 .map_err(log_and_500)?
957 .is_some();
958 if exists {
959 if parent.is_some() {
960 return Err(bad_request(
961 "Setting the parent of an existing database is not supported".into(),
962 ));
963 }
964
965 return self::reset(
966 State(ctx),
967 Path(ResetDatabaseParams {
968 name_or_identity: name_or_identity.clone(),
969 }),
970 Query(ResetDatabaseQueryParams {
971 num_replicas,
972 host_type,
973 }),
974 Extension(auth),
975 Some(program_bytes),
976 )
977 .await;
978 }
979 }
980 }
981
982 let (database_identity, db_name) = get_or_create_identity_and_name(&ctx, &auth, name_or_identity.as_ref()).await?;
983 let maybe_parent_database_identity = match parent.as_ref() {
984 None => None,
985 Some(parent) => parent.resolve(&ctx).await.map(Some)?,

Callers

nothing calls this directly

Calls 15

bad_requestFunction · 0.85
resetFunction · 0.85
QueryInterface · 0.85
allow_creationFunction · 0.85
schema_migration_policyFunction · 0.85
try_resolveMethod · 0.80
flattenMethod · 0.80
wait_forMethod · 0.80
ErrFunction · 0.50
OkFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…