From 843264773a8b604aa3873145641732541e764dad Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Fri, 10 Jan 2014 11:55:45 +0100 Subject: [PATCH] =?utf8?q?=C3=9Cbersetzungen=20von=20Steuern=20l=C3=B6sche?= =?utf8?q?n,=20wenn=20Steuer=20gel=C3=B6scht=20wird.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Via Trigger. Außerdem löscht das Update-Skript alle verweisten Übersetzungen der Steuern. --- .../delete_translations_on_tax_delete.sql | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 sql/Pg-upgrade2/delete_translations_on_tax_delete.sql diff --git a/sql/Pg-upgrade2/delete_translations_on_tax_delete.sql b/sql/Pg-upgrade2/delete_translations_on_tax_delete.sql new file mode 100644 index 000000000..5243ace63 --- /dev/null +++ b/sql/Pg-upgrade2/delete_translations_on_tax_delete.sql @@ -0,0 +1,24 @@ +-- @tag: delete_translations_on_tax_delete +-- @description: Übersetzungen löschen, wenn Steuer gelöscht wird +-- @depends: release_3_0_0 +-- @encoding: utf-8 + +CREATE OR REPLACE FUNCTION generic_translations_delete_on_tax_delete_trigger() +RETURNS TRIGGER AS $$ + BEGIN + DELETE FROM generic_translations + WHERE translation_id = OLD.id AND translation_type LIKE 'SL::DB::Tax/taxdescription'; + RETURN OLD; + END; +$$ LANGUAGE plpgsql; + +DROP TRIGGER IF EXISTS after_delete_tax_trigger ON tax; + +CREATE TRIGGER after_delete_tax_trigger + AFTER DELETE ON tax + FOR EACH ROW EXECUTE PROCEDURE generic_translations_delete_on_tax_delete_trigger(); + +-- delete orphaned translations +DELETE FROM generic_translations + WHERE translation_type LIKE 'SL::DB::Tax/taxdescription' + AND translation_id NOT IN (SELECT id FROM tax); -- 2.20.1