Skip to content

feat: production-table DDL (PARTITION/TTL/INDEX/SETTINGS) + parametrised DateTime64#8

Open
brentrager wants to merge 4 commits into
mainfrom
SMOODEV-2115-ddl-extensions
Open

feat: production-table DDL (PARTITION/TTL/INDEX/SETTINGS) + parametrised DateTime64#8
brentrager wants to merge 4 commits into
mainfrom
SMOODEV-2115-ddl-extensions

Conversation

@brentrager

Copy link
Copy Markdown
Contributor

Problem

The Rust kit's TableSpec modeled only name / columns / engine / order_by, so it could not express any of the SmooAI production observability/audit ClickHouse tables: all use PARTITION BY; observability_traces/observability_logs use TTL + secondary INDEXes + SETTINGS; audit_log_events uses DateTime64(3, 'UTC') (explicit timezone). Per the kit principle — a gap lands in the crate, not app code — this adds the missing DDL surface so the kit can be adopted in rust/api-prime + rust/audit-worker (SmooAI/smooai SMOODEV-2115).

Changes

  • TableSpec + FlexibleConfig gain partition_by: Option<String>, ttl: Option<TtlSpec>, indexes: Vec<IndexSpec>, settings: Vec<(String, String)>.
  • to_create_table_sql renders INDEX lines (inside the column parens), PARTITION BY (between ENGINE and ORDER BY), TTL (a DateTime64 ttl column is auto-wrapped in toDateTime(...)), and SETTINGSbackward-compatible: a spec with all-empty/None knobs renders the exact legacy output.
  • New IndexSpec / TtlSpec / TtlMove types.
  • ColumnTypeSpec::DateTime64 { datetime64: DateTime64Spec } with validated precision (0..=9) + IANA-charset timezone; bare "DateTime64" still renders DateTime64(3).
  • Version 0.1.00.2.0.

Safety posture

Only identifiers are validated (table/column/index names, ttl column, order_by — and ttl/order_by must be real columns). partition_by, index expression/type_def, ttl intervals/volume, and settings values are app-controlled raw fragments (same stance as engine) — never sourced from untrusted input. Untrusted DateTime64 precision/timezone IS validated before rendering.

Verification

cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo test — all clean. 51 unit tests pass (+12), including a byte-for-byte reproduction of the live observability_traces DDL. The 2 testcontainer integration tests run in CI (rust.yml).

Release

Crate publish is the manual publish-crate.yml (workflow_dispatch) after merge to main — gated to a maintainer. The SmooAI/smooai SMOODEV-2115 PR consumes this via a temporary git/path patch until 0.2.0 is on crates.io.

🤖 Generated with Claude Code

…parametrised DateTime64

Adds the structural DDL knobs the SmooAI observability + audit ClickHouse tables
need so the Rust kit can express the real production schema — it previously
modeled only name/columns/engine/order_by, which couldn't represent any of the
o11y tables (all use PARTITION BY; traces/logs use TTL/INDEX/SETTINGS; audit uses
DateTime64 with an explicit timezone). Per the kit principle, the gap lands in
the crate, not app code.

- TableSpec + FlexibleConfig gain partition_by / ttl / indexes / settings.
- to_create_table_sql renders INDEX lines (inside the column parens), PARTITION
  BY (between ENGINE and ORDER BY), TTL (DateTime64 ttl column auto-wrapped in
  toDateTime()), and SETTINGS — fully backward-compatible when all are empty/None.
- New IndexSpec / TtlSpec / TtlMove types. Safety posture: partition_by, index
  expression/type, ttl intervals/volume, and settings values are app-controlled
  raw fragments (like engine); only identifiers (table/column/index name, ttl
  column, order_by) are validated, and ttl/order_by columns must be real columns.
- ColumnTypeSpec::DateTime64 { datetime64: DateTime64Spec } with validated
  precision (0..=9) + IANA-charset timezone; bare "DateTime64" still renders (3).
- Version 0.1.0 -> 0.2.0. +12 tests (45 -> 51 unit), fmt/clippy clean.

Consumed by SmooAI/smooai SMOODEV-2115 (observability_logs/observability_traces
in api-prime, audit_log_events in audit-worker).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8b40af1

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant