api.vessels_view
Description
Expose vessels listing to web api
Table Definition
CREATE VIEW vessels_view AS (
WITH metrics AS (
SELECT COALESCE((( SELECT m."time"
FROM api.metrics m
WHERE (m.vessel_id = current_setting('vessel.id'::text))
ORDER BY m."time" DESC
LIMIT 1))::text, NULL::text) AS last_metrics
), metadata AS (
SELECT COALESCE((( SELECT m."time"
FROM api.metadata m
WHERE (m.vessel_id = current_setting('vessel.id'::text))))::text, NULL::text) AS last_contact
)
SELECT v.name,
v.mmsi,
v.created_at,
metadata.last_contact,
((((now() AT TIME ZONE 'UTC'::text))::timestamp with time zone - (metadata.last_contact)::timestamp with time zone) > 'PT1H10M'::interval) AS offline,
(((now() AT TIME ZONE 'UTC'::text))::timestamp with time zone - (metadata.last_contact)::timestamp with time zone) AS duration,
metrics.last_metrics,
((((now() AT TIME ZONE 'UTC'::text))::timestamp with time zone - (metrics.last_metrics)::timestamp with time zone) > 'PT1H10M'::interval) AS metrics_offline,
(((now() AT TIME ZONE 'UTC'::text))::timestamp with time zone - (metrics.last_metrics)::timestamp with time zone) AS duration_last_metrics
FROM auth.vessels v,
metadata,
metrics
WHERE ((v.owner_email)::text = current_setting('user.email'::text))
)
Columns
| Name | Type | Default | Nullable |
|---|---|---|---|
| created_at | timestamp with time zone | true | |
| duration | interval | true | |
| duration_last_metrics | interval | true | |
| last_contact | text | true | |
| last_metrics | text | true | |
| metrics_offline | boolean | true | |
| mmsi | numeric | true | |
| name | text | true | |
| offline | boolean | true |
Referenced Tables
| Name | Columns | Comment | Type |
|---|---|---|---|
| api.metrics | 11 | Stores metrics from vessel | BASE TABLE |
| api.metadata | 18 | Stores metadata received from vessel, aka signalk plugin | BASE TABLE |
| auth.vessels | 7 | vessels table link to accounts email user_id column | BASE TABLE |
Relations
erDiagram
"api.vessels_view" {
timestamp_with_time_zone created_at ""
interval duration ""
interval duration_last_metrics ""
text last_contact ""
text last_metrics ""
boolean metrics_offline ""
numeric mmsi ""
text name ""
boolean offline ""
}
Generated by tbls