Skip to content

Commit

Permalink
fix: minor-fix in meta.sql file
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilender-bongirwar authored Dec 9, 2024
1 parent 99606ef commit 5ba8c03
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions extension/sql/meta.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,35 @@ GRANT SELECT ON ALL SEQUENCES IN SCHEMA vectorize TO pg_monitor;
ALTER DEFAULT PRIVILEGES IN SCHEMA vectorize GRANT SELECT ON TABLES TO pg_monitor;
ALTER DEFAULT PRIVILEGES IN SCHEMA vectorize GRANT SELECT ON SEQUENCES TO pg_monitor;

CREATE OR REPLACE FUNCTION handle_table_drop()
CREATE OR REPLACE FUNCTION handle_table_drop()
RETURNS event_trigger AS $$
DECLARE
obj RECORD;
schema_name TEXT;
table_name TEXT;
BEGIN
FOR obj IN SELECT * FROM pg_event_trigger_dropped_objects() LOOP
IF obj.object_type = 'table' THEN
DELETE FROM vectorize.job
WHERE params ->> 'table' = obj.object_name
AND params ->> 'schema' = obj.object_schema;
schema_name := split_part(obj.object_identity, '.', 1);
table_name := split_part(obj.object_identity, '.', 2);

RAISE NOTICE 'Event Trigger Fired for table drop: %, schema: %', table_name, schema_name;

-- Perform cleanup: delete the associated job from the vectorize.job table
DELETE FROM vectorize.job
WHERE params ->> 'table' = table_name
AND params ->> 'schema' = schema_name;

IF NOT FOUND THEN
RAISE NOTICE 'No matching job found for table: %, schema: %', table_name, schema_name;
END IF;
END IF;
END LOOP;
END;
$$ LANGUAGE plpgsql;

DROP EVENT TRIGGER IF EXISTS vectorize_job_drop_trigger;

CREATE EVENT TRIGGER vectorize_job_drop_trigger
ON sql_drop
WHEN TAG IN ('DROP TABLE')
Expand Down

0 comments on commit 5ba8c03

Please sign in to comment.