Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

154 as an inpector i want to store all registration numbers #214

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions db-creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def create_db(DB_URL, SCHEMA : str):
path = "fertiscan/db/bytebase/update_inspection_function.sql"
execute_sql_file(cur, path)

path = "fertiscan/db/bytebase/update_inspection"
loop_for_sql_files(cur, path)

path = "fertiscan/db/bytebase/delete_inspection_function.sql"
execute_sql_file(cur, path)

Expand Down
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.16".olap_guaranteed_creation()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".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.16"."label_dimension"
UPDATE "fertiscan_0.0.17"."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.16".guaranteed;
DROP TRIGGER IF EXISTS guaranteed_creation ON "fertiscan_0.0.17".guaranteed;
CREATE TRIGGER guaranteed_creation
AFTER INSERT ON "fertiscan_0.0.16".guaranteed
AFTER INSERT ON "fertiscan_0.0.17".guaranteed
FOR EACH ROW
EXECUTE FUNCTION olap_guaranteed_creation();

CREATE OR REPLACE FUNCTION "fertiscan_0.0.16".olap_guaranteed_deletion()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".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.16"."label_dimension"
UPDATE "fertiscan_0.0.17"."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.16".guaranteed;
DROP TRIGGER IF EXISTS guaranteed_deletion ON "fertiscan_0.0.17".guaranteed;
CREATE TRIGGER guaranteed_deletion
AFTER DELETE ON "fertiscan_0.0.16".guaranteed
AFTER DELETE ON "fertiscan_0.0.17".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.16".olap_ingredient_creation()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".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.16"."label_dimension"
UPDATE "fertiscan_0.0.17"."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.16".ingredient;
DROP TRIGGER IF EXISTS ingredient_creation ON "fertiscan_0.0.17".ingredient;
CREATE TRIGGER ingredient_creation
AFTER INSERT ON "fertiscan_0.0.16".ingredient
AFTER INSERT ON "fertiscan_0.0.17".ingredient
FOR EACH ROW
EXECUTE FUNCTION olap_ingredient_creation();

CREATE OR REPLACE FUNCTION "fertiscan_0.0.16".olap_ingredient_deletion()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".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.16"."label_dimension"
UPDATE "fertiscan_0.0.17"."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.16".ingredient;
DROP TRIGGER IF EXISTS ingredient_deletion ON "fertiscan_0.0.17".ingredient;
CREATE TRIGGER ingredient_deletion
AFTER DELETE ON "fertiscan_0.0.16".ingredient
AFTER DELETE ON "fertiscan_0.0.17".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.16".olap_inspection_creation()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".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.16".time_dimension (
INSERT INTO "fertiscan_0.0.17".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.16".inspection_factual (
INSERT INTO "fertiscan_0.0.17".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.16".inspection;
DROP TRIGGER IF EXISTS inspection_creation ON "fertiscan_0.0.17".inspection;
CREATE TRIGGER inspection_creation
AFTER INSERT ON "fertiscan_0.0.16".inspection
AFTER INSERT ON "fertiscan_0.0.17".inspection
FOR EACH ROW
EXECUTE FUNCTION olap_inspection_creation();

CREATE OR REPLACE FUNCTION "fertiscan_0.0.16".olap_inspection_update()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".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.16".inspection_factual
UPDATE "fertiscan_0.0.17".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.16".inspection;
DROP TRIGGER IF EXISTS inspection_update ON "fertiscan_0.0.17".inspection;
CREATE TRIGGER inspection_update
BEFORE UPDATE ON "fertiscan_0.0.16".inspection
BEFORE UPDATE ON "fertiscan_0.0.17".inspection
FOR EACH ROW
EXECUTE FUNCTION olap_inspection_update();

CREATE OR REPLACE FUNCTION "fertiscan_0.0.16".olap_inspection_deletion()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".olap_inspection_deletion()
RETURNS TRIGGER AS $$
BEGIN
IF (TG_OP = 'DELETE') THEN
IF (OLD.id IS NOT NULL) THEN
DELETE FROM "fertiscan_0.0.16".inspection_factual
DELETE FROM "fertiscan_0.0.17".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.16".inspection;
DROP TRIGGER IF EXISTS inspection_deletion ON "fertiscan_0.0.17".inspection;
CREATE TRIGGER inspection_deletion
AFTER DELETE ON "fertiscan_0.0.16".inspection
AFTER DELETE ON "fertiscan_0.0.17".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.16".olap_label_information_creation()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".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.16"."label_dimension" (
INSERT INTO "fertiscan_0.0.17"."label_dimension" (
label_id, company_info_id, manufacturer_info_id
) VALUES (
NEW.id, NEW.company_info_id, NEW.manufacturer_info_id
Expand All @@ -18,19 +18,19 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

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

CREATE OR REPLACE FUNCTION "fertiscan_0.0.16".olap_label_information_update()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".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.16"."label_dimension"
UPDATE "fertiscan_0.0.17"."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 @@ BEGIN
END;
$$ LANGUAGE plpgsql;

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

CREATE OR REPLACE FUNCTION "fertiscan_0.0.16".olap_label_information_deletion()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".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.16"."label_dimension"
DELETE FROM "fertiscan_0.0.17"."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.16".label_information;
DROP TRIGGER IF EXISTS label_information_deletion ON "fertiscan_0.0.17".label_information;
CREATE TRIGGER label_information_deletion
AFTER DELETE ON "fertiscan_0.0.16".label_information
AFTER DELETE ON "fertiscan_0.0.17".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.16".olap_metrics_creation()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".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.16"."label_dimension"
EXECUTE format('UPDATE "fertiscan_0.0.17"."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.16".metric;
DROP TRIGGER IF EXISTS metrics_creation ON "fertiscan_0.0.17".metric;
CREATE TRIGGER metrics_creation
AFTER INSERT ON "fertiscan_0.0.16".metric
AFTER INSERT ON "fertiscan_0.0.17".metric
FOR EACH ROW
EXECUTE FUNCTION olap_metrics_creation();

CREATE OR REPLACE FUNCTION "fertiscan_0.0.16".olap_metrics_deletion()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".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.16"."label_dimension"
EXECUTE format('UPDATE "fertiscan_0.0.17"."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.16".metric;
DROP TRIGGER IF EXISTS metrics_deletion ON "fertiscan_0.0.17".metric;
CREATE TRIGGER metrics_deletion
AFTER DELETE ON "fertiscan_0.0.16".metric
AFTER DELETE ON "fertiscan_0.0.17".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.16".olap_micronutrient_creation()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".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.16"."label_dimension"
UPDATE "fertiscan_0.0.17"."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.16".micronutrient;
DROP TRIGGER IF EXISTS micronutrient_creation ON "fertiscan_0.0.17".micronutrient;
CREATE TRIGGER micronutrient_creation
AFTER INSERT ON "fertiscan_0.0.16".micronutrient
AFTER INSERT ON "fertiscan_0.0.17".micronutrient
FOR EACH ROW
EXECUTE FUNCTION olap_micronutrient_creation();

CREATE OR REPLACE FUNCTION "fertiscan_0.0.16".olap_micronutrient_deletion()
CREATE OR REPLACE FUNCTION "fertiscan_0.0.17".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.16"."label_dimension"
UPDATE "fertiscan_0.0.17"."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.16".micronutrient;
DROP TRIGGER IF EXISTS micronutrient_deletion ON "fertiscan_0.0.17".micronutrient;
CREATE TRIGGER micronutrient_deletion
AFTER DELETE ON "fertiscan_0.0.16".micronutrient
AFTER DELETE ON "fertiscan_0.0.17".micronutrient
FOR EACH ROW
EXECUTE FUNCTION olap_micronutrient_deletion();
Loading
Loading