From 40a199771b751ebf7378efe32a68584ad7570ee7 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Sun, 11 Mar 2007 00:21:19 +0000 Subject: Bug 373442: Add referential integrity against the profiles table in some more simple places Patch By Max Kanat-Alexander (module owner) a=mkanat --- Bugzilla/Install/DB.pm | 53 ++++---------------------------------------------- 1 file changed, 4 insertions(+), 49 deletions(-) (limited to 'Bugzilla/Install') diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm index 5e6401828..6ddca06bd 100644 --- a/Bugzilla/Install/DB.pm +++ b/Bugzilla/Install/DB.pm @@ -49,39 +49,6 @@ sub indicate_progress { } } -# This is used before adding a foreign key to a column, to make sure -# that the database won't fail adding the key. -sub check_references { - my ($table, $column, $foreign_table, $foreign_column) = @_; - my $dbh = Bugzilla->dbh; - - my $bad_values = $dbh->selectcol_arrayref( - "SELECT DISTINCT $table.$column - FROM $table LEFT JOIN $foreign_table - ON $table.$column = $foreign_table.$foreign_column - WHERE $foreign_table.$foreign_column IS NULL"); - - if (@$bad_values) { - my $values = join(', ', @$bad_values); - print <bz_column_info('components', 'initialqacontact')->{NOTNULL}) { $dbh->bz_alter_column('components', 'initialqacontact', {TYPE => 'INT3'}); - $dbh->do("UPDATE components SET initialqacontact = NULL " . - "WHERE initialqacontact = 0"); } + $dbh->do("UPDATE components SET initialqacontact = NULL " . + "WHERE initialqacontact = 0"); _migrate_email_prefs_to_new_table(); _initialize_dependency_tree_changes_email_pref(); @@ -552,25 +519,13 @@ sub update_table_definitions { $dbh->bz_add_column('milestones', 'id', {TYPE => 'MEDIUMSERIAL', NOTNULL => 1, PRIMARYKEY => 1}); - # Referential Integrity begins here - check_references('profiles_activity', 'userid', 'profiles', 'userid'); - $dbh->bz_alter_column('profiles_activity', 'userid', - {TYPE => 'INT3', NOTNULL => 1, REFERENCES => - {TABLE => 'profiles', COLUMN => 'userid', DELETE => 'CASCADE'}}); - check_references('profiles_activity', 'who', 'profiles', 'userid'); - $dbh->bz_alter_column('profiles_activity', 'who', - {TYPE => 'INT3', NOTNULL => 1, REFERENCES => - {TABLE => 'profiles', COLUMN => 'userid'}}); - check_references('profiles_activity', 'fieldid', 'fielddefs', 'id'); - $dbh->bz_alter_column('profiles_activity', 'fieldid', - {TYPE => 'INT3', NOTNULL => 1, REFERENCES => - {TABLE => 'fielddefs', COLUMN => 'id'}}); - ################################################################ # New --TABLE-- changes should go *** A B O V E *** this point # ################################################################ Bugzilla::Hook::process('install-update_db'); + + $dbh->bz_setup_foreign_keys(); } # Subroutines should be ordered in the order that they are called. -- cgit v1.2.3-24-g4f1b