# clickhouse-database

A database and a user on a ClickHouse server, credentials in the consumer's namespace

This page is generated from [`kix/packages/experimental/clickhouse-database`](https://github.com/kix-run/kix/tree/main/kix/packages/experimental/clickhouse-database).

| | |
| --- | --- |
| Stability | Experimental |
| `package` value | `packages.experimental.clickhouse-database` |
| Default aliases | `clickhouseDatabase` |

## Dependencies

Kix matches each dependency below to another package instance by instance name, alias, or role. To bind a specific instance, set [`deps.<name>`](/docs/reference/instances-and-composition/#deps) in your cluster definition. See [Declaring dependencies](/docs/reference/package-anatomy/#declaring-dependencies) for how required and optional dependencies work.

| Dependency | Requirement |
| --- | --- |
| `clickhouse` | Required |
| `password` | Optional |

## Options

### `database`

Database to create. Defaults to the namespace and the instance name, joined by an underscore, with dashes as underscores.

- **Type:** `string matching the pattern [A-Za-z_][A-Za-z0-9_]*`
- **Default:** `"<namespace>_<instance>", dashes as underscores`

### `grants`

ClickHouse privileges granted to the user on objects outside its
database, keyed by `<database>.<table>` with `*` for any
(`GRANT <these> ON <key>`): SQL user-defined functions belong to no
database (`*.*`), and reading a system table needs its own grant.
A consumer that needs one injects it through its dependency's
config.

- **Type:** `attribute set of list of string matching the pattern [A-Z][A-Z ]*`
- **Default:** `{ }`
- **Example:**

  ```nix
  {
    "*.*" = [
      "CREATE FUNCTION"
    ];
    "system.replicas" = [
      "SELECT"
    ];
  }
  ```

### `image`

Container image for this instance. Set it from a pin file (`kix.pins`) so the deployed reference is committed and resolved.

- **Type:** `submodule`
- **Default:**

  ```nix
  {
    digest = "sha256:6d462904f276dc6c1fa531d887cac02d4ef7a8f212d6142377d36608c2330d59";
    pullPolicy = "IfNotPresent";
    repository = "docker.io/clickhouse/clickhouse-server";
    tag = "26.8.40.7";
  }
  ```

### `image.digest`

Resolved manifest digest, `sha256:` followed by 64 hex characters. What will actually run. Null means not resolved.

- **Type:** `null or string`
- **Default:** the package's digest while `tag` is the package's tag, otherwise null

### `image.note`

Whatever a person wanted to say about this pin. Kix never reads it and a promotion never discards it. Declared here for the same reason as the three fields above: a pin carries its own record-keeping, and the option accepts the whole pin rather than a subset of it.

- **Type:** `null or string`
- **Default:** `null`

### `image.promotedBy`

Who resolved this pin, for the record. Null when unknown.

- **Type:** `null or string`
- **Default:** `null`

### `image.pullPolicy`

imagePullPolicy for containers using this image. Null leaves it to Kubernetes.

- **Type:** `null or string`
- **Default:** `"IfNotPresent"`

### `image.repository`

Image repository, registry host included.

- **Type:** `string`
- **Default:** `"docker.io/clickhouse/clickhouse-server"`

### `image.resolvedAt`

When this pin was resolved, RFC 3339. Null when unknown.

- **Type:** `null or string`
- **Default:** `null`

### `image.sourceRev`

Revision of the source the image was built from, when Kix built it. Null for upstream images.

- **Type:** `null or string`
- **Default:** `null`

### `image.tag`

Image tag. What was asked for.

- **Type:** `string`
- **Default:** `"26.8.40.7"`

### `privileges`

ClickHouse privileges granted to the user on every table of the
database (`GRANT <these> ON <database>.*`). A log shipper wants
[ "INSERT" ], a dashboard [ "SELECT" ].

- **Type:** `list of string matching the pattern [A-Z][A-Z ]*`
- **Default:**

  ```nix
  [
    "ALL"
  ]
  ```
- **Example:**

  ```nix
  [
    "SELECT"
    "INSERT"
  ]
  ```

### `schema`

SQL files run after the database and user exist, in name order, as
the server's administrator. `{database:Identifier}` is bound to the
database name. Each file must be safe to run again.

- **Type:** `attribute set of strings concatenated with "\n"`
- **Default:** `{ }`
- **Example:**

  ```nix
  {
    "01-events.sql" = ''
      CREATE TABLE IF NOT EXISTS {database:Identifier}.events ON CLUSTER '{cluster}'
      (ts DateTime, message String)
      ENGINE = ReplicatedMergeTree ORDER BY ts
    '';
  }
  ```

### `user`

User to create. Defaults to the namespace and the instance name, joined by an underscore, with dashes as underscores.

- **Type:** `string matching the pattern [A-Za-z_][A-Za-z0-9_]*`
- **Default:** `"<namespace>_<instance>", dashes as underscores`