Skip to content

Sync 0.1.0: Pull data between PhoenixKit sites over permanent connections

Sync 0.1.0 is the first release of the PhoenixKit data sync module. It connects two PhoenixKit sites, for example development and production, so one can pull table data from the other, and it keeps a history of every transfer.

Connections between sites

Under Sync in the admin, Connections has two lists. Outgoing holds the sites that can pull data from this one: you add one with New Connection, giving a name and the other site’s URL. The module creates a token, stores only its hash and shows the token once. It then calls the other site’s API, which adds a matching connection to its Incoming list, the sites it can pull data from. If that call fails, you can share the token by hand.

What the other site does with the request depends on its incoming mode: accept it at once, keep it pending for approval (the default), ask for a password, or refuse it. The mode is set in code with PhoenixKitSync.set_incoming_mode/1; the admin has no switch for it.

A connection can be approved, suspended, reactivated or revoked, and its token regenerated. The form holds the name, direction, site URL and default conflict strategy. A connection also has fields for allowed and excluded tables, download and record limits, an IP whitelist, allowed hours and an expiry date, set through the module’s functions.

Pulling data

An incoming connection has a sync page with two tabs. Bulk Transfer lists the other site’s tables next to the local row counts: pick tables and a conflict strategy, and pull. Precise Transfer works on one table: its schema, a preview that can be narrowed to some IDs or an ID range, and Create Table when the table does not exist here yet. The strategies are skip existing records, overwrite them, merge with them, or append. The results screen shows what was imported, skipped or failed.

Some tables are never offered: schema_migrations, Oban’s tables and anything starting with pg_.

History

History lists the transfers with their direction, table, records, status, connection and date, can be filtered by direction and status, and lets an admin approve or deny a transfer waiting for approval.

Getting started

Add {:phoenix_kit_sync, "~> 0.1.0"} to your app; it needs PhoenixKit 1.7. Enable Sync under Modules in the admin. The two tables come from PhoenixKit’s core migrations; where they are missing, PhoenixKitSync.Migration.up/0 creates them. Scheduled automatic sync is not part of this version: the connection has the fields, but nothing runs them.

 

 


Sync 0.1.0. Install or update: {:phoenix_kit_sync, "~> 0.1"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.