sql-yodeler-example-clickhouse

ClickHouse, 2 objects, from chant build of the declared schema. Written by yodel docs.

Objects

Entity relationships

Mermaid source; erd.md next to this file renders it on GitHub, GitLab and Forgejo.

erDiagram
  shop_events["shop.events"] {
    UInt64 id PK
    LowCardinality(String) kind PK
    DateTime at
    LowCardinality(String) country
    LowCardinality(String) source
  }

Reference

shopClickHouse::Database, export shopDb

The SQL Yodeler ClickHouse example

Engine
Atomic

History

MigrationStep
20261010T1722-baselineSQLCH200 create: CREATE DATABASE shop ENGINE = Atomic COMMENT 'The SQL Yodeler ClickHouse example [chant managed-by=chant]'
DDL
CREATE DATABASE shop
  ENGINE = Atomic
  COMMENT 'The SQL Yodeler ClickHouse example'

shop.eventsClickHouse::Table, export events

Engine
MergeTree
ORDER BY
(kind, id)
PARTITION BY
toYYYYMM(at)
ColumnTypeNullKeyDefaultComment
idUInt64noPK
kindLowCardinality(String)noPK
atDateTimeno
countryLowCardinality(String)noDEFAULT ''
sourceLowCardinality(String)noDEFAULT 'web'

History

MigrationStep
20261010T1722-baselineSQLCH200 create: CREATE TABLE shop.events ( id UInt64, kind LowCardinality(String), at DateTime ) ENGINE = MergeTree PARTITION BY toYYYYMM(at) ORDER BY (kind, at) COMMENT '[chant managed-by=chant]'
20261010T1722-add-countrySQLCH201 metadata: ALTER TABLE `shop`.`events` ADD COLUMN country LowCardinality(String) DEFAULT '' AFTER `at`
20261010T1722-events-by-idClickHouseRebuildOp step (SQLCH220 orderBy)
20261010T1723-add-sourceSQLCH201 metadata: ALTER TABLE `shop`.`events` ADD COLUMN source LowCardinality(String) DEFAULT 'web' AFTER `country`
DDL
CREATE TABLE shop.events
  (
      id UInt64,
      kind LowCardinality(String),
      at DateTime,
      country LowCardinality(String) DEFAULT '',
      source LowCardinality(String) DEFAULT 'web'
  )
  ENGINE = MergeTree
  PARTITION BY toYYYYMM(at)
  ORDER BY (kind, id)