feat: add support for multiple route numbers in alert notifications
- Updated FCM alert notifications documentation to include handling of multiple route numbers. - Enhanced Telegram cancellation import logic to support multiple route numbers, ensuring correct notifications are sent for all directions. - Modified frontend components to allow selection of multiple route numbers for alerts, improving user experience. - Implemented backend migration to add `route_numbers` column to alerts and adjusted related database constraints. - Introduced new utility functions for normalizing and validating route numbers in alert processing.
This commit is contained in:
20
backend/migrations/015_alert_route_numbers.sql
Normal file
20
backend/migrations/015_alert_route_numbers.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
BEGIN;
|
||||
|
||||
-- Numbers target every direction in the city. Keep route_id for older clients.
|
||||
ALTER TABLE alerts ADD COLUMN IF NOT EXISTS route_numbers TEXT[] NOT NULL DEFAULT '{}';
|
||||
UPDATE alerts a SET route_numbers = ARRAY[upper(regexp_replace(r.route_number, '[[:space:]№]', '', 'g'))]
|
||||
FROM routes r WHERE r.id=a.route_id AND cardinality(a.route_numbers)=0;
|
||||
CREATE INDEX IF NOT EXISTS idx_alerts_route_numbers ON alerts USING gin(route_numbers);
|
||||
|
||||
-- Removing one direction must not remove a notification for the whole number.
|
||||
ALTER TABLE alerts DROP CONSTRAINT IF EXISTS alerts_route_id_fkey;
|
||||
ALTER TABLE alerts ADD CONSTRAINT alerts_route_id_fkey FOREIGN KEY(route_id) REFERENCES routes(id) ON DELETE SET NULL;
|
||||
|
||||
-- One source publication creates one alert. A NULL alert_id preserves deletion.
|
||||
-- Legacy per-direction links stay intact until that publication is edited/reviewed.
|
||||
CREATE TABLE IF NOT EXISTS telegram_message_alerts (
|
||||
message_id INTEGER PRIMARY KEY REFERENCES telegram_import_messages(id) ON DELETE CASCADE,
|
||||
alert_id INTEGER UNIQUE REFERENCES alerts(id) ON DELETE SET NULL
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
Reference in New Issue
Block a user