From 8b5b345202694d9f57b9c304da24d98b4bce8fe5 Mon Sep 17 00:00:00 2001 From: Yu Sun Date: Fri, 7 Oct 2022 19:26:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(ENodeConfigure):=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=96=B0=E8=B6=85=E8=A1=A8=E7=9A=84=E6=97=B6=E5=80=99=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=80=82=E9=85=8D=E6=98=AF=E5=90=A6=E4=B8=BA=E5=88=86?= =?UTF-8?q?=E5=B8=83=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EdgeManager/EDataCapture/ENodeConfigure.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/EdgeManager/EDataCapture/ENodeConfigure.php b/EdgeManager/EDataCapture/ENodeConfigure.php index 3dac386..9297714 100644 --- a/EdgeManager/EDataCapture/ENodeConfigure.php +++ b/EdgeManager/EDataCapture/ENodeConfigure.php @@ -62,7 +62,13 @@ class ENodeConfigure { ", $table_name )); if (!in_array($table_name, pg_fetch_all_columns($table_exists, 1))) { - $res[] = pg_query($this -> dbconn, sprintf("SELECT create_hypertable('\"%s\"', 'capture_time')", $table_name)); + $res[] = $node_count = pg_query($this -> dbconn, "SELECT COUNT(*) from timescaledb_information.data_nodes"); + if (intval(pg_fetch_assoc($node_count)['count']) === 0) { + $res[] = pg_query($this -> dbconn, sprintf("SELECT create_hypertable('\"%s\"', 'capture_time')", $table_name)); + } else { + $res[] = pg_query($this -> dbconn, sprintf("SELECT create_distributed_hypertable('\"%s\"', 'capture_time', 'code', 'device_code', 'parent_device_code', 'batch')", $table_name)); + } + $res[] = pg_query($this -> dbconn, sprintf( 'CREATE INDEX ON "%s" (v_string, v_int, v_float, v_bool, capture_time DESC) WHERE COALESCE(v_string, v_int::text, v_float::text, v_bool::text) IS NOT NULL