From 47a38554e3bbf58ee12fef43a5511c4db5331eee Mon Sep 17 00:00:00 2001 From: Mark Chadwick Date: Sat, 23 Nov 2024 17:55:48 +1300 Subject: [PATCH] update --- cmd/deltadb/delta.svg | 4647 +++++++++++++++++++++------------------ meta/sqlite/db.go | 70 +- meta/sqlite/receiver.go | 200 ++ 3 files changed, 2779 insertions(+), 2138 deletions(-) create mode 100644 meta/sqlite/receiver.go diff --git a/cmd/deltadb/delta.svg b/cmd/deltadb/delta.svg index fbafb75d0..08e2d7e20 100644 --- a/cmd/deltadb/delta.svg +++ b/cmd/deltadb/delta.svg @@ -4,2328 +4,2769 @@ - - + + structs - - + + +antenna + +antenna + +🔑 + +antenna_id + + + +* + +  + +asset_id + + + +* + +  + +mark_id + + + +* + +  + +height + + + +* + +  + +north + + + +* + +  + +east + + + +* + +  + +azimuth + + + +* + +  + +start_date + + + +* + +  + +end_date + + + +* + + + asset - -asset - -🔑 - -asset_id - - - -* - -  - -model_id - - - -* - -  - -serial - - - -* - -  - -number - - - -* - -  - -notes - - - -* + +asset + +🔑 + +asset_id + + + +* + +  + +model_id + + + +* + +  + +serial + + + +* + +  + +number + + + +* + +  + +notes + + + +* + + + +antenna:e->asset:w + + + + + +mark + +mark + +🔑 + +mark_id + + + +* + +  + +datum_id + + + +* + +  + +mark + + + +* + +  + +igs + + + +* + +  + +name + + + +* + +  + +latitude + + + +* + +  + +longitude + + + +* + +  + +elevation + + + +* + +  + +start_date + + +* + +  + +end_date + + +* + + + +antenna:e->mark:w + + - + model - -model - -🔑 - -model_id - - - -* - -  - -make_id - - - -* - -  - -model - - - -* + +model + +🔑 + +model_id + + + +* + +  + +make_id + + + +* + +  + +model + + + +* - + asset:e->model:w - - + + - + bedrock - -bedrock - -🔑 - -bedrock_id - - - -* - -  - -bedrock - - - -* + +bedrock + +🔑 + +bedrock_id + + + +* + +  + +bedrock + + + +* - + calibration - -calibration - -🔑 - -calibration_id - - - -* - -  - -asset_id - - - -* - -  - -number - - - -* - -  - -scale_factor - - - -* - -  - -scale_bias - - - -* - -  - -scale_absolute - - - -* - -  - -frequency - - - - -  - -start_date - - - -* - -  - -end_date - - - -* + +calibration + +🔑 + +calibration_id + + + +* + +  + +asset_id + + + +* + +  + +number + + + +* + +  + +scale_factor + + + +* + +  + +scale_bias + + + +* + +  + +scale_absolute + + + +* + +  + +frequency + + + + +  + +start_date + + + +* + +  + +end_date + + + +* - + calibration:e->asset:w - - + + - + camera - -camera - -🔑 - -camera_id - - - -* - -  - -asset_id - - - -* - -  - -view_id - - - -* - -  - -dip - - - -* - -  - -azimuth - - - -* - -  - -height - - - -* - -  - -north - - - -* - -  - -east - - - -* - -  - -notes - - - -* - -  - -start_date - - - -* - -  - -end_date - - - -* + +camera + +🔑 + +camera_id + + + +* + +  + +asset_id + + + +* + +  + +view_id + + + +* + +  + +dip + + + +* + +  + +azimuth + + + +* + +  + +height + + + +* + +  + +north + + + +* + +  + +east + + + +* + +  + +notes + + + +* + +  + +start_date + + + +* + +  + +end_date + + + +* - + camera:e->asset:w - - + + - + view - -view - -🔑 - -view_id - - - -* - -  - -mount_id - - - -* - -  - -view - - - -* - -  - -label - - - - -  - -azimuth - - - -* - -  - -dip - - - -* - -  - -method - - - - -  - -description - - - -* - -  - -start_date - - - -* - -  - -end_date - - - -* + +view + +🔑 + +view_id + + + +* + +  + +mount_id + + + +* + +  + +view + + + +* + +  + +label + + + + +  + +azimuth + + + +* + +  + +dip + + + +* + +  + +method + + + + +  + +description + + + +* + +  + +start_date + + + +* + +  + +end_date + + + +* - + camera:e->view:w - - + + - + channel - -channel - -🔑 - -channel_id - - - -* - -  - -model_id - - - -* - -  - -channel_type - - - -* - -  - -number - - - -* - -  - -sampling_rate - - - -* - -  - -response - - - -* + +channel + +🔑 + +channel_id + + + +* + +  + +model_id + + + +* + +  + +channel_type + + + +* + +  + +number + + + +* + +  + +sampling_rate + + + +* + +  + +response + + + +* - + channel:e->model:w - - + + - + citation - -citation - -🔑 - -citation_id - - - -* - -  - -key - - - -* - -  - -author - - - -* - -  - -year - - - -* - -  - -title - - - -* - -  - -published - - - - -  - -volume - - - - -  - -pages - - - - -  - -doi - - - - -  - -link - - - - -  - -retrieved - - - + +citation + +🔑 + +citation_id + + + +* + +  + +key + + + +* + +  + +author + + + +* + +  + +year + + + +* + +  + +title + + + +* + +  + +published + + + + +  + +volume + + + + +  + +pages + + + + +  + +doi + + + + +  + +link + + + + +  + +retrieved + + + - + class - -class - -🔑 - -class_id - - - -* - -  - -station_id - - - -* - -  - -site_class - - - -* - -  - -vs30 - - - -* - -  - -vs30_quality - - - -* - -  - -tsite - - - -* - -  - -tsite_method - - - -* - -  - -tsite_quality - - - -* - -  - -basement_depth - - - -* - -  - -depth_quality - - - -* - -  - -link - - - - -  - -notes - - - + +class + +🔑 + +class_id + + + +* + +  + +station_id + + + +* + +  + +site_class + + + +* + +  + +vs30 + + + +* + +  + +vs30_quality + + + +* + +  + +tsite + + + +* + +  + +tsite_method + + + +* + +  + +tsite_quality + + + +* + +  + +basement_depth + + + +* + +  + +depth_quality + + + +* + +  + +link + + + + +  + +notes + + + - + station - -station - -🔑 - -station_id - - - -* - -  - -datum_id - - - -* - -  - -station - - - -* - -  - -name - - - -* - -  - -latitude - - - -* - -  - -longitude - - - -* - -  - -elevation - - - -* - -  - -depth - - - -* - -  - -start_date - - - -* - -  - -end_date - - - -* + +station + +🔑 + +station_id + + + +* + +  + +datum_id + + + +* + +  + +station + + + +* + +  + +name + + + +* + +  + +latitude + + + +* + +  + +longitude + + + +* + +  + +elevation + + + +* + +  + +depth + + + +* + +  + +start_date + + + +* + +  + +end_date + + + +* - + class:e->station:w - - + + - + class_citation - -class_citation - -🔑 - -class_citation_id - - - -* - -  - -class_id - - - -* - -  - -citation_id - - - -* + +class_citation + +🔑 + +class_citation_id + + + +* + +  + +class_id + + + +* + +  + +citation_id + + + +* - + class_citation:e->citation:w - - + + - + class_citation:e->class:w - - + + - + component - -component - -🔑 - -component_id - - - -* - -  - -model_id - - - -* - -  - -component_type - - - - -  - -number - - - -* - -  - -source - - - - -  - -subsource - - - -* - -  - -dip - - - -* - -  - -azimuth - - - -* - -  - -types - - - -* - -  - -sampling_rate - - - - -  - -response - - - -* + +component + +🔑 + +component_id + + + +* + +  + +model_id + + + +* + +  + +component_type + + + + +  + +number + + + +* + +  + +source + + + + +  + +subsource + + + +* + +  + +dip + + + +* + +  + +azimuth + + + +* + +  + +types + + + +* + +  + +sampling_rate + + + + +  + +response + + + +* - + component:e->model:w - - + + - + constituent - -constituent - -🔑 - -constituent_id - - - -* - -  - -gauge_id - - - -* - -  - -number - - - -* - -  - -constituent - - - -* - -  - -amplitude - - - -* - -  - -lag - - - -* - -  - -start_date - - - -* - -  - -end_date - - - -* + +constituent + +🔑 + +constituent_id + + + +* + +  + +gauge_id + + + +* + +  + +number + + + +* + +  + +constituent + + + +* + +  + +amplitude + + + +* + +  + +lag + + + +* + +  + +start_date + + + +* + +  + +end_date + + + +* - + gauge - -gauge - -🔑 - -gauge_id - - - -* - -  - -gauge - - - -* - -  - -identification_number - - - -* - -  - -analysis_time_zone - - - -* - -  - -analysis_latitude - - - -* - -  - -analysis_longitude - - - -* - -  - -crex_tag - - - -* - -  - -start_date - - - -* - -  - -end_date - - - -* + +gauge + +🔑 + +gauge_id + + + +* + +  + +gauge + + + +* + +  + +identification_number + + + +* + +  + +analysis_time_zone + + + +* + +  + +analysis_latitude + + + +* + +  + +analysis_longitude + + + +* + +  + +crex_tag + + + +* + +  + +start_date + + + +* + +  + +end_date + + + +* - + constituent:e->gauge:w - - + + - + dart - -dart - -🔑 - -dart_id - - - -* - -  - -station_id - - - -* - -  - -pid - - - -* - -  - -wmo_identifier - - - -* - -  - -start_date - - - -* - -  - -end_date - - - -* + +dart + +🔑 + +dart_id + + + +* + +  + +station_id + + + +* + +  + +pid + + + +* + +  + +wmo_identifier + + + +* + +  + +start_date + + + +* + +  + +end_date + + + +* - + dart:e->station:w - - + + - + datum - -datum - -🔑 - -datum_id - - - -* - -  - -datum - - - -* + +datum + +🔑 + +datum_id + + + +* + +  + +datum + + + +* - + doas - -doas - -🔑 - -doas_id - - - -* - -  - -asset_id - - - -* - -  - -view_id - - - -* - -  - -dip - - - -* - -  - -azimuth - - - -* - -  - -height - - - -* - -  - -north - - - -* - -  - -east - - - -* - -  - -start_date - - - -* - -  - -end_date - - - -* + +doas + +🔑 + +doas_id + + + +* + +  + +asset_id + + + +* + +  + +view_id + + + +* + +  + +dip + + + +* + +  + +azimuth + + + +* + +  + +height + + + +* + +  + +north + + + +* + +  + +east + + + +* + +  + +start_date + + + +* + +  + +end_date + + + +* - + doas:e->asset:w - - + + - + doas:e->view:w - - + + - + feature - -feature - -🔑 - -feature_id - - - -* - -  - -site_id - - - -* - -  - -sublocation - - - - -  - -property - - - -* - -  - -description - - - - -  - -aspect - - - - -  - -start_date - - - -* - -  - -end_date - - - -* + +feature + +🔑 + +feature_id + + + +* + +  + +site_id + + + +* + +  + +sublocation + + + + +  + +property + + + +* + +  + +description + + + + +  + +aspect + + + + +  + +start_date + + + +* + +  + +end_date + + + +* - + site - -site - -🔑 - -site_id - - - -* - -  - -station_id - - - -* - -  - -datum_id - - - -* - -  - -location - - - -* - -  - -latitude - - - -* - -  - -longitude - - - -* - -  - -elevation - - - -* - -  - -depth - - - -* - -  - -survey - - - -* - -  - -start_date - - - -* - -  - -end_date - - - -* + +site + +🔑 + +site_id + + + +* + +  + +station_id + + + +* + +  + +datum_id + + + +* + +  + +location + + + +* + +  + +latitude + + + +* + +  + +longitude + + + +* + +  + +elevation + + + +* + +  + +depth + + + +* + +  + +survey + + + +* + +  + +start_date + + + +* + +  + +end_date + + + +* - + feature:e->site:w - - + + - + firmware - -firmware - -🔑 - -firmware_id - - - -* - -  - -asset_id - - - -* - -  - -version - - - -* - -  - -notes - - - -* - -  - -start_date - - - -* - -  - -end_date - - - -* + +firmware + +🔑 + +firmware_id + + + +* + +  + +asset_id + + + +* + +  + +version + + + +* + +  + +notes + + + +* + +  + +start_date + + + +* + +  + +end_date + + + +* - + firmware:e->asset:w - - + + - + foundation_type - -foundation_type - -🔑 - -foundation_type_id - - - -* - -  - -foundation_type - - - -* + +foundation_type + +🔑 + +foundation_type_id + + + +* + +  + +foundation_type + + + +* - + geology - -geology - -🔑 - -geology_id - - - -* - -  - -geology - - - -* + +geology + +🔑 + +geology_id + + + +* + +  + +geology + + + +* - -make - -make - -🔑 - -make_id - - - -* - -  - -make - - - -* - - -mark - -mark - -🔑 - -mark_id - - - -* - -  - -datum_id - - - -* - -  - -mark - - - -* - -  - -igs - - - -* - -  - -name - - - -* - -  - -latitude - - - -* - -  - -longitude - - - -* - -  - -elevation - - - -* - -  - -start_date - - -* - -  - -end_date - - -* +make + +make + +🔑 + +make_id + + + +* + +  + +make + + + +* - + mark:e->datum:w - - + + - + mark_network - -mark_network - -🔑 - -mark_network_id - - - -* - -  - -mark_id - - - -* - -  - -network_id - - - -* + +mark_network + +🔑 + +mark_network_id + + + +* + +  + +mark_id + + + +* + +  + +network_id + + + +* - + mark_network:e->mark:w - - + + - + network - -network - -🔑 - -network_id - - - -* - -  - -network - - - -* - -  - -external - - - -* - -  - -description - - - -* - -  - -restricted - - - -* + +network + +🔑 + +network_id + + + +* + +  + +network + + + +* + +  + +external + + + +* + +  + +description + + + +* + +  + +restricted + + + +* - + mark_network:e->network:w - - + + - + mark_type - -mark_type - -🔑 - -mark_type_id - - - -* - -  - -mark_type - - - -* + +mark_type + +🔑 + +mark_type_id + + + +* + +  + +mark_type + + + +* - + method - -method - -🔑 - -method_id - - - -* - -  - -method - - - -* + +method + +🔑 + +method_id + + + +* + +  + +method + + + +* + + + +metsensor + +metsensor + +🔑 + +metsensor_id + + + +* + +  + +asset_id + + + +* + +  + +mark_id + + + +* + +  + +datum_id + + + +* + +  + +ims_comment + + + + +  + +humidity + + + +* + +  + +pressure + + + +* + +  + +temperature + + + +* + +  + +latitude + + + +* + +  + +longitude + + + +* + +  + +elevation + + + +* + +  + +start_date + + + +* + +  + +end_date + + + +* + + + +metsensor:e->asset:w + + + + + +metsensor:e->datum:w + + + + + +metsensor:e->mark:w + + - + model:e->make:w - - + + - + monument - -monument - -🔑 - -monument_id - - - -* - -  - -mark_id - - - -* - -  - -mark_type_id - - - -* - -  - -monument_type_id - - - -* - -  - -foundation_type_id - - - -* - -  - -bedrock_id - - - -* - -  - -geology_id - - - -* - -  - -domes_number - - - -* - -  - -ground_relationship - - - -* - -  - -foundation_depth - - - -* - -  - -start_date - - -* - -  - -end_date - - -* + +monument + +🔑 + +monument_id + + + +* + +  + +mark_id + + + +* + +  + +mark_type_id + + + +* + +  + +monument_type_id + + + +* + +  + +foundation_type_id + + + +* + +  + +bedrock_id + + + +* + +  + +geology_id + + + +* + +  + +domes_number + + + +* + +  + +ground_relationship + + + +* + +  + +foundation_depth + + + +* + +  + +start_date + + +* + +  + +end_date + + +* - + monument:e->bedrock:w - - + + - + monument:e->foundation_type:w - - + + - + monument:e->geology:w - - + + - + monument:e->mark:w - - + + - + monument:e->mark_type:w - - + + - + monument_type - -monument_type - -🔑 - -monument_type_id - - - -* - -  - -monument_type - - - -* + +monument_type + +🔑 + +monument_type_id + + + +* + +  + +monument_type + + + +* - + monument:e->monument_type:w - - + + - + mount - -mount - -🔑 - -mount_id - - - -* - -  - -datum_id - - - -* - -  - -mount - - - -* - -  - -name - - - -* - -  - -latitude - - - -* - -  - -longitude - - - -* - -  - -elevation - - - -* - -  - -description - - - -* - -  - -start_date - - - -* - -  - -end_date - - - -* + +mount + +🔑 + +mount_id + + + +* + +  + +datum_id + + + +* + +  + +mount + + + +* + +  + +name + + + +* + +  + +latitude + + + +* + +  + +longitude + + + +* + +  + +elevation + + + +* + +  + +description + + + +* + +  + +start_date + + + +* + +  + +end_date + + + +* - + mount:e->datum:w - - + + - + mount_network - -mount_network - -🔑 - -mount_network_id - - - -* - -  - -mount_id - - - -* - -  - -network_id - - - -* + +mount_network + +🔑 + +mount_network_id + + + +* + +  + +mount_id + + + +* + +  + +network_id + + + +* - + mount_network:e->mount:w - - + + - + mount_network:e->network:w - - + + - + point - -point - -🔑 - -point_id - - - -* - -  - -sample_id - - - -* - -  - -datum_id - - - -* - -  - -location - - - -* - -  - -latitude - - - -* - -  - -longitude - - - -* - -  - -elevation - - - -* - -  - -depth - - - -* - -  - -survey - - - -* - -  - -start_date - - - -* - -  - -end_date - - - -* + +point + +🔑 + +point_id + + + +* + +  + +sample_id + + + +* + +  + +datum_id + + + +* + +  + +location + + + +* + +  + +latitude + + + +* + +  + +longitude + + + +* + +  + +elevation + + + +* + +  + +depth + + + +* + +  + +survey + + + +* + +  + +start_date + + + +* + +  + +end_date + + + +* - + point:e->datum:w - - + + - + sample - -sample - -🔑 - -sample_id - - - -* - -  - -datum_id - - - -* - -  - -station - - - -* - -  - -name - - - -* - -  - -latitude - - - -* - -  - -longitude - - - -* - -  - -elevation - - - -* - -  - -depth - - - - -  - -start_date - - - -* - -  - -end_date - - - -* + +sample + +🔑 + +sample_id + + + +* + +  + +datum_id + + + +* + +  + +station + + + +* + +  + +name + + + +* + +  + +latitude + + + +* + +  + +longitude + + + +* + +  + +elevation + + + +* + +  + +depth + + + + +  + +start_date + + + +* + +  + +end_date + + + +* - + point:e->sample:w - - + + + + + +radome + +radome + +🔑 + +radome_id + + + +* + +  + +asset_id + + + +* + +  + +mark_id + + + +* + +  + +start_date + + + +* + +  + +end_date + + + +* + + + +radome:e->asset:w + + + + + +radome:e->mark:w + + + + + +receiver + +receiver + +🔑 + +receiver_id + + + +* + +  + +asset_id + + + +* + +  + +mark_id + + + +* + +  + +start_date + + + +* + +  + +end_date + + + +* + + + +receiver:e->asset:w + + + + + +receiver:e->mark:w + + - + sample:e->datum:w - - + + + + + +session + +session + +🔑 + +session_id + + + +* + +  + +mark_id + + + +* + +  + +operator + + + +* + +  + +agency + + + +* + +  + +model + + + +* + +  + +satellite_system + + + +* + +  + +interval + + + +* + +  + +elevation_mask + + + +* + +  + +header_comment + + + +* + +  + +format + + + +* + +  + +start_date + + + +* + +  + +end_date + + + +* + + + +session:e->mark:w + + - + site:e->datum:w - - + + - + site:e->station:w - - + + - + station:e->datum:w - - + + - + station_network - -station_network - -🔑 - -station_network_id - - - -* - -  - -station_id - - - -* - -  - -network_id - - - -* + +station_network + +🔑 + +station_network_id + + + +* + +  + +station_id + + + +* + +  + +network_id + + + +* - + station_network:e->network:w - - + + - + station_network:e->station:w - - + + - + view:e->mount:w - - + + - + visibility - -visibility - -🔑 - -visibility_id - - - -* - -  - -mark_id - - - -* - -  - -sky_visibility - - - -* - -  - -start_date - - - -* - -  - -end_date - - - -* + +visibility + +🔑 + +visibility_id + + + +* + +  + +mark_id + + + +* + +  + +sky_visibility + + + +* + +  + +start_date + + + +* + +  + +end_date + + + +* - + visibility:e->mark:w - - + + diff --git a/meta/sqlite/db.go b/meta/sqlite/db.go index 162fc4001..a34811d4a 100644 --- a/meta/sqlite/db.go +++ b/meta/sqlite/db.go @@ -271,6 +271,41 @@ func (d DB) Init(ctx context.Context, list []meta.TableList) error { if err := d.prepare(ctx, tx, visibility.Insert(), visibility.Columns(l)...); err != nil { return err } + case "Antenna": + if err := d.exec(ctx, tx, antenna.Create); err != nil { + return err + } + if err := d.prepare(ctx, tx, antenna.Insert(), antenna.Columns(l)...); err != nil { + return err + } + case "MetSensor": + if err := d.exec(ctx, tx, metsensor.Create); err != nil { + return err + } + if err := d.prepare(ctx, tx, metsensor.Insert(), metsensor.Columns(l)...); err != nil { + return err + } + case "Radome": + if err := d.exec(ctx, tx, radome.Create); err != nil { + return err + } + if err := d.prepare(ctx, tx, radome.Insert(), radome.Columns(l)...); err != nil { + return err + } + case "Receiver": + if err := d.exec(ctx, tx, receiver.Create); err != nil { + return err + } + if err := d.prepare(ctx, tx, receiver.Insert(), receiver.Columns(l)...); err != nil { + return err + } + case "Session": + if err := d.exec(ctx, tx, session.Create); err != nil { + return err + } + if err := d.prepare(ctx, tx, session.Insert(), session.Columns(l)...); err != nil { + return err + } case "Gauge": if err := d.exec(ctx, tx, gauge.Create); err != nil { return err @@ -398,41 +433,6 @@ func (d DB) Init(ctx context.Context, list []meta.TableList) error { if err := d.prepare(ctx, tx, preampInsert(), columns(l, preampFields(), nil, "")...); err != nil { return err } - case "Antenna": - if err := d.exec(ctx, tx, antennaCreate); err != nil { - return err - } - if err := d.prepare(ctx, tx, antennaInsert(), columns(l, antennaFields(), nil, "")...); err != nil { - return err - } - case "MetSensor": - if err := d.exec(ctx, tx, metsensorCreate); err != nil { - return err - } - if err := d.prepare(ctx, tx, metsensorInsert(), columns(l, metsensorFields(), nil, "")...); err != nil { - return err - } - case "Radome": - if err := d.exec(ctx, tx, radomeCreate); err != nil { - return err - } - if err := d.prepare(ctx, tx, radomeInsert(), columns(l, radomeFields(), nil, "")...); err != nil { - return err - } - case "Receiver": - if err := d.exec(ctx, tx, receiverCreate); err != nil { - return err - } - if err := d.prepare(ctx, tx, receiverInsert(), columns(l, receiverFields(), nil, "")...); err != nil { - return err - } - case "Session": - if err := d.exec(ctx, tx, sessionCreate); err != nil { - return err - } - if err := d.prepare(ctx, tx, sessionInsert(), columns(l, sessionFields(), nil, "")...); err != nil { - return err - } case "Stream": if err := d.exec(ctx, tx, streamCreate); err != nil { return err diff --git a/meta/sqlite/receiver.go b/meta/sqlite/receiver.go new file mode 100644 index 000000000..13014555a --- /dev/null +++ b/meta/sqlite/receiver.go @@ -0,0 +1,200 @@ +package sqlite + +import ( + "fmt" +) + +const antennaCreate = ` +DROP TABLE IF EXISTS antenna; +CREATE TABLE IF NOT EXISTS antenna ( + antenna_id INTEGER PRIMARY KEY NOT NULL, + asset_id INTEGER NOT NULL, + mark_id INTEGER NOT NULL, + height REAL NOT NULL, + north REAL NOT NULL, + east REAL NOT NULL, + azimuth REAL NOT NULL, + start_date DATETIME NOT NULL CHECK (start_date IS strftime('%Y-%m-%dT%H:%M:%SZ', start_date)), + end_date DATETIME NOT NULL CHECK (end_date IS strftime('%Y-%m-%dT%H:%M:%SZ', end_date)), + FOREIGN KEY (asset_id) REFERENCES asset (asset_id), + FOREIGN KEY (mark_id) REFERENCES mark (mark_id), + UNIQUE(asset_id, mark_id, start_date) +); +CREATE TRIGGER IF NOT EXISTS no_overlap_on_antenna BEFORE INSERT ON antenna +WHEN EXISTS ( + SELECT * FROM antenna + WHERE datetime(start_date) <= datetime(NEW.end_date) + AND datetime(end_date) > datetime(NEW.start_date) + AND asset_id = NEW.asset_id + AND mark_id = NEW.mark_id +) +BEGIN + SELECT RAISE(FAIL, "overlapping intervals on antenna"); +END; +` + +var antenna = Table{ + Create: antennaCreate, + Insert: func() string { + return fmt.Sprintf("INSERT OR IGNORE INTO antenna (asset_id, mark_id, height, north, east, azimuth, start_date, end_date) VALUES ((%s), (%s), ?, ?, ?, ?, ?, ?);", + asset.Select(), mark.Select(), + ) + }, + Fields: []string{"Make", "Model", "Serial", "Mark", "Height", "North", "East", "Azimuth", "Start Date", "End Date"}, +} + +const metsensorCreate = ` +DROP TABLE IF EXISTS metsensor; +CREATE TABLE IF NOT EXISTS metsensor ( + metsensor_id INTEGER PRIMARY KEY NOT NULL, + asset_id INTEGER NOT NULL, + mark_id INTEGER NOT NULL, + datum_id INTEGER NOT NULL, + ims_comment TEXT NULL, + humidity REAL NOT NULL, + pressure REAL NOT NULL, + temperature REAL NOT NULL, + latitude REAL NOT NULL, + longitude REAL NOT NULL, + elevation REAL NOT NULL, + start_date DATETIME NOT NULL CHECK (start_date IS strftime('%Y-%m-%dT%H:%M:%SZ', start_date)), + end_date DATETIME NOT NULL CHECK (end_date IS strftime('%Y-%m-%dT%H:%M:%SZ', end_date)), + FOREIGN KEY (asset_id) REFERENCES asset (asset_id), + FOREIGN KEY (mark_id) REFERENCES mark (mark_id), + FOREIGN KEY (datum_id) REFERENCES datum (datum_id), + UNIQUE(asset_id, mark_id, start_date, end_date) +); +CREATE TRIGGER IF NOT EXISTS no_overlap_on_metsensor BEFORE INSERT ON metsensor +WHEN EXISTS ( + SELECT * FROM metsensor + WHERE datetime(start_date) <= datetime(NEW.end_date) + AND datetime(end_date) > datetime(NEW.start_date) + AND asset_id = NEW.asset_id + AND mark_id = NEW.mark_id +) +BEGIN + SELECT RAISE(FAIL, "overlapping intervals on metsensor"); +END; +` + +var metsensor = Table{ + Create: metsensorCreate, + Insert: func() string { + return fmt.Sprintf("INSERT OR IGNORE INTO metsensor (asset_id, mark_id, datum_id, ims_comment, humidity, pressure, temperature, latitude, longitude, elevation, start_date, end_date) VALUES ((%s), (%s), (%s), ?, ?, ?, ?, ?, ?, ?, ?, ?);", + asset.Select(), mark.Select(), datum.Select(), + ) + }, + Fields: []string{"Make", "Model", "Serial", "Mark", "Datum", "IMS Comment", "Humidity", "Pressure", "Temperature", "Latitude", "Longitude", "Elevation", "Start Date", "End Date"}, +} + +var radomeCreate = ` +DROP TABLE IF EXISTS radome; +CREATE TABLE IF NOT EXISTS radome ( + radome_id INTEGER PRIMARY KEY NOT NULL, + asset_id INTEGER NOT NULL, + mark_id INTEGER NOT NULL, + start_date DATETIME NOT NULL CHECK (start_date IS strftime('%Y-%m-%dT%H:%M:%SZ', start_date)), + end_date DATETIME NOT NULL CHECK (end_date IS strftime('%Y-%m-%dT%H:%M:%SZ', end_date)), + FOREIGN KEY (asset_id) REFERENCES asset (asset_id), + FOREIGN KEY (mark_id) REFERENCES mark (mark_id), + UNIQUE(asset_id, mark_id, start_date, end_date) +); +CREATE TRIGGER IF NOT EXISTS no_overlap_on_radome BEFORE INSERT ON radome +WHEN EXISTS ( + SELECT * FROM radome + WHERE datetime(start_date) <= datetime(NEW.end_date) + AND datetime(end_date) > datetime(NEW.start_date) + AND mark_id = NEW.mark_id + AND asset_id = NEW.asset_id +) +BEGIN + SELECT RAISE(FAIL, "overlapping intervals on radome"); +END; +` + +var radome = Table{ + Create: radomeCreate, + Insert: func() string { + return fmt.Sprintf("INSERT OR IGNORE INTO radome (asset_id, mark_id, start_date, end_date) VALUES ((%s), (%s), ?, ?);", + asset.Select(), mark.Select(), + ) + }, + Fields: []string{"Make", "Model", "Serial", "Mark", "Start Date", "End Date"}, +} + +var receiverCreate = ` +DROP TABLE IF EXISTS receiver; +CREATE TABLE IF NOT EXISTS receiver ( + receiver_id INTEGER PRIMARY KEY NOT NULL, + asset_id INTEGER NOT NULL, + mark_id INTEGER NOT NULL, + start_date DATETIME NOT NULL CHECK (start_date IS strftime('%Y-%m-%dT%H:%M:%SZ', start_date)), + end_date DATETIME NOT NULL CHECK (end_date IS strftime('%Y-%m-%dT%H:%M:%SZ', end_date)), + FOREIGN KEY (asset_id) REFERENCES asset (asset_id), + FOREIGN KEY (mark_id) REFERENCES mark (mark_id), + UNIQUE(asset_id, mark_id, start_date, end_date) +); +CREATE TRIGGER IF NOT EXISTS no_overlap_on_receiver BEFORE INSERT ON receiver +WHEN EXISTS ( + SELECT * FROM receiver + WHERE datetime(start_date) <= datetime(NEW.end_date) + AND datetime(end_date) > datetime(NEW.start_date) + AND asset_id = NEW.asset_id + AND mark_id = NEW.mark_id +) +BEGIN + SELECT RAISE(FAIL, "overlapping intervals on receiver"); +END; +` + +var receiver = Table{ + Create: receiverCreate, + Insert: func() string { + return fmt.Sprintf("INSERT OR IGNORE INTO receiver (asset_id, mark_id, start_date, end_date) VALUES ((%s), (%s), ?, ?);", + asset.Select(), mark.Select(), + ) + }, + Fields: []string{"Make", "Model", "Serial", "Mark", "Start Date", "End Date"}, +} + +const sessionCreate = ` +DROP TABLE IF EXISTS session; +CREATE TABLE IF NOT EXISTS session ( + session_id INTEGER PRIMARY KEY NOT NULL, + mark_id INTEGER NOT NULL, + operator TEXT NOT NULL, + agency TEXT NOT NULL, + model TEXT NOT NULL, + satellite_system TEXT NOT NULL, + interval TEXT NOT NULL, + elevation_mask REAL NOT NULL, + header_comment TEXT NOT NULL, + format TEXT NOT NULL, + start_date DATETIME NOT NULL CHECK (start_date IS strftime('%Y-%m-%dT%H:%M:%SZ', start_date)), + end_date DATETIME NOT NULL CHECK (end_date IS strftime('%Y-%m-%dT%H:%M:%SZ', end_date)), + FOREIGN KEY (mark_id) REFERENCES mark (mark_id), + UNIQUE(interval, mark_id, start_date) +); + +CREATE TRIGGER IF NOT EXISTS no_overlap_on_session BEFORE INSERT ON session +WHEN EXISTS ( + SELECT * FROM session + WHERE datetime(start_date) <= datetime(NEW.end_date) + AND datetime(end_date) > datetime(NEW.start_date) + AND mark_id = NEW.mark_id + AND interval = NEW.interval +) +BEGIN + SELECT RAISE(FAIL, "overlapping intervals on session"); +END; +` + +var session = Table{ + Create: sessionCreate, + Insert: func() string { + return fmt.Sprintf("INSERT OR IGNORE INTO session (mark_id, operator, agency, model, satellite, interval, elevation_mask, header_comment, format, start_date, end_date) VALUES ((%s), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", + mark.Select(), + ) + }, + Fields: []string{"Make", "Operator", "Agency", "Model", "Satellite", "Interval", "Elevation Mask", "Header Comment", "Format", "Start Date", "End Date"}, +}