Skip to content

Commit

Permalink
Issue #218: SCHEMA 18
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois-Werbrouck committed Nov 22, 2024
1 parent a8f6a1a commit 2e962d4
Show file tree
Hide file tree
Showing 38 changed files with 771 additions and 300 deletions.
16 changes: 8 additions & 8 deletions fertiscan/db/bytebase/OLAP/guaranteed_triggers.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".olap_guaranteed_creation()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.18".olap_guaranteed_creation()
RETURNS TRIGGER AS $$
BEGIN
IF (TG_OP = 'INSERT') THEN
IF (NEW.id IS NOT NULL) AND (NEW.label_id IS NOT NULL) THEN
-- Update the label_dimension table with the new guaranteed_analysis_id
UPDATE "fertiscan_0.0.17"."label_dimension"
UPDATE "fertiscan_0.0.18"."label_dimension"
SET guaranteed_ids = array_append(guaranteed_ids, NEW.id)
WHERE label_dimension.label_id = NEW.label_id;
ELSE
Expand All @@ -17,19 +17,19 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS guaranteed_creation ON "fertiscan_0.0.17".guaranteed;
DROP TRIGGER IF EXISTS guaranteed_creation ON "fertiscan_0.0.18".guaranteed;
CREATE TRIGGER guaranteed_creation
AFTER INSERT ON "fertiscan_0.0.17".guaranteed
AFTER INSERT ON "fertiscan_0.0.18".guaranteed
FOR EACH ROW
EXECUTE FUNCTION olap_guaranteed_creation();

CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".olap_guaranteed_deletion()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.18".olap_guaranteed_deletion()
RETURNS TRIGGER AS $$
BEGIN
IF (TG_OP = 'DELETE') THEN
IF (OLD.id IS NOT NULL) AND (OLD.label_id IS NOT NULL) THEN
-- Update the label_dimension table with the new guaranteed_analysis_id
UPDATE "fertiscan_0.0.17"."label_dimension"
UPDATE "fertiscan_0.0.18"."label_dimension"
SET guaranteed_ids = array_remove(guaranteed_ids, OLD.id)
WHERE label_dimension.label_id = OLD.label_id;
ELSE
Expand All @@ -41,8 +41,8 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS guaranteed_deletion ON "fertiscan_0.0.17".guaranteed;
DROP TRIGGER IF EXISTS guaranteed_deletion ON "fertiscan_0.0.18".guaranteed;
CREATE TRIGGER guaranteed_deletion
AFTER DELETE ON "fertiscan_0.0.17".guaranteed
AFTER DELETE ON "fertiscan_0.0.18".guaranteed
FOR EACH ROW
EXECUTE FUNCTION olap_guaranteed_deletion();
16 changes: 8 additions & 8 deletions fertiscan/db/bytebase/OLAP/ingredient_trigger.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".olap_ingredient_creation()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.18".olap_ingredient_creation()
RETURNS TRIGGER AS $$
BEGIN
IF (TG_OP = 'INSERT') THEN
IF (NEW.id IS NOT NULL) AND (NEW.label_id IS NOT NULL) THEN
-- Update the label_dimension table with the new ingredient_analysis_id
UPDATE "fertiscan_0.0.17"."label_dimension"
UPDATE "fertiscan_0.0.18"."label_dimension"
SET ingredient_ids = array_append(ingredient_ids, NEW.id)
WHERE label_dimension.label_id = NEW.label_id;
ELSE
Expand All @@ -17,19 +17,19 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS ingredient_creation ON "fertiscan_0.0.17".ingredient;
DROP TRIGGER IF EXISTS ingredient_creation ON "fertiscan_0.0.18".ingredient;
CREATE TRIGGER ingredient_creation
AFTER INSERT ON "fertiscan_0.0.17".ingredient
AFTER INSERT ON "fertiscan_0.0.18".ingredient
FOR EACH ROW
EXECUTE FUNCTION olap_ingredient_creation();

CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".olap_ingredient_deletion()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.18".olap_ingredient_deletion()
RETURNS TRIGGER AS $$
BEGIN
IF (TG_OP = 'DELETE') THEN
IF (OLD.id IS NOT NULL) AND (OLD.label_id IS NOT NULL) THEN
-- Update the label_dimension table with the new ingredient_analysis_id
UPDATE "fertiscan_0.0.17"."label_dimension"
UPDATE "fertiscan_0.0.18"."label_dimension"
SET ingredient_ids = array_remove(ingredient_ids, OLD.id)
WHERE label_dimension.label_id = OLD.label_id;
ELSE
Expand All @@ -41,8 +41,8 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS ingredient_deletion ON "fertiscan_0.0.17".ingredient;
DROP TRIGGER IF EXISTS ingredient_deletion ON "fertiscan_0.0.18".ingredient;
CREATE TRIGGER ingredient_deletion
AFTER DELETE ON "fertiscan_0.0.17".ingredient
AFTER DELETE ON "fertiscan_0.0.18".ingredient
FOR EACH ROW
EXECUTE FUNCTION olap_ingredient_deletion();
26 changes: 13 additions & 13 deletions fertiscan/db/bytebase/OLAP/inspection_triggers.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".olap_inspection_creation()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.18".olap_inspection_creation()
RETURNS TRIGGER AS $$
DECLARE
time_id UUID;
BEGIN
IF (TG_OP = 'INSERT') THEN
IF (NEW.id IS NOT NULL) AND (NEW.label_info_id IS NOT NULL) THEN
-- Time Dimension
INSERT INTO "fertiscan_0.0.17".time_dimension (
INSERT INTO "fertiscan_0.0.18".time_dimension (
date_value, year,month,day)
VALUES (
CURRENT_DATE,
Expand All @@ -16,7 +16,7 @@ BEGIN
EXTRACT(DAY FROM CURRENT_DATE)
) RETURNING id INTO time_id;
-- Create the Inspection_factual entry
INSERT INTO "fertiscan_0.0.17".inspection_factual (
INSERT INTO "fertiscan_0.0.18".inspection_factual (
inspection_id, inspector_id, label_info_id, time_id, sample_id, company_id, manufacturer_id, picture_set_id, original_dataset
) VALUES (
NEW.id,
Expand All @@ -38,19 +38,19 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS inspection_creation ON "fertiscan_0.0.17".inspection;
DROP TRIGGER IF EXISTS inspection_creation ON "fertiscan_0.0.18".inspection;
CREATE TRIGGER inspection_creation
AFTER INSERT ON "fertiscan_0.0.17".inspection
AFTER INSERT ON "fertiscan_0.0.18".inspection
FOR EACH ROW
EXECUTE FUNCTION olap_inspection_creation();

CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".olap_inspection_update()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.18".olap_inspection_update()
RETURNS TRIGGER AS $$
BEGIN
IF (TG_OP = 'UPDATE') THEN
IF (NEW.id IS NOT NULL) THEN
IF (NEW.label_info_id != OLD.label_info_id) OR (NEW.inspector_id != OLD.inspector_id) OR (NEW.picture_set_id != OLD.picture_set_id) THEN
UPDATE "fertiscan_0.0.17".inspection_factual
UPDATE "fertiscan_0.0.18".inspection_factual
SET inspector_id = NEW.inspector_id, label_info_id = NEW.label_info_id, picture_set_id = NEW.picture_set_id
WHERE inspection_id = NEW.id;
END IF;
Expand All @@ -63,18 +63,18 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS inspection_update ON "fertiscan_0.0.17".inspection;
DROP TRIGGER IF EXISTS inspection_update ON "fertiscan_0.0.18".inspection;
CREATE TRIGGER inspection_update
BEFORE UPDATE ON "fertiscan_0.0.17".inspection
BEFORE UPDATE ON "fertiscan_0.0.18".inspection
FOR EACH ROW
EXECUTE FUNCTION olap_inspection_update();

CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".olap_inspection_deletion()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.18".olap_inspection_deletion()
RETURNS TRIGGER AS $$
BEGIN
IF (TG_OP = 'DELETE') THEN
IF (OLD.id IS NOT NULL) THEN
DELETE FROM "fertiscan_0.0.17".inspection_factual
DELETE FROM "fertiscan_0.0.18".inspection_factual
WHERE inspection_id = OLD.id;
ELSE
-- Raise a warning if the condition is not met
Expand All @@ -85,8 +85,8 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS inspection_deletion ON "fertiscan_0.0.17".inspection;
DROP TRIGGER IF EXISTS inspection_deletion ON "fertiscan_0.0.18".inspection;
CREATE TRIGGER inspection_deletion
AFTER DELETE ON "fertiscan_0.0.17".inspection
AFTER DELETE ON "fertiscan_0.0.18".inspection
FOR EACH ROW
EXECUTE FUNCTION olap_inspection_deletion();
24 changes: 12 additions & 12 deletions fertiscan/db/bytebase/OLAP/label_information_triggers.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".olap_label_information_creation()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.18".olap_label_information_creation()
RETURNS TRIGGER AS $$
BEGIN
IF (TG_OP = 'INSERT') THEN
IF (NEW.id IS NOT NULL) THEN
INSERT INTO "fertiscan_0.0.17"."label_dimension" (
INSERT INTO "fertiscan_0.0.18"."label_dimension" (
label_id
) VALUES (
NEW.id
Expand All @@ -18,19 +18,19 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS label_information_creation ON "fertiscan_0.0.17".label_information;
DROP TRIGGER IF EXISTS label_information_creation ON "fertiscan_0.0.18".label_information;
CREATE TRIGGER label_information_creation
AFTER INSERT ON "fertiscan_0.0.17".label_information
AFTER INSERT ON "fertiscan_0.0.18".label_information
FOR EACH ROW
EXECUTE FUNCTION olap_label_information_creation();

-- CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".olap_label_information_update()
-- CREATE OR REPLACE FUNCTION "fertiscan_0.0.18".olap_label_information_update()
-- RETURNS TRIGGER AS $$
-- BEGIN
-- IF (TG_OP = 'UPDATE') THEN
-- IF (NEW.id IS NOT NULL) THEN
-- IF (NEW.company_info_id !=OLD.company_info_id) OR (NEW.manufacturer_info_id != OLD.manufacturer_info_id) THEN
-- UPDATE "fertiscan_0.0.17"."label_dimension"
-- UPDATE "fertiscan_0.0.18"."label_dimension"
-- SET company_info_id = NEW.company_info_id, manufacturer_info_id = NEW.manufacturer_info_id
-- WHERE label_id = NEW.id;
-- END IF;
Expand All @@ -43,18 +43,18 @@ EXECUTE FUNCTION olap_label_information_creation();
-- END;
-- $$ LANGUAGE plpgsql;

-- DROP TRIGGER IF EXISTS label_information_update ON "fertiscan_0.0.17".label_information;
-- DROP TRIGGER IF EXISTS label_information_update ON "fertiscan_0.0.18".label_information;
-- CREATE TRIGGER label_information_update
-- BEFORE UPDATE ON "fertiscan_0.0.17".label_information
-- BEFORE UPDATE ON "fertiscan_0.0.18".label_information
-- FOR EACH ROW
-- EXECUTE FUNCTION olap_label_information_update();

CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".olap_label_information_deletion()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.18".olap_label_information_deletion()
RETURNS TRIGGER AS $$
BEGIN
IF (TG_OP = 'DELETE') THEN
IF (OLD.id IS NOT NULL) THEN
DELETE FROM "fertiscan_0.0.17"."label_dimension"
DELETE FROM "fertiscan_0.0.18"."label_dimension"
WHERE label_id = OLD.id;
ELSE
-- Raise a warning if the condition is not met
Expand All @@ -65,8 +65,8 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS label_information_deletion ON "fertiscan_0.0.17".label_information;
DROP TRIGGER IF EXISTS label_information_deletion ON "fertiscan_0.0.18".label_information;
CREATE TRIGGER label_information_deletion
AFTER DELETE ON "fertiscan_0.0.17".label_information
AFTER DELETE ON "fertiscan_0.0.18".label_information
FOR EACH ROW
EXECUTE FUNCTION olap_label_information_deletion();
16 changes: 8 additions & 8 deletions fertiscan/db/bytebase/OLAP/metrics_triggers.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".olap_metrics_creation()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.18".olap_metrics_creation()
RETURNS TRIGGER AS $$
DECLARE
metric_type TEXT;
Expand All @@ -11,7 +11,7 @@ BEGIN
IF (metric_type ILIKE 'test%') THEN
RETURN NEW;
END IF;
EXECUTE format('UPDATE "fertiscan_0.0.17"."label_dimension"
EXECUTE format('UPDATE "fertiscan_0.0.18"."label_dimension"
SET %I = array_append(%I, %L)
WHERE label_dimension.label_id = %L',
metric_type, metric_type, NEW.id, NEW.label_id);
Expand All @@ -24,13 +24,13 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS metrics_creation ON "fertiscan_0.0.17".metric;
DROP TRIGGER IF EXISTS metrics_creation ON "fertiscan_0.0.18".metric;
CREATE TRIGGER metrics_creation
AFTER INSERT ON "fertiscan_0.0.17".metric
AFTER INSERT ON "fertiscan_0.0.18".metric
FOR EACH ROW
EXECUTE FUNCTION olap_metrics_creation();

CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".olap_metrics_deletion()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.18".olap_metrics_deletion()
RETURNS TRIGGER AS $$
DECLARE
metric_type TEXT;
Expand All @@ -42,7 +42,7 @@ BEGIN
IF (metric_type ILIKE 'test%') THEN
RETURN OLD;
END IF;
EXECUTE format('UPDATE "fertiscan_0.0.17"."label_dimension"
EXECUTE format('UPDATE "fertiscan_0.0.18"."label_dimension"
SET %I = array_remove(%I, %L)
WHERE label_dimension.label_id = %L',
metric_type, metric_type, OLD.id, OLD.label_id);
Expand All @@ -55,8 +55,8 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS metrics_deletion ON "fertiscan_0.0.17".metric;
DROP TRIGGER IF EXISTS metrics_deletion ON "fertiscan_0.0.18".metric;
CREATE TRIGGER metrics_deletion
AFTER DELETE ON "fertiscan_0.0.17".metric
AFTER DELETE ON "fertiscan_0.0.18".metric
FOR EACH ROW
EXECUTE FUNCTION olap_metrics_deletion();
16 changes: 8 additions & 8 deletions fertiscan/db/bytebase/OLAP/micronutrient_triggers.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".olap_micronutrient_creation()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.18".olap_micronutrient_creation()
RETURNS TRIGGER AS $$
BEGIN
IF (TG_OP = 'INSERT') THEN
IF (NEW.id IS NOT NULL) AND (NEW.label_id IS NOT NULL) THEN
-- Update the label_dimension table with the new micronutrient_analysis_id
UPDATE "fertiscan_0.0.17"."label_dimension"
UPDATE "fertiscan_0.0.18"."label_dimension"
SET micronutrient_ids = array_append(micronutrient_ids, NEW.id)
WHERE label_dimension.label_id = NEW.label_id;
ELSE
Expand All @@ -17,19 +17,19 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS micronutrient_creation ON "fertiscan_0.0.17".micronutrient;
DROP TRIGGER IF EXISTS micronutrient_creation ON "fertiscan_0.0.18".micronutrient;
CREATE TRIGGER micronutrient_creation
AFTER INSERT ON "fertiscan_0.0.17".micronutrient
AFTER INSERT ON "fertiscan_0.0.18".micronutrient
FOR EACH ROW
EXECUTE FUNCTION olap_micronutrient_creation();

CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".olap_micronutrient_deletion()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.18".olap_micronutrient_deletion()
RETURNS TRIGGER AS $$
BEGIN
IF (TG_OP = 'DELETE') THEN
IF (OLD.id IS NOT NULL) AND (OLD.label_id IS NOT NULL) THEN
-- Update the label_dimension table with the new micronutrient_analysis_id
UPDATE "fertiscan_0.0.17"."label_dimension"
UPDATE "fertiscan_0.0.18"."label_dimension"
SET micronutrient_ids = array_remove(micronutrient_ids, OLD.id)
WHERE label_dimension.label_id = OLD.label_id;
ELSE
Expand All @@ -41,8 +41,8 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS micronutrient_deletion ON "fertiscan_0.0.17".micronutrient;
DROP TRIGGER IF EXISTS micronutrient_deletion ON "fertiscan_0.0.18".micronutrient;
CREATE TRIGGER micronutrient_deletion
AFTER DELETE ON "fertiscan_0.0.17".micronutrient
AFTER DELETE ON "fertiscan_0.0.18".micronutrient
FOR EACH ROW
EXECUTE FUNCTION olap_micronutrient_deletion();
12 changes: 6 additions & 6 deletions fertiscan/db/bytebase/OLAP/organization_triggers.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".olap_organization_information_creation()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.18".olap_organization_information_creation()
RETURNS TRIGGER AS $$
BEGIN
IF (TG_OP = 'INSERT') THEN
IF (NEW.id IS NOT NULL) THEN
UPDATE "fertiscan_0.0.17"."label_dimension"
UPDATE "fertiscan_0.0.18"."label_dimension"
SET organization_info_ids = array_append(organization_info_ids, NEW.id)
WHERE label_dimension.label_id = NEW.label_id;
ELSE
Expand All @@ -16,18 +16,18 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS organization_information_creation ON "fertiscan_0.0.17".organization_information;
DROP TRIGGER IF EXISTS organization_information_creation ON "fertiscan_0.0.18".organization_information;
CREATE TRIGGER organization_information_creation
AFTER INSERT ON "fertiscan_0.0.17".organization_information
AFTER INSERT ON "fertiscan_0.0.18".organization_information
FOR EACH ROW
EXECUTE FUNCTION olap_organization_information_creation();

CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".olap_organization_information_deletion()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.18".olap_organization_information_deletion()
RETURNS TRIGGER AS $$
BEGIN
IF (TG_OP = 'DELETE') THEN
IF (OLD.id IS NOT NULL) THEN
UPDATE "fertiscan_0.0.17"."label_dimension"
UPDATE "fertiscan_0.0.18"."label_dimension"
SET organization_info_ids = array_remove(organization_info_ids, OLD.id)
WHERE label_dimension.label_id = OLD.label_id;
ELSE
Expand Down
Loading

0 comments on commit 2e962d4

Please sign in to comment.