Skip to content
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
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ GTC is a PostgreSQL Change Data Capture (CDC) platform written in Go. It capture
go build -o gateway ./cmd/gateway
go test ./...
go run ./cmd/gateway
go run ./cmd/gateway doctor # preflight checks (PG settings, privileges, sinks); exit 1 on failure

# End-to-end test (real PostgreSQL wal_level=logical + Redis; also run in CI):
GTC_TEST_DATABASE_URL=postgres://... GTC_TEST_REDIS_URL=redis://... \
Expand Down
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ PostgreSQL ──logical replication──▶ GTC ──▶ Redis Streams (eve

- **Single binary, plug and play** — point it at a database with
`wal_level=logical`, set a Redis URL, and every table is mirrored. The
replication slot and publication are created automatically.
replication slot and publication are created automatically, and
`gtc doctor` verifies the whole environment (settings, privileges, sinks)
before the first run.
- **Lock-free initial backfill** — on first start, existing table data is
synced to the sinks *concurrently with live streaming* using watermark
chunking (the DBLog algorithm): no table locks, no paused replication, and
Expand Down Expand Up @@ -137,6 +139,34 @@ enable the other sinks. `gateway --version` prints the build version.
> (`SELECT pg_drop_replication_slot('cdc_demo_slot');`) or your disk will
> slowly fill.

### Preflight: `gtc doctor`

Before the first run (or when something is off), let GTC diagnose the
environment instead of reading startup logs:

```bash
DATABASE_URL="postgres://...?replication=database" REDIS_URL="redis://..." \
./gateway doctor
```

It verifies everything in one pass — `wal_level`, replication privileges
(including a real `IDENTIFY_SYSTEM` handshake), free replication slots and
WAL senders, publication/slot existence vs. auto-create permissions, tables
that would reject UPDATE/DELETE for lack of a replica identity, sink
reachability (Redis `PING`, RedisJSON module presence, Meilisearch health),
transform compilation, and whether your sink timeouts fit inside
`wal_sender_timeout` — then exits 0 if GTC is ready to stream, 1 if
something needs fixing, with a concrete hint per finding:

```
PostgreSQL
✓ connection PostgreSQL 16.13
✗ wal_level "replica" — logical replication needs wal_level=logical
(ALTER SYSTEM SET wal_level = 'logical'; then restart PostgreSQL)
✓ privileges user "postgres" is superuser
...
```

## Event format

Redis Stream entries carry two fields — `event_id` (dedupe key) and
Expand Down
9 changes: 9 additions & 0 deletions cmd/gateway/main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package main

import (
"context"
"fmt"
"log/slog"
"os"
"strings"

"github.com/joho/godotenv"
"go.uber.org/fx"

"github.com/emoss08/gtc/internal/infrastructure/doctor"
)

// Overridden at release time via -ldflags "-X main.version=...".
Expand All @@ -23,6 +26,12 @@ func main() {

_ = godotenv.Load()

// `gtc doctor` checks prerequisites (PostgreSQL settings, privileges,
// sink reachability) and exits instead of starting the pipeline.
if len(os.Args) > 1 && os.Args[1] == "doctor" {
os.Exit(doctor.Run(context.Background(), os.Stdout))
}

logger := newLogger()
logger.Info("starting GTC", slog.String("version", version))

Expand Down
Loading
Loading