| 427 | } |
| 428 | |
| 429 | func clickHouseLogCreateTableSQL(ttlDays int) string { |
| 430 | return fmt.Sprintf(` |
| 431 | CREATE TABLE IF NOT EXISTS logs ( |
| 432 | id Int64 DEFAULT 0, |
| 433 | user_id Int32 DEFAULT 0, |
| 434 | created_at Int64 DEFAULT 0, |
| 435 | type Int32 DEFAULT 0, |
| 436 | content String DEFAULT '', |
| 437 | username String DEFAULT '', |
| 438 | token_name String DEFAULT '', |
| 439 | model_name String DEFAULT '', |
| 440 | quota Int32 DEFAULT 0, |
| 441 | prompt_tokens Int32 DEFAULT 0, |
| 442 | completion_tokens Int32 DEFAULT 0, |
| 443 | use_time Int32 DEFAULT 0, |
| 444 | is_stream UInt8 DEFAULT 0, |
| 445 | channel_id Int32 DEFAULT 0, |
| 446 | token_id Int32 DEFAULT 0, |
| 447 | `+"`group`"+` String DEFAULT '', |
| 448 | ip String DEFAULT '', |
| 449 | request_id String DEFAULT '', |
| 450 | upstream_request_id String DEFAULT '', |
| 451 | other String DEFAULT '' |
| 452 | ) |
| 453 | ENGINE = MergeTree() |
| 454 | PARTITION BY toYYYYMM(toDateTime(created_at)) |
| 455 | ORDER BY (created_at, request_id)%s`, clickHouseLogTTLClause(ttlDays)) |
| 456 | } |
| 457 | |
| 458 | func syncClickHouseLogTTL(ttlDays int) error { |
| 459 | expression := clickHouseLogTTLExpression(ttlDays) |