Self-hosted apply client for Entity Enricher schema databases.
Entity Enricher can mirror every enrichment into your own database as plain relational tables. This CLI runs next to that database, connects outward over WSS (no inbound access, no credentials shared with Entity Enricher), receives delta batches, applies them and acknowledges:
Entity Enricher ──WSS──▶ ee-database ──SQL──▶ your PostgreSQL or SQL Server
◀──────ack───────┘
The database type is chosen when the database sync is created in Entity Enricher: PostgreSQL or SQL Server (2022 or later). The client applies whichever the sync says — see Target databases.
- Bootstrap included — on first run it fetches the
.sqlsnapshot (tables + current data) and applies it before consuming deltas. - Replay-safe — every delta is an idempotent, revision-guarded upsert; if the client dies mid-batch, the batch is redelivered after its lease expires and re-applying converges to the same rows.
- Your DSN stays local — the connection string is passed on the command line or stored mode-600 on the machine; it is never sent anywhere.
- Quarantine on failure — a SQL error rolls back the batch and reports the failing delta. The server then sets that enrichment's whole batch aside and re-sends the queue without it, so one bad row can no longer stall everything behind it; the client keeps applying the rest. Nothing is silently skipped: the quarantined work stays listed in the Database Sync page's Quarantine tab until you reinject it (re-projected from current state) or drop it. A failure that names no delta still exits, since there would be nothing to quarantine and the same window would come straight back.
- Several databases per machine — each pairing lives in its own local
profile;
run --allsyncs every paired database concurrently from one process.
curl -fsSL https://entityenricher.ai/install-eedatabase.sh | sh(Windows: iwr -useb https://entityenricher.ai/install-eedatabase.ps1 | iex.
Both URLs are 302 aliases of install.sh /
install.ps1 at the root of this repo.)
The installer prints what it's about to do, pauses 5 seconds, and verifies the
binary's Sigstore keyless signature before making it executable: releases
are signed in CI by this repo's release.yml GitHub OIDC identity and logged
in the public Rekor transparency log — there is
no long-lived signing key anywhere.
Alternatively, download a signed binary from Releases yourself, or build from source (Go ≥ 1.25):
go build -o ee-database .For an editable install while hacking on the CLI, symlink the build output
onto your PATH so every rebuild is instantly live:
mkdir -p ~/.local/bin
go build -o tmp/ee-database .
ln -sfn "$PWD/tmp/ee-database" ~/.local/bin/ee-database # ensure ~/.local/bin is on PATH# 1. In Entity Enricher, on the Database Sync page: create a database sync on your
# schema, choose PostgreSQL or SQL Server, then publish the schema from its Model tab
# 2. Pair this machine (opens the browser to pick that database sync)
ee-database pair --server https://entityenricher.ai
# 3. Run it next to your database, with the DSN of the sync's type:
# PostgreSQL
ee-database run --dsn "postgres://user:pass@localhost:5432/mydb" --save-dsn
# or SQL Server
ee-database run --dsn "sqlserver://user:pass@localhost:1433?database=mydb" --save-dsnRun in a terminal without a DSN, ee-database run asks for its parts instead
(host, port, user, hidden password, database) and tests the connection. When it
fails, it says why and asks again for the parts at fault only: host and port
when nothing answers, user and password when the login is refused, the database
when it does not exist. Once connected, it offers to save the DSN.
Alternatively, issue a token on the Databases page (Sync client → Pair a client)
and paste it: ee-database pair --server https://entityenricher.ai <refresh-token>.
If the target database does not exist yet, add --create-missing to the run
command: the client creates it with the DSN's own credentials before syncing.
The login then needs the server-level create right — CREATEDB on PostgreSQL
(the client goes through the standard postgres maintenance database),
CREATE ANY DATABASE on SQL Server (through master).
When even the DSN's login does not exist yet, add --admin-dsn with an
administrative connection: the client then bootstraps everything the target
DSN names — the login (with the target DSN's password) when missing, and the
database, which it hands to that login (owner on PostgreSQL, db_owner member
on SQL Server). The target DSN needs no create rights of its own in this mode:
ee-database run \
--dsn "postgres://ee_replica:secret@localhost:5432/my_replica" \
--create-missing --admin-dsn "postgres://postgres:admin@localhost:5432/postgres"
ee-database run \
--dsn "sqlserver://ee_replica:Secret_123@localhost:1433?database=my_replica" \
--create-missing --admin-dsn "sqlserver://sa:Admin_123@localhost:1433"The admin DSN is used only for this bootstrap — it is never stored. On SQL Server the new login's password must pass the server's password policy; a refusal is reported in the server's own words. Also on SQL Server, a database that exists and in which the login has no user is opened to it the same way (a bootstrap that was interrupted is finished by running it again); a user that exists keeps the rights it has.
On every run the client self-checks its login's provisioning rights — create database (from the catalog), DDL and DML (a create/insert/delete/drop probe table) — prints the result and reports it to the Databases page's Sync client card, so a missing grant is visible there before deltas fail to apply. On SQL Server it also checks the version and the database compatibility level (see Target databases); an older target is reported as unable to apply DDL. The check is advisory: it never blocks the run.
If none of the database's linked schemas is published yet, the first run has nothing to bootstrap: the client stays connected and waits, and the first publish starts the feed on its own — no restart needed.
Assuming the target database already exists, the login needs only:
CONNECTon the database,USAGEandCREATEon the target schema (note: since PostgreSQL 15,publicno longer grantsCREATEto everyone by default).
Everything else follows from ownership: the client creates the replica
tables itself, so it owns them, and ownership implies the INSERT / UPDATE
/ DELETE / SELECT the data deltas need. Ownership is not optional — the
feed also ships migration statements (ALTER TABLE …, CREATE INDEX …) that
PostgreSQL restricts to the table owner; no combination of GRANTs
substitutes for it, and IF NOT EXISTS does not help (ownership is checked
before the duplicate-name check, so even re-applying an existing index fails
for a non-owner). If the replica tables pre-exist under a different owner, the
preflight passes (the login can create new tables) but the first migration
delta will fail — transfer them with ALTER TABLE … OWNER TO <login> (or
grant the login membership in the owning role) rather than adding grants.
Schemas can flag text properties for substring search; on PostgreSQL those ship
as trigram indexes, which need the pg_trgm extension. On connect the client
checks for it and, when the login is allowed to, installs it itself
(CREATE EXTENSION IF NOT EXISTS pg_trgm). When it cannot, the sync still runs
in full — the search-index statements are self-guarded and simply no-op — and a
warning explains the one-time fix: have a database owner run
CREATE EXTENSION pg_trgm; on the replica. The indexes then materialize on the
next publish or reconcile.
Assuming the target database already exists, the login needs a user in it that
is a member of db_owner — what --create-missing --admin-dsn sets up:
CREATE LOGIN [ee_replica] WITH PASSWORD = N'Secret_123'; -- once, if the login does not exist
USE [my_replica]; -- the target database
CREATE USER [ee_replica] FOR LOGIN [ee_replica];
ALTER ROLE db_owner ADD MEMBER [ee_replica];For --create-missing without --admin-dsn:
USE master; GRANT CREATE ANY DATABASE TO [ee_replica];
The feed creates and alters tables, indexes and constraints, so read and write grants alone are not enough. SQL Server replicas need no extension: it has no trigram index, so the substring-search indexes are not created there (Entity Enricher says so when the sync is created).
Each pushed window is applied in one transaction — the server never ends a window inside an enrichment — and is reported with the shape it wrote, per table:
applying 12 delta(s) (10831 .. 10842) in one transaction
applied 12 delta(s) in 84ms — 38 statement(s): mushroom 4 upserts, mushroom_common_names 12 upserts + 4 prunes, mushroom_human_uses 14 upserts + 4 prunes
acked up to delta 10842
Read it as the write shape of the feed, which is what sizing a nightly re-enrichment needs:
- upsert — one
INSERT … ON CONFLICT DO UPDATE(PostgreSQL) or oneMERGE(SQL Server) per projected row, so the count is the row count — except that on SQL Server the rows of one list or junction share oneMERGEper 1000 rows. Children are reconciled in place; they are never wiped and re-inserted. - prune — a revision-guarded
DELETEremoving the child or junction rows the new payload no longer claims. One statement per relationship, however many rows it clears. - delete — a tombstone (an entity deleted upstream) or its owned cascade.
- wipe — an unscoped
DELETE; only a keyless parent's children are replaced wholesale. - ddl — schema deltas: table, column and index statements, including the
ones the feed guards inside a
DOblock (PostgreSQL) or anEXEC(…)(SQL Server).
--verbose adds one line per delta, with its id, kind, entity type, wall time
and its own shape — the per-entity cost, which is otherwise unrecoverable once
a delta is acked and purged server-side:
applying 12 delta(s) (10831 .. 10842) in one transaction
delta 10831 data upsert Mushroom (7ms) — 3 statement(s): mushroom 1 upsert, mushroom_common_names 3 upserts + 1 prune
…
It also reports the bootstrap snapshot's table inventory and apply time.
| Command | Purpose |
|---|---|
pair --server URL |
Browser-confirmed device-code pairing |
pair --server URL <token> |
Pair with a token from the Databases page |
run --dsn DSN [--save-dsn] [--skip-bootstrap] |
Connect and apply deltas |
run … --create-missing |
Create the target database first when it does not exist |
run … --create-missing --admin-dsn DSN |
Also create the target DSN's missing login via an admin connection (never stored) |
run --all |
Sync every paired database concurrently (each needs a saved DSN) |
run … --verbose / host run … --verbose |
Log every delta's write shape and timing, not just the per-window summary |
run … --queries off|read|write / host run … --queries … |
What Entity Enricher may do with the replica through this client (default write); see Queries from Entity Enricher |
host pair --server URL --dsn BASE_DSN [--admin-dsn DSN] <token> |
Pair this machine as a managed sync host (token from the Sync hosts dialog — the "Sync hosts" toolbar button on the Database Sync page); one pairing per server, so several backends can be paired side by side. The base DSN's scheme (postgres:// or sqlserver://) is the database type the host serves |
host run [--server URL] |
Managed mode: auto-claim, create and sync every database sync assigned to this host — every paired server at once, or one with --server |
host status / host disconnect [--server URL] |
Show / forget host pairings (--server picks one when several servers are paired) |
status |
Show pairing state (all paired databases) |
disconnect |
Forget one pairing's local credentials (revoke server-side in the UI) |
version |
Print version |
Pairing is per database; managed mode moves the ceremony one level up. Pair the
machine once per server — --dsn is a base server DSN with no database name
(it never leaves the machine) — then host run holds one control-plane WebSocket
per paired server (pair against several backends — say staging and production —
and one host run syncs them all; --server URL restricts it to one) and
reacts to assignments made in the Entity Enricher UI (or API): it claims the
credential, derives the database's DSN from the base DSN plus the
server-suggested snake_cased name (override per registration via
database_names in the host config.json), creates the database if missing,
runs the rights preflight, and starts the ordinary sync loop. A database
already paired with another client is reported and skipped — never hijacked.
Revoking the host in the UI cuts the machine off entirely, including every
credential it claimed.
# 1. Register a host on the Database Sync page ("Sync hosts" toolbar button →
# Add host) — the one-time token is shown embedded in this command:
ee-database host pair --server https://entityenricher.ai \
--dsn "postgres://ee_replica:secret@dbserver:5432/" \
--admin-dsn "postgres://postgres:admin@dbserver:5432/postgres" <token>
# 2. Keep it running; assign database syncs to the host in the UI
ee-database host runA SQL Server host is paired with a sqlserver:// base DSN, without the
database parameter:
ee-database host pair --server https://entityenricher.ai \
--dsn "sqlserver://ee_replica:Secret_123@dbserver:1433" \
--admin-dsn "sqlserver://sa:Admin_123@dbserver:1433" <token>--admin-dsn plays the same role as on run --create-missing: provisioning
creates the target login and each claimed database through the admin
connection, so the base DSN's login needs no create rights of its own. It is
stored on this machine only (mode 0600) and never sent to Entity Enricher.
Pairing preflights the rights of the login that will create the databases —
the admin DSN's when given, else the base DSN's own — and fails fast when it
may not, quoting the statement that grants the right (--skip-preflight to
override; host run re-checks and reports to the Sync hosts card either way).
A base DSN that is not a postgres:// or sqlserver:// URL is refused before
the token is used.
One database type per pairing. A host pairing serves the database type of
its base DSN, and a machine holds one pairing per Entity Enricher server. A
database sync of the other type assigned to the host is skipped with a log
line (Entity Enricher only auto-assigns syncs of the host's type). Pairing the
same server again with the other type is refused until
ee-database host disconnect --server URL forgets the first pairing: to serve
both types for one server, pair a second machine, or a second user account on
the same one.
Pair once per schema database — every pairing gets its own profile directory
(~/.config/ee-database/profiles/<database-id>/ on Linux, the OS config dir
elsewhere), so pairing a second database never disturbs the first.
When several databases are paired, run, status and disconnect accept
--database NAME|ID to pick one. Without the flag, a terminal prompts with a
numbered list; a non-interactive run (systemd, Docker, cron) fails with the
list instead of hanging — pass --database there, or use run --all:
# Save each DSN once…
ee-database run --database analytics --dsn "postgres://…/analytics" --save-dsn
ee-database run --database staging --dsn "postgres://…/staging" --save-dsn
# …then one process syncs both (log lines are prefixed per database)
ee-database run --allA per-profile lock prevents two processes from running the same pairing at the same time (they would evict each other's WebSocket session in a loop).
Pairings made with ee-database ≤ 0.1.x are migrated into a profile automatically on first use.
The target database type belongs to the database sync in Entity Enricher; the client reads it when pairing and applies that type's SQL.
| Type | DSN | Requires |
|---|---|---|
PostgreSQL (postgres) |
postgres://user:pass@host:5432/database |
|
SQL Server (sqlserver) |
sqlserver://user:pass@host:1433?database=database |
SQL Server 2022 or later, database compatibility level 130 or more. The version check also accepts Azure SQL Database and Azure SQL Managed Instance, which are not tested |
What a SQL Server replica stores and constrains differently (400-character keys
and indexed text, exact text comparison, language columns, …) is described on
the Database Sync page. Index
names starting with idx_ or uq_ are reserved for the sync: a migration may
drop an index with such a name, so give yours another prefix.
A SQL Server DSN must be this URL form (ADO and ODBC connection strings are
refused), with the database in the database parameter. A DSN that names no
database is refused — the server would open the login's default database,
usually master — and a path after the host (sqlserver://host/name) is an
instance name, not a database. The other parameters
of go-mssqldb
pass through. Without an encrypt parameter only the login is encrypted and the
certificate is not checked. Add &encrypt=true to encrypt the connection and
check the certificate; with a self-signed certificate, add
&TrustServerCertificate=true as well.
The user and the password are parts of a URL, on both types: percent-encode
#, /, ?, % and @ in them (# is %23, / is %2F, ? is %3F,
% is %25, @ is %40).
"Change target database" in Entity Enricher points a sync at another database, of the same type or the other one, and restarts it there from a snapshot. It revokes the client's credential, so nothing more is written to the previous database, which is left as it is.
- Paired client —
runstops and asks to pair again. Pairing again discards the saved DSN, which names the previous database, and says so: pass the new database's--dsn(with--save-dsn) on the next run. - Managed host — nothing to do: the host claims the sync again and creates
a new database for it, named after the sync plus the number of changes
(
films, thenfilms__1). Adatabase_namesoverride in the hostconfig.jsonstill wins over that name: change it too if the new target must be another database. A sync changed to the other database type leaves this host, which serves one type: in Entity Enricher it is assigned to a host of the new type.
A sync whose target was changed, and any SQL Server sync, needs ee-database
1.7.0 or later. ee-database version prints the installed version; running the
install command again replaces it with the latest. An older client
is refused with a message that names the version to install, or stops on
unsupported dialect "sqlserver".
When the target database rejects the snapshot or a delta, ee-database prints
everything the database reported — on PostgreSQL the SQLSTATE, detail and
hint, on SQL Server the error number and state — and, when the database
located the error, the offending script line. The same text is sent to Entity
Enricher, which shows it on the Sync client card. A failed snapshot is
additionally saved to the pairing's profile directory as snapshot-failed.sql
(mode 0600, replaced on each attempt, removed on the next success), so the
failing statement can be inspected or replayed:
psql "$DSN" -v ON_ERROR_STOP=1 -f snapshot-failed.sql # PostgreSQL
sqlcmd -S host,1433 -d database -U user -I -b -x -i snapshot-failed.sql # SQL ServerA SQL Server snapshot is a sqlcmd script: batches separated by GO lines,
which the client sends one by one over a single connection. -I turns quoted
identifiers on, -b stops at the first error and -x keeps sqlcmd from
reading $(…) in a value as one of its variables. -d names the target
database: without it sqlcmd writes to the login's default database, usually
master. Add -C when the server's certificate is self-signed.
Nothing is partially applied: the snapshot is one transaction, and a failed delta batch rolls back and is quarantined until you reinject it.
From 1.8.0 the client also answers SQL queries the Entity Enricher interface sends over the same WebSocket, so the app can read the replica it fills. A query is one statement; its rows stream back in chunks, at most the number of rows the server asked for (it is told when there were more), and a query that runs too long times out or can be cancelled from the app.
--queries (on run and host run) says what the interface may do:
| Mode | Meaning |
|---|---|
write (default) |
Queries run, and the interface may offer write features. Those writes never travel as queries: they arrive as ordinary deltas. |
read |
Queries run; the interface offers no write feature. |
off |
Every query is answered with an error, and the server is told not to send any. |
A query is read-only in every mode. It runs on a connection pool of its own (at most 4 connections, opened from the same DSN), never on the one applying deltas, and its transaction is always rolled back:
- PostgreSQL runs it in a
READ ONLYtransaction, which the server enforces, and through the extended protocol, which refuses a string holding several statements. - SQL Server has no read-only transaction, so the client reads the batch
first and refuses one that names, as a keyword outside strings, comments and
quoted names, a statement that writes or ends the transaction (
INSERT,UPDATE,DELETE,MERGE,EXEC,COMMIT,SELECT … INTO,NEXT VALUE FOR, …), or that does not start withSELECT,WITH,DECLARE,SETorWAITFOR(a name opening a batch runs the procedure of that name). This guarantee is weaker than PostgreSQL's: it rests on that reading. The client's login still bounds what any statement can reach, so keep it to the replica's database; where no query may ever run, use--queries=off.
A query can also be only validated: PostgreSQL prepares it without executing
it, SQL Server compiles it under SET NOEXEC ON.
- One credential = one schema database = one client. Pairing again rotates the credential; the old token stops working immediately.
- The refresh token (365 days) is stored mode-600 in the pairing's profile directory; it is exchanged for 15-minute access tokens that authenticate the WebSocket.
- The host pairing key (
eeh_…) is a short opaque secret, not a JWT: the server keeps only its hash, it never expires, and revoking the host in the UI is what ends it. - Revoking the credential in the UI disconnects a live client instantly.
- Recommended: run against a dedicated database role scoped to the synced schema.
- Queries the app sends run read-only and can be refused altogether with
--queries=off(see Queries from Entity Enricher).
MIT — see LICENSE.