Bug 16170: Update DB rev (3.22.06.003)

Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
This commit is contained in:
Kyle M Hall 2016-05-03 15:04:20 +00:00 committed by Julian Maurice
parent a839f0f77d
commit 4ebc3a2bca
3 changed files with 22 additions and 30 deletions

View File

@ -29,7 +29,7 @@ use vars qw{ $VERSION };
# - #4 : the developer version. The 4th number is the database subversion.
# used by developers when the database changes. updatedatabase take care of the changes itself
# and is automatically called by Auth.pm when needed.
$VERSION = "3.22.06.002";
$VERSION = "3.22.06.003";
sub version {
return $VERSION;

View File

@ -1,29 +0,0 @@
#!/usr/bin/perl
use C4::Context;
my $dbh = C4::Context->dbh;
my $DBversion = "XXX";
# RM: Copy/paste from here, and uncomment
#if ( CheckVersion($DBversion) ) {
# this should normally not be needed, but just in case
my ( $cnt ) = $dbh->selectrow_array( q|
SELECT COUNT(*) FROM items it
LEFT JOIN biblio bi ON bi.biblionumber=it.biblionumber
LEFT JOIN biblioitems bii USING (biblioitemnumber)
WHERE bi.biblionumber IS NULL
|);
if( $cnt ) {
print "WARNING: You have corrupted data in your items table!! The table contains $cnt references to biblio records that do not exist.\nPlease correct your data IMMEDIATELY after this upgrade and manually add the foreign key constraint for biblionumber in the items table.\n";
} else {
# now add FK
$dbh->do( q|
ALTER TABLE items
ADD FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
|);
print "Upgrade to $DBversion done (Bug 1xxxx - Add FK for biblionumber in items)\n";
}
#SetVersion($DBversion);
#}

View File

@ -11583,6 +11583,27 @@ if ( CheckVersion($DBversion) ) {
SetVersion($DBversion);
}
$DBversion = "3.22.06.003";
if ( CheckVersion($DBversion) ) {
my ( $cnt ) = $dbh->selectrow_array( q|
SELECT COUNT(*) FROM items it
LEFT JOIN biblio bi ON bi.biblionumber=it.biblionumber
LEFT JOIN biblioitems bii USING (biblioitemnumber)
WHERE bi.biblionumber IS NULL
|);
if( $cnt ) {
print "WARNING: You have corrupted data in your items table!! The table contains $cnt references to biblio records that do not exist.\nPlease correct your data IMMEDIATELY after this upgrade and manually add the foreign key constraint for biblionumber in the items table.\n";
} else {
# now add FK
$dbh->do( q|
ALTER TABLE items
ADD FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
|);
print "Upgrade to $DBversion done (Bug 16170 - Add FK for biblionumber in items)\n";
}
SetVersion($DBversion);
}
# DEVELOPER PROCESS, search for anything to execute in the db_update directory
# SEE bug 13068