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
↘
cancelledRecord Tracking
The transfer tracks various record counts:
records_requested- Total records requestedrecords_transferred- Records actually transferredrecords_created- New records insertedrecords_updated- Existing records updatedrecords_skipped- Records skipped due to conflictsrecords_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)
Summary
Types
A transfer row. An association is Ecto.Association.NotLoaded until
preloaded. There is no updated_at: the lifecycle is in the status and
its *_at fields.
Functions
Checks if a transfer is currently active.
Checks if a transfer's approval has expired.
Changeset for approving a transfer.
Checks if a transfer can be started.
Changeset for cancelling a transfer.
Creates a changeset for transfer creation.
Changeset for completing a transfer successfully.
Changeset for denying a transfer.
Calculates the transfer duration in seconds. Returns nil if transfer hasn't completed.
Changeset for marking a transfer approval as expired.
Changeset for marking a transfer as failed. stats takes the same record
counts as complete_changeset/2, for a transfer that moved some rows
before it stopped.
Changeset for a transfer recorded once it is over, in one write: the
creation fields plus its record counts, its final status ("completed"
or "failed") and, for a failure, the error_message.
Checks if a transfer is pending approval.
Changeset for updating transfer progress.
Changeset for requesting approval.
Changeset for starting a transfer.
Calculates the success rate of a transfer. Returns a float between 0.0 and 1.0.
Checks if a transfer is in a terminal state.
Types
@type t() :: %PhoenixKitSync.Transfer{ __meta__: term(), approval_expires_at: DateTime.t() | nil, approved_at: DateTime.t() | nil, approved_by_user: PhoenixKit.Users.Auth.User.t() | Ecto.Association.NotLoaded.t() | nil, approved_by_uuid: UUIDv7.t() | nil, bytes_transferred: integer() | nil, completed_at: DateTime.t() | nil, conflict_strategy: String.t() | nil, connection: PhoenixKitSync.Connection.t() | Ecto.Association.NotLoaded.t() | nil, connection_uuid: UUIDv7.t() | nil, denial_reason: String.t() | nil, denied_at: DateTime.t() | nil, denied_by_user: PhoenixKit.Users.Auth.User.t() | Ecto.Association.NotLoaded.t() | nil, denied_by_uuid: UUIDv7.t() | nil, direction: String.t() | nil, error_message: String.t() | nil, initiated_by_user: PhoenixKit.Users.Auth.User.t() | Ecto.Association.NotLoaded.t() | nil, initiated_by_uuid: UUIDv7.t() | nil, inserted_at: DateTime.t() | nil, metadata: map() | nil, records_created: integer() | nil, records_failed: integer() | nil, records_requested: integer() | nil, records_skipped: integer() | nil, records_transferred: integer() | nil, records_updated: integer() | nil, remote_site_url: String.t() | nil, requester_ip: String.t() | nil, requester_user_agent: String.t() | nil, requires_approval: boolean() | nil, session_code: String.t() | nil, started_at: DateTime.t() | nil, status: String.t() | nil, table_name: String.t() | nil, uuid: UUIDv7.t() | nil }
A transfer row. An association is Ecto.Association.NotLoaded until
preloaded. There is no updated_at: the lifecycle is in the status and
its *_at fields.
Functions
Checks if a transfer is currently active.
Checks if a transfer's approval has expired.
@spec approve_changeset(t(), String.t() | map() | nil) :: Ecto.Changeset.t()
Changeset for approving a transfer.
Checks if a transfer can be started.
@spec cancel_changeset(t()) :: Ecto.Changeset.t()
Changeset for cancelling a transfer.
@spec changeset(t() | Ecto.Changeset.t(), map()) :: Ecto.Changeset.t()
Creates a changeset for transfer creation.
@spec complete_changeset(t(), map()) :: Ecto.Changeset.t()
Changeset for completing a transfer successfully.
@spec deny_changeset(t(), String.t() | map() | nil, String.t() | nil) :: Ecto.Changeset.t()
Changeset for denying a transfer.
@spec duration_seconds(t()) :: non_neg_integer() | nil
Calculates the transfer duration in seconds. Returns nil if transfer hasn't completed.
@spec expire_changeset(t()) :: Ecto.Changeset.t()
Changeset for marking a transfer approval as expired.
@spec fail_changeset(t(), String.t(), map()) :: Ecto.Changeset.t()
Changeset for marking a transfer as failed. stats takes the same record
counts as complete_changeset/2, for a transfer that moved some rows
before it stopped.
@spec finished_changeset(t(), map(), String.t(), String.t() | nil) :: Ecto.Changeset.t()
Changeset for a transfer recorded once it is over, in one write: the
creation fields plus its record counts, its final status ("completed"
or "failed") and, for a failure, the error_message.
Checks if a transfer is pending approval.
@spec progress_changeset(t(), map()) :: Ecto.Changeset.t()
Changeset for updating transfer progress.
@spec request_approval_changeset(t(), pos_integer()) :: Ecto.Changeset.t()
Changeset for requesting approval.
@spec start_changeset(t()) :: Ecto.Changeset.t()
Changeset for starting a transfer.
Calculates the success rate of a transfer. Returns a float between 0.0 and 1.0.
Checks if a transfer is in a terminal state.