Bugzilla – Attachment 185856 Details for
Bug 40725
DBRev 23.12.00.053 should be made more resilient
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40725: Add TableExists check to db_revs/231200053.pl
Bug-40725-Add-TableExists-check-to-dbrevs231200053.patch (text/plain), 8.68 KB, created by
Lucas Gass (lukeg)
on 2025-08-28 19:06:09 UTC
(
hide
)
Description:
Bug 40725: Add TableExists check to db_revs/231200053.pl
Filename:
MIME Type:
Creator:
Lucas Gass (lukeg)
Created:
2025-08-28 19:06:09 UTC
Size:
8.68 KB
patch
obsolete
>From a409ac1460944ffa19ff30a5557b69825e28467e Mon Sep 17 00:00:00 2001 >From: Lucas Gass <lucas@bywatersolutions.com> >Date: Thu, 28 Aug 2025 19:05:15 +0000 >Subject: [PATCH] Bug 40725: Add TableExists check to db_revs/231200053.pl > >--- > installer/data/mysql/db_revs/231200053.pl | 121 +++++++++++++++------- > 1 file changed, 83 insertions(+), 38 deletions(-) > >diff --git a/installer/data/mysql/db_revs/231200053.pl b/installer/data/mysql/db_revs/231200053.pl >index 79116c24a6b..1eb8289e16d 100755 >--- a/installer/data/mysql/db_revs/231200053.pl >+++ b/installer/data/mysql/db_revs/231200053.pl >@@ -8,62 +8,107 @@ return { > my ( $dbh, $out ) = @$args{qw(dbh out)}; > > # Drop related tables constraints >- if ( foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) ) { >- $dbh->do( >- q{ALTER TABLE pseudonymized_borrower_attributes DROP FOREIGN KEY anonymized_borrower_attributes_ibfk_2} >- ); >+ if ( TableExists('pseudonymized_borrower_attributes') ) { >+ if ( foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) ) { >+ $dbh->do( >+ q{ALTER TABLE pseudonymized_borrower_attributes DROP FOREIGN KEY anonymized_borrower_attributes_ibfk_2} >+ ); >+ } > } >- if ( foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) ) { >- $dbh->do( >- q{ALTER TABLE borrower_attribute_types_branches DROP FOREIGN KEY borrower_attribute_types_branches_ibfk_1} >- ); >+ >+ if ( TableExists('borrower_attribute_types_branches') ) { >+ if ( foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) ) >+ { >+ $dbh->do( >+ q{ALTER TABLE borrower_attribute_types_branches DROP FOREIGN KEY borrower_attribute_types_branches_ibfk_1} >+ ); >+ } > } >- if ( foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) { >- $dbh->do(q{ALTER TABLE borrower_attributes DROP FOREIGN KEY borrower_attributes_ibfk_2}); >+ >+ if ( TableExists('borrower_attributes') ) { >+ if ( foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) { >+ $dbh->do(q{ALTER TABLE borrower_attributes DROP FOREIGN KEY borrower_attributes_ibfk_2}); >+ } > } > > # Update the column we want >- unless ( foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) >- || foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) >- || foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) >- { >+ my $fkcheck1 = 0; >+ if ( TableExists('pseudonymized_borrower_attributes') ) { >+ $fkcheck1 = >+ foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ); >+ } >+ >+ my $fkcheck2 = 0; >+ if ( TableExists('borrower_attribute_types_branches') ) { >+ $fkcheck2 = >+ foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ); >+ } >+ >+ my $fkcheck3 = 0; >+ if ( TableExists('borrower_attributes') ) { >+ $fkcheck3 = foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ); >+ } >+ >+ unless ( $fkcheck1 || $fkcheck2 || $fkcheck3 ) { > $dbh->do( > q{ALTER TABLE borrower_attribute_types MODIFY COLUMN code VARCHAR(64) NOT NULL COMMENT 'unique key used to identify each custom field'} > ); > } > > # Update the related tables >- unless ( foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) ) { >- $dbh->do( >- q{ALTER TABLE pseudonymized_borrower_attributes MODIFY COLUMN code VARCHAR(64) NOT NULL COMMENT 'foreign key from the borrower_attribute_types table, defines which custom field this value was entered for'} >- ); >+ if ( TableExists('pseudonymized_borrower_attributes') ) { >+ unless ( >+ foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) ) >+ { >+ $dbh->do( >+ q{ALTER TABLE pseudonymized_borrower_attributes MODIFY COLUMN code VARCHAR(64) NOT NULL COMMENT 'foreign key from the borrower_attribute_types table, defines which custom field this value was entered for'} >+ ); >+ } > } >- unless ( foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) ) >- { >- $dbh->do(q{ALTER TABLE borrower_attribute_types_branches MODIFY COLUMN bat_code VARCHAR(64) DEFAULT NULL}); >+ >+ if ( TableExists('borrower_attribute_types_branches') ) { >+ unless ( >+ foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) ) >+ { >+ $dbh->do( >+ q{ALTER TABLE borrower_attribute_types_branches MODIFY COLUMN bat_code VARCHAR(64) DEFAULT NULL}); >+ } > } >- unless ( foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) { >- $dbh->do( >- q{ALTER TABLE borrower_attributes MODIFY COLUMN code VARCHAR(64) NOT NULL COMMENT 'foreign key from the borrower_attribute_types table, defines which custom field this value was entered for'} >- ); >+ >+ if ( TableExists('borrower_attributes') ) { >+ unless ( foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) { >+ $dbh->do( >+ q{ALTER TABLE borrower_attributes MODIFY COLUMN code VARCHAR(64) NOT NULL COMMENT 'foreign key from the borrower_attribute_types table, defines which custom field this value was entered for'} >+ ); >+ } > } > > # Restore related tables constraints >- unless ( foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) ) { >- $dbh->do( >- q{ALTER TABLE pseudonymized_borrower_attributes ADD CONSTRAINT anonymized_borrower_attributes_ibfk_2 FOREIGN KEY (code) REFERENCES borrower_attribute_types(code) ON DELETE CASCADE ON UPDATE CASCADE} >- ); >+ if ( TableExists('pseudonymized_borrower_attributes') ) { >+ unless ( >+ foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) ) >+ { >+ $dbh->do( >+ q{ALTER TABLE pseudonymized_borrower_attributes ADD CONSTRAINT anonymized_borrower_attributes_ibfk_2 FOREIGN KEY (code) REFERENCES borrower_attribute_types(code) ON DELETE CASCADE ON UPDATE CASCADE} >+ ); >+ } > } >- unless ( foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) ) >- { >- $dbh->do( >- q{ALTER TABLE borrower_attribute_types_branches ADD CONSTRAINT borrower_attribute_types_branches_ibfk_1 FOREIGN KEY (bat_code) REFERENCES borrower_attribute_types(code) ON DELETE CASCADE} >- ); >+ if ( TableExists('borrower_attribute_types_branches') ) { >+ unless ( >+ foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) ) >+ { >+ $dbh->do( >+ q{ALTER TABLE borrower_attribute_types_branches ADD CONSTRAINT borrower_attribute_types_branches_ibfk_1 FOREIGN KEY (bat_code) REFERENCES borrower_attribute_types(code) ON DELETE CASCADE} >+ ); >+ } > } >- unless ( foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) { >- $dbh->do( >- q{ALTER TABLE borrower_attributes ADD CONSTRAINT borrower_attributes_ibfk_2 FOREIGN KEY (code) REFERENCES borrower_attribute_types(code) ON DELETE CASCADE ON UPDATE CASCADE} >- ); >+ >+ if ( TableExists('borrower_attributes') ) { >+ unless ( foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) { >+ $dbh->do( >+ q{ALTER TABLE borrower_attributes ADD CONSTRAINT borrower_attributes_ibfk_2 FOREIGN KEY (code) REFERENCES borrower_attribute_types(code) ON DELETE CASCADE ON UPDATE CASCADE} >+ ); >+ } > } > > # HTML customizations >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 40725
:
185856
|
185857