ivy: flow/v1
name: Import customers
description: Copy the customers of another system into a collection every hour, and remove the ones that are gone.

on:
  schedule: { cron: "0 * * * *" } # every hour, on the hour

steps:
  - id: read
    code: Flows/import/read_customers.py # a code file of this space that writes {"customers": [...]} as its output
    connections: [crm] # the connection in connections.ivy.yaml the code reads the other system through
  - id: save
    record:
      collection: customers # a collection of this space that declares `key`
      upsert:
        from: "{{ steps.read.output.customers }}" # at most 500 items
        key: "{{ item.id }}"
        values: # the collection's fields, each from the item
          name: "{{ item.name }}"
          segment: "{{ item.segment }}"
          arr: "{{ item.arr }}"
      sync: { delete_missing: true } # deletes the customers the list no longer names
