X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/deb4d2dbb676d7d6f69dfe7815d6e0cb09bd4a44..53593baa211863fbf66540cf1bcc36c8fb37257f:/sql/Pg-upgrade2/contact_departments_own_table.sql

diff --git a/sql/Pg-upgrade2/contact_departments_own_table.sql b/sql/Pg-upgrade2/contact_departments_own_table.sql
new file mode 100644
index 000000000..8535f1e92
--- /dev/null
+++ b/sql/Pg-upgrade2/contact_departments_own_table.sql
@@ -0,0 +1,15 @@
+-- @tag: contact_departments_own_table
+-- @description: Eigene Tabelle fÃ¼r Abteilungen bei Ansprechpersonen
+-- @depends: release_3_5_5
+
+CREATE TABLE contact_departments (
+  id          SERIAL,
+  description TEXT    NOT NULL,
+  PRIMARY KEY (id),
+  UNIQUE (description)
+);
+
+UPDATE contacts SET cp_abteilung = trim(cp_abteilung) WHERE cp_abteilung NOT LIKE trim(cp_abteilung);
+
+INSERT INTO contact_departments (description)
+  SELECT DISTINCT cp_abteilung FROM contacts WHERE cp_abteilung IS NOT NULL AND cp_abteilung NOT LIKE '' ORDER BY cp_abteilung;
