- Improve Lint support
- Update new account email subject
- Update first badge message
- Add public.stay_delete_trigger_fn trigger function to delete stays_ext and process_queue entries
- Create trigger to delete stays_ext and process_queue entries
- Remove trigger that duplicate the OTP validation entry on insert for new account, it is handle by api.login
- Update api.login function to handle user disable and email verification, update error code with invalid_email_or_password
- Update cron_windy_fn to support custom user metrics
- Update merge_logbook_fn to handle more metrics and limit moorage deletion
- Add api.counts_fn to count logbook, moorages and stays entries
- Allow user_role to delete on api.stays_ext
2025-09-04 18:40:36 +02:00
9 changed files with 672 additions and 9 deletions
-- This file is part of PostgSail which is released under Apache License, Version 2.0 (the "License").
-- See file LICENSE or go to http://www.apache.org/licenses/LICENSE-2.0 for full license details.
--
-- Migration August 2025
--
-- List current database
selectcurrent_database();
-- connect to the DB
\csignalk
\echo'Timing mode is enabled'
\timing
\echo'Force timezone, just in case'
settimezoneto'UTC';
-- Lint fix
CREATEINDEXONapi.stays_ext(vessel_id);
ALTERTABLEapi.stays_extFORCEROWLEVELSECURITY;
ALTERTABLEapi.metadata_extFORCEROWLEVELSECURITY;
ALTERTABLEapi.metadataADDPRIMARYKEY(vessel_id);
COMMENTONCONSTRAINTmetadata_vessel_id_fkeyONapi.metadataIS'Link api.metadata with auth.vessels via vessel_id using FOREIGN KEY and REFERENCES';
COMMENTONCONSTRAINTmetrics_vessel_id_fkeyONapi.metricsIS'Link api.metrics api.metadata via vessel_id using FOREIGN KEY and REFERENCES';
COMMENTONCONSTRAINTlogbook_vessel_id_fkeyONapi.logbookIS'Link api.stays with api.metadata via vessel_id using FOREIGN KEY and REFERENCES';
COMMENTONCONSTRAINTmoorages_vessel_id_fkeyONapi.mooragesIS'Link api.stays with api.metadata via vessel_id using FOREIGN KEY and REFERENCES';
COMMENTONCONSTRAINTstays_vessel_id_fkeyONapi.staysIS'Link api.stays with api.metadata via vessel_id using FOREIGN KEY and REFERENCES';
COMMENTONCOLUMNapi.logbook._fromIS'Name of the location where the log started, usually a moorage name';
COMMENTONCOLUMNapi.logbook._toIS'Name of the location where the log ended, usually a moorage name';
COMMENTONCOLUMNapi.logbook.vessel_idIS'Unique identifier for the vessel associated with the api.metadata entry';
COMMENTONCOLUMNapi.metrics.vessel_idIS'Unique identifier for the vessel associated with the api.metadata entry';
COMMENTONCOLUMNapi.moorages.vessel_idIS'Unique identifier for the vessel associated with the api.metadata entry';
COMMENTONCOLUMNapi.moorages.nominatimIS'Output of the nominatim reverse geocoding service, see https://nominatim.org/release-docs/develop/api/Reverse/';
COMMENTONCOLUMNapi.moorages.overpassIS'Output of the overpass API, see https://wiki.openstreetmap.org/wiki/Overpass_API';
COMMENTONCOLUMNapi.stays.vessel_idIS'Unique identifier for the vessel associated with the api.metadata entry';
COMMENTONCOLUMNapi.stays_ext.vessel_idIS'Unique identifier for the vessel associated with the api.metadata entry';
COMMENTONCOLUMNapi.metadata_ext.vessel_idIS'Unique identifier for the vessel associated with the api.metadata entry';
COMMENTONCOLUMNapi.metadata.mmsiIS'Maritime Mobile Service Identity (MMSI) number associated with the vessel, link to public.mid';
COMMENTONCOLUMNapi.metadata.ship_typeIS'Type of ship associated with the vessel, link to public.aistypes';
COMMENTONTRIGGERts_insert_blockerONapi.metricsIS'manage by timescaledb, prevent direct insert on hypertable api.metrics';
COMMENTONTRIGGERensure_vessel_role_existsONauth.vesselsIS'ensure vessel role exists';
COMMENTONTRIGGERencrypt_passONauth.accountsIS'execute function auth.encrypt_pass()';
-- Fix typo in comment
COMMENTONFUNCTIONpublic.new_account_entry_fn()IS'trigger process_queue on INSERT for new account';
-- Update missing comment on trigger
COMMENTONTRIGGERencrypt_passONauth.accountsIS'execute function auth.encrypt_pass()';
-- Update new account email subject
UPDATEpublic.email_templates
SETemail_subject='Welcome aboard!',
email_content='Welcome aboard __RECIPIENT__,
Congratulations!
You successfully created an account.
Keep in mind to register your vessel.
Happy sailing!'
WHERE"name"='new_account';
-- Update deactivated email subject
UPDATEpublic.email_templates
SETemail_subject='We hate to see you go'
WHERE"name"='deactivated';
-- Update first badge message
UPDATEpublic.badges
SETdescription='Nice work logging your first sail! You’re officially a helmsman now!
While you’re at it, why not spread the word about Postgsail? ⭐
If you found it useful, consider starring the project on GitHub, contributing, or even sponsoring the project to help steer it forward.
Happy sailing! 🌊
https://github.com/xbgmsharp/postgsail
https://github.com/sponsors/xbgmsharp/'
WHERE"name"='Helmsman';
-- DROP FUNCTION public.stays_delete_trigger_fn();
-- Add public.stay_delete_trigger_fn trigger function to delete stays_ext and process_queue entries
COMMENTONTRIGGERstay_delete_triggerONapi.staysIS'BEFORE DELETE ON api.stays run function public.stay_delete_trigger_fn to delete reference and stay_ext need to deleted.';
-- Remove trigger that duplicate the OTP validation entry on insert for new account, it is handle by api.login
COMMENTONFUNCTIONpublic.cron_windy_fn()IS'init by pg_cron to create (or update) station and uploading observations to Windy Personal Weather Station observations';
-- DROP FUNCTION api.merge_logbook_fn(int4, int4);
-- Update merge_logbook_fn to handle more metrics and limit moorage deletion
RAISEWARNING'-> merge_logbook_fn delete moorage id [%]',logbook_rec_start._to_moorage_id;
END;
$function$
;
-- Description
COMMENTONFUNCTIONapi.merge_logbook_fn(int4,int4)IS'Merge 2 logbook by id, from the start of the lower log id and the end of the higher log id, update the calculate data as well (avg, geojson)';
-- Add api.counts_fn to count logbook, moorages and stays entries
CREATEORREPLACEFUNCTIONapi.counts_fn()
RETURNSjsonb
LANGUAGEsql
AS$function$
SELECTjsonb_build_object(
'logs',(SELECTCOUNT(*)FROMapi.logbook),
'moorages',(SELECTCOUNT(*)FROMapi.moorages),
'stays',(SELECTCOUNT(*)FROMapi.stays)
);
$function$;
-- Description
COMMENTONFUNCTIONapi.counts_fn()IS'count logbook, moorages and stays entries';
-[ RECORD 1 ]-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.