# `PhoenixKit.Modules.Sync.Transfer`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L1)

Schema for DB Sync data transfers.

Tracks all data transfers between PhoenixKit instances, including both
uploads (sending data) and downloads (receiving data).

## Direction

- `"send"` - This site sent data to another site
- `"receive"` - This site received data from another site

## Status Flow

```
pending → pending_approval → approved → in_progress → completed
                          ↘
                          denied
                          ↘
                          expired (approval timed out)

pending → in_progress → completed
                     ↘
                     failed
                     ↘
                     cancelled
```

## Record Tracking

The transfer tracks various record counts:
- `records_requested` - Total records requested
- `records_transferred` - Records actually transferred
- `records_created` - New records inserted
- `records_updated` - Existing records updated
- `records_skipped` - Records skipped due to conflicts
- `records_failed` - Records that failed to import

## Usage Examples

    # Create a transfer record
    {:ok, transfer} = Transfers.create_transfer(%{
      direction: "receive",
      connection_uuid: conn.uuid,
      table_name: "users",
      records_requested: 100,
      conflict_strategy: "skip"
    })

    # Update transfer progress
    {:ok, transfer} = Transfers.update_progress(transfer, %{
      records_transferred: 50,
      records_created: 45,
      records_skipped: 5
    })

    # Complete a transfer
    {:ok, transfer} = Transfers.complete_transfer(transfer)

# `t`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L67)

```elixir
@type t() :: %PhoenixKit.Modules.Sync.Transfer{
  __meta__: term(),
  approval_expires_at: term(),
  approved_at: term(),
  approved_by_user: term(),
  approved_by_uuid: term(),
  bytes_transferred: term(),
  completed_at: term(),
  conflict_strategy: term(),
  connection: term(),
  connection_uuid: term(),
  denial_reason: term(),
  denied_at: term(),
  denied_by_user: term(),
  denied_by_uuid: term(),
  direction: term(),
  error_message: term(),
  initiated_by_user: term(),
  initiated_by_uuid: term(),
  inserted_at: term(),
  metadata: term(),
  records_created: term(),
  records_failed: term(),
  records_requested: term(),
  records_skipped: term(),
  records_transferred: term(),
  records_updated: term(),
  remote_site_url: term(),
  requester_ip: term(),
  requester_user_agent: term(),
  requires_approval: term(),
  session_code: term(),
  started_at: term(),
  status: term(),
  table_name: term(),
  uuid: term()
}
```

# `active?`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L321)

Checks if a transfer is currently active.

# `approval_expired?`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L296)

Checks if a transfer's approval has expired.

# `approve_changeset`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L249)

Changeset for approving a transfer.

# `can_start?`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L305)

Checks if a transfer can be started.

# `cancel_changeset`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L224)

Changeset for cancelling a transfer.

# `changeset`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L132)

Creates a changeset for transfer creation.

# `complete_changeset`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L193)

Changeset for completing a transfer successfully.

# `deny_changeset`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L261)

Changeset for denying a transfer.

# `duration_seconds`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L342)

Calculates the transfer duration in seconds.
Returns nil if transfer hasn't completed.

# `expire_changeset`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L274)

Changeset for marking a transfer approval as expired.

# `fail_changeset`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L212)

Changeset for marking a transfer as failed.

# `pending_approval?`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L290)

Checks if a transfer is pending approval.

# `progress_changeset`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L172)

Changeset for updating transfer progress.

# `request_approval_changeset`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L235)

Changeset for requesting approval.

# `start_changeset`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L161)

Changeset for starting a transfer.

# `success_rate`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L328)

Calculates the success rate of a transfer.
Returns a float between 0.0 and 1.0.

# `terminal?`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.62/lib/modules/sync/transfer.ex#L312)

Checks if a transfer is in a terminal state.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
