Abteilungen bei Ansprechpersonen in eigene Tabelle: DB-Upgrade und Rose
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Fri, 8 May 2020 15:03:18 +0000 (17:03 +0200)
committerBernd Bleßmann <bernd@kivitendo-premium.de>
Mon, 11 May 2020 15:04:47 +0000 (17:04 +0200)
SL/DB/ContactDepartment.pm [new file with mode: 0644]
SL/DB/Helper/ALL.pm
SL/DB/Helper/Mappings.pm
SL/DB/Manager/ContactDepartment.pm [new file with mode: 0644]
SL/DB/MetaSetup/ContactDepartment.pm [new file with mode: 0644]
sql/Pg-upgrade2/contact_departments_own_table.sql [new file with mode: 0644]

diff --git a/SL/DB/ContactDepartment.pm b/SL/DB/ContactDepartment.pm
new file mode 100644 (file)
index 0000000..a7645b1
--- /dev/null
@@ -0,0 +1,13 @@
+# This file has been auto-generated only because it didn't exist.
+# Feel free to modify it at will; it will not be overwritten automatically.
+
+package SL::DB::ContactDepartment;
+
+use strict;
+
+use SL::DB::MetaSetup::ContactDepartment;
+use SL::DB::Manager::ContactDepartment;
+
+__PACKAGE__->meta->initialize;
+
+1;
index 5fd1d76..006a389 100644 (file)
@@ -27,6 +27,7 @@ use SL::DB::Buchungsgruppe;
 use SL::DB::Business;
 use SL::DB::Chart;
 use SL::DB::Contact;
+use SL::DB::ContactDepartment;
 use SL::DB::ContactTitle;
 use SL::DB::CsvImportProfile;
 use SL::DB::CsvImportProfileSetting;
index 6f58596..da931f9 100644 (file)
@@ -110,6 +110,7 @@ my %kivitendo_package_names = (
   bin                            => 'bin',
   business                       => 'business',
   chart                          => 'chart',
+  contact_departments            => 'contact_department',
   contact_titles                 => 'contact_title',
   contacts                       => 'contact',
   customer                       => 'customer',
diff --git a/SL/DB/Manager/ContactDepartment.pm b/SL/DB/Manager/ContactDepartment.pm
new file mode 100644 (file)
index 0000000..f545f65
--- /dev/null
@@ -0,0 +1,14 @@
+# This file has been auto-generated only because it didn't exist.
+# Feel free to modify it at will; it will not be overwritten automatically.
+
+package SL::DB::Manager::ContactDepartment;
+
+use strict;
+
+use parent qw(SL::DB::Helper::Manager);
+
+sub object_class { 'SL::DB::ContactDepartment' }
+
+__PACKAGE__->make_manager_methods;
+
+1;
diff --git a/SL/DB/MetaSetup/ContactDepartment.pm b/SL/DB/MetaSetup/ContactDepartment.pm
new file mode 100644 (file)
index 0000000..bba52e1
--- /dev/null
@@ -0,0 +1,21 @@
+# This file has been auto-generated. Do not modify it; it will be overwritten
+# by rose_auto_create_model.pl automatically.
+package SL::DB::ContactDepartment;
+
+use strict;
+
+use parent qw(SL::DB::Object);
+
+__PACKAGE__->meta->table('contact_departments');
+
+__PACKAGE__->meta->columns(
+  description => { type => 'text', not_null => 1 },
+  id          => { type => 'serial', not_null => 1 },
+);
+
+__PACKAGE__->meta->primary_key_columns([ 'id' ]);
+
+__PACKAGE__->meta->unique_keys([ 'description' ]);
+
+1;
+;
diff --git a/sql/Pg-upgrade2/contact_departments_own_table.sql b/sql/Pg-upgrade2/contact_departments_own_table.sql
new file mode 100644 (file)
index 0000000..8535f1e
--- /dev/null
@@ -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;