#!/usr/bin/perl -w

BEGIN {
    if (!$ENV{'PERL5LIB'} || !$ENV{'OPALS_CONF'}) {
        exit 1;
    }
}
use Opals::CallNumberUtil qw(
    cn_parseLCC
    cn_getLccGrp
    cn_parseDewey
    cn_getCallNumSortByDewey
    cn_getCallNumSortByLcc
    cn_getDeweyClass
    cn_getShelfList
    get_LCC
);

use Opals::Context;
use File::stat;
use Time::localtime;
use JSON;
use strict;
my $dbh = Opals::Context->dbh();
END {
    if ($dbh) {
        $dbh->disconnect();
    }
}
$| = 1;
updateInvTables();
exit 0;

#############################################################
sub updateInvTables{
    my $sth = $dbh->prepare("SELECT * FROM  opl_inventory LIMIT 1");
      $sth->execute();
    my $field = $sth->{NAME};
    my $existField={};
    foreach my $f (@$field){
        $existField->{$f}=1;
    }
    if(!defined $existField->{'location'}){
        $dbh->do("ALTER table opl_inventory add location varchar(100) DEFAULT '' after callNumberSort");
    }
    if(!defined $existField->{'misplacedBy'}){
        $dbh->do("ALTER table opl_inventory add misplacedBy int(10) DEFAULT '0' after status");
    }

    $sth = $dbh->prepare("SELECT * FROM  opl_inventoryInfo LIMIT 1");
    $sth->execute();
    $field = $sth->{NAME};
    $existField={};
    foreach my $f (@$field){
        $existField->{$f}=1;
    }
    if(!defined $existField->{'location'}){
        $dbh->do("ALTER table opl_inventoryInfo add location varchar(100) DEFAULT '' after callNoE");
    }
}

