X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/4e9b1b0261e212d0d7e8c77a2e44cd92610da53a..e0412b7e60eb334d00a4df775041ce469907c62e:/sql/Pg-upgrade2/delete_translations_on_payment_term_delete.sql

diff --git a/sql/Pg-upgrade2/delete_translations_on_payment_term_delete.sql b/sql/Pg-upgrade2/delete_translations_on_payment_term_delete.sql
new file mode 100644
index 000000000..950245240
--- /dev/null
+++ b/sql/Pg-upgrade2/delete_translations_on_payment_term_delete.sql
@@ -0,0 +1,24 @@
+-- @tag: delete_translations_on_payment_term_delete
+-- @description: Ãbersetzungen lÃ¶schen, wenn Lieferbedingung gelÃ¶scht wird
+-- @depends: payment_terms_translation2
+-- @encoding: utf-8
+
+CREATE OR REPLACE FUNCTION generic_translations_delete_on_payment_terms_delete_trigger()
+RETURNS TRIGGER AS $$
+  BEGIN
+    DELETE FROM generic_translations
+      WHERE translation_id = OLD.id AND translation_type LIKE 'SL::DB::PaymentTerm/description_long';
+    RETURN OLD;
+  END;
+$$ LANGUAGE plpgsql;
+
+DROP TRIGGER IF EXISTS after_delete_payment_term_trigger ON payment_terms;
+
+CREATE TRIGGER after_delete_payment_term_trigger
+  AFTER DELETE ON payment_terms
+  FOR EACH ROW EXECUTE PROCEDURE generic_translations_delete_on_payment_terms_delete_trigger();
+
+-- delete orphaned translations
+DELETE FROM generic_translations
+  WHERE translation_type LIKE 'SL::DB::PaymentTerm/description_long'
+  AND   translation_id NOT IN (SELECT id FROM payment_terms);
