Schema for DB Sync persistent connections between PhoenixKit instances.
Connections allow two PhoenixKit sites to establish a permanent relationship for data synchronization, replacing ephemeral session codes with token-based authentication.
Direction
Each connection has a direction:
"sender"- This site will send data (configured on the data-sharing site)"receiver"- This site will receive data (configured on the data-receiving site)
Approval Modes (Sender-side)
"auto_approve"- All transfers are automatically approved"require_approval"- Each transfer needs manual approval"per_table"- Tables inauto_approve_tablesdon't need approval, others do
Status Flow
pending → active → suspended → revoked
↘
expired (auto-set when limits exceeded or past expires_at)Security Features
- Token-based authentication (auth_token_hash)
- Optional download password
- IP whitelist
- Time-of-day restrictions
- Download and record limits
- Expiration date
Usage Examples
# Create a sender connection
{:ok, conn} = Connections.create_connection(%{
name: "Production Receiver",
direction: "sender",
site_url: "https://receiver.example.com",
approval_mode: "auto_approve"
})
# Approve a pending connection
{:ok, conn} = Connections.approve_connection(conn, admin_user_id)
# Suspend a connection
{:ok, conn} = Connections.suspend_connection(conn, admin_user_id, "Security audit")
Summary
Functions
Checks if a connection is currently active and within limits.
Changeset for approving a connection.
Creates a changeset for connection creation.
Checks if a connection has expired.
Generates a secure random token for connection authentication.
Checks if an IP address is in the whitelist.
Changeset for reactivating a suspended connection.
Checks if a table requires approval based on the connection's approval mode.
Changeset for revoking a connection.
Changeset for updating connection settings.
Changeset for updating connection statistics.
Changeset for suspending a connection.
Checks if a table is allowed to be accessed.
Verifies an auth token against the stored hash.
Verifies a download password against the stored hash.
Checks if current time is within allowed hours.
Checks if a connection is within download limits.
Checks if a connection is within record limits.
Types
@type t() :: %PhoenixKit.Modules.Sync.Connection{ __meta__: term(), allowed_hours_end: term(), allowed_hours_start: term(), allowed_tables: term(), approval_mode: term(), approved_at: term(), approved_by: term(), approved_by_user: term(), approved_by_uuid: term(), auth_token: term(), auth_token_hash: term(), auto_approve_tables: term(), auto_sync_enabled: term(), auto_sync_interval_minutes: term(), auto_sync_tables: term(), created_by: term(), created_by_user: term(), created_by_uuid: term(), default_conflict_strategy: term(), direction: term(), download_password: term(), download_password_hash: term(), downloads_used: term(), excluded_tables: term(), expires_at: term(), id: term(), inserted_at: term(), ip_whitelist: term(), last_connected_at: term(), last_transfer_at: term(), max_downloads: term(), max_records_per_request: term(), max_records_total: term(), metadata: term(), name: term(), rate_limit_requests_per_minute: term(), records_downloaded: term(), revoked_at: term(), revoked_by: term(), revoked_by_user: term(), revoked_by_uuid: term(), revoked_reason: term(), site_url: term(), status: term(), suspended_at: term(), suspended_by: term(), suspended_by_user: term(), suspended_by_uuid: term(), suspended_reason: term(), total_bytes_transferred: term(), total_records_transferred: term(), total_transfers: term(), updated_at: term(), uuid: term() }
Functions
Checks if a connection is currently active and within limits.
Changeset for approving a connection.
Creates a changeset for connection creation.
Checks if a connection has expired.
Generates a secure random token for connection authentication.
Checks if an IP address is in the whitelist.
Changeset for reactivating a suspended connection.
Checks if a table requires approval based on the connection's approval mode.
Changeset for revoking a connection.
Changeset for updating connection settings.
Changeset for updating connection statistics.
Changeset for suspending a connection.
Checks if a table is allowed to be accessed.
Verifies an auth token against the stored hash.
Verifies a download password against the stored hash.
Checks if current time is within allowed hours.
Checks if a connection is within download limits.
Checks if a connection is within record limits.