generic_translations: DB-Upgrade in Perl geschrieben wg. Constraint-Namen
authorMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 8 Jun 2016 14:05:09 +0000 (16:05 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 8 Jun 2016 14:06:58 +0000 (16:06 +0200)
In alten PostgreSQL-Versionen hießen Foreign-Key-Constraints oft noch so
was wie »$1«. Da sich das Upgrade-Script also bzgl. des Namens nicht
sicher sein kann, gibt's momentan nur die Möglichkeit, einmal alle
Foreign-Keys zu einer Tabelle wegzuwerfen und diese neu anzulegen.

Dafür wiederum haben wir Support-Funktionen in SL::DBUpgrade2::Base, die
wie nutzen können. Also Umstellung des Scripts auf Perl.

sql/Pg-upgrade2/delete_from_generic_translations_on_language_deletion.pl [new file with mode: 0644]
sql/Pg-upgrade2/delete_from_generic_translations_on_language_deletion.sql [deleted file]

diff --git a/sql/Pg-upgrade2/delete_from_generic_translations_on_language_deletion.pl b/sql/Pg-upgrade2/delete_from_generic_translations_on_language_deletion.pl
new file mode 100644 (file)
index 0000000..24ee4eb
--- /dev/null
@@ -0,0 +1,35 @@
+# @tag: delete_from_generic_translations_on_language_deletion
+# @description: Übersetzungen automatisch löschen, wenn die dazugehörige Sprache gelöscht wird
+# @depends: release_3_4_0
+package SL::DBUpgrade2::delete_from_generic_translations_on_language_deletion;
+
+use strict;
+use utf8;
+
+use parent qw(SL::DBUpgrade2::Base);
+
+sub run {
+  my ($self) = @_;
+
+  $self->drop_constraints(table => 'generic_translations');
+
+  $self->db_query(<<SQL);
+    ALTER TABLE generic_translations
+    ADD CONSTRAINT generic_translations_language_id_fkey
+      FOREIGN KEY (language_id)
+      REFERENCES language (id)
+      ON DELETE CASCADE
+SQL
+
+  $self->db_query(<<SQL);
+    DELETE FROM generic_translations
+    WHERE language_id NOT IN (
+      SELECT id
+      FROM language
+    )
+SQL
+
+  return 1;
+}
+
+1;
diff --git a/sql/Pg-upgrade2/delete_from_generic_translations_on_language_deletion.sql b/sql/Pg-upgrade2/delete_from_generic_translations_on_language_deletion.sql
deleted file mode 100644 (file)
index 94cca1b..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
--- @tag: delete_from_generic_translations_on_language_deletion
--- @description: Übersetzungen automatisch löschen, wenn die dazugehörige Sprache gelöscht wird
--- @depends: release_3_4_0
-ALTER TABLE generic_translations
-  DROP CONSTRAINT generic_translations_language_id_fkey,
-  ADD CONSTRAINT generic_translations_language_id_fkey
-    FOREIGN KEY (language_id)
-    REFERENCES language (id)
-    ON DELETE CASCADE;
-
-DELETE FROM generic_translations
-WHERE language_id NOT IN (
-  SELECT id
-  FROM language
-);