Sync connections: link two sites so one can pull data from the other
Describes Sync 0.4.0.
A connection lets another PhoenixKit site pull tables from this one, or lets this site pull from another. You create the outgoing side here; the other site gets the matching incoming connection on its own.
Where to find it
In the admin sidebar, open Sync. Its subpages are Overview, Connections and History. The pages are at /admin/sync, /admin/sync/connections and /admin/sync/history. You need the Admin or Owner role, or a role with the Sync permission.
The Sync module must be enabled on the Modules page. While it is off, the Overview page says The DB Sync module is disabled. with a link, Enable it on the Modules page, and its two cards can’t be clicked.
DB Sync.
The Overview page
The page is titled DB Sync. It has two cards:
- Manage Connections opens the Connections page.
- Transfer History, with its View History button, opens the History page.
Below them, How Cross-Site Connections Work sums up the two roles, As a Sender and As a Receiver.
Two kinds of connection
- Outgoing (shown as Sender): “Sites that can pull data from this site”. You create these.
- Incoming (shown as Receiver): “Sites this site can pull data from”. These appear when another site creates an outgoing connection to you.
Only an outgoing connection gives the other site access. An incoming one is this site’s pass to read the other site’s data and gives that site nothing here.
The Connections list
The page shows an Outgoing card and an Incoming card, each with a count. The menu at the top left narrows it to All Connections, Outgoing Only or Incoming Only.
Connections to other sites.
Outgoing rows show Name, Site URL and Status. Incoming rows show Site URL and Status. For an active incoming connection, the status is the one the other site reports, so it may read Loading at first, or Offline, Not found or Error when the other site can’t be asked. Other incoming rows show their own status.
The buttons on a row:
- Sync data: only on an incoming row whose sending site reports it active. Opens the page where you pull tables; see the guide on pulling data.
- View details: the connection’s own page.
- Edit: change its settings.
- Delete connection (outgoing) or Sever connection (incoming): asks “Are you sure you want to delete this connection? You will need to set it up again.” and then deletes it here. The other site is told to delete its side too.
- Approve: only on a Pending connection, in either list.
- Suspend: only on an active outgoing connection.
- Reactivate: only on a suspended outgoing connection.
Each status change on an outgoing connection is reported to the other site.
When you open the page, this site also checks each outgoing connection with the other site. If the other site says it no longer has it, the connection is suspended here and a message says so. You can then delete it, or reactivate it.
Creating an outgoing connection
Click New Connection. The form has:
- Name *: your label for it, for example the other site’s name.
- Direction: always Sender here: “Allow remote site to pull data from here”.
- Site URL *: “The URL of the remote site that will connect to pull data”.
- Records per request: the most rows the other site gets in one answer. Larger tables are sent in pages.
Click Create Connection. The connection is created Pending, and the page says: “Connection created. It is pending: approve it in the list before the other site can use it”. Click Approve on its row when the other site may start pulling. Until then it grants nothing.
At the same time, this site contacts the other site to register the matching incoming connection there. What happens next depends on how the other site handles incoming connections:
- Require Approval (the default): the incoming connection waits as Pending until an admin there approves it.
- auto accept: it is active at once.
- Require Password: it is accepted only with the right password.
- deny all: it is refused.
Approving an incoming connection
An incoming connection that arrives under Require Approval shows as Pending in the Incoming card. Click Approve on its row. Until you do, this site never contacts the other site for it, and it can’t be used to pull data.
At most 50 incoming connections wait for approval at a time. Further requests are refused until some are approved or deleted.
The connection’s own page
View details shows:
- Direction and Site URL.
- For an incoming connection, Import Settings with its Conflict Strategy.
- Statistics: Total Transfers, Records Transferred, Bytes Transferred, Last Connected and Last Transfer (Never until it happens).
- Actions: Suspend or Reactivate (outgoing only), Revoke while the connection isn’t revoked yet (it asks “Are you sure you want to revoke this connection?”), and Delete.
Back to List returns to the list.
Statuses
- Pending: created, not approved yet. It grants and uses nothing.
- Active: in use.
- Suspended: switched off for now. An outgoing connection can be reactivated.
- Revoked: switched off for good.
The other site can suspend or revoke your incoming connection from its side, and lift a suspension it made. It can’t approve a pending connection here, and it can’t change your outgoing connections.
Editing a connection
Edit opens the same form with Save Changes. For an outgoing connection you can change Name, Site URL and Records per request. For an incoming connection there is also Default Conflict Strategy, the strategy the sync page starts with:
- Skip - Don’t overwrite existing records
- Overwrite - Replace existing records
- Merge - Combine with existing records
The direction can’t be changed, and the form never changes the status.
What it doesn’t do
- The form doesn’t set the other access controls: allowed and excluded tables, download and record limits, a download password, an IP whitelist, allowed hours, an expiry date or requests per minute. They exist and are enforced, but a developer sets them in code.
- There’s no page for choosing how this site handles incoming connections (auto accept, Require Approval and so on). It stays Require Approval unless a developer changes it.
- The connection’s token is never shown, and there’s no button to replace it: to get a new token, delete the connection and create it again.
- Scheduled, automatic syncing isn’t implemented. Every pull is started by hand.
- Some tables are never synced whatever a connection allows: Sync’s own tables, the settings table, and tables that hold session tokens, OAuth tokens, invitations and provider keys, among others. The users table, password hashes included, is synced to any connection whose tables allow it, so connect only to sites you fully trust.
For developers
The settings the form leaves out are set with PhoenixKitSync.Connections.update_connection/2. The incoming mode and its password are set with PhoenixKitSync.set_incoming_mode/1 ("auto_accept", "require_approval", "require_password", "deny_all") and PhoenixKitSync.set_incoming_password/1.
A connection’s Site URL may not point at localhost or a private address unless you allow it:
config :phoenix_kit_sync, allow_internal_urls: true
If the other site mounts PhoenixKit under a different URL prefix, set config :phoenix_kit_sync, remote_url_prefix: "/prefix". The waiting-approval cap is max_pending_incoming (default 50).