Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: switch config examples to use direct writes mode. #1358

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Configuration options are passed as environment variables, e.g.:
```shell
docker run \
-e "DATABASE_URL=postgresql://..." \
-e "LOGICAL_PUBLISHER_HOST=..." \
-e "ELECTRIC_WRITE_TO_PG_MODE=direct_writes" \
-e "PG_PROXY_PASSWORD=..." \
-e "AUTH_JWT_ALG=HS512" \
-e "AUTH_JWT_KEY=..." \
Expand Down
12 changes: 2 additions & 10 deletions docs/deployment/_render.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,8 @@ services:
value: "..."
- key: DATABASE_URL
value: "postgresql://..."
- key: LOGICAL_PUBLISHER_HOST
fromService:
type: web
name: tcp-proxy
property: host
- key: LOGICAL_PUBLISHER_PORT
fromService:
type: web
name: tcp-proxy
property: port
- key: ELECTRIC_WRITE_TO_PG_MODE
value: "direct_writes"
- type: web
name: http-proxy
runtime: image
Expand Down
2 changes: 1 addition & 1 deletion docs/deployment/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ See <DocPageLink path="usage/installation/service" /> to get familiar with confi
```shell
docker run \
-e "DATABASE_URL=postgresql://..." \
-e "LOGICAL_PUBLISHER_HOST=..." \
-e "ELECTRIC_WRITE_TO_PG_MODE=direct_writes" \
-e "PG_PROXY_PASSWORD=..." \
-e "AUTH_JWT_ALG=HS512" \
-e "AUTH_JWT_KEY=..." \
Expand Down
4 changes: 2 additions & 2 deletions docs/deployment/k8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ spec:
env:
- name: DATABASE_URL
value: "postgresql://..."
- name: LOGICAL_PUBLISHER_HOST
value: "..."
- name: ELECTRIC_WRITE_TO_PG_MODE
value: "direct_writes"
- name: PG_PROXY_PASSWORD
value: "..."
- name: AUTH_JWT_ALG
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/notes/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ npm run dev

### Connecting Electric to Postgres

The Electric sync service connects to Postgres using the `DATABASE_URL` environment variable. Depending on your choice of write mode, Postgres may also need to connect to Electric to consume a logical replication publication.
The Electric sync service connects to Postgres using the `DATABASE_URL` environment variable. Depending on your [choice of write mode](../../api/service#write-to-pg-mode), Postgres may also need to connect to Electric to consume a logical replication publication.

This is configured using the `LOGICAL_PUBLISHER_HOST` (and `LOGICAL_PUBLISHER_PORT`) environment variables:
If so, this is configured using the `LOGICAL_PUBLISHER_HOST` (and `LOGICAL_PUBLISHER_PORT`) environment variables:

```
|<--------DATABASE_URL----------|
Expand Down
2 changes: 1 addition & 1 deletion docs/quickstart/_setup_manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ docker pull electricsql/electric:latest
docker run \
-e "DATABASE_URL=postgresql://..." \
-e "DATABASE_REQUIRE_SSL=false \
-e "LOGICAL_PUBLISHER_HOST=..." \
-e "ELECTRIC_WRITE_TO_PG_MODE=direct_writes" \
-e "PG_PROXY_PASSWORD=..." \
-e "AUTH_MODE=insecure" \
-p 5133:5133 \
Expand Down
9 changes: 3 additions & 6 deletions docs/reference/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,15 @@ ElectricSQL aims to provide **finality** of local writes. That is to say: valid

Whilst local writes are final, they are still subject to concurrent merge semantics. One way to understand this is that writes are always *factored in* to the history, even if their operations are actually overridden by the semantics of the conflict resolution logic.


### Streaming into Electric

When the local database migrations are generated from the Postgres DDL changes, triggers are added that automatically copy insert, update and delete operations on the tables to the "oplog" table. The satellite process then processes these operations by sending them to the Electric server over the Satellite protocol. Electric then applies server-side validation and authorisation before sending on to Postgres over the incoming logical-replication stream.
When the local database migrations are generated from the Postgres DDL changes, triggers are added that automatically copy insert, update and delete operations on the tables to the "oplog" table. The satellite process then processes these operations by sending them to the Electric server over the Satellite protocol.

:::note
Electric acts as a [logical replication publisher](https://www.postgresql.org/docs/current/logical-replication.html). This is why you configure a `LOGICAL_PUBLISHER_HOST` when deploying the Electric sync service -- so that Postgres can connect to consume inbound logical replication.
:::
Electric then applies server-side validation and authorisation before writing into Postgres using the [`ELECTRIC_WRITE_TO_PG_MODE`](../api/service#write-to-pg-mode).

### Streaming into Postgres

When you electrify a table in the Postgres DDL schema, this installs triggers that handle insert, update and delete operations. When Postgres applies the operations from the inbound logical replication stream, these triggers fire and run database-side merge logic.
When you electrify a table in the Postgres DDL schema, this installs triggers that handle insert, update and delete operations. When Postgres applies writes from the Electric sync service, these triggers fire and run database-side merge logic.

### Direct writes to Postgres

Expand Down
18 changes: 12 additions & 6 deletions docs/usage/installation/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ You can run the [pre-packaged Docker images](#images) published on Docker Hub, o

## Configuration

The Electric sync service is configured using environment variables. The three required variables are:
The Electric sync service is configured using environment variables. The required variables are:

- `DATABASE_URL` in the format of a Postgres [Connection URI](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING-URIS)
- `LOGICAL_PUBLISHER_HOST` that the sync service is running on (must be accessible from the Postgres instance to establish an inbound replication subscription)
- `PG_PROXY_PASSWORD` to safe-guard access to the [Migrations proxy](../data-modelling/migrations.md#migrations-proxy)

Plus depending on your [Write to PG mode](../../api/service#write-to-pg-mode) you must either:

- set `ELECTRIC_WRITE_TO_PG_MODE=direct_writes`; or
- set `LOGICAL_PUBLISHER_HOST` to a hostname that the Postgres can connect to the sync service on

For example:

```shell
DATABASE_URL="postgresql://user:password@localhost:5432/electric"
LOGICAL_PUBLISHER_HOST="localhost"
ELECTRIC_WRITE_TO_PG_MODE="direct_writes"
PG_PROXY_PASSWORD="..."
```

Expand All @@ -34,7 +40,7 @@ Pre-packaged images are available on Docker Hub at [electricsql/electric](https:
```shell
docker run \
-e "DATABASE_URL=postgresql://..." \
-e "LOGICAL_PUBLISHER_HOST=..." \
-e "ELECTRIC_WRITE_TO_PG_MODE=direct_writes" \
-e "PG_PROXY_PASSWORD=..." \
-e "AUTH_MODE=insecure" \
-p 5133:5133 \
Expand Down Expand Up @@ -75,7 +81,7 @@ services:
environment:
DATABASE_URL: postgresql://postgres:pg_password@pg/postgres
DATABASE_REQUIRE_SSL: false
LOGICAL_PUBLISHER_HOST: electric
ELECTRIC_WRITE_TO_PG_MODE: direct_writes
PG_PROXY_PASSWORD: proxy_password
AUTH_MODE: insecure
ports:
Expand Down Expand Up @@ -103,7 +109,7 @@ Then run:
```shell
docker run \
-e "DATABASE_URL=postgresql://..." \
-e "LOGICAL_PUBLISHER_HOST=..." \
-e "ELECTRIC_WRITE_TO_PG_MODE=direct_writes" \
-e "PG_PROXY_PASSWORD=..." \
-e "AUTH_MODE=insecure" \
-p 5133:5133 \
Expand Down