Skip to main content

add_to_collection

Function add_to_collection 

Source
pub fn add_to_collection(
    templates_dir: &Path,
    store: &Store,
    hub_slug: &str,
    collection_slug: &str,
) -> Result<TemplateRecord, TemplateError>
Expand description

Install a catalog entry into a user-chosen collection.

  • When neither the file nor a membership row exists, this is a normal first install: write the canonical JSON, write the sibling DSL, upsert the membership row.
  • When the file exists AND a membership row exists, refuse - the caller must explicitly go through update_installed to overwrite.
  • When the file exists but no row references it (the DB was reset, migrated, or the row was hand-deleted), heal silently: write the missing row pointing at the on-disk file without overwriting any user edits. The user clicked Add and now the install is tracked, which is what they wanted.