Skip to content

Commit

Permalink
Merge pull request #106 from pzaino/develop
Browse files Browse the repository at this point in the history
Minor DB schema improvements
  • Loading branch information
pzaino authored Feb 16, 2024
2 parents a5ec028 + db316c2 commit 344b6ae
Showing 1 changed file with 53 additions and 22 deletions.
75 changes: 53 additions & 22 deletions pkg/database/postgresql-setup-v1.2.pgsql
Original file line number Diff line number Diff line change
Expand Up @@ -898,16 +898,6 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER after_httpinfoindex_deletion
AFTER DELETE ON HTTPInfoIndex
FOR EACH ROW
EXECUTE FUNCTION cleanup_orphaned_httpinfo();

CREATE TRIGGER after_netinfoindex_deletion
AFTER DELETE ON NetInfoIndex
FOR EACH ROW
EXECUTE FUNCTION cleanup_orphaned_netinfo();

-- Function to handle the deletion of shared entities when no longer linked to any Source.
CREATE OR REPLACE FUNCTION handle_shared_entity_deletion()
RETURNS TRIGGER AS $$
Expand All @@ -934,17 +924,48 @@ $$ LANGUAGE plpgsql;
-- Repeat this logic for each linking table: SearchIndexMetaTags, PageWebObjectsIndex, KeywordIndex.
-- Adjust the referencing table name and the column names accordingly.

CREATE TRIGGER handle_meta_tags_deletion
AFTER DELETE ON SearchIndexMetaTags
FOR EACH ROW EXECUTE FUNCTION handle_shared_entity_deletion();
-- Creates a trigger to handle the deletion of shared entities when no longer linked to any Source.
DO $$
BEGIN
-- Check if the trigger already exists
IF NOT EXISTS (SELECT 1 FROM pg_trigger WHERE tgname = 'trg_after_delete_searchindexmetatags') THEN
-- Create the trigger if it doesn't exist
CREATE TRIGGER trg_after_delete_searchindexmetatags
AFTER DELETE ON SearchIndexMetaTags
FOR EACH ROW
EXECUTE FUNCTION handle_shared_entity_deletion();
END IF;
END
$$;

CREATE TRIGGER handle_web_objects_deletion
AFTER DELETE ON PageWebObjectsIndex
FOR EACH ROW EXECUTE FUNCTION handle_shared_entity_deletion();
-- Creates a trigger to handle the deletion of shared entities when no longer linked to any Source.
DO $$
BEGIN
-- Check if the trigger already exists
IF NOT EXISTS (SELECT 1 FROM pg_trigger WHERE tgname = 'trg_after_delete_pagewebobjectsindex') THEN
-- Create the trigger if it doesn't exist
CREATE TRIGGER trg_after_delete_pagewebobjectsindex
AFTER DELETE ON PageWebObjectsIndex
FOR EACH ROW
EXECUTE FUNCTION handle_shared_entity_deletion();
END IF;
END
$$;

-- Creates a trigger to handle the deletion of shared entities when no longer linked to any Source.
DO $$
BEGIN
-- Check if the trigger already exists
IF NOT EXISTS (SELECT 1 FROM pg_trigger WHERE tgname = 'trg_after_delete_keywordindex') THEN
-- Create the trigger if it doesn't exist
CREATE TRIGGER trg_after_delete_keywordindex
AFTER DELETE ON KeywordIndex
FOR EACH ROW
EXECUTE FUNCTION handle_shared_entity_deletion();
END IF;
END
$$;

CREATE TRIGGER handle_keywords_deletion
AFTER DELETE ON KeywordIndex
FOR EACH ROW EXECUTE FUNCTION handle_shared_entity_deletion();

CREATE OR REPLACE FUNCTION handle_searchindex_deletion()
RETURNS TRIGGER AS $$
Expand All @@ -958,9 +979,19 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER trg_after_delete_source_searchindex
AFTER DELETE ON SourceSearchIndex
FOR EACH ROW EXECUTE FUNCTION handle_searchindex_deletion();

-- Creates a trigger to handle the deletion of SearchIndex entries when no longer linked to any Source.
DO $$
BEGIN
-- Check if the trigger already exists
IF NOT EXISTS (SELECT 1 FROM pg_trigger WHERE tgname = 'trg_after_delete_source_searchindex') THEN
-- Create the trigger if it doesn't exist
CREATE TRIGGER trg_after_delete_source_searchindex
AFTER DELETE ON SourceSearchIndex
FOR EACH ROW EXECUTE FUNCTION handle_searchindex_deletion();
END IF;
END
$$;

-- Ensure that the ON CASCADE DELETE is defined correctly:

Expand Down

0 comments on commit 344b6ae

Please sign in to comment.