fix label names update not reflected

This commit is contained in:
Hongbo Wu
2023-09-20 15:05:22 +08:00
parent 867c31a582
commit ac77580cca
3 changed files with 23 additions and 2 deletions

View File

@ -12,7 +12,7 @@ CREATE TABLE omnivore.entity_labels (
unique(label_id, library_item_id, highlight_id)
);
GRANT SELECT, INSERT, DELETE ON omnivore.entity_labels TO omnivore_user;
GRANT SELECT, INSERT, UPDATE, DELETE ON omnivore.entity_labels TO omnivore_user;
CREATE OR REPLACE FUNCTION update_library_item_labels()
RETURNS trigger AS $$
@ -29,7 +29,7 @@ BEGIN
END IF;
IF current_library_item_id IS NOT NULL THEN
-- for labels of the ABORTlibrary_item
-- for labels of the library_item
WITH labels_agg AS (
SELECT array_agg(l.name) as names_agg
FROM omnivore.labels l

View File

@ -9,6 +9,25 @@ ALTER TABLE omnivore.labels ADD COLUMN updated_at timestamptz;
CREATE TRIGGER update_labels_modtime BEFORE UPDATE ON omnivore.labels
FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column();
CREATE OR REPLACE FUNCTION update_entity_labels()
RETURNS trigger AS $$
BEGIN
-- update entity_labels table to trigger update on library_item table
UPDATE omnivore.entity_labels
SET label_id = NEW.id
WHERE label_id = OLD.id;
return NEW;
END;
$$ LANGUAGE plpgsql;
-- triggers when label name is updated
CREATE TRIGGER entity_labels_update
AFTER UPDATE ON omnivore.labels
FOR EACH ROW
WHEN (OLD.name <> NEW.name)
EXECUTE FUNCTION update_entity_labels();
ALTER TABLE omnivore.abuse_report DROP COLUMN page_id;
ALTER TABLE omnivore.abuse_report RENAME COLUMN elastic_page_id TO library_item_id;
ALTER TABLE omnivore.content_display_report DROP COLUMN page_id;

View File

@ -9,6 +9,8 @@ ALTER TABLE omnivore.abuse_report ADD COLUMN page_id text;
ALTER TABLE omnivore.content_display_report RENAME COLUMN library_item_id TO elastic_page_id;
ALTER TABLE omnivore.content_display_report ADD COLUMN page_id text;
DROP TRIGGER IF EXISTS entity_labels_update ON omnivore.labels;
DROP FUNCTION IF EXISTS update_entity_labels();
DROP TRIGGER update_labels_modtime ON omnivore.labels;
ALTER TABLE omnivore.labels DROP COLUMN updated_at;