Skip to content

Commit 8a92a65

Browse files
Copilotcschleiden
andcommitted
Add PostgreSQL backend documentation following SQLite/MySQL pattern
Co-authored-by: cschleiden <[email protected]>
1 parent e065cb2 commit 8a92a65

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ web/app/node_modules
99
*.sqlite-wal
1010

1111
custom-gcl
12+
13+
# Docs build artifacts
14+
docs/build/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func runWorker(ctx context.Context, mb backend.Backend) {
7474

7575
### Backend
7676

77-
The backend is responsible for persisting the workflow events. Currently there is an in-memory backend implementation for testing, one using [SQLite](http://sqlite.org), one using MySql, and one using Redis.
77+
The backend is responsible for persisting the workflow events. Currently there is an in-memory backend implementation for testing, one using [SQLite](http://sqlite.org), one using MySQL, one using PostgreSQL, and one using Redis.
7878

7979
```go
8080
b := sqlite.NewSqliteBackend("simple.sqlite")

backend/postgres/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# PostgreSQL backend
2+
3+
## Adding a migration
4+
5+
1. Install [golang-migrate/migrate](https://www.github.com/golang-migrate/migrate)
6+
1. ```bash
7+
migrate create -ext sql -dir ./db/migrations -seq <name>
8+
```

docs/source/includes/_backends.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Backends
22

3-
There are three backend implementations maintained in this repository. Some backend implementations have custom options and all of them accept:
3+
There are four backend implementations maintained in this repository. Some backend implementations have custom options and all of them accept:
44

55
- `WithStickyTimeout(timeout time.Duration)` - Set the timeout for sticky tasks. Defaults to 30 seconds
66
- `WithWorkflowLockTimeout(timeout time.Duration)` - Set the timeout for workflow task locks. Defaults to 1 minute
@@ -61,6 +61,31 @@ See `migrations/mysql` for the schema and migrations. Main tables:
6161
- `activities` - Queue of pending activities
6262
- `attributes` - Payloads of events
6363

64+
## PostgreSQL
65+
66+
```go
67+
func NewPostgresBackend(host string, port int, user, password, database string, opts ...option)
68+
```
69+
70+
Create a new PostgreSQL backend instance with `NewPostgresBackend`.
71+
72+
### Options
73+
74+
- `WithPostgresOptions(f func(db *sql.DB))` - Apply custom options to the PostgreSQL database connection
75+
- `WithApplyMigrations(applyMigrations bool)` - Set whether migrations should be applied on startup. Defaults to `true`
76+
- `WithBackendOptions(opts ...backend.BackendOption)` - Apply generic backend options
77+
78+
79+
### Schema
80+
81+
See `migrations/postgres` for the schema and migrations. Main tables:
82+
83+
- `instances` - Tracks workflow instances. Functions as instance queue joined with `pending_events`
84+
- `pending_events` - Pending events for workflow instances
85+
- `history` - History for workflow instances
86+
- `activities` - Queue of pending activities
87+
- `attributes` - Payloads of events
88+
6489
## Redis
6590

6691
```go

docs/source/index.html.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ go-workflows is an embedded engine for orchestrating long running processes or "
2525

2626
It borrows heavily from [Temporal](https://github.com/temporalio/temporal) (and since it's a fork also [Cadence](https://github.com/uber/cadence)) as well as Azure's [Durable Task Framework (DTFx)](https://github.com/Azure/durabletask). Workflows are written in plain Go.
2727

28-
go-workflows support pluggable backends with official implementations for Sqlite, MySql, and Redis.
28+
go-workflows support pluggable backends with official implementations for Sqlite, MySQL, PostgreSQL, and Redis.
2929

3030
See also the following blog posts:
3131

0 commit comments

Comments
 (0)