From 11792f8c537d24b89ad971826ffd8b16449d517f Mon Sep 17 00:00:00 2001 From: Pieter Hollander Date: Wed, 21 Feb 2024 11:17:09 +0100 Subject: [PATCH] Add timestamp index. Allow to add TimescaleDB after initial setup. --- main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 750c375..6932561 100644 --- a/main.go +++ b/main.go @@ -341,6 +341,7 @@ func connectToPostgreSQL(pgConnStr string) error { returning_l2 INT, returning_l3 INT ); + CREATE UNIQUE INDEX IF NOT EXISTS timestamp_idx ON log (timestamp); `) if err != nil { log.Fatal("Error creating table:", err) @@ -352,7 +353,7 @@ func connectToPostgreSQL(pgConnStr string) error { // Enable TimescaleDB _, err = db.Exec(` CREATE EXTENSION IF NOT EXISTS timescaledb; - SELECT create_hypertable('p1', 'timestamp', if_not_exists => TRUE); + SELECT create_hypertable('p1', 'timestamp', if_not_exists => TRUE), migrate_data => TRUE; `) if err != nil { log.Fatal("Error creating TimescaleDB extension:", err)