fix #17

Merged
emmatveev merged 1 commits from master into dev 2025-06-13 23:32:32 +03:00

View File

@ -27,7 +27,7 @@ func Close() {
func connect() (*driver.Conn, error) { func connect() (*driver.Conn, error) {
var ( var (
ctx = context.Background() ctx = context.Background()
conn, err = clickhouse.Open(&clickhouse.Options{ conn, err = clickhouse.Open(&clickhouse.Options{
Addr: []string{"clickhouse:9000"}, Addr: []string{"clickhouse:9000"},
Auth: clickhouse.Auth{ Auth: clickhouse.Auth{
@ -54,7 +54,7 @@ func connect() (*driver.Conn, error) {
func Migrate() error { func Migrate() error {
err := Connection.Exec( err := Connection.Exec(
context.TODO(), context.TODO(),
`CREATE TABLE IF NOT EXISTS endpoints ( `CREATE TABLE IF NOT EXISTS endpoints (
timestamp DateTime, timestamp DateTime,
service_name LowCardinality(String), service_name LowCardinality(String),
@ -67,9 +67,27 @@ func Migrate() error {
PARTITION BY toYYYYMM(timestamp) PARTITION BY toYYYYMM(timestamp)
ORDER BY (service_name, endpoint, request_method, timestamp);`, ORDER BY (service_name, endpoint, request_method, timestamp);`,
) )
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
return err return err
} }
err = Connection.Exec(
context.TODO(),
`CREATE TABLE IF NOT EXISTS tasks (
timestamp DateTime,
service_name LowCardinality(String),
queue_name LowCardinality(String),
success Bool,
execution_time_ms UInt32
)
ENGINE = MergeTree
PARTITION BY toYYYYMM(timestamp)
ORDER BY (service_name, queue_name, timestamp);`,
)
if err != nil {
log.Fatal(err)
return err
}
return nil return nil
} }