From 11f9c4450c9630d58a6280e661a00ed505216d54 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Thu, 26 Mar 2026 10:23:26 -0500 Subject: [PATCH] done i think (#177) Reviewed-on: https://git.mcintire.me/graham/towerops-web/pulls/177 --- lib/towerops/capacity.ex | 2 +- lib/towerops/monitoring.ex | 44 + lib/towerops/snmp/discovery.ex | 144 +- .../snmp/profiles/vendors/airfiber.ex | 1 + lib/towerops/topology.ex | 66 +- lib/towerops/workers/device_poller_worker.ex | 38 +- lib/towerops_web/live/weathermap_live.ex | 4 +- .../live/weathermap_live.html.heex | 40 +- mix.lock | 2 +- ...325215632_deduplicate_discovery_checks.exs | 40 + priv/repo/structure.sql | 1480 ++++++++++++++++- test/towerops/monitoring_test.exs | 106 ++ .../snmp/profiles/vendors/airfiber_test.exs | 6 +- 13 files changed, 1769 insertions(+), 204 deletions(-) create mode 100644 priv/repo/migrations/20260325215632_deduplicate_discovery_checks.exs diff --git a/lib/towerops/capacity.ex b/lib/towerops/capacity.ex index 7c219c97..6017dd66 100644 --- a/lib/towerops/capacity.ex +++ b/lib/towerops/capacity.ex @@ -211,7 +211,7 @@ defmodule Towerops.Capacity do def percentile(values, n) when n >= 0 and n <= 100 do sorted = Enum.sort(values) - rank = Float.ceil(n / 100 * length(sorted)) |> trunc() |> max(1) + rank = (n / 100 * length(sorted)) |> Float.ceil() |> trunc() |> max(1) Enum.at(sorted, rank - 1) end diff --git a/lib/towerops/monitoring.ex b/lib/towerops/monitoring.ex index 7e1f1f4b..b238a4ba 100644 --- a/lib/towerops/monitoring.ex +++ b/lib/towerops/monitoring.ex @@ -556,6 +556,50 @@ defmodule Towerops.Monitoring do end end + @doc """ + Finds an existing auto-discovered check or creates a new one. + + Uses `(device_id, check_type, source_id)` as the uniqueness key. + If a check already exists, updates its name and config. Otherwise creates it + and schedules a CheckExecutorWorker job. + + Attrs must include: `:device_id`, `:check_type`, `:source_id`, `:source_type`, + `:organization_id`, `:name`, `:config`. + """ + def ensure_discovery_check(attrs) do + device_id = Map.fetch!(attrs, :device_id) + check_type = Map.fetch!(attrs, :check_type) + source_id = Map.fetch!(attrs, :source_id) + + existing = + Repo.one( + from(c in Check, + where: c.device_id == ^device_id, + where: c.check_type == ^check_type, + where: c.source_id == ^source_id, + limit: 1 + ) + ) + + case existing do + nil -> + with {:ok, check} <- create_check(attrs) do + _ = schedule_check(check) + {:ok, check} + end + + check -> + name = Map.get(attrs, :name, check.name) + config = Map.get(attrs, :config, check.config) + + if check.name == name and check.config == config do + {:ok, check} + else + update_check(check, %{name: name, config: config}) + end + end + end + ## Legacy ping-based monitoring compatibility (stub) @doc false diff --git a/lib/towerops/snmp/discovery.ex b/lib/towerops/snmp/discovery.ex index 206c8cbd..4f052dad 100644 --- a/lib/towerops/snmp/discovery.ex +++ b/lib/towerops/snmp/discovery.ex @@ -446,8 +446,6 @@ defmodule Towerops.Snmp.Discovery do ``` """ def create_checks_from_discovery(device, snmp_device) do - alias Towerops.Monitoring - # Ensure associations are loaded snmp_device = Repo.preload(snmp_device, [:sensors, :interfaces, :processors, :storage]) @@ -510,98 +508,74 @@ defmodule Towerops.Snmp.Discovery do # Private functions defp create_sensor_check(device, sensor) do - alias Towerops.Monitoring - - with {:ok, check} <- - Monitoring.create_check(%{ - organization_id: device.organization_id, - device_id: device.id, - name: sensor.sensor_descr, - check_type: "snmp_sensor", - source_type: "auto_discovery", - source_id: sensor.id, - interval_seconds: 60, - enabled: true, - config: %{ - "sensor_type" => sensor.sensor_type, - "sensor_class" => sensor.sensor_class, - "sensor_oid" => sensor.sensor_oid, - "sensor_divisor" => sensor.sensor_divisor, - "sensor_unit" => sensor.sensor_unit - } - }), - {:ok, _job} <- Monitoring.schedule_check(check) do - {:ok, check} - end + Towerops.Monitoring.ensure_discovery_check(%{ + organization_id: device.organization_id, + device_id: device.id, + name: sensor.sensor_descr, + check_type: "snmp_sensor", + source_type: "auto_discovery", + source_id: sensor.id, + interval_seconds: 60, + enabled: true, + config: %{ + "sensor_type" => sensor.sensor_type, + "sensor_class" => sensor.sensor_class, + "sensor_oid" => sensor.sensor_oid, + "sensor_divisor" => sensor.sensor_divisor, + "sensor_unit" => sensor.sensor_unit + } + }) end defp create_interface_check(device, interface) do - alias Towerops.Monitoring - - with {:ok, check} <- - Monitoring.create_check(%{ - organization_id: device.organization_id, - device_id: device.id, - name: "Interface #{interface.if_descr}", - check_type: "snmp_interface", - source_type: "auto_discovery", - source_id: interface.id, - interval_seconds: 60, - enabled: true, - config: %{ - "if_index" => interface.if_index, - "if_descr" => interface.if_descr - } - }), - {:ok, _job} <- Monitoring.schedule_check(check) do - {:ok, check} - end + Towerops.Monitoring.ensure_discovery_check(%{ + organization_id: device.organization_id, + device_id: device.id, + name: "Interface #{interface.if_descr}", + check_type: "snmp_interface", + source_type: "auto_discovery", + source_id: interface.id, + interval_seconds: 60, + enabled: true, + config: %{ + "if_index" => interface.if_index, + "if_descr" => interface.if_descr + } + }) end defp create_processor_check(device, processor) do - alias Towerops.Monitoring - - with {:ok, check} <- - Monitoring.create_check(%{ - organization_id: device.organization_id, - device_id: device.id, - name: "CPU #{processor.processor_index}", - check_type: "snmp_processor", - source_type: "auto_discovery", - source_id: processor.id, - interval_seconds: 60, - enabled: true, - config: %{ - "processor_index" => processor.processor_index, - "processor_descr" => processor.processor_descr - } - }), - {:ok, _job} <- Monitoring.schedule_check(check) do - {:ok, check} - end + Towerops.Monitoring.ensure_discovery_check(%{ + organization_id: device.organization_id, + device_id: device.id, + name: "CPU #{processor.processor_index}", + check_type: "snmp_processor", + source_type: "auto_discovery", + source_id: processor.id, + interval_seconds: 60, + enabled: true, + config: %{ + "processor_index" => processor.processor_index, + "processor_descr" => processor.processor_descr + } + }) end defp create_storage_check(device, storage) do - alias Towerops.Monitoring - - with {:ok, check} <- - Monitoring.create_check(%{ - organization_id: device.organization_id, - device_id: device.id, - name: storage.description || storage.device_name || "Storage #{storage.storage_index}", - check_type: "snmp_storage", - source_type: "auto_discovery", - source_id: storage.id, - interval_seconds: 60, - enabled: true, - config: %{ - "storage_index" => storage.storage_index, - "storage_descr" => storage.description - } - }), - {:ok, _job} <- Monitoring.schedule_check(check) do - {:ok, check} - end + Towerops.Monitoring.ensure_discovery_check(%{ + organization_id: device.organization_id, + device_id: device.id, + name: storage.description || storage.device_name || "Storage #{storage.storage_index}", + check_type: "snmp_storage", + source_type: "auto_discovery", + source_id: storage.id, + interval_seconds: 60, + enabled: true, + config: %{ + "storage_index" => storage.storage_index, + "storage_descr" => storage.description + } + }) end defp log_check_creation_results(device_id, check_counts) do diff --git a/lib/towerops/snmp/profiles/vendors/airfiber.ex b/lib/towerops/snmp/profiles/vendors/airfiber.ex index 72282903..d3c00834 100644 --- a/lib/towerops/snmp/profiles/vendors/airfiber.ex +++ b/lib/towerops/snmp/profiles/vendors/airfiber.ex @@ -33,6 +33,7 @@ defmodule Towerops.Snmp.Profiles.Vendors.Airfiber do case Client.get(v1_opts, "1.3.6.1.2.1.1.5.0") do {:ok, sys_name} when is_binary(sys_name) and sys_name != "" -> "Ubiquiti AirFiber (#{sys_name})" + _ -> "Ubiquiti AirFiber" end diff --git a/lib/towerops/topology.ex b/lib/towerops/topology.ex index fdfbf287..18ac1f48 100644 --- a/lib/towerops/topology.ex +++ b/lib/towerops/topology.ex @@ -6,6 +6,7 @@ defmodule Towerops.Topology do import Ecto.Query + alias Towerops.Capacity alias Towerops.Devices alias Towerops.Devices.Device alias Towerops.Repo @@ -22,7 +23,6 @@ defmodule Towerops.Topology do alias Towerops.Topology.DeviceNeighbor alias Towerops.Topology.Identifier alias Towerops.Topology.Lldp - alias Towerops.Capacity require Logger @@ -1402,57 +1402,57 @@ defmodule Towerops.Topology do defp enrich_edges_with_utilization(edges, device_ids) do # Get all interfaces with configured capacity for these devices interface_utilizations = get_interface_utilizations(device_ids) - + Enum.map(edges, fn edge -> # Try to find utilization data for the source or target interface source_util = get_edge_utilization(edge, :source, interface_utilizations) target_util = get_edge_utilization(edge, :target, interface_utilizations) - + # Use the higher utilization of the two interfaces utilization = combine_interface_utilizations(source_util, target_util) - + Map.merge(edge, utilization) end) end defp get_interface_utilizations(device_ids) do # Query interfaces with capacity configuration and recent stats - Repo.all( - from i in Interface, - join: sd in SnmpDevice, on: i.snmp_device_id == sd.id, - join: d in Device, on: sd.device_id == d.id, - where: d.id in ^device_ids and not is_nil(i.configured_capacity_bps), - select: %{ - interface_id: i.id, - device_id: d.id, - interface_name: i.if_name, - capacity_bps: i.configured_capacity_bps, - if_index: i.if_index - } + from(i in Interface, + join: sd in SnmpDevice, + on: i.snmp_device_id == sd.id, + join: d in Device, + on: sd.device_id == d.id, + where: d.id in ^device_ids and not is_nil(i.configured_capacity_bps), + select: %{ + interface_id: i.id, + device_id: d.id, + interface_name: i.if_name, + capacity_bps: i.configured_capacity_bps, + if_index: i.if_index + } ) + |> Repo.all() |> Enum.map(fn interface -> # Calculate current utilization using the Capacity module interface_struct = %Interface{ id: interface.interface_id, configured_capacity_bps: interface.capacity_bps } - + utilization = Capacity.get_utilization(interface_struct) - - Map.merge(interface, %{ - utilization_data: utilization - }) + + Map.put(interface, :utilization_data, utilization) end) |> Map.new(fn interface -> {interface.interface_id, interface} end) end defp get_edge_utilization(edge, direction, interface_utilizations) do - interface_id = + interface_id = case direction do :source -> edge[:source_interface_id] :target -> edge[:target_interface_id] end - + case interface_id do nil -> nil id -> Map.get(interface_utilizations, id) @@ -1469,18 +1469,18 @@ defmodule Towerops.Topology do capacity_bps: nil, utilization_text: nil } - + {util, nil} -> process_single_utilization(util) - + {nil, util} -> process_single_utilization(util) - + {source, target} -> # Use the higher utilization of the two interfaces source_data = process_single_utilization(source) target_data = process_single_utilization(target) - + if (source_data.utilization_pct || 0) >= (target_data.utilization_pct || 0) do source_data else @@ -1499,11 +1499,11 @@ defmodule Towerops.Topology do capacity_bps: util_data.capacity_bps, utilization_text: nil } - + util -> utilization_pct = Float.round(util.utilization_pct, 1) level = classify_utilization_level(utilization_pct) - + %{ utilization_pct: utilization_pct, utilization_level: level, @@ -1517,7 +1517,7 @@ defmodule Towerops.Topology do defp classify_utilization_level(nil), do: nil defp classify_utilization_level(pct) when pct < 30, do: :low - defp classify_utilization_level(pct) when pct < 60, do: :medium + defp classify_utilization_level(pct) when pct < 60, do: :medium defp classify_utilization_level(pct) when pct < 80, do: :high defp classify_utilization_level(_pct), do: :critical @@ -1528,22 +1528,26 @@ defmodule Towerops.Topology do end defp format_bps(nil), do: "N/A" + defp format_bps(bps) when bps >= 1_000_000_000 do "#{Float.round(bps / 1_000_000_000, 1)} Gbps" end + defp format_bps(bps) when bps >= 1_000_000 do "#{Float.round(bps / 1_000_000, 0)} Mbps" end + defp format_bps(bps) when bps >= 1_000 do "#{Float.round(bps / 1_000, 0)} Kbps" end + defp format_bps(bps) do "#{Float.round(bps, 0)} bps" end # Compute utilization statistics for the weathermap dashboard. defp compute_utilization_stats(edges) do - utilization_counts = + utilization_counts = edges |> Enum.map(& &1[:utilization_level]) |> Enum.frequencies() diff --git a/lib/towerops/workers/device_poller_worker.ex b/lib/towerops/workers/device_poller_worker.ex index 8722787e..7d05e72b 100644 --- a/lib/towerops/workers/device_poller_worker.ex +++ b/lib/towerops/workers/device_poller_worker.ex @@ -1013,7 +1013,9 @@ defmodule Towerops.Workers.DevicePollerWorker do fn interface -> stat_data = case get_airfiber_stats(af_overrides, interface, client_opts) do - {:ok, data} -> data + {:ok, data} -> + data + _ -> {:ok, data} = get_interface_stats(client_opts, interface.if_index) data @@ -1048,8 +1050,9 @@ defmodule Towerops.Workers.DevicePollerWorker do # Ubiquiti uses two enterprise OIDs: # - 1.3.6.1.4.1.41112 (new UBNT enterprise OID) # - 1.3.6.1.4.1.10002 (old UBNT enterprise OID, used by AirFiber AF11/AF24) - is_ubnt = String.starts_with?(sys_oid, "1.3.6.1.4.1.41112") or - String.starts_with?(sys_oid, "1.3.6.1.4.1.10002") + is_ubnt = + String.starts_with?(sys_oid, "1.3.6.1.4.1.41112") or + String.starts_with?(sys_oid, "1.3.6.1.4.1.10002") if is_ubnt do # Probe for the AirFiber statistics table — if it exists, this device @@ -1058,7 +1061,9 @@ defmodule Towerops.Workers.DevicePollerWorker do # Check for LTU first (more specific) case Client.get(v1_opts, "1.3.6.1.4.1.41112.1.10.1.2.2.0") do - {:ok, val} when val != nil -> :airfiber_ltu + {:ok, val} when val != nil -> + :airfiber_ltu + _ -> # Check for regular AirFiber stats table (index field) case Client.get(v1_opts, "1.3.6.1.4.1.41112.1.3.3.1.1.1") do @@ -1066,8 +1071,6 @@ defmodule Towerops.Workers.DevicePollerWorker do _ -> nil end end - else - nil end end @@ -1077,8 +1080,7 @@ defmodule Towerops.Workers.DevicePollerWorker do # since the proprietary counters represent the radio link's actual throughput. # Only skip lo and sit0 (loopback/tunnel with no real traffic). defp get_airfiber_stats(nil, _interface, _client_opts), do: :not_airfiber - defp get_airfiber_stats(_af_type, %{if_descr: descr}, _client_opts) - when descr in ["lo", "sit0"], do: :skip_loopback + defp get_airfiber_stats(_af_type, %{if_descr: descr}, _client_opts) when descr in ["lo", "sit0"], do: :skip_loopback defp get_airfiber_stats(:airfiber, _interface, client_opts) do # UBNT-AirFIBER-MIB: airFiberStatistics table (1.3.6.1.4.1.41112.1.3.3.1) @@ -1090,20 +1092,28 @@ defmodule Towerops.Workers.DevicePollerWorker do v1_opts = Keyword.put(client_opts, :version, "1") oids = [ - {"1.3.6.1.4.1.41112.1.3.3.1.7.1", :if_in_octets}, # rxOctetsOK - {"1.3.6.1.4.1.41112.1.3.3.1.6.1", :if_out_octets}, # txOctetsOK - {"1.3.6.1.4.1.41112.1.3.3.1.10.1", :if_in_errors}, # rxErroredFrames - {"1.3.6.1.4.1.41112.1.3.3.1.11.1", :if_out_errors} # txErroredFrames + # rxOctetsOK + {"1.3.6.1.4.1.41112.1.3.3.1.7.1", :if_in_octets}, + # txOctetsOK + {"1.3.6.1.4.1.41112.1.3.3.1.6.1", :if_out_octets}, + # rxErroredFrames + {"1.3.6.1.4.1.41112.1.3.3.1.10.1", :if_in_errors}, + # txErroredFrames + {"1.3.6.1.4.1.41112.1.3.3.1.11.1", :if_out_errors} ] + fetch_proprietary_stats(v1_opts, oids, true) end defp get_airfiber_stats(:airfiber_ltu, _interface, client_opts) do # UBNT-AFLTU-MIB: afLTUeth table (1.3.6.1.4.1.41112.1.10.1.6) oids = [ - {"1.3.6.1.4.1.41112.1.10.1.6.1.6.0", :if_in_octets}, # afLTUethRxBytes - {"1.3.6.1.4.1.41112.1.10.1.6.1.4.0", :if_out_octets} # afLTUethTxBytes + # afLTUethRxBytes + {"1.3.6.1.4.1.41112.1.10.1.6.1.6.0", :if_in_octets}, + # afLTUethTxBytes + {"1.3.6.1.4.1.41112.1.10.1.6.1.4.0", :if_out_octets} ] + fetch_proprietary_stats(client_opts, oids, true) end diff --git a/lib/towerops_web/live/weathermap_live.ex b/lib/towerops_web/live/weathermap_live.ex index 841b41bb..ebd8d079 100644 --- a/lib/towerops_web/live/weathermap_live.ex +++ b/lib/towerops_web/live/weathermap_live.ex @@ -132,7 +132,7 @@ defmodule ToweropsWeb.WeathermapLive do def handle_event("toggle_fullscreen", _params, socket) do new_fullscreen = not socket.assigns.fullscreen - path_with_params = + path_with_params = if new_fullscreen do ~p"/weathermap?#{%{tab: socket.assigns.active_tab, fullscreen: true}}" else @@ -192,4 +192,4 @@ defmodule ToweropsWeb.WeathermapLive do detail -> assign(socket, :selected_node_detail, detail) end end -end \ No newline at end of file +end diff --git a/lib/towerops_web/live/weathermap_live.html.heex b/lib/towerops_web/live/weathermap_live.html.heex index 5b76576e..8a13d408 100644 --- a/lib/towerops_web/live/weathermap_live.html.heex +++ b/lib/towerops_web/live/weathermap_live.html.heex @@ -1,4 +1,7 @@ -
+
<%= if not @fullscreen do %>
<% end %> - - + +
- +
@@ -263,7 +266,8 @@ High Utilization (60%+) <%= if (@topology.stats[:high_utilization_links] || 0) + (@topology.stats[:overutilized_links] || 0) > 0 do %> - {(@topology.stats[:high_utilization_links] || 0) + (@topology.stats[:overutilized_links] || 0)} + {(@topology.stats[:high_utilization_links] || 0) + + (@topology.stats[:overutilized_links] || 0)} <% end %> @@ -338,7 +342,7 @@
- +
- +
- - + +

Link Utilization

@@ -407,7 +411,7 @@
- + <%= if @selected_node_detail do %>
- +

@@ -494,7 +498,7 @@ <% end %>

- + <%= if @selected_node_detail[:utilization_stats] do %>

@@ -529,7 +533,7 @@

<% end %> - + <%= if length(@selected_node_detail.connections) > 0 do %>

@@ -574,7 +578,7 @@

<% end %> - + <%= if @selected_node_detail.type == :managed do %>
<.link @@ -592,7 +596,7 @@
- + <%= if @topology.stats.total_devices == 0 do %>
@@ -601,7 +605,9 @@ {t("No network data available")}

- {t("Add devices with SNMP enabled and configure interface capacities to view utilization.")} + {t( + "Add devices with SNMP enabled and configure interface capacities to view utilization." + )}

<.button navigate={~p"/devices/new"} variant="primary"> @@ -612,4 +618,4 @@
<% end %> <% end %> -
\ No newline at end of file +
diff --git a/mix.lock b/mix.lock index be398abf..5276c875 100644 --- a/mix.lock +++ b/mix.lock @@ -62,7 +62,7 @@ "nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"}, "nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"}, "nimble_totp": {:hex, :nimble_totp, "1.0.0", "79753bae6ce59fd7cacdb21501a1dbac249e53a51c4cd22b34fa8438ee067283", [:mix], [], "hexpm", "6ce5e4c068feecdb782e85b18237f86f66541523e6bad123e02ee1adbe48eda9"}, - "oban": {:hex, :oban, "2.21.0", "25b2d22061628f60ffa93e5c945bdd7dcd90ab3892ae0734da41ec6ede23b9ed", [:mix], [{:ecto_sql, "~> 3.10", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:ecto_sqlite3, "~> 0.9", [hex: :ecto_sqlite3, repo: "hexpm", optional: true]}, {:igniter, "~> 0.5", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:myxql, "~> 0.7", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.20", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 1.3", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3209e3d008a2dc46085ed9dce2f9cf0b4e1c58d1ab32615cf64ac1830bdb90bf"}, + "oban": {:hex, :oban, "2.21.1", "4b6af7b901ef9baca09e239b5a991ef2fa429cf5a13799bc429a131d610ff692", [:mix], [{:ecto_sql, "~> 3.10", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:ecto_sqlite3, "~> 0.9", [hex: :ecto_sqlite3, repo: "hexpm", optional: true]}, {:igniter, "~> 0.5", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:myxql, "~> 0.7", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.20", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 1.3", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "8162a160924cf4a25905fed2a9242e7787d88e320e3b5b0dcf324eb17c51c4e6"}, "oban_met": {:hex, :oban_met, "1.0.6", "2a5500aff496b7ac4b830b0b03b08e920625a051bb6890981fbb53b15f1cbdc0", [:mix], [{:oban, "~> 2.19", [hex: :oban, repo: "hexpm", optional: false]}], "hexpm", "15ea3303de76225878a8e6c25a9d62bd1e2e9dd1c46ac8487d873b9f99e8dcee"}, "parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"}, "phoenix": {:hex, :phoenix, "1.8.5", "919db335247e6d4891764dc3063415b0d2457641c5f9b3751b5df03d8e20bbcf", [:mix], [{:bandit, "~> 1.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.7", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "83b2bb125127e02e9f475c8e3e92736325b5b01b0b9b05407bcb4083b7a32485"}, diff --git a/priv/repo/migrations/20260325215632_deduplicate_discovery_checks.exs b/priv/repo/migrations/20260325215632_deduplicate_discovery_checks.exs new file mode 100644 index 00000000..9ee98be3 --- /dev/null +++ b/priv/repo/migrations/20260325215632_deduplicate_discovery_checks.exs @@ -0,0 +1,40 @@ +defmodule Towerops.Repo.Migrations.DeduplicateDiscoveryChecks do + use Ecto.Migration + + def up do + # Delete duplicate auto-discovered checks, keeping the oldest one per + # (device_id, check_type, source_id) combination. + execute(""" + DELETE FROM checks + WHERE id IN ( + SELECT id FROM ( + SELECT id, + ROW_NUMBER() OVER ( + PARTITION BY device_id, check_type, source_id + ORDER BY inserted_at ASC + ) AS rn + FROM checks + WHERE source_type = 'auto_discovery' + AND source_id IS NOT NULL + ) ranked + WHERE rn > 1 + ) + """) + + # Prevent future duplicates for auto-discovered checks. + create( + unique_index(:checks, [:device_id, :check_type, :source_id], + where: "source_type = 'auto_discovery' AND source_id IS NOT NULL", + name: :checks_device_type_source_unique_index + ) + ) + end + + def down do + drop_if_exists( + index(:checks, [:device_id, :check_type, :source_id], + name: :checks_device_type_source_unique_index + ) + ) + end +end diff --git a/priv/repo/structure.sql b/priv/repo/structure.sql index d90ee4c6..204e07ca 100644 --- a/priv/repo/structure.sql +++ b/priv/repo/structure.sql @@ -2,7 +2,7 @@ -- PostgreSQL database dump -- -\restrict RRAhb3L0Us7vE3B3YUZQWFpUy9oe9JDkh3ZeMLm2wvwJPMjBbIXH8zFu6qq0U19 +\restrict 58n9yz3M1gCN5t2tMwVCXpismPQgdWzmGfJI4AZxbUhDND1zz8QIj8oDYzqLMz8 -- Dumped from database version 17.9 (Homebrew) -- Dumped by pg_dump version 17.9 (Homebrew) @@ -211,7 +211,8 @@ CREATE TABLE public.snmp_interface_stats ( if_in_discards bigint, if_out_discards bigint, checked_at timestamp(0) without time zone NOT NULL, - inserted_at timestamp(0) without time zone NOT NULL + inserted_at timestamp(0) without time zone NOT NULL, + is_hc boolean DEFAULT true NOT NULL ); @@ -430,6 +431,16 @@ CREATE TABLE _timescaledb_internal._hyper_10_174_chunk ( INHERITS (_timescaledb_internal._materialized_hypertable_10); +-- +-- Name: _hyper_10_205_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_10_205_chunk ( + CONSTRAINT constraint_125 CHECK (((bucket >= '2026-03-18 00:00:00'::timestamp without time zone) AND (bucket < '2026-03-28 00:00:00'::timestamp without time zone))) +) +INHERITS (_timescaledb_internal._materialized_hypertable_10); + + -- -- Name: _hyper_10_60_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - -- @@ -477,6 +488,16 @@ CREATE TABLE _timescaledb_internal._hyper_11_15_chunk ( INHERITS (_timescaledb_internal._materialized_hypertable_11); +-- +-- Name: _hyper_11_194_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_11_194_chunk ( + CONSTRAINT constraint_117 CHECK (((bucket >= '2026-03-18 00:00:00'::timestamp without time zone) AND (bucket < '2026-03-28 00:00:00'::timestamp without time zone))) +) +INHERITS (_timescaledb_internal._materialized_hypertable_11); + + -- -- Name: _hyper_11_33_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - -- @@ -544,6 +565,16 @@ CREATE TABLE _timescaledb_internal._hyper_12_175_chunk ( INHERITS (_timescaledb_internal._materialized_hypertable_12); +-- +-- Name: _hyper_12_206_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_12_206_chunk ( + CONSTRAINT constraint_126 CHECK (((bucket >= '2026-03-18 00:00:00'::timestamp without time zone) AND (bucket < '2026-03-28 00:00:00'::timestamp without time zone))) +) +INHERITS (_timescaledb_internal._materialized_hypertable_12); + + -- -- Name: _hyper_12_45_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - -- @@ -554,6 +585,43 @@ CREATE TABLE _timescaledb_internal._hyper_12_45_chunk ( INHERITS (_timescaledb_internal._materialized_hypertable_12); +-- +-- Name: check_results; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.check_results ( + id uuid NOT NULL, + checked_at timestamp(0) without time zone NOT NULL, + organization_id uuid NOT NULL, + check_id uuid NOT NULL, + status integer NOT NULL, + output text, + response_time_ms double precision, + agent_token_id uuid, + value double precision +); + + +-- +-- Name: _hyper_14_191_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_14_191_chunk ( + CONSTRAINT constraint_114 CHECK (((checked_at >= '2026-03-19 00:00:00'::timestamp without time zone) AND (checked_at < '2026-03-26 00:00:00'::timestamp without time zone))) +) +INHERITS (public.check_results); + + +-- +-- Name: _hyper_14_210_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_14_210_chunk ( + CONSTRAINT constraint_130 CHECK (((checked_at >= '2026-03-26 00:00:00'::timestamp without time zone) AND (checked_at < '2026-04-02 00:00:00'::timestamp without time zone))) +) +INHERITS (public.check_results); + + -- -- Name: _hyper_1_112_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - -- @@ -654,6 +722,46 @@ CREATE TABLE _timescaledb_internal._hyper_1_170_chunk ( INHERITS (public.monitoring_checks); +-- +-- Name: _hyper_1_188_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_1_188_chunk ( + CONSTRAINT constraint_111 CHECK (((checked_at >= '2026-03-23 00:00:00'::timestamp without time zone) AND (checked_at < '2026-03-24 00:00:00'::timestamp without time zone))) +) +INHERITS (public.monitoring_checks); + + +-- +-- Name: _hyper_1_198_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_1_198_chunk ( + CONSTRAINT constraint_118 CHECK (((checked_at >= '2026-03-24 00:00:00'::timestamp without time zone) AND (checked_at < '2026-03-25 00:00:00'::timestamp without time zone))) +) +INHERITS (public.monitoring_checks); + + +-- +-- Name: _hyper_1_201_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_1_201_chunk ( + CONSTRAINT constraint_121 CHECK (((checked_at >= '2026-03-25 00:00:00'::timestamp without time zone) AND (checked_at < '2026-03-26 00:00:00'::timestamp without time zone))) +) +INHERITS (public.monitoring_checks); + + +-- +-- Name: _hyper_1_209_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_1_209_chunk ( + CONSTRAINT constraint_129 CHECK (((checked_at >= '2026-03-26 00:00:00'::timestamp without time zone) AND (checked_at < '2026-03-27 00:00:00'::timestamp without time zone))) +) +INHERITS (public.monitoring_checks); + + -- -- Name: _hyper_2_103_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - -- @@ -774,6 +882,46 @@ CREATE TABLE _timescaledb_internal._hyper_2_18_chunk ( INHERITS (public.snmp_sensor_readings); +-- +-- Name: _hyper_2_190_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_2_190_chunk ( + CONSTRAINT constraint_113 CHECK (((checked_at >= '2026-03-23 00:00:00'::timestamp without time zone) AND (checked_at < '2026-03-24 00:00:00'::timestamp without time zone))) +) +INHERITS (public.snmp_sensor_readings); + + +-- +-- Name: _hyper_2_200_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_2_200_chunk ( + CONSTRAINT constraint_120 CHECK (((checked_at >= '2026-03-24 00:00:00'::timestamp without time zone) AND (checked_at < '2026-03-25 00:00:00'::timestamp without time zone))) +) +INHERITS (public.snmp_sensor_readings); + + +-- +-- Name: _hyper_2_203_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_2_203_chunk ( + CONSTRAINT constraint_123 CHECK (((checked_at >= '2026-03-25 00:00:00'::timestamp without time zone) AND (checked_at < '2026-03-26 00:00:00'::timestamp without time zone))) +) +INHERITS (public.snmp_sensor_readings); + + +-- +-- Name: _hyper_2_207_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_2_207_chunk ( + CONSTRAINT constraint_127 CHECK (((checked_at >= '2026-03-26 00:00:00'::timestamp without time zone) AND (checked_at < '2026-03-27 00:00:00'::timestamp without time zone))) +) +INHERITS (public.snmp_sensor_readings); + + -- -- Name: _hyper_2_21_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - -- @@ -1034,6 +1182,26 @@ CREATE TABLE _timescaledb_internal._hyper_3_172_chunk ( INHERITS (public.snmp_interface_stats); +-- +-- Name: _hyper_3_189_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_3_189_chunk ( + CONSTRAINT constraint_112 CHECK (((checked_at >= '2026-03-23 00:00:00'::timestamp without time zone) AND (checked_at < '2026-03-24 00:00:00'::timestamp without time zone))) +) +INHERITS (public.snmp_interface_stats); + + +-- +-- Name: _hyper_3_199_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_3_199_chunk ( + CONSTRAINT constraint_119 CHECK (((checked_at >= '2026-03-24 00:00:00'::timestamp without time zone) AND (checked_at < '2026-03-25 00:00:00'::timestamp without time zone))) +) +INHERITS (public.snmp_interface_stats); + + -- -- Name: _hyper_3_19_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - -- @@ -1044,6 +1212,26 @@ CREATE TABLE _timescaledb_internal._hyper_3_19_chunk ( INHERITS (public.snmp_interface_stats); +-- +-- Name: _hyper_3_202_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_3_202_chunk ( + CONSTRAINT constraint_122 CHECK (((checked_at >= '2026-03-25 00:00:00'::timestamp without time zone) AND (checked_at < '2026-03-26 00:00:00'::timestamp without time zone))) +) +INHERITS (public.snmp_interface_stats); + + +-- +-- Name: _hyper_3_208_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_3_208_chunk ( + CONSTRAINT constraint_128 CHECK (((checked_at >= '2026-03-26 00:00:00'::timestamp without time zone) AND (checked_at < '2026-03-27 00:00:00'::timestamp without time zone))) +) +INHERITS (public.snmp_interface_stats); + + -- -- Name: _hyper_3_22_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - -- @@ -1260,6 +1448,16 @@ CREATE TABLE _timescaledb_internal._hyper_7_148_chunk ( INHERITS (_timescaledb_internal._materialized_hypertable_7); +-- +-- Name: _hyper_7_192_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_7_192_chunk ( + CONSTRAINT constraint_115 CHECK (((bucket >= '2026-03-18 00:00:00'::timestamp without time zone) AND (bucket < '2026-03-28 00:00:00'::timestamp without time zone))) +) +INHERITS (_timescaledb_internal._materialized_hypertable_7); + + -- -- Name: _hyper_7_34_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - -- @@ -1316,6 +1514,16 @@ CREATE TABLE _timescaledb_internal._hyper_8_173_chunk ( INHERITS (_timescaledb_internal._materialized_hypertable_8); +-- +-- Name: _hyper_8_204_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_8_204_chunk ( + CONSTRAINT constraint_124 CHECK (((bucket >= '2026-03-18 00:00:00'::timestamp without time zone) AND (bucket < '2026-03-28 00:00:00'::timestamp without time zone))) +) +INHERITS (_timescaledb_internal._materialized_hypertable_8); + + -- -- Name: _hyper_8_46_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - -- @@ -1360,6 +1568,16 @@ CREATE TABLE _timescaledb_internal._hyper_9_146_chunk ( INHERITS (_timescaledb_internal._materialized_hypertable_9); +-- +-- Name: _hyper_9_193_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal._hyper_9_193_chunk ( + CONSTRAINT constraint_116 CHECK (((bucket >= '2026-03-18 00:00:00'::timestamp without time zone) AND (bucket < '2026-03-28 00:00:00'::timestamp without time zone))) +) +INHERITS (_timescaledb_internal._materialized_hypertable_9); + + -- -- Name: _hyper_9_50_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - -- @@ -1870,6 +2088,80 @@ ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_183_chunk ALTER COLUMN _ ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_183_chunk ALTER COLUMN agent_token_id SET STATISTICS 0; +-- +-- Name: compress_hyper_4_185_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal.compress_hyper_4_185_chunk ( + _ts_meta_count integer, + device_id uuid, + id _timescaledb_internal.compressed_data, + _ts_meta_v2_bloomh_status _timescaledb_internal.bloom1, + status _timescaledb_internal.compressed_data, + response_time_ms _timescaledb_internal.compressed_data, + _ts_meta_min_1 timestamp(0) without time zone, + _ts_meta_max_1 timestamp(0) without time zone, + checked_at _timescaledb_internal.compressed_data, + inserted_at _timescaledb_internal.compressed_data, + _ts_meta_min_2 uuid, + _ts_meta_max_2 uuid, + agent_token_id _timescaledb_internal.compressed_data +) +WITH (toast_tuple_target='128'); +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_185_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_185_chunk ALTER COLUMN device_id SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_185_chunk ALTER COLUMN id SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_185_chunk ALTER COLUMN _ts_meta_v2_bloomh_status SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_185_chunk ALTER COLUMN _ts_meta_v2_bloomh_status SET STORAGE EXTERNAL; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_185_chunk ALTER COLUMN status SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_185_chunk ALTER COLUMN status SET STORAGE EXTENDED; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_185_chunk ALTER COLUMN response_time_ms SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_185_chunk ALTER COLUMN _ts_meta_min_1 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_185_chunk ALTER COLUMN _ts_meta_max_1 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_185_chunk ALTER COLUMN checked_at SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_185_chunk ALTER COLUMN inserted_at SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_185_chunk ALTER COLUMN _ts_meta_min_2 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_185_chunk ALTER COLUMN _ts_meta_max_2 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_185_chunk ALTER COLUMN agent_token_id SET STATISTICS 0; + + +-- +-- Name: compress_hyper_4_195_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal.compress_hyper_4_195_chunk ( + _ts_meta_count integer, + device_id uuid, + id _timescaledb_internal.compressed_data, + _ts_meta_v2_bloomh_status _timescaledb_internal.bloom1, + status _timescaledb_internal.compressed_data, + response_time_ms _timescaledb_internal.compressed_data, + _ts_meta_min_1 timestamp(0) without time zone, + _ts_meta_max_1 timestamp(0) without time zone, + checked_at _timescaledb_internal.compressed_data, + inserted_at _timescaledb_internal.compressed_data, + _ts_meta_min_2 uuid, + _ts_meta_max_2 uuid, + agent_token_id _timescaledb_internal.compressed_data +) +WITH (toast_tuple_target='128'); +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_195_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_195_chunk ALTER COLUMN device_id SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_195_chunk ALTER COLUMN id SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_195_chunk ALTER COLUMN _ts_meta_v2_bloomh_status SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_195_chunk ALTER COLUMN _ts_meta_v2_bloomh_status SET STORAGE EXTERNAL; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_195_chunk ALTER COLUMN status SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_195_chunk ALTER COLUMN status SET STORAGE EXTENDED; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_195_chunk ALTER COLUMN response_time_ms SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_195_chunk ALTER COLUMN _ts_meta_min_1 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_195_chunk ALTER COLUMN _ts_meta_max_1 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_195_chunk ALTER COLUMN checked_at SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_195_chunk ALTER COLUMN inserted_at SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_195_chunk ALTER COLUMN _ts_meta_min_2 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_195_chunk ALTER COLUMN _ts_meta_max_2 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_4_195_chunk ALTER COLUMN agent_token_id SET STATISTICS 0; + + -- -- Name: compress_hyper_5_106_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - -- @@ -2425,6 +2717,80 @@ ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_182_chunk ALTER COLUMN s ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_182_chunk ALTER COLUMN state_descr SET STORAGE EXTENDED; +-- +-- Name: compress_hyper_5_186_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal.compress_hyper_5_186_chunk ( + _ts_meta_count integer, + sensor_id uuid, + id _timescaledb_internal.compressed_data, + value _timescaledb_internal.compressed_data, + _ts_meta_min_2 character varying(255), + _ts_meta_max_2 character varying(255), + status _timescaledb_internal.compressed_data, + _ts_meta_min_1 timestamp(0) without time zone, + _ts_meta_max_1 timestamp(0) without time zone, + checked_at _timescaledb_internal.compressed_data, + inserted_at _timescaledb_internal.compressed_data, + state_descr _timescaledb_internal.compressed_data +) +WITH (toast_tuple_target='128'); +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_186_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_186_chunk ALTER COLUMN sensor_id SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_186_chunk ALTER COLUMN id SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_186_chunk ALTER COLUMN value SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_186_chunk ALTER COLUMN _ts_meta_min_2 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_186_chunk ALTER COLUMN _ts_meta_min_2 SET STORAGE PLAIN; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_186_chunk ALTER COLUMN _ts_meta_max_2 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_186_chunk ALTER COLUMN _ts_meta_max_2 SET STORAGE PLAIN; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_186_chunk ALTER COLUMN status SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_186_chunk ALTER COLUMN status SET STORAGE EXTENDED; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_186_chunk ALTER COLUMN _ts_meta_min_1 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_186_chunk ALTER COLUMN _ts_meta_max_1 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_186_chunk ALTER COLUMN checked_at SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_186_chunk ALTER COLUMN inserted_at SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_186_chunk ALTER COLUMN state_descr SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_186_chunk ALTER COLUMN state_descr SET STORAGE EXTENDED; + + +-- +-- Name: compress_hyper_5_196_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal.compress_hyper_5_196_chunk ( + _ts_meta_count integer, + sensor_id uuid, + id _timescaledb_internal.compressed_data, + value _timescaledb_internal.compressed_data, + _ts_meta_min_2 character varying(255), + _ts_meta_max_2 character varying(255), + status _timescaledb_internal.compressed_data, + _ts_meta_min_1 timestamp(0) without time zone, + _ts_meta_max_1 timestamp(0) without time zone, + checked_at _timescaledb_internal.compressed_data, + inserted_at _timescaledb_internal.compressed_data, + state_descr _timescaledb_internal.compressed_data +) +WITH (toast_tuple_target='128'); +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_196_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_196_chunk ALTER COLUMN sensor_id SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_196_chunk ALTER COLUMN id SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_196_chunk ALTER COLUMN value SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_196_chunk ALTER COLUMN _ts_meta_min_2 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_196_chunk ALTER COLUMN _ts_meta_min_2 SET STORAGE PLAIN; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_196_chunk ALTER COLUMN _ts_meta_max_2 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_196_chunk ALTER COLUMN _ts_meta_max_2 SET STORAGE PLAIN; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_196_chunk ALTER COLUMN status SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_196_chunk ALTER COLUMN status SET STORAGE EXTENDED; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_196_chunk ALTER COLUMN _ts_meta_min_1 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_196_chunk ALTER COLUMN _ts_meta_max_1 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_196_chunk ALTER COLUMN checked_at SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_196_chunk ALTER COLUMN inserted_at SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_196_chunk ALTER COLUMN state_descr SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_5_196_chunk ALTER COLUMN state_descr SET STORAGE EXTENDED; + + -- -- Name: compress_hyper_5_41_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - -- @@ -2775,7 +3141,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_101_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_101_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -2810,7 +3177,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_107_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_107_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -2845,7 +3213,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_113_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_113_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -2880,7 +3249,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_118_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_118_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -2915,7 +3285,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_124_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_124_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -2950,7 +3321,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_126_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_126_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -2985,7 +3357,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_130_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_130_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3020,7 +3393,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_135_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_135_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3055,7 +3429,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_138_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_138_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3090,7 +3465,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_142_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_142_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3125,7 +3501,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_151_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_151_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3160,7 +3537,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_153_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_153_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3195,7 +3573,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_157_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_157_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3230,7 +3609,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_177_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_177_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3265,7 +3645,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_181_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_181_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3300,7 +3681,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_184_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_184_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3318,6 +3700,78 @@ ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_184_chunk ALTER COLUMN c ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_184_chunk ALTER COLUMN inserted_at SET STATISTICS 0; +-- +-- Name: compress_hyper_6_187_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal.compress_hyper_6_187_chunk ( + _ts_meta_count integer, + interface_id uuid, + id _timescaledb_internal.compressed_data, + if_in_octets _timescaledb_internal.compressed_data, + if_out_octets _timescaledb_internal.compressed_data, + if_in_errors _timescaledb_internal.compressed_data, + if_out_errors _timescaledb_internal.compressed_data, + if_in_discards _timescaledb_internal.compressed_data, + if_out_discards _timescaledb_internal.compressed_data, + _ts_meta_min_1 timestamp(0) without time zone, + _ts_meta_max_1 timestamp(0) without time zone, + checked_at _timescaledb_internal.compressed_data, + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data +) +WITH (toast_tuple_target='128'); +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_187_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_187_chunk ALTER COLUMN interface_id SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_187_chunk ALTER COLUMN id SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_187_chunk ALTER COLUMN if_in_octets SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_187_chunk ALTER COLUMN if_out_octets SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_187_chunk ALTER COLUMN if_in_errors SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_187_chunk ALTER COLUMN if_out_errors SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_187_chunk ALTER COLUMN if_in_discards SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_187_chunk ALTER COLUMN if_out_discards SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_187_chunk ALTER COLUMN _ts_meta_min_1 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_187_chunk ALTER COLUMN _ts_meta_max_1 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_187_chunk ALTER COLUMN checked_at SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_187_chunk ALTER COLUMN inserted_at SET STATISTICS 0; + + +-- +-- Name: compress_hyper_6_197_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - +-- + +CREATE TABLE _timescaledb_internal.compress_hyper_6_197_chunk ( + _ts_meta_count integer, + interface_id uuid, + id _timescaledb_internal.compressed_data, + if_in_octets _timescaledb_internal.compressed_data, + if_out_octets _timescaledb_internal.compressed_data, + if_in_errors _timescaledb_internal.compressed_data, + if_out_errors _timescaledb_internal.compressed_data, + if_in_discards _timescaledb_internal.compressed_data, + if_out_discards _timescaledb_internal.compressed_data, + _ts_meta_min_1 timestamp(0) without time zone, + _ts_meta_max_1 timestamp(0) without time zone, + checked_at _timescaledb_internal.compressed_data, + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data +) +WITH (toast_tuple_target='128'); +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_197_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_197_chunk ALTER COLUMN interface_id SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_197_chunk ALTER COLUMN id SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_197_chunk ALTER COLUMN if_in_octets SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_197_chunk ALTER COLUMN if_out_octets SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_197_chunk ALTER COLUMN if_in_errors SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_197_chunk ALTER COLUMN if_out_errors SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_197_chunk ALTER COLUMN if_in_discards SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_197_chunk ALTER COLUMN if_out_discards SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_197_chunk ALTER COLUMN _ts_meta_min_1 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_197_chunk ALTER COLUMN _ts_meta_max_1 SET STATISTICS 1000; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_197_chunk ALTER COLUMN checked_at SET STATISTICS 0; +ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_197_chunk ALTER COLUMN inserted_at SET STATISTICS 0; + + -- -- Name: compress_hyper_6_31_chunk; Type: TABLE; Schema: _timescaledb_internal; Owner: - -- @@ -3335,7 +3789,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_31_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_31_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3370,7 +3825,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_36_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_36_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3405,7 +3861,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_42_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_42_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3440,7 +3897,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_51_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_51_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3475,7 +3933,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_58_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_58_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3510,7 +3969,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_65_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_65_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3545,7 +4005,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_70_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_70_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3580,7 +4041,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_78_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_78_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3615,7 +4077,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_80_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_80_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3650,7 +4113,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_87_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_87_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3685,7 +4149,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_90_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_90_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3720,7 +4185,8 @@ CREATE TABLE _timescaledb_internal.compress_hyper_6_98_chunk ( _ts_meta_min_1 timestamp(0) without time zone, _ts_meta_max_1 timestamp(0) without time zone, checked_at _timescaledb_internal.compressed_data, - inserted_at _timescaledb_internal.compressed_data + inserted_at _timescaledb_internal.compressed_data, + is_hc _timescaledb_internal.compressed_data ) WITH (toast_tuple_target='128'); ALTER TABLE ONLY _timescaledb_internal.compress_hyper_6_98_chunk ALTER COLUMN _ts_meta_count SET STATISTICS 1000; @@ -3895,23 +4361,6 @@ CREATE TABLE public.browser_sessions ( ); --- --- Name: check_results; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.check_results ( - id uuid NOT NULL, - checked_at timestamp(0) without time zone NOT NULL, - organization_id uuid NOT NULL, - check_id uuid NOT NULL, - status integer NOT NULL, - output text, - response_time_ms double precision, - agent_token_id uuid, - value double precision -); - - -- -- Name: checks; Type: TABLE; Schema: public; Owner: - -- @@ -4921,7 +5370,8 @@ CREATE TABLE public.organizations ( custom_free_device_limit integer, custom_price_per_device numeric(10,2), default_escalation_policy_id uuid, - alert_routing character varying(255) DEFAULT 'builtin'::character varying NOT NULL + alert_routing character varying(255) DEFAULT 'builtin'::character varying NOT NULL, + data_retention_days integer DEFAULT 365 NOT NULL ); @@ -5861,6 +6311,244 @@ CREATE TABLE public.wireless_clients ( ); +-- +-- Name: _hyper_3_102_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_102_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_10_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_10_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_110_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_110_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_117_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_117_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_122_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_122_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_133_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_133_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_145_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_145_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_160_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_160_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_162_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_162_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_166_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_166_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_169_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_169_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_172_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_172_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_189_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_189_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_199_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_199_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_19_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_19_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_202_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_202_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_208_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_208_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_22_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_22_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_25_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_25_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_28_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_28_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_30_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_30_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_37_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_37_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_40_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_40_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_49_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_49_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_56_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_56_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_63_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_63_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_69_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_69_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_74_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_74_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_7_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_7_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_83_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_83_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_85_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_85_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_8_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_8_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_93_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_93_chunk ALTER COLUMN is_hc SET DEFAULT true; + + +-- +-- Name: _hyper_3_9_chunk is_hc; Type: DEFAULT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_9_chunk ALTER COLUMN is_hc SET DEFAULT true; + + -- -- Name: error_tracker_errors id; Type: DEFAULT; Schema: public; Owner: - -- @@ -5882,6 +6570,22 @@ ALTER TABLE ONLY public.error_tracker_occurrences ALTER COLUMN id SET DEFAULT ne ALTER TABLE ONLY public.oban_jobs ALTER COLUMN id SET DEFAULT nextval('public.oban_jobs_id_seq'::regclass); +-- +-- Name: _hyper_14_191_chunk 191_124_check_results_pkey; Type: CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_14_191_chunk + ADD CONSTRAINT "191_124_check_results_pkey" PRIMARY KEY (id, checked_at); + + +-- +-- Name: _hyper_14_210_chunk 210_140_check_results_pkey; Type: CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_14_210_chunk + ADD CONSTRAINT "210_140_check_results_pkey" PRIMARY KEY (id, checked_at); + + -- -- Name: agent_assignments agent_assignments_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -6724,6 +7428,20 @@ CREATE INDEX _hyper_10_174_chunk__materialized_hypertable_10_bucket_idx ON _time CREATE INDEX _hyper_10_174_chunk__materialized_hypertable_10_sensor_id_bucke ON _timescaledb_internal._hyper_10_174_chunk USING btree (sensor_id, bucket DESC); +-- +-- Name: _hyper_10_205_chunk__materialized_hypertable_10_bucket_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_10_205_chunk__materialized_hypertable_10_bucket_idx ON _timescaledb_internal._hyper_10_205_chunk USING btree (bucket DESC); + + +-- +-- Name: _hyper_10_205_chunk__materialized_hypertable_10_sensor_id_bucke; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_10_205_chunk__materialized_hypertable_10_sensor_id_bucke ON _timescaledb_internal._hyper_10_205_chunk USING btree (sensor_id, bucket DESC); + + -- -- Name: _hyper_10_60_chunk__materialized_hypertable_10_bucket_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - -- @@ -6766,6 +7484,20 @@ CREATE INDEX _hyper_11_15_chunk__materialized_hypertable_11_bucket_idx ON _times CREATE INDEX _hyper_11_15_chunk__materialized_hypertable_11_interface_id_buc ON _timescaledb_internal._hyper_11_15_chunk USING btree (interface_id, bucket DESC); +-- +-- Name: _hyper_11_194_chunk__materialized_hypertable_11_bucket_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_11_194_chunk__materialized_hypertable_11_bucket_idx ON _timescaledb_internal._hyper_11_194_chunk USING btree (bucket DESC); + + +-- +-- Name: _hyper_11_194_chunk__materialized_hypertable_11_interface_id_bu; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_11_194_chunk__materialized_hypertable_11_interface_id_bu ON _timescaledb_internal._hyper_11_194_chunk USING btree (interface_id, bucket DESC); + + -- -- Name: _hyper_11_33_chunk__materialized_hypertable_11_bucket_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - -- @@ -6836,6 +7568,20 @@ CREATE INDEX _hyper_12_175_chunk__materialized_hypertable_12_bucket_idx ON _time CREATE INDEX _hyper_12_175_chunk__materialized_hypertable_12_interface_id_bu ON _timescaledb_internal._hyper_12_175_chunk USING btree (interface_id, bucket DESC); +-- +-- Name: _hyper_12_206_chunk__materialized_hypertable_12_bucket_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_12_206_chunk__materialized_hypertable_12_bucket_idx ON _timescaledb_internal._hyper_12_206_chunk USING btree (bucket DESC); + + +-- +-- Name: _hyper_12_206_chunk__materialized_hypertable_12_interface_id_bu; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_12_206_chunk__materialized_hypertable_12_interface_id_bu ON _timescaledb_internal._hyper_12_206_chunk USING btree (interface_id, bucket DESC); + + -- -- Name: _hyper_12_45_chunk__materialized_hypertable_12_bucket_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - -- @@ -6850,6 +7596,76 @@ CREATE INDEX _hyper_12_45_chunk__materialized_hypertable_12_bucket_idx ON _times CREATE INDEX _hyper_12_45_chunk__materialized_hypertable_12_interface_id_buc ON _timescaledb_internal._hyper_12_45_chunk USING btree (interface_id, bucket DESC); +-- +-- Name: _hyper_14_191_chunk_check_results_check_id_checked_at_index; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_14_191_chunk_check_results_check_id_checked_at_index ON _timescaledb_internal._hyper_14_191_chunk USING btree (check_id, checked_at); + + +-- +-- Name: _hyper_14_191_chunk_check_results_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_14_191_chunk_check_results_checked_at_idx ON _timescaledb_internal._hyper_14_191_chunk USING btree (checked_at DESC); + + +-- +-- Name: _hyper_14_191_chunk_check_results_organization_id_checked_at_in; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_14_191_chunk_check_results_organization_id_checked_at_in ON _timescaledb_internal._hyper_14_191_chunk USING btree (organization_id, checked_at); + + +-- +-- Name: _hyper_14_191_chunk_check_results_organization_id_status_index; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_14_191_chunk_check_results_organization_id_status_index ON _timescaledb_internal._hyper_14_191_chunk USING btree (organization_id, status); + + +-- +-- Name: _hyper_14_191_chunk_check_results_value_index; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_14_191_chunk_check_results_value_index ON _timescaledb_internal._hyper_14_191_chunk USING btree (value); + + +-- +-- Name: _hyper_14_210_chunk_check_results_check_id_checked_at_index; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_14_210_chunk_check_results_check_id_checked_at_index ON _timescaledb_internal._hyper_14_210_chunk USING btree (check_id, checked_at); + + +-- +-- Name: _hyper_14_210_chunk_check_results_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_14_210_chunk_check_results_checked_at_idx ON _timescaledb_internal._hyper_14_210_chunk USING btree (checked_at DESC); + + +-- +-- Name: _hyper_14_210_chunk_check_results_organization_id_checked_at_in; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_14_210_chunk_check_results_organization_id_checked_at_in ON _timescaledb_internal._hyper_14_210_chunk USING btree (organization_id, checked_at); + + +-- +-- Name: _hyper_14_210_chunk_check_results_organization_id_status_index; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_14_210_chunk_check_results_organization_id_status_index ON _timescaledb_internal._hyper_14_210_chunk USING btree (organization_id, status); + + +-- +-- Name: _hyper_14_210_chunk_check_results_value_index; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_14_210_chunk_check_results_value_index ON _timescaledb_internal._hyper_14_210_chunk USING btree (value); + + -- -- Name: _hyper_1_112_chunk_monitoring_checks_agent_token_id_device_id_c; Type: INDEX; Schema: _timescaledb_internal; Owner: - -- @@ -7130,6 +7946,118 @@ CREATE INDEX _hyper_1_170_chunk_monitoring_checks_device_id_agent_token_id_s ON CREATE INDEX _hyper_1_170_chunk_monitoring_checks_device_id_checked_at_idx ON _timescaledb_internal._hyper_1_170_chunk USING btree (device_id, checked_at DESC); +-- +-- Name: _hyper_1_188_chunk_monitoring_checks_agent_token_id_device_id_c; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_1_188_chunk_monitoring_checks_agent_token_id_device_id_c ON _timescaledb_internal._hyper_1_188_chunk USING btree (agent_token_id, device_id, checked_at); + + +-- +-- Name: _hyper_1_188_chunk_monitoring_checks_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_1_188_chunk_monitoring_checks_checked_at_idx ON _timescaledb_internal._hyper_1_188_chunk USING btree (checked_at DESC); + + +-- +-- Name: _hyper_1_188_chunk_monitoring_checks_device_id_agent_token_id_s; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_1_188_chunk_monitoring_checks_device_id_agent_token_id_s ON _timescaledb_internal._hyper_1_188_chunk USING btree (device_id, agent_token_id, status, checked_at); + + +-- +-- Name: _hyper_1_188_chunk_monitoring_checks_device_id_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_1_188_chunk_monitoring_checks_device_id_checked_at_idx ON _timescaledb_internal._hyper_1_188_chunk USING btree (device_id, checked_at DESC); + + +-- +-- Name: _hyper_1_198_chunk_monitoring_checks_agent_token_id_device_id_c; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_1_198_chunk_monitoring_checks_agent_token_id_device_id_c ON _timescaledb_internal._hyper_1_198_chunk USING btree (agent_token_id, device_id, checked_at); + + +-- +-- Name: _hyper_1_198_chunk_monitoring_checks_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_1_198_chunk_monitoring_checks_checked_at_idx ON _timescaledb_internal._hyper_1_198_chunk USING btree (checked_at DESC); + + +-- +-- Name: _hyper_1_198_chunk_monitoring_checks_device_id_agent_token_id_s; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_1_198_chunk_monitoring_checks_device_id_agent_token_id_s ON _timescaledb_internal._hyper_1_198_chunk USING btree (device_id, agent_token_id, status, checked_at); + + +-- +-- Name: _hyper_1_198_chunk_monitoring_checks_device_id_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_1_198_chunk_monitoring_checks_device_id_checked_at_idx ON _timescaledb_internal._hyper_1_198_chunk USING btree (device_id, checked_at DESC); + + +-- +-- Name: _hyper_1_201_chunk_monitoring_checks_agent_token_id_device_id_c; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_1_201_chunk_monitoring_checks_agent_token_id_device_id_c ON _timescaledb_internal._hyper_1_201_chunk USING btree (agent_token_id, device_id, checked_at); + + +-- +-- Name: _hyper_1_201_chunk_monitoring_checks_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_1_201_chunk_monitoring_checks_checked_at_idx ON _timescaledb_internal._hyper_1_201_chunk USING btree (checked_at DESC); + + +-- +-- Name: _hyper_1_201_chunk_monitoring_checks_device_id_agent_token_id_s; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_1_201_chunk_monitoring_checks_device_id_agent_token_id_s ON _timescaledb_internal._hyper_1_201_chunk USING btree (device_id, agent_token_id, status, checked_at); + + +-- +-- Name: _hyper_1_201_chunk_monitoring_checks_device_id_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_1_201_chunk_monitoring_checks_device_id_checked_at_idx ON _timescaledb_internal._hyper_1_201_chunk USING btree (device_id, checked_at DESC); + + +-- +-- Name: _hyper_1_209_chunk_monitoring_checks_agent_token_id_device_id_c; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_1_209_chunk_monitoring_checks_agent_token_id_device_id_c ON _timescaledb_internal._hyper_1_209_chunk USING btree (agent_token_id, device_id, checked_at); + + +-- +-- Name: _hyper_1_209_chunk_monitoring_checks_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_1_209_chunk_monitoring_checks_checked_at_idx ON _timescaledb_internal._hyper_1_209_chunk USING btree (checked_at DESC); + + +-- +-- Name: _hyper_1_209_chunk_monitoring_checks_device_id_agent_token_id_s; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_1_209_chunk_monitoring_checks_device_id_agent_token_id_s ON _timescaledb_internal._hyper_1_209_chunk USING btree (device_id, agent_token_id, status, checked_at); + + +-- +-- Name: _hyper_1_209_chunk_monitoring_checks_device_id_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_1_209_chunk_monitoring_checks_device_id_checked_at_idx ON _timescaledb_internal._hyper_1_209_chunk USING btree (device_id, checked_at DESC); + + -- -- Name: _hyper_2_103_chunk_snmp_sensor_readings_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - -- @@ -7382,6 +8310,90 @@ CREATE INDEX _hyper_2_18_chunk_snmp_sensor_readings_sensor_id_checked_at_idx ON CREATE INDEX _hyper_2_18_chunk_snmp_sensor_readings_status_idx ON _timescaledb_internal._hyper_2_18_chunk USING btree (status); +-- +-- Name: _hyper_2_190_chunk_snmp_sensor_readings_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_2_190_chunk_snmp_sensor_readings_checked_at_idx ON _timescaledb_internal._hyper_2_190_chunk USING btree (checked_at DESC); + + +-- +-- Name: _hyper_2_190_chunk_snmp_sensor_readings_sensor_id_checked_at_id; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_2_190_chunk_snmp_sensor_readings_sensor_id_checked_at_id ON _timescaledb_internal._hyper_2_190_chunk USING btree (sensor_id, checked_at DESC); + + +-- +-- Name: _hyper_2_190_chunk_snmp_sensor_readings_status_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_2_190_chunk_snmp_sensor_readings_status_idx ON _timescaledb_internal._hyper_2_190_chunk USING btree (status); + + +-- +-- Name: _hyper_2_200_chunk_snmp_sensor_readings_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_2_200_chunk_snmp_sensor_readings_checked_at_idx ON _timescaledb_internal._hyper_2_200_chunk USING btree (checked_at DESC); + + +-- +-- Name: _hyper_2_200_chunk_snmp_sensor_readings_sensor_id_checked_at_id; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_2_200_chunk_snmp_sensor_readings_sensor_id_checked_at_id ON _timescaledb_internal._hyper_2_200_chunk USING btree (sensor_id, checked_at DESC); + + +-- +-- Name: _hyper_2_200_chunk_snmp_sensor_readings_status_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_2_200_chunk_snmp_sensor_readings_status_idx ON _timescaledb_internal._hyper_2_200_chunk USING btree (status); + + +-- +-- Name: _hyper_2_203_chunk_snmp_sensor_readings_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_2_203_chunk_snmp_sensor_readings_checked_at_idx ON _timescaledb_internal._hyper_2_203_chunk USING btree (checked_at DESC); + + +-- +-- Name: _hyper_2_203_chunk_snmp_sensor_readings_sensor_id_checked_at_id; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_2_203_chunk_snmp_sensor_readings_sensor_id_checked_at_id ON _timescaledb_internal._hyper_2_203_chunk USING btree (sensor_id, checked_at DESC); + + +-- +-- Name: _hyper_2_203_chunk_snmp_sensor_readings_status_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_2_203_chunk_snmp_sensor_readings_status_idx ON _timescaledb_internal._hyper_2_203_chunk USING btree (status); + + +-- +-- Name: _hyper_2_207_chunk_snmp_sensor_readings_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_2_207_chunk_snmp_sensor_readings_checked_at_idx ON _timescaledb_internal._hyper_2_207_chunk USING btree (checked_at DESC); + + +-- +-- Name: _hyper_2_207_chunk_snmp_sensor_readings_sensor_id_checked_at_id; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_2_207_chunk_snmp_sensor_readings_sensor_id_checked_at_id ON _timescaledb_internal._hyper_2_207_chunk USING btree (sensor_id, checked_at DESC); + + +-- +-- Name: _hyper_2_207_chunk_snmp_sensor_readings_status_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_2_207_chunk_snmp_sensor_readings_status_idx ON _timescaledb_internal._hyper_2_207_chunk USING btree (status); + + -- -- Name: _hyper_2_21_chunk_snmp_sensor_readings_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - -- @@ -7844,6 +8856,34 @@ CREATE INDEX _hyper_3_172_chunk_snmp_interface_stats_checked_at_idx ON _timescal CREATE INDEX _hyper_3_172_chunk_snmp_interface_stats_interface_id_checked_at ON _timescaledb_internal._hyper_3_172_chunk USING btree (interface_id, checked_at DESC); +-- +-- Name: _hyper_3_189_chunk_snmp_interface_stats_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_3_189_chunk_snmp_interface_stats_checked_at_idx ON _timescaledb_internal._hyper_3_189_chunk USING btree (checked_at DESC); + + +-- +-- Name: _hyper_3_189_chunk_snmp_interface_stats_interface_id_checked_at; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_3_189_chunk_snmp_interface_stats_interface_id_checked_at ON _timescaledb_internal._hyper_3_189_chunk USING btree (interface_id, checked_at DESC); + + +-- +-- Name: _hyper_3_199_chunk_snmp_interface_stats_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_3_199_chunk_snmp_interface_stats_checked_at_idx ON _timescaledb_internal._hyper_3_199_chunk USING btree (checked_at DESC); + + +-- +-- Name: _hyper_3_199_chunk_snmp_interface_stats_interface_id_checked_at; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_3_199_chunk_snmp_interface_stats_interface_id_checked_at ON _timescaledb_internal._hyper_3_199_chunk USING btree (interface_id, checked_at DESC); + + -- -- Name: _hyper_3_19_chunk_snmp_interface_stats_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - -- @@ -7858,6 +8898,34 @@ CREATE INDEX _hyper_3_19_chunk_snmp_interface_stats_checked_at_idx ON _timescale CREATE INDEX _hyper_3_19_chunk_snmp_interface_stats_interface_id_checked_at_ ON _timescaledb_internal._hyper_3_19_chunk USING btree (interface_id, checked_at DESC); +-- +-- Name: _hyper_3_202_chunk_snmp_interface_stats_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_3_202_chunk_snmp_interface_stats_checked_at_idx ON _timescaledb_internal._hyper_3_202_chunk USING btree (checked_at DESC); + + +-- +-- Name: _hyper_3_202_chunk_snmp_interface_stats_interface_id_checked_at; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_3_202_chunk_snmp_interface_stats_interface_id_checked_at ON _timescaledb_internal._hyper_3_202_chunk USING btree (interface_id, checked_at DESC); + + +-- +-- Name: _hyper_3_208_chunk_snmp_interface_stats_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_3_208_chunk_snmp_interface_stats_checked_at_idx ON _timescaledb_internal._hyper_3_208_chunk USING btree (checked_at DESC); + + +-- +-- Name: _hyper_3_208_chunk_snmp_interface_stats_interface_id_checked_at; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_3_208_chunk_snmp_interface_stats_interface_id_checked_at ON _timescaledb_internal._hyper_3_208_chunk USING btree (interface_id, checked_at DESC); + + -- -- Name: _hyper_3_22_chunk_snmp_interface_stats_checked_at_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - -- @@ -8138,6 +9206,20 @@ CREATE INDEX _hyper_7_148_chunk__materialized_hypertable_7_bucket_idx ON _timesc CREATE INDEX _hyper_7_148_chunk__materialized_hypertable_7_device_id_bucket_ ON _timescaledb_internal._hyper_7_148_chunk USING btree (device_id, bucket DESC); +-- +-- Name: _hyper_7_192_chunk__materialized_hypertable_7_bucket_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_7_192_chunk__materialized_hypertable_7_bucket_idx ON _timescaledb_internal._hyper_7_192_chunk USING btree (bucket DESC); + + +-- +-- Name: _hyper_7_192_chunk__materialized_hypertable_7_device_id_bucket_; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_7_192_chunk__materialized_hypertable_7_device_id_bucket_ ON _timescaledb_internal._hyper_7_192_chunk USING btree (device_id, bucket DESC); + + -- -- Name: _hyper_7_34_chunk__materialized_hypertable_7_bucket_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - -- @@ -8194,6 +9276,20 @@ CREATE INDEX _hyper_8_173_chunk__materialized_hypertable_8_bucket_idx ON _timesc CREATE INDEX _hyper_8_173_chunk__materialized_hypertable_8_device_id_bucket_ ON _timescaledb_internal._hyper_8_173_chunk USING btree (device_id, bucket DESC); +-- +-- Name: _hyper_8_204_chunk__materialized_hypertable_8_bucket_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_8_204_chunk__materialized_hypertable_8_bucket_idx ON _timescaledb_internal._hyper_8_204_chunk USING btree (bucket DESC); + + +-- +-- Name: _hyper_8_204_chunk__materialized_hypertable_8_device_id_bucket_; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_8_204_chunk__materialized_hypertable_8_device_id_bucket_ ON _timescaledb_internal._hyper_8_204_chunk USING btree (device_id, bucket DESC); + + -- -- Name: _hyper_8_46_chunk__materialized_hypertable_8_bucket_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - -- @@ -8236,6 +9332,20 @@ CREATE INDEX _hyper_9_146_chunk__materialized_hypertable_9_bucket_idx ON _timesc CREATE INDEX _hyper_9_146_chunk__materialized_hypertable_9_sensor_id_bucket_ ON _timescaledb_internal._hyper_9_146_chunk USING btree (sensor_id, bucket DESC); +-- +-- Name: _hyper_9_193_chunk__materialized_hypertable_9_bucket_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_9_193_chunk__materialized_hypertable_9_bucket_idx ON _timescaledb_internal._hyper_9_193_chunk USING btree (bucket DESC); + + +-- +-- Name: _hyper_9_193_chunk__materialized_hypertable_9_sensor_id_bucket_; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX _hyper_9_193_chunk__materialized_hypertable_9_sensor_id_bucket_ ON _timescaledb_internal._hyper_9_193_chunk USING btree (sensor_id, bucket DESC); + + -- -- Name: _hyper_9_50_chunk__materialized_hypertable_9_bucket_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - -- @@ -8474,6 +9584,20 @@ CREATE INDEX compress_hyper_4_179_chunk_device_id__ts_meta_min_1__ts_met_idx ON CREATE INDEX compress_hyper_4_183_chunk_device_id__ts_meta_min_1__ts_met_idx ON _timescaledb_internal.compress_hyper_4_183_chunk USING btree (device_id, _ts_meta_min_1 DESC, _ts_meta_max_1 DESC, _ts_meta_min_2, _ts_meta_max_2); +-- +-- Name: compress_hyper_4_185_chunk_device_id__ts_meta_min_1__ts_met_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX compress_hyper_4_185_chunk_device_id__ts_meta_min_1__ts_met_idx ON _timescaledb_internal.compress_hyper_4_185_chunk USING btree (device_id, _ts_meta_min_1 DESC, _ts_meta_max_1 DESC, _ts_meta_min_2, _ts_meta_max_2); + + +-- +-- Name: compress_hyper_4_195_chunk_device_id__ts_meta_min_1__ts_met_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX compress_hyper_4_195_chunk_device_id__ts_meta_min_1__ts_met_idx ON _timescaledb_internal.compress_hyper_4_195_chunk USING btree (device_id, _ts_meta_min_1 DESC, _ts_meta_max_1 DESC, _ts_meta_min_2, _ts_meta_max_2); + + -- -- Name: compress_hyper_5_106_chunk_sensor_id__ts_meta_min_1__ts_met_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - -- @@ -8579,6 +9703,20 @@ CREATE INDEX compress_hyper_5_180_chunk_sensor_id__ts_meta_min_1__ts_met_idx ON CREATE INDEX compress_hyper_5_182_chunk_sensor_id__ts_meta_min_1__ts_met_idx ON _timescaledb_internal.compress_hyper_5_182_chunk USING btree (sensor_id, _ts_meta_min_1 DESC, _ts_meta_max_1 DESC, _ts_meta_min_2, _ts_meta_max_2); +-- +-- Name: compress_hyper_5_186_chunk_sensor_id__ts_meta_min_1__ts_met_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX compress_hyper_5_186_chunk_sensor_id__ts_meta_min_1__ts_met_idx ON _timescaledb_internal.compress_hyper_5_186_chunk USING btree (sensor_id, _ts_meta_min_1 DESC, _ts_meta_max_1 DESC, _ts_meta_min_2, _ts_meta_max_2); + + +-- +-- Name: compress_hyper_5_196_chunk_sensor_id__ts_meta_min_1__ts_met_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX compress_hyper_5_196_chunk_sensor_id__ts_meta_min_1__ts_met_idx ON _timescaledb_internal.compress_hyper_5_196_chunk USING btree (sensor_id, _ts_meta_min_1 DESC, _ts_meta_max_1 DESC, _ts_meta_min_2, _ts_meta_max_2); + + -- -- Name: compress_hyper_5_41_chunk_sensor_id__ts_meta_min_1__ts_meta_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - -- @@ -8754,6 +9892,20 @@ CREATE INDEX compress_hyper_6_181_chunk_interface_id__ts_meta_min_1__ts__idx ON CREATE INDEX compress_hyper_6_184_chunk_interface_id__ts_meta_min_1__ts__idx ON _timescaledb_internal.compress_hyper_6_184_chunk USING btree (interface_id, _ts_meta_min_1 DESC, _ts_meta_max_1 DESC); +-- +-- Name: compress_hyper_6_187_chunk_interface_id__ts_meta_min_1__ts__idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX compress_hyper_6_187_chunk_interface_id__ts_meta_min_1__ts__idx ON _timescaledb_internal.compress_hyper_6_187_chunk USING btree (interface_id, _ts_meta_min_1 DESC, _ts_meta_max_1 DESC); + + +-- +-- Name: compress_hyper_6_197_chunk_interface_id__ts_meta_min_1__ts__idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - +-- + +CREATE INDEX compress_hyper_6_197_chunk_interface_id__ts_meta_min_1__ts__idx ON _timescaledb_internal.compress_hyper_6_197_chunk USING btree (interface_id, _ts_meta_min_1 DESC, _ts_meta_max_1 DESC); + + -- -- Name: compress_hyper_6_31_chunk_interface_id__ts_meta_min_1__ts_m_idx; Type: INDEX; Schema: _timescaledb_internal; Owner: - -- @@ -9139,6 +10291,13 @@ CREATE INDEX checks_check_type_index ON public.checks USING btree (check_type); CREATE INDEX checks_device_id_index ON public.checks USING btree (device_id); +-- +-- Name: checks_device_type_source_unique_index; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX checks_device_type_source_unique_index ON public.checks USING btree (device_id, check_type, source_id) WHERE (((source_type)::text = 'auto_discovery'::text) AND (source_id IS NOT NULL)); + + -- -- Name: checks_enabled_index; Type: INDEX; Schema: public; Owner: - -- @@ -9482,6 +10641,13 @@ CREATE INDEX escalation_rules_escalation_policy_id_index ON public.escalation_ru CREATE INDEX escalation_targets_escalation_rule_id_index ON public.escalation_targets USING btree (escalation_rule_id); +-- +-- Name: escalation_targets_user_id_index; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX escalation_targets_user_id_index ON public.escalation_targets USING btree (user_id); + + -- -- Name: firmware_releases_vendor_product_line_index; Type: INDEX; Schema: public; Owner: - -- @@ -9811,6 +10977,13 @@ CREATE INDEX monitoring_checks_device_id_agent_token_id_status_checked_at_in ON CREATE INDEX monitoring_checks_device_id_checked_at_idx ON public.monitoring_checks USING btree (device_id, checked_at DESC); +-- +-- Name: notification_digests_organization_id_index; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX notification_digests_organization_id_index ON public.notification_digests USING btree (organization_id); + + -- -- Name: notification_digests_user_id_window_start_index; Type: INDEX; Schema: public; Owner: - -- @@ -9916,6 +11089,13 @@ CREATE INDEX on_call_layer_members_layer_id_index ON public.on_call_layer_member CREATE UNIQUE INDEX on_call_layer_members_layer_id_user_id_index ON public.on_call_layer_members USING btree (layer_id, user_id); +-- +-- Name: on_call_layer_members_user_id_index; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX on_call_layer_members_user_id_index ON public.on_call_layer_members USING btree (user_id); + + -- -- Name: on_call_layers_schedule_id_index; Type: INDEX; Schema: public; Owner: - -- @@ -9930,6 +11110,13 @@ CREATE INDEX on_call_layers_schedule_id_index ON public.on_call_layers USING btr CREATE INDEX on_call_notifications_incident_id_index ON public.on_call_notifications USING btree (incident_id); +-- +-- Name: on_call_notifications_user_id_index; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX on_call_notifications_user_id_index ON public.on_call_notifications USING btree (user_id); + + -- -- Name: on_call_overrides_schedule_id_start_time_end_time_index; Type: INDEX; Schema: public; Owner: - -- @@ -9937,6 +11124,13 @@ CREATE INDEX on_call_notifications_incident_id_index ON public.on_call_notificat CREATE INDEX on_call_overrides_schedule_id_start_time_end_time_index ON public.on_call_overrides USING btree (schedule_id, start_time, end_time); +-- +-- Name: on_call_overrides_user_id_index; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX on_call_overrides_user_id_index ON public.on_call_overrides USING btree (user_id); + + -- -- Name: on_call_schedules_organization_id_index; Type: INDEX; Schema: public; Owner: - -- @@ -10280,6 +11474,13 @@ CREATE INDEX site_outages_active_idx ON public.site_outages USING btree (site_id CREATE INDEX site_outages_organization_id_started_at_index ON public.site_outages USING btree (organization_id, started_at); +-- +-- Name: site_outages_site_id_index; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX site_outages_site_id_index ON public.site_outages USING btree (site_id); + + -- -- Name: sites_agent_token_id_index; Type: INDEX; Schema: public; Owner: - -- @@ -11317,6 +12518,30 @@ ALTER TABLE ONLY _timescaledb_internal._hyper_3_172_chunk ADD CONSTRAINT "172_116_snmp_interface_stats_interface_id_fkey" FOREIGN KEY (interface_id) REFERENCES public.snmp_interfaces(id) ON DELETE CASCADE; +-- +-- Name: _hyper_1_188_chunk 188_117_monitoring_checks_agent_token_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_1_188_chunk + ADD CONSTRAINT "188_117_monitoring_checks_agent_token_id_fkey" FOREIGN KEY (agent_token_id) REFERENCES public.agent_tokens(id) ON DELETE SET NULL; + + +-- +-- Name: _hyper_1_188_chunk 188_118_monitoring_checks_device_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_1_188_chunk + ADD CONSTRAINT "188_118_monitoring_checks_device_id_fkey" FOREIGN KEY (device_id) REFERENCES public.devices(id) ON DELETE CASCADE; + + +-- +-- Name: _hyper_3_189_chunk 189_119_snmp_interface_stats_interface_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_189_chunk + ADD CONSTRAINT "189_119_snmp_interface_stats_interface_id_fkey" FOREIGN KEY (interface_id) REFERENCES public.snmp_interfaces(id) ON DELETE CASCADE; + + -- -- Name: _hyper_2_18_chunk 18_12_snmp_sensor_readings_sensor_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - -- @@ -11325,6 +12550,62 @@ ALTER TABLE ONLY _timescaledb_internal._hyper_2_18_chunk ADD CONSTRAINT "18_12_snmp_sensor_readings_sensor_id_fkey" FOREIGN KEY (sensor_id) REFERENCES public.snmp_sensors(id) ON DELETE CASCADE; +-- +-- Name: _hyper_2_190_chunk 190_120_snmp_sensor_readings_sensor_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_2_190_chunk + ADD CONSTRAINT "190_120_snmp_sensor_readings_sensor_id_fkey" FOREIGN KEY (sensor_id) REFERENCES public.snmp_sensors(id) ON DELETE CASCADE; + + +-- +-- Name: _hyper_14_191_chunk 191_121_check_results_agent_token_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_14_191_chunk + ADD CONSTRAINT "191_121_check_results_agent_token_id_fkey" FOREIGN KEY (agent_token_id) REFERENCES public.agent_tokens(id) ON DELETE SET NULL; + + +-- +-- Name: _hyper_14_191_chunk 191_122_check_results_check_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_14_191_chunk + ADD CONSTRAINT "191_122_check_results_check_id_fkey" FOREIGN KEY (check_id) REFERENCES public.checks(id) ON DELETE CASCADE; + + +-- +-- Name: _hyper_14_191_chunk 191_123_check_results_organization_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_14_191_chunk + ADD CONSTRAINT "191_123_check_results_organization_id_fkey" FOREIGN KEY (organization_id) REFERENCES public.organizations(id) ON DELETE CASCADE; + + +-- +-- Name: _hyper_1_198_chunk 198_125_monitoring_checks_agent_token_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_1_198_chunk + ADD CONSTRAINT "198_125_monitoring_checks_agent_token_id_fkey" FOREIGN KEY (agent_token_id) REFERENCES public.agent_tokens(id) ON DELETE SET NULL; + + +-- +-- Name: _hyper_1_198_chunk 198_126_monitoring_checks_device_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_1_198_chunk + ADD CONSTRAINT "198_126_monitoring_checks_device_id_fkey" FOREIGN KEY (device_id) REFERENCES public.devices(id) ON DELETE CASCADE; + + +-- +-- Name: _hyper_3_199_chunk 199_127_snmp_interface_stats_interface_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_199_chunk + ADD CONSTRAINT "199_127_snmp_interface_stats_interface_id_fkey" FOREIGN KEY (interface_id) REFERENCES public.snmp_interfaces(id) ON DELETE CASCADE; + + -- -- Name: _hyper_3_19_chunk 19_13_snmp_interface_stats_interface_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - -- @@ -11333,6 +12614,102 @@ ALTER TABLE ONLY _timescaledb_internal._hyper_3_19_chunk ADD CONSTRAINT "19_13_snmp_interface_stats_interface_id_fkey" FOREIGN KEY (interface_id) REFERENCES public.snmp_interfaces(id) ON DELETE CASCADE; +-- +-- Name: _hyper_2_200_chunk 200_128_snmp_sensor_readings_sensor_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_2_200_chunk + ADD CONSTRAINT "200_128_snmp_sensor_readings_sensor_id_fkey" FOREIGN KEY (sensor_id) REFERENCES public.snmp_sensors(id) ON DELETE CASCADE; + + +-- +-- Name: _hyper_1_201_chunk 201_129_monitoring_checks_agent_token_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_1_201_chunk + ADD CONSTRAINT "201_129_monitoring_checks_agent_token_id_fkey" FOREIGN KEY (agent_token_id) REFERENCES public.agent_tokens(id) ON DELETE SET NULL; + + +-- +-- Name: _hyper_1_201_chunk 201_130_monitoring_checks_device_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_1_201_chunk + ADD CONSTRAINT "201_130_monitoring_checks_device_id_fkey" FOREIGN KEY (device_id) REFERENCES public.devices(id) ON DELETE CASCADE; + + +-- +-- Name: _hyper_3_202_chunk 202_131_snmp_interface_stats_interface_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_202_chunk + ADD CONSTRAINT "202_131_snmp_interface_stats_interface_id_fkey" FOREIGN KEY (interface_id) REFERENCES public.snmp_interfaces(id) ON DELETE CASCADE; + + +-- +-- Name: _hyper_2_203_chunk 203_132_snmp_sensor_readings_sensor_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_2_203_chunk + ADD CONSTRAINT "203_132_snmp_sensor_readings_sensor_id_fkey" FOREIGN KEY (sensor_id) REFERENCES public.snmp_sensors(id) ON DELETE CASCADE; + + +-- +-- Name: _hyper_2_207_chunk 207_133_snmp_sensor_readings_sensor_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_2_207_chunk + ADD CONSTRAINT "207_133_snmp_sensor_readings_sensor_id_fkey" FOREIGN KEY (sensor_id) REFERENCES public.snmp_sensors(id) ON DELETE CASCADE; + + +-- +-- Name: _hyper_3_208_chunk 208_134_snmp_interface_stats_interface_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_3_208_chunk + ADD CONSTRAINT "208_134_snmp_interface_stats_interface_id_fkey" FOREIGN KEY (interface_id) REFERENCES public.snmp_interfaces(id) ON DELETE CASCADE; + + +-- +-- Name: _hyper_1_209_chunk 209_135_monitoring_checks_agent_token_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_1_209_chunk + ADD CONSTRAINT "209_135_monitoring_checks_agent_token_id_fkey" FOREIGN KEY (agent_token_id) REFERENCES public.agent_tokens(id) ON DELETE SET NULL; + + +-- +-- Name: _hyper_1_209_chunk 209_136_monitoring_checks_device_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_1_209_chunk + ADD CONSTRAINT "209_136_monitoring_checks_device_id_fkey" FOREIGN KEY (device_id) REFERENCES public.devices(id) ON DELETE CASCADE; + + +-- +-- Name: _hyper_14_210_chunk 210_137_check_results_agent_token_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_14_210_chunk + ADD CONSTRAINT "210_137_check_results_agent_token_id_fkey" FOREIGN KEY (agent_token_id) REFERENCES public.agent_tokens(id) ON DELETE SET NULL; + + +-- +-- Name: _hyper_14_210_chunk 210_138_check_results_check_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_14_210_chunk + ADD CONSTRAINT "210_138_check_results_check_id_fkey" FOREIGN KEY (check_id) REFERENCES public.checks(id) ON DELETE CASCADE; + + +-- +-- Name: _hyper_14_210_chunk 210_139_check_results_organization_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - +-- + +ALTER TABLE ONLY _timescaledb_internal._hyper_14_210_chunk + ADD CONSTRAINT "210_139_check_results_organization_id_fkey" FOREIGN KEY (organization_id) REFERENCES public.organizations(id) ON DELETE CASCADE; + + -- -- Name: _hyper_2_21_chunk 21_21_snmp_sensor_readings_sensor_id_fkey; Type: FK CONSTRAINT; Schema: _timescaledb_internal; Owner: - -- @@ -12801,7 +14178,7 @@ ALTER TABLE ONLY public.wireless_clients -- PostgreSQL database dump complete -- -\unrestrict RRAhb3L0Us7vE3B3YUZQWFpUy9oe9JDkh3ZeMLm2wvwJPMjBbIXH8zFu6qq0U19 +\unrestrict 58n9yz3M1gCN5t2tMwVCXpismPQgdWzmGfJI4AZxbUhDND1zz8QIj8oDYzqLMz8 INSERT INTO public."schema_migrations" (version) VALUES (20251221192340); INSERT INTO public."schema_migrations" (version) VALUES (20251221192454); @@ -12996,3 +14373,8 @@ INSERT INTO public."schema_migrations" (version) VALUES (20260322152809); INSERT INTO public."schema_migrations" (version) VALUES (20260322161037); INSERT INTO public."schema_migrations" (version) VALUES (20260322161750); INSERT INTO public."schema_migrations" (version) VALUES (20260322175649); +INSERT INTO public."schema_migrations" (version) VALUES (20260324193531); +INSERT INTO public."schema_migrations" (version) VALUES (20260324193820); +INSERT INTO public."schema_migrations" (version) VALUES (20260325180211); +INSERT INTO public."schema_migrations" (version) VALUES (20260325200000); +INSERT INTO public."schema_migrations" (version) VALUES (20260325215632); diff --git a/test/towerops/monitoring_test.exs b/test/towerops/monitoring_test.exs index e877ce01..c9a13b1b 100644 --- a/test/towerops/monitoring_test.exs +++ b/test/towerops/monitoring_test.exs @@ -620,6 +620,112 @@ defmodule Towerops.MonitoringTest do end end + describe "ensure_discovery_check/1" do + test "creates a new check when none exists", %{organization: org, device: device} do + attrs = %{ + organization_id: org.id, + device_id: device.id, + name: "eth0 Status", + check_type: "snmp_interface", + source_type: "auto_discovery", + source_id: Ecto.UUID.generate(), + interval_seconds: 60, + enabled: true, + config: %{"if_index" => 1, "if_descr" => "eth0"} + } + + assert {:ok, check} = Monitoring.ensure_discovery_check(attrs) + assert check.name == "eth0 Status" + assert check.check_type == "snmp_interface" + assert check.source_type == "auto_discovery" + end + + test "is idempotent - returns existing check on repeated calls", %{organization: org, device: device} do + source_id = Ecto.UUID.generate() + + attrs = %{ + organization_id: org.id, + device_id: device.id, + name: "eth0 Status", + check_type: "snmp_interface", + source_type: "auto_discovery", + source_id: source_id, + interval_seconds: 60, + enabled: true, + config: %{"if_index" => 1, "if_descr" => "eth0"} + } + + assert {:ok, first} = Monitoring.ensure_discovery_check(attrs) + assert {:ok, second} = Monitoring.ensure_discovery_check(attrs) + assert first.id == second.id + + # Verify only one check exists in DB + checks = + Repo.all( + from(c in Check, + where: c.device_id == ^device.id, + where: c.check_type == "snmp_interface", + where: c.source_id == ^source_id + ) + ) + + assert length(checks) == 1 + end + + test "updates name if it changed", %{organization: org, device: device} do + source_id = Ecto.UUID.generate() + + attrs = %{ + organization_id: org.id, + device_id: device.id, + name: "eth0 Status", + check_type: "snmp_interface", + source_type: "auto_discovery", + source_id: source_id, + interval_seconds: 60, + enabled: true, + config: %{"if_index" => 1, "if_descr" => "eth0"} + } + + assert {:ok, first} = Monitoring.ensure_discovery_check(attrs) + assert first.name == "eth0 Status" + + updated_attrs = %{attrs | name: "Interface eth0"} + assert {:ok, second} = Monitoring.ensure_discovery_check(updated_attrs) + assert second.id == first.id + assert second.name == "Interface eth0" + end + + test "differentiates checks by source_id", %{organization: org, device: device} do + base_attrs = %{ + organization_id: org.id, + device_id: device.id, + check_type: "snmp_interface", + source_type: "auto_discovery", + interval_seconds: 60, + enabled: true + } + + attrs1 = + Map.merge(base_attrs, %{ + name: "eth0 Status", + source_id: Ecto.UUID.generate(), + config: %{"if_index" => 1, "if_descr" => "eth0"} + }) + + attrs2 = + Map.merge(base_attrs, %{ + name: "eth1 Status", + source_id: Ecto.UUID.generate(), + config: %{"if_index" => 2, "if_descr" => "eth1"} + }) + + assert {:ok, check1} = Monitoring.ensure_discovery_check(attrs1) + assert {:ok, check2} = Monitoring.ensure_discovery_check(attrs2) + refute check1.id == check2.id + end + end + describe "ensure_default_ping_check/1" do test "creates a ping check for a device that has none", %{organization: org, device: device} do assert {:ok, check} = Monitoring.ensure_default_ping_check(device) diff --git a/test/towerops/snmp/profiles/vendors/airfiber_test.exs b/test/towerops/snmp/profiles/vendors/airfiber_test.exs index 3d3482b3..85e972dd 100644 --- a/test/towerops/snmp/profiles/vendors/airfiber_test.exs +++ b/test/towerops/snmp/profiles/vendors/airfiber_test.exs @@ -24,8 +24,7 @@ defmodule Towerops.Snmp.Profiles.Vendors.AirfiberTest do describe "detect_hardware/1" do test "returns hardware string with sysName when available" do - SnmpMock - |> expect(:get, fn _target, "1.3.6.1.2.1.1.5.0", _opts -> + expect(SnmpMock, :get, fn _target, "1.3.6.1.2.1.1.5.0", _opts -> {:ok, {:octet_string, "Climax-380 AF24"}} end) @@ -33,8 +32,7 @@ defmodule Towerops.Snmp.Profiles.Vendors.AirfiberTest do end test "returns generic hardware string when sysName unavailable" do - SnmpMock - |> expect(:get, fn _target, "1.3.6.1.2.1.1.5.0", _opts -> + expect(SnmpMock, :get, fn _target, "1.3.6.1.2.1.1.5.0", _opts -> {:error, :timeout} end)