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