use nodedb_types::sync::wire::{CollectionDescriptor, CollectionSchemaSyncMsg};
use tracing::warn;
use crate::control::state::SharedState;
use super::super::session::SyncSession;
use super::super::wire::{SyncFrame, SyncMessageType};
pub(in crate::control::server::sync) fn build_collection_schema_frame(
shared: &SharedState,
session: &SyncSession,
tenant_id: u64,
collection: &str,
) -> Option<SyncFrame> {
if session.announced_collections.contains(collection) {
return None;
}
let stored = shared
.credentials
.catalog()
.get_collection(crate::types::DatabaseId::DEFAULT, tenant_id, collection)
.ok()
.flatten();
let Some(stored) = stored else {
warn!(
session = %session.session_id,
collection,
tenant_id,
"sync: collection not found in catalog; cannot announce schema before data"
);
return None;
};
let msg = CollectionSchemaSyncMsg {
descriptor: CollectionDescriptor::from(&stored),
creation_hlc: nodedb_types::hlc::Hlc::ZERO,
};
SyncFrame::new_msgpack(SyncMessageType::CollectionSchema, &msg)
}