/

Using Params

Connecting using individual parameters


Finally, it's possible to connect to a database using parameters defined in YAML, if connection strings are not desirable. When using this method, SchemaHero will create a connection string from the parameters provided.

The following fields are supported:

FieldDescription
hostThe hostname to SchemaHero should use to connect to the database. This must be resolvable from the namespace that the database object is deployed to
portThe port that the database server is accepting connections on
userThe username to use when connecting to the database
passwordThe password to use when onnecting to the database
dbnameThe name of the database to connect to

Postgresql and CockroachDB

In addition to the fields above, Postgresql and CockroachDB connections support the following parameters:

FieldDescription
sslmodeThe ssl mode to use when connecting. Set to disable to disable ssl verification for testing.

Connection string generation

When using this mode, the following connection string will be generated and used by SchemaHero:

postgres://<user>:<password>@<host>:<port>/<dbname>?sslmode=<sslmode>

If sslmode is not provided, the sslmode query parameter will not be appended.

MySQL

In addition to the fields above, MySQL connections support the following parameters:

FieldDescription
disableTLSA boolean, set to true to disable TLS on connections.

Connection string generation

When using this mode, the following connection string will be generated and used by SchemaHero:

<user>:<password>@tcp(<host>:<port>)/<dbname>

When disableTLS is set to true, SchemaHero will append ?tls=false to the generated connection string.

Examples

An example of connecting to postgres database using parameters is:

apiVersion: databases.schemahero.io/v1alpha4
kind: Database
metadata:
  name: my-db
spec:
  connection:
    postgres:
      host:
        value: postgres
      user:
        value: username
      password:
        value: password
      port:
        value: 5432
      dbname:
        value: db_name
      sslmode:
        value: disable

It's also possible to use secrets for some or all values:

apiVersion: databases.schemahero.io/v1alpha4
kind: Database
metadata:
  name: my-db
spec:
  connection:
    postgres:
      host:
        value: postgres
      user:
        value: username
      password:
        valueFrom:
          secretKeyRef:
            name: postgres
            key: password
      port:
        value: "5432"
      dbname:
        value: db-name
      sslmode:
        value: disable
Edit on GitHub