Database
We currently support sqlite3, postgres and cockroach databases.
| Name | Type | Env | Values | Default | Description |
|---|---|---|---|---|---|
| Type | string | DB_TYPE | postgres,sqlite3 | Database type | |
| Dsn | string | DB_CONNECTION | Database url | ||
| Host | string | DB_HOST | Database host | ||
| Port | uint | DB_PORT | 1-65535 | Database port | |
| Name | string | DB_NAME | Database name | ||
| User | string | DB_USER | Database user | ||
| Pass | string | DB_PASS | database password | ||
| ConnMaxLifetime | time duration | DB_CONN_MAX_LIFETIME | “100s”,“10m” | Connection life time | |
| MaxIdleConns | int | DB_MAX_IDLE_CONNS | Max idle connections | ||
| MaxOpenConns | int | DB_MAX_OPEN_CONNS | Max open connections | ||
| ReadOnly | bool | DB_READ_ONLY | false | Read only mode | |
| Migrate | bool | DB_MIGRATE | false | Enable migrations |
If you use
dsnyou don’t need to specify databasetype,host,port,name,userorpass.
Migrations
Upon startup the system checks if there are any pending database schema migrations and applies them in sequence. If one of the migrations fail everything gets rolled back and the startup fails with details in its log output.
The
migratesetting allows you to control automatic schema migrations. If you want toupdateorupgradethe system you must set this totrue.
Database opts
The opts setting allows you to set additional configuration parameters for the database.
| Name | Type | Env | Values | Default | Description |
|---|---|---|---|---|---|
| Set | string | Option setting | |||
| Val | string | Option value |
The options you can set depends on the database type and version you are using.
Example
sqlite3 database configuration.
[site.database]
type = "sqlite3"
name = "/storage/site.db"
migrate = true
[[site.database.opts]]
set = "foreign_keys"
val = "ON"
[[site.database.opts]]
set = "journal_mode"
val = "WAL"
The database file gets created if it doesn’t exist.
Example
Postgres database configuration.
[site.database]
type = "postgres"
name = "site"
user = "postgres"
pass = "postgres"
host = "127.0.0.1"
port = 5432
migrate = true
If you have granted
create databasepermission to the dbuserthe database is created.
Example
Cockroach database configuration using dsn.
[site.database]
dsn = "cockroach://root@localhost:26257/site?sslmode=disable"
migrate = true
You must first create the
sitedatabase in cockroach or it will usedefaultdbinstead.
Backend
Server backend (message bus), if this is unset the message bus gets embedded into the server.
| Name | Type | Env | Values | Default | Description |
|---|---|---|---|---|---|
| Url | string | BACKEND_URL | url | Url to backend server (message bus) |
Example
[site.backend]
url = "nats://172.16.172.16:4222"
Service
The service configuration is for the embedded messaging service.
If you don’t want to embed a message bus you need to configure backend.url.
| Name | Type | Env | Values | Default | Description |
|---|---|---|---|---|---|
| Host | string | SITE_SERVICE_HOST | hostname or IP | Server host (NATS) | |
| Port | uint | SITE_SERVICE_PORT | 1-65535 | 4222 | Server port (NATS) |
| Dir | string | SITE_SERVICE_DIR | tmp | Server directrory (NATS/Jetstream) | |
| MaxPayload | uint | SITE_SERVICE_MAX_PAYLOAD | 16777216 | Max message payload size | |
| Trace | bool | SITE_SERVICE_TRACE | false | Enable message trace |
When
backend.urlis unset the server embeds a NATS messaging service.
Example
[site.service]
Host="site.server.internal"
Port=4222
Dir="/tmp"
Cluster
The site service cluster configuration enables embedded messaging to join a cluster.
| Name | Type | Env | Values | Default | Description |
|---|---|---|---|---|---|
| Name | string | SITE_CLUSTER_NAME | Cluster name | ||
| Host | string | SITE_CLUSTER_HOST | Cluster host | ||
| Port | uint | SITE_CLUSTER_PORT | Cluster port | ||
| Routes | []string | SITE_CLUSTER_ROUTES | Cluster host peers |