Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

api.moorages

Description

The moorages table stores locations where vessels can stay (marinas, anchorages, etc.). Each moorage has geographic coordinates and metadata.

Columns

NameTypeDefaultNullableChildrenParentsComment
countrytexttrue
geoggeography(Point,4326)truepostgis geography type default SRID 4326 Unit: degres
home_flagbooleanfalsetrue
idintegerfalseapi.logbook api.stays
latitudedouble precisiontrue
longitudedouble precisiontrue
nametexttrue
nominatimjsonbtrueOutput of the nominatim reverse geocoding service, see https://nominatim.org/release-docs/develop/api/Reverse/
notestexttrue
overpassjsonbtrueOutput of the overpass API, see https://wiki.openstreetmap.org/wiki/Overpass_API
stay_codeinteger1trueapi.stays_atLink api.stays_at with api.moorages via FOREIGN KEY and REFERENCES
updated_attimestamp with time zonenow()falseTimestamp of last row modification, maintained automatically by moorages_moddatetime trigger. Use for incremental sync.
user_datajsonb‘{}’::jsonbtrueUser-defined data Mooring-specific data including images and custom fields
vessel_idtextfalseapi.metadataUnique identifier for the vessel associated with the api.metadata entry

Constraints

NameTypeDefinitionComment
moorages_geog_consistentCHECKCHECK ((geog = geography(st_makepoint(longitude, latitude))))Ensure geog column is consistent with longitude and latitude columns
moorages_id_not_nullnNOT NULL id
moorages_pkeyPRIMARY KEYPRIMARY KEY (id)
moorages_stay_code_fkeyFOREIGN KEYFOREIGN KEY (stay_code) REFERENCES api.stays_at(stay_code) ON DELETE RESTRICT
moorages_updated_at_not_nullnNOT NULL updated_at
moorages_vessel_id_fkeyFOREIGN KEYFOREIGN KEY (vessel_id) REFERENCES api.metadata(vessel_id) ON DELETE RESTRICTLink api.stays with api.metadata via vessel_id using FOREIGN KEY and REFERENCES
moorages_vessel_id_not_nullnNOT NULL vessel_id

Indexes

NameDefinitionComment
moorages_pkeyCREATE UNIQUE INDEX moorages_pkey ON api.moorages USING btree (id)
moorages_stay_code_idxCREATE INDEX moorages_stay_code_idx ON api.moorages USING btree (stay_code)Optimizes: Join with stays_at reference table
Query pattern: JOIN stays_at ON moorages.stay_code = stays_at.stay_code
Key strategy: stay_code first (join condition), vessel_id for RLS
Partial index: Valid moorages with coordinates only
Size: ~20 bytes per entry
Used by: Moorage views joining stay type descriptions
Performance: Enables efficient hash joins with stays_at lookup table
moorages_vessel_id_idxCREATE INDEX moorages_vessel_id_idx ON api.moorages USING btree (vessel_id)
moorages_vessel_idxCREATE INDEX moorages_vessel_idx ON api.moorages USING btree (vessel_id, id) INCLUDE (name, stay_code, notes, home_flag, geog, latitude, longitude, user_data) WHERE (geog IS NOT NULL)Optimizes: Vessel-specific moorage list and lookups
Query pattern: SELECT * FROM moorages WHERE vessel_id=X
Key strategy: vessel_id (RLS) + id (unique lookup)
INCLUDE clause: All display columns for index-only scans
Partial index: Only moorages with valid geographic coordinates
Size: ~200-300 bytes per entry (due to user_data JSONB)
Used by: Moorage list view, map displays, moorage detail lookups
Performance: Enables index-only scans for most moorage queries
Note: Large INCLUDE clause but justified by query patterns (small table, ~10-100 moorages per vessel)
moorages_vessel_updated_at_idxCREATE INDEX moorages_vessel_updated_at_idx ON api.moorages USING btree (vessel_id, updated_at DESC)Supports incremental sync: WHERE vessel_id = $1 AND updated_at > $cursor

Triggers

NameDefinitionComment
moorage_delete_triggerCREATE TRIGGER moorage_delete_trigger BEFORE DELETE ON api.moorages FOR EACH ROW EXECUTE FUNCTION moorage_delete_trigger_fn()Automatic delete logbook and stays reference when delete a moorage
moorage_update_triggerCREATE TRIGGER moorage_update_trigger AFTER UPDATE ON api.moorages FOR EACH ROW EXECUTE FUNCTION moorage_update_trigger_fn()Automatic update of name and stay_code on logbook and stays reference
moorages_moddatetimeCREATE TRIGGER moorages_moddatetime BEFORE UPDATE ON api.moorages FOR EACH ROW EXECUTE FUNCTION moddatetime(‘updated_at’)Automatic update of updated_at on table modification
moorages_update_user_data_triggerCREATE TRIGGER moorages_update_user_data_trigger BEFORE UPDATE ON api.moorages FOR EACH ROW EXECUTE FUNCTION update_tbl_userdata_added_at_trigger_fn()BEFORE UPDATE ON api.moorages run function public.update_tbl_userdata_added_at_trigger_fn to update the user_data field with current date in ISO format when polar or images change

Relations

erDiagram

"api.logbook" }o--o| "api.moorages" : "FOREIGN KEY (_from_moorage_id) REFERENCES api.moorages(id) ON DELETE RESTRICT"
"api.logbook" }o--o| "api.moorages" : "FOREIGN KEY (_to_moorage_id) REFERENCES api.moorages(id) ON DELETE RESTRICT"
"api.logbook" }o--|| "api.metadata" : "FOREIGN KEY (vessel_id) REFERENCES api.metadata(vessel_id) ON DELETE RESTRICT"
"api.stays" }o--o| "api.moorages" : "FOREIGN KEY (moorage_id) REFERENCES api.moorages(id) ON DELETE RESTRICT"
"api.stays" }o--o| "api.stays_at" : "FOREIGN KEY (stay_code) REFERENCES api.stays_at(stay_code) ON DELETE RESTRICT"
"api.stays" }o--|| "api.metadata" : "FOREIGN KEY (vessel_id) REFERENCES api.metadata(vessel_id) ON DELETE RESTRICT"
"api.moorages" }o--o| "api.stays_at" : "FOREIGN KEY (stay_code) REFERENCES api.stays_at(stay_code) ON DELETE RESTRICT"
"api.moorages" }o--|| "api.metadata" : "FOREIGN KEY (vessel_id) REFERENCES api.metadata(vessel_id) ON DELETE RESTRICT"
"api.metadata" |o--|| "auth.vessels" : "FOREIGN KEY (vessel_id) REFERENCES auth.vessels(vessel_id) ON DELETE RESTRICT"
"api.metrics" }o--|| "api.metadata" : "FOREIGN KEY (vessel_id) REFERENCES api.metadata(vessel_id) ON DELETE RESTRICT"

"api.moorages" {
  text country ""
  geography_Point_4326_ geog "postgis geography type default SRID 4326 Unit: degres"
  boolean home_flag ""
  integer id ""
  double_precision latitude ""
  double_precision longitude ""
  text name ""
  jsonb nominatim "Output of the nominatim reverse geocoding service, see https://nominatim.org/release-docs/develop/api/Reverse/"
  text notes ""
  jsonb overpass "Output of the overpass API, see https://wiki.openstreetmap.org/wiki/Overpass_API"
  integer stay_code FK "Link api.stays_at with api.moorages via FOREIGN KEY and REFERENCES"
  timestamp_with_time_zone updated_at "Timestamp of last row modification, maintained automatically by moorages_moddatetime trigger. Use for incremental sync."
  jsonb user_data "User-defined data Mooring-specific data including images and custom fields"
  text vessel_id FK "Unique identifier for the vessel associated with the api.metadata entry"
}
"api.logbook" {
  text _from "Name of the location where the log started, usually a moorage name"
  double_precision _from_lat ""
  double_precision _from_lng ""
  integer _from_moorage_id FK "Link api.moorages with api.logbook via FOREIGN KEY and REFERENCES"
  timestamp_with_time_zone _from_time ""
  text _to "Name of the location where the log ended, usually a moorage name"
  double_precision _to_lat ""
  double_precision _to_lng ""
  integer _to_moorage_id FK "Link api.moorages with api.logbook via FOREIGN KEY and REFERENCES"
  timestamp_with_time_zone _to_time ""
  boolean active ""
  double_precision avg_speed "avg speed in knots"
  numeric distance "Distance in Nautical Miles converted mobilitydb meters to NM"
  interval duration "Duration in ISO 8601 format"
  jsonb extra "Computed SignalK metrics such as runtime, current level, etc."
  integer id ""
  double_precision max_speed "max speed in knots"
  double_precision max_wind_speed "true wind speed converted in knots, m/s from signalk plugin"
  text name ""
  text notes ""
  tgeogpoint trip "MobilityDB trajectory, speed in m/s, distance in meters"
  tfloat trip_awa "AWA (Apparent Wind Angle) in degrees converted from radians by signalk plugin"
  tfloat trip_aws "AWS (Apparent Wind Speed), windSpeedApparent in knots converted by signalk plugin"
  tfloat trip_batt_charge "Battery Charge"
  tfloat trip_batt_voltage "Battery Voltage"
  tfloat trip_cog "COG - Course Over Ground True in degrees converted from radians by signalk plugin"
  tfloat trip_depth "Depth in meters, raw from signalk plugin"
  tfloat trip_heading "Heading True in degrees converted from radians, raw from signalk plugin"
  tfloat trip_hum_out "Humidity outside"
  ttext trip_notes ""
  tfloat trip_pres_out "Pressure outside"
  tfloat trip_sog "SOG - Speed Over Ground in knots converted by signalk plugin"
  tfloat trip_solar_power "solar powerPanel"
  tfloat trip_solar_voltage "solar voltage"
  ttext trip_status ""
  tfloat trip_tank_level "Tank currentLevel"
  tfloat trip_temp_out "Temperature outside in Kelvin, raw from signalk plugin"
  tfloat trip_temp_water "Temperature water in Kelvin, raw from signalk plugin"
  tfloat trip_twd "TWD - True Wind Direction in degrees converted from radians, raw from signalk plugin"
  tfloat trip_tws "TWS - True Wind Speed in knots converted from m/s, raw from signalk plugin"
  timestamp_with_time_zone updated_at "Timestamp of last row modification, maintained automatically by logbook_moddatetime trigger. Use for incremental sync."
  jsonb user_data "User-defined data Log-specific data including actual tags, observations, images and custom fields"
  text vessel_id FK "Unique identifier for the vessel associated with the api.metadata entry"
}
"api.metadata" {
  boolean active "trigger monitor online/offline"
  jsonb available_keys "Signalk paths with unit for custom mapping"
  double_precision beam ""
  jsonb configuration "User-defined Signalk path mapping for metrics"
  timestamp_with_time_zone created_at ""
  double_precision height ""
  text ip "Store vessel ip address"
  double_precision length ""
  text mmsi "Maritime Mobile Service Identity (MMSI) number associated with the vessel, link to public.mid"
  text name ""
  text platform ""
  text plugin_version ""
  numeric ship_type "Type of ship associated with the vessel, link to public.aistypes"
  text signalk_version ""
  timestamp_with_time_zone time ""
  timestamp_with_time_zone updated_at ""
  jsonb user_data "User-defined data including vessel polar (theoretical performance), make/model, and preferences"
  text vessel_id FK "Link auth.vessels with api.metadata via FOREIGN KEY and REFERENCES"
}
"api.stays" {
  boolean active ""
  timestamp_with_time_zone arrived ""
  timestamp_with_time_zone departed ""
  interval duration "Best to use standard ISO 8601"
  geography_Point_4326_ geog "postgis geography type default SRID 4326 Unit: degres"
  integer id ""
  double_precision latitude ""
  double_precision longitude ""
  integer moorage_id FK "Link api.moorages with api.stays via FOREIGN KEY and REFERENCES"
  text name ""
  text notes ""
  integer stay_code FK "Link api.stays_at with api.stays via FOREIGN KEY and REFERENCES"
  timestamp_with_time_zone updated_at "Timestamp of last row modification, maintained automatically by stays_moddatetime trigger. Use for incremental sync."
  jsonb user_data "User-defined data Stay-specific data including images and custom fields"
  text vessel_id FK "Unique identifier for the vessel associated with the api.metadata entry"
}
"api.stays_at" {
  text description ""
  integer stay_code ""
}
"auth.vessels" {
  timestamp_with_time_zone created_at ""
  numeric mmsi "MMSI can be optional but if present must be a valid one and unique but must be in numeric range between 100000000 and 800000000"
  text name ""
  citext owner_email FK ""
  name role ""
  timestamp_with_time_zone updated_at ""
  text vessel_id ""
}
"api.metrics" {
  double_precision anglespeedapparent ""
  text client_id "Deprecated client_id to be removed"
  double_precision courseovergroundtrue ""
  double_precision latitude "With CONSTRAINT but allow NULL value to be ignored silently by trigger"
  double_precision longitude "With CONSTRAINT but allow NULL value to be ignored silently by trigger"
  jsonb metrics ""
  double_precision speedoverground ""
  text status ""
  timestamp_with_time_zone time ""
  text vessel_id FK "Unique identifier for the vessel associated with the api.metadata entry"
  double_precision windspeedapparent ""
}

Generated by tbls