Databases

Add managed database instances to your test environment with automatic provisioning and seed scripts.

Required fields

FieldTypeDescription
type"DATABASE"Item type
namestringUnique name (1-63 chars). Used as DNS hostname for service connections.
databaseenum"postgres", "mysql", "mongodb", or "redis"

Optional fields

FieldTypeDefaultDescription
descriptionstringHuman-readable description (max 500 chars)
dbNamestringdokkimiDatabase/schema name
dbUserstringdokkimiDatabase username
dbPasswordstringdokkimiDatabase password
initFilePathstringRelative path to a single init script
initFilePathsstring[]Relative paths to multiple init scripts (executed in order). Use one or the other, not both.
minCpunumberMinimum CPU cores
minMemorynumberMinimum memory in MB
maxCpunumberMaximum CPU cores
maxMemorynumberMaximum memory in MB

Engine details

EngineImagePortDefault connection string
postgrespostgres:155432postgresql://dokkimi:dokkimi@{name}:5432/dokkimi
mysqlmysql:83306mysql://dokkimi:dokkimi@{name}:3306/dokkimi
mongodbmongo:727017mongodb://dokkimi:dokkimi@{name}:27017/dokkimi?authSource=admin
redisredis:7-alpine6379redis://:dokkimi@{name}:6379

Examples

PostgreSQL

{
  "type": "DATABASE",
  "name": "postgres-db",
  "database": "postgres",
  "dbName": "myapp",
  "dbUser": "appuser",
  "dbPassword": "secret",
  "initFilePath": "../init-files/schema.sql"
}

MySQL

{
  "type": "DATABASE",
  "name": "mysql-db",
  "database": "mysql",
  "initFilePaths": ["../init-files/schema.sql", "../init-files/seed.sql"]
}

MongoDB

{
  "type": "DATABASE",
  "name": "mongo-db",
  "database": "mongodb",
  "initFilePath": "../init-files/init.js"
}

Redis

{
  "type": "DATABASE",
  "name": "redis-cache",
  "database": "redis"
}

Connection strings

Use the database item's name as the hostname. The connection string format varies by engine. With the defaults (dbUser: dokkimi, dbPassword: dokkimi, dbName: dokkimi):

PostgreSQL

postgresql://dokkimi:dokkimi@postgres-db:5432/dokkimi

MySQL

mysql://dokkimi:dokkimi@mysql-db:3306/dokkimi

MongoDB

mongodb://dokkimi:dokkimi@mongo-db:27017/dokkimi?authSource=admin

MongoDB requires ?authSource=admin. Dokkimi creates MongoDB users as root users that authenticate against the admin database. Without this parameter, authentication will fail.

Redis

redis://:dokkimi@redis-cache:6379

Note the ://:password@ format — Redis has no username, just a password.

If you customize dbUser, dbPassword, or dbName, substitute those values in the connection string accordingly.

Connecting services to databases

Pass the connection string to your service via environment variables:

{
  "type": "SERVICE",
  "name": "my-service",
  "port": 3000,
  "healthCheck": "/health",
  "env": [
    { "name": "DATABASE_URL", "value": "postgresql://dokkimi:dokkimi@postgres-db:5432/dokkimi" },
    { "name": "REDIS_URL", "value": "redis://:dokkimi@redis-cache:6379" },
    { "name": "MONGO_URL", "value": "mongodb://dokkimi:dokkimi@mongo-db:27017/dokkimi?authSource=admin" }
  ]
}