Relay

Sync tables

What syncs, in which direction, with which operations allowed.

A sync table is one table, in one direction. It says who owns the data, what the receiving side is allowed to do with it, and where it lands in the queue when changes are applied.

Setting one up for the first time

Get started walks through configuring a table and running the capture script. This page describes the fields and screens themselves.

Direction

Direction records authorship: which database is the source for this table.

DirectionSourceCaptured onApplied to
UpThe school's local databaseLocalOnline
DownThe online databaseOnlineLocal

A side only captures the tables it owns, so direction decides which database's setup script grows a trigger for the table. A table edited on both sides is added once per direction.

Fields

Add sync table opens the same form Edit in the row menu opens, in a dialog. The arrow beside it has Add several tables, which opens a page for adding many at once. Adding, editing, activating, deactivating and removing sync tables is for admins only; other accounts see the list and its details but not those actions.

Add several tables adds many at once, all in one direction. Tick them in a searchable list of table names (hold Shift while ticking to tick or untick every name since the last one) and pick the direction; everything else is set per table. Each ticked table gets a row with its own Create, Update and Delete toggles, apply order and primary key column, so parents can be ordered ahead of the tables that point at them and each table can keep its own key. The All tables row above them sets any of those for every ticked table (and for any ticked afterwards); where the tables differ it shows Mixed. Names the school already syncs in that direction are greyed out, and any added by someone else in the meantime are skipped rather than failing the rest. Re-run the setup SQL afterwards so the new tables are captured; the toast that confirms the add has an Open Setup SQL button that opens the script for the source database.

Each name in the list says where the table exists: On both sides, Local only, Online only, On neither side, or Not scanned. Tick names and press Scan selected to ask both agents to describe them on their next cycle; the list updates once they answer. A scan reads column metadata only, never rows. Once a table is scanned, its row starts with the primary key the scan found rather than id, and the key you set is checked against its columns: a table without that column is marked No "id" column in the list and its key field is outlined in red, with the real key on hover. Agents older than 1.4.0 only describe tables they already sync, and the dialog says which side needs updating.

FieldDefaultNotes
Table name—Picked from Table names. It must be listed and switched on there; a table keeps its name if that entry is switched off later
Primary key columnidHow a row is matched on the receiving side
Apply order100Lower numbers are applied first
DirectionUpSee above
Create new rowsonInsert rows the receiving side does not have
Update existing rowsonOverwrite matching rows; soft deletes arrive as updates
Delete rowsoffRemove rows on the receiving side

Apply order keeps foreign keys satisfied. Changes are applied in this order, so a parent table needs a lower number than the rows that reference it. Unrelated tables stay at the default.

Delete is off by default. With it off, a delete on the source leaves the receiving row in place, so a mistaken mass delete cannot propagate.

The list

Each row shows the table name with its direction, the operations it allows as icons (hover one for its name), whether it is active, the row count on each side with the difference, and a Backfill button for admins. Search covers name, direction, primary key and active state, with separate Direction and Status filters.

A table's page

Click a row to open the table's own page. It shows the row counts and difference, the operations and apply order, when each side was last counted, any backfill or queued changes, and the Backfill, Recount now and row-menu actions.

Below that, Applied rows lists every row the agents wrote for the table, newest first and in both directions, with older rows loading as you scroll. Open a row to see the column values that were applied.

The row menu offers Copy table name, and for admins Edit, Deactivate or Activate, and Remove.

Deactivating discards what is queued

An inactive table disappears from the configuration the agent fetches, and the agent treats outbox rows for tables it does not recognise as unconfigured — they are marked handled and never sent. Deactivate to stop a table syncing, but expect changes captured while it was off to stay behind. Request a backfill after reactivating it.

Setup SQL

Configuring a table here does not capture anything by itself. The capture is done by database triggers, and those are created by the script behind Setup SQL.

The dialog has one tab per database, because each side only captures what it owns:

  • Local database — triggers for the UP tables.
  • Online database — triggers for the DOWN tables.

The script creates a sync_outbox table plus three triggers per synced table, and is safe to re-run. Above the script, Captures UP or Captures DOWN lists the tables it covers.

There are two ways to take the script out of the dialog:

  • Copy puts it on the clipboard, for pasting into SQLyog, HeidiSQL or another client that understands DELIMITER.
  • Download .sql saves it as <school code>-<side>-outbox.sql, for example riv001-local-outbox.sql, for piping into the mysql command line client.

A tab whose direction has no active tables reports that instead of a script, and both buttons are disabled.

Re-run it after every change to the table list

Adding a table in the dashboard does not create its triggers. Until the script is run again on that database, the table is configured but nothing is ever captured for it.

Checking the triggers

Each agent reads its database's capture triggers every cycle, and the school's Overview compares them with the tables configured here. The Capture triggers panel has one side per database:

StatusMeaning
Up to dateEvery configured table has exactly the triggers the script would create
IssuesA trigger is missing or out of date, so some changes are not captured, or are captured wrongly
Leftover triggersA trigger the configuration no longer wants. What it captures is discarded
Not checkedNo report yet. The agent reports on its next cycle

The comparison uses the configuration as it is now, so changing a table shows the triggers as out of date straight away, before the agent has checked again. Re-running the script clears it on that agent's next cycle.

Each missing or out-of-date trigger also shows the SQL for just that trigger: it drops it if present and creates it exactly as the script would, so one trigger can be fixed without re-running the whole script. Copy all at the top of a side copies every statement listed there, creates first and then the drops for leftovers, as one script to paste in.

An out-of-date trigger says why: it records a different column than the configured key, fires before the write instead of after it, or does not skip the agent's own writes and so sends every applied change back. Only triggers named sync_<table>_… or writing to sync_outbox are read. The application's own triggers are never sent to the monitor.

Leftovers on a removed table need dropping by hand

The script only drops triggers for tables it still covers. A trigger on a table that is no longer synced from that database stays until someone drops it; the panel shows the statement to run.

On this page