Siddhant 2f39b76c33
Fix Fetching Successfully Sent Change Events For Debuggability API (#18493)
* fix getSuccessfullySentChangeEventsForAlert

* migrations.

* offset-based pagination

* add startingOffset in EventSubscriptionDiagnosticInfo

* fix missing paginationOffset

* Record successfully sent change events in a separate table, clean up associated successful and failed records on alert deletion.

* Remove oldest 30 records if record count reaches 100 for successful_sent_change_events.

* list unprocessed changeEvents based on alert subscription rules, ensuring only relevant unprocessed events are listed.

* refactor: enhance eventSubscriptionDiagnosticInfo

Added new fields to the eventSubscriptionDiagnosticInfo schema to support detailed diagnostics:
- `relevantUnprocessedEventsCount`: Count of relevant unprocessed events based on alert filtering rules.
- `relevantUnprocessedEventsList`: List of relevant unprocessed events based on alert filtering rules.
- `totalUnprocessedEventsCount`: Count of all unprocessed events.
- `totalUnprocessedEventsList`: List of all unprocessed events.

* Refactor: delete 30 oldest records per alert when the count reaches 100 records

* fix: table creation issue in PostgreSQL

* fix tests.

* scheduleCleanupJob

* remove in-line deletion of records.

* fix postgres table structure issue.
2024-11-08 12:47:16 +01:00

37 lines
1.3 KiB
SQL

-- Clean dangling workflows not removed after test connection
truncate automations_workflow;
-- App Data Store
CREATE TABLE IF NOT EXISTS apps_data_store (
identifier VARCHAR(256) NOT NULL,
type VARCHAR(256) NOT NULL,
json JSON NOT NULL
);
-- Add the source column to the consumers_dlq table
ALTER TABLE consumers_dlq ADD COLUMN source VARCHAR(255);
-- Create an index on the source column in the consumers_dlq table
CREATE INDEX idx_consumers_dlq_source ON consumers_dlq (source);
-- Rename 'offset' to 'currentOffset' and add 'startingOffset'
UPDATE change_event_consumers
SET json = jsonb_set(
jsonb_set(json, '{currentOffset}', json -> 'offset'),
'{startingOffset}', json -> 'offset'
)
WHERE json -> 'offset' IS NOT NULL
AND jsonSchema = 'eventSubscriptionOffset';
-- Create table successful_sent_change_events for storing successfully sent events per alert
CREATE TABLE IF NOT EXISTS successful_sent_change_events (
id VARCHAR(36) PRIMARY KEY,
change_event_id VARCHAR(36) NOT NULL,
event_subscription_id VARCHAR(36) NOT NULL,
json jsonb NOT NULL,
timestamp BIGINT NOT NULL
);
-- Create an index on the event_subscription_id column in the successful_sent_change_events table
CREATE INDEX idx_event_subscription_id ON successful_sent_change_events (event_subscription_id);