From f29d838b7c6996cf544d4292dcc18994194000ab Mon Sep 17 00:00:00 2001 From: ma0068 Date: Fri, 18 Mar 2022 13:45:33 +0100 Subject: [PATCH] =?UTF-8?q?Adaptierungen=20f=C3=BCr=20checksystem=20entwic?= =?UTF-8?q?klungteam=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- system/dbupdate_3.3.php | 99 ++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 51 deletions(-) diff --git a/system/dbupdate_3.3.php b/system/dbupdate_3.3.php index f4d7a01bc..8ed1bce94 100644 --- a/system/dbupdate_3.3.php +++ b/system/dbupdate_3.3.php @@ -5973,104 +5973,100 @@ if(!@$db->db_query("SELECT entwicklungsteam_id FROM bis.tbl_entwicklungsteam LIM if(!$db->db_query($qry)) echo ' bis.tbl_entwicklungsteam '.$db->db_last_error().'
'; else - echo '
Neue Spalte entwicklungsteam_id zu Tabelle bis.tbl_entwicklungsteam hinzugefügt'; + echo '
bis.tbl_entwicklungsteam: Neue Spalte entwicklungsteam_id hinzugefügt'; } //Column entwicklungsteam_id mit Werten befüllen -//if($result = @$db->db_query("SELECT entwicklungsteam_id FROM bis.tbl_entwicklungsteam where entwicklungsteam_id is null")) -if(!@$db->db_query("SELECT entwicklungsteam_id FROM bis.tbl_entwicklungsteam where entwicklungsteam_id is not null LIMIT 1")) +if($result = @$db->db_query("SELECT entwicklungsteam_id FROM bis.tbl_entwicklungsteam where entwicklungsteam_id is not null LIMIT 1")) { - - $qry = 'UPDATE bis.tbl_entwicklungsteam et SET entwicklungsteam_id = - (SELECT rownumber FROM (SELECT ROW_NUMBER() OVER (ORDER BY mitarbeiter_uid, studiengang_kz) - AS rownumber, t.* FROM bis.tbl_entwicklungsteam t ORDER BY mitarbeiter_uid, studiengang_kz) rn - WHERE rn.mitarbeiter_uid = et.mitarbeiter_uid - AND rn.studiengang_kz = et.studiengang_kz); - '; - - if(!$db->db_query($qry)) - echo ' bis.tbl_entwicklungsteam '.$db->db_last_error().'
'; - else - echo '
Spalte bis.tbl_entwicklungsteam_id mit Werten aufgefüllt'; - - -} - -//Create Sequence bis.tbl_entwicklungsteam -if (!@$db->db_query("SELECT * FROM pg_class WHERE relname = 'tbl_entwicklungsteam_entwicklungsteam_id_seq'")) -{ - if ($count = @$db->db_query("SELECT (MAX(entwicklungsteam_id) + 1) AS start FROM bis.tbl_entwicklungsteam")) + if ($db->db_num_rows($result) == 0) { - $qry = 'CREATE SEQUENCE bis.tbl_entwicklungsteam_entwicklungsteam_id_seq START '; - $qry .= $count; + $qry = 'UPDATE bis.tbl_entwicklungsteam et SET entwicklungsteam_id = + (SELECT rownumber FROM (SELECT ROW_NUMBER() OVER (ORDER BY mitarbeiter_uid, studiengang_kz) + AS rownumber, t.* FROM bis.tbl_entwicklungsteam t ORDER BY mitarbeiter_uid, studiengang_kz) rn + WHERE rn.mitarbeiter_uid = et.mitarbeiter_uid + AND rn.studiengang_kz = et.studiengang_kz); + '; + if(!$db->db_query($qry)) - echo ' bis.tbl_entwicklungsteam '.$db->db_last_error().'
'; - else - echo '
Sequence bis.tbl_entwicklungsteam_entwicklungsteam_id_seq mit startwert' . $count . ' erstellt'; + echo ' bis.tbl_entwicklungsteam '.$db->db_last_error().'
'; + else + echo '
bis.tbl_entwicklungsteam: Spalte bis.tbl_entwicklungsteam_id mit Werten aufgefüllt'; } } -//Add Permission to sequence tbl_entwicklungsteam_entwicklungsteam_id_seq -if($result = @$db->db_query("SELECT * FROM information_schema.role_table_grants WHERE table_name='tbl_entwicklungsteam' AND table_schema='bis' AND grantee='web' AND privilege_type='INSERT'")) +//Create Sequence bis.tbl_entwicklungsteam and grant Rights +if ($result = @$db->db_query("SELECT * FROM pg_class WHERE relname = 'tbl_entwicklungsteam_entwicklungsteam_id_seq'")) { - if($db->db_num_rows($result)==0) + if ($db->db_num_rows($result) == 0) { - $qry = " - GRANT SELECT, UPDATE ON bis.tbl_entwicklungsteam_entwicklungsteam_id_seq TO vilesci; - GRANT SELECT, UPDATE ON bis.tbl_entwicklungsteam_entwicklungsteam_id_seq TO web;"; + if ($count = @$db->db_query("SELECT * FROM bis.tbl_entwicklungsteam")) + { + $count = $db->db_num_rows($count) + 1; + $qry = 'CREATE SEQUENCE bis.tbl_entwicklungsteam_entwicklungsteam_id_seq START '; + $qry .= $count; + if(!$db->db_query($qry)) + { + echo ' bis.tbl_entwicklungsteam '.$db->db_last_error().'
'; + } + else + { + echo '
bis.tbl_entwicklungsteam: Sequence bis.tbl_entwicklungsteam_entwicklungsteam_id_seq mit Startwert ' . $count . ' erstellt'; + $qry2 = "GRANT SELECT, UPDATE ON bis.tbl_entwicklungsteam_entwicklungsteam_id_seq TO vilesci; + GRANT SELECT, UPDATE ON bis.tbl_entwicklungsteam_entwicklungsteam_id_seq TO web;"; + if(!$db->db_query($qry2)) + { + echo 'bis.tbl_entwicklungsteam_entwicklungsteam_id_seqBerechtigungen: '.$db->db_last_error().'
'; + } + else + { + echo '
bis.tbl_entwicklungsteam: Rechte auf bis.tbl_entwicklungsteam_entwicklungsteam_id_seq fuer web user und vilesci gesetzt '; + } + } - if(!$db->db_query($qry)) - { - echo 'bis.tbl_entwicklungsteam_entwicklungsteam_id_seqBerechtigungen: '.$db->db_last_error().'
'; - } - else - { - echo '
SELECT und UPDATE Rechte auf bis.tbl_entwicklungsteam_entwicklungsteam_id_seq fuer web user und vilesci gesetzt '; } } } //Bis.tbl_entwicklungsteam auf NOTNULL setzen -if ($result = @$db->db_query("SELECT is_nullable FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'tbl_entwicklungsteam' AND column_name = 'entwicklungsteam_id'")) +if ($result = @$db->db_query("SELECT is_nullable FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'tbl_entwicklungsteam' AND column_name = 'entwicklungsteam_id' and is_nullable = 'NO'")) { - if ($result == 'YES') + if($db->db_num_rows($result)==0) { $qry = 'ALTER TABLE bis.tbl_entwicklungsteam ALTER COLUMN entwicklungsteam_id SET NOT NULL'; if(!$db->db_query($qry)) echo ' bis.tbl_entwicklungsteam '.$db->db_last_error().'
'; else - echo '
Spalte bis.tbl_entwicklungsteam_id auf NOT NULL gesetzt'; + echo '
bis.tbl_entwicklungsteam: Spalte bis.tbl_entwicklungsteam_id auf NOT NULL gesetzt'; } - } //Bis.tbl_entwicklungsteam DEFAULT einstellen if ($result = @$db->db_query("SELECT column_default FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'tbl_entwicklungsteam'AND column_name = 'entwicklungsteam_id' and column_default is null")) { - if ($result == null) + if($db->db_num_rows($result)==1) { $qry = "ALTER TABLE bis.tbl_entwicklungsteam ALTER COLUMN entwicklungsteam_id SET DEFAULT nextval('bis.tbl_entwicklungsteam_entwicklungsteam_id_seq'::regclass);"; if(!$db->db_query($qry)) echo ' bis.tbl_entwicklungsteam '.$db->db_last_error().'
'; else - echo '
Spalte bis.tbl_entwicklungsteam_id: Defaultwert gesetzt'; + echo '
bis.tbl_entwicklungsteam: Defaultwert bei Spalte bis.tbl_entwicklungsteam_id gesetzt'; } - } //DELETE PRIMARY KEY pk_tbl_entwicklungsteam (mitarbeiter_uid, studiengang_kz) entfernen if ($result = @$db->db_query("SELECT conname FROM pg_constraint WHERE conname = 'pk_tbl_entwicklungsteam'")) { - if ($db->db_num_rows($result) == 1) + if($db->db_num_rows($result)==1) { $qry = "ALTER TABLE bis.tbl_entwicklungsteam DROP CONSTRAINT pk_tbl_entwicklungsteam;"; if (!$db->db_query($qry)) echo 'bis.tbl_entwicklungsteam: '.$db->db_last_error().'
'; else - echo '
Spalte bis.tbl_entwicklungsteam: Primary Key pk_tbl_entwicklungsteam entfernt '; + echo '
bis.tbl_entwicklungsteam: Primary Key pk_tbl_entwicklungsteam (mitarbeiter_uid, studiengang_kz) entfernt '; } } @@ -6085,12 +6081,13 @@ if ($result = @$db->db_query("SELECT conname FROM pg_constraint WHERE conname = if (!$db->db_query($qry)) echo 'sbis.tbl_entwicklungsteam: '.$db->db_last_error().'
'; else - echo '
Spalte bis.tbl_entwicklungsteam: Primary Key tbl_entwicklungsteam_pk (entwicklungsteam_id) hinzugefügt'; + echo '
bis.tbl_entwicklungsteam: Primary Key tbl_entwicklungsteam_pk (entwicklungsteam_id) hinzugefügt'; } } + // *** Pruefung und hinzufuegen der neuen Attribute und Tabellen echo '

Pruefe Tabellen und Attribute!

';