Bug 24161: DB changes

Sponsored-by: Cork Institute of Technology
Signed-off-by: Angela O'Connor Desmond <angela.oconnordesmond@staff.ittralee.ie>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Jonathan Druart 2019-12-16 17:20:31 +01:00 committed by Martin Renvoize
parent 0963451d65
commit 878ab699fc
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F
2 changed files with 48 additions and 2 deletions

View file

@ -0,0 +1,36 @@
$DBversion = 'XXX'; # will be replaced by the RM
if( CheckVersion( $DBversion ) ) {
unless ( TableExists( 'aqorders_claims' ) ) {
$dbh->do(q|
CREATE TABLE aqorders_claims (
id int(11) AUTO_INCREMENT,
ordernumber INT(11) NOT NULL,
claimed_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
CONSTRAINT aqorders_claims_ibfk_1 FOREIGN KEY (ordernumber) REFERENCES aqorders (ordernumber) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci
|);
my $orders = $dbh->selectall_arrayref(q|
SELECT ordernumber, claims_count, claimed_date
FROM aqorders
WHERE claims_count > 0
|, { Slice => {} });
my $insert_claim_sth = $dbh->prepare(q|
INSERT INTO aqorders_claims (ordernumber, claimed_on)
VALUES (?,?)
|);
for my $order ( @$orders ) {
for my $claim (1..$order->{claims_count}) {
$insert_claim_sth->execute($order->{ordernumber}, $order->{claimed_on});
}
}
$dbh->do(q|ALTER TABLE aqorders DROP COLUMN claims_count, DROP COLUMN claimed_date|);
}
# Always end with this (adjust the bug info)
SetVersion( $DBversion );
print "Upgrade to $DBversion done (Bug 24161 - Add new join table aqorders_claims to keep track of claims)\n";
}

View file

@ -3204,8 +3204,6 @@ CREATE TABLE `aqorders` ( -- information related to the basket line items
`sort1_authcat` varchar(10) default NULL,
`sort2_authcat` varchar(10) default NULL,
`uncertainprice` tinyint(1), -- was this price uncertain (1 for yes, 0 for no)
`claims_count` int(11) default 0, -- count of claim letters generated
`claimed_date` date default NULL, -- last date a claim was generated
`subscriptionid` int(11) default NULL, -- links this order line to a subscription (subscription.subscriptionid)
parent_ordernumber int(11) default NULL, -- ordernumber of parent order line, or same as ordernumber if no parent
`orderstatus` varchar(16) default 'new', -- the current status for this line item. Can be 'new', 'ordered', 'partial', 'complete' or 'cancelled'
@ -3270,6 +3268,18 @@ CREATE TABLE aqorders_transfers (
CONSTRAINT aqorders_transfers_ordernumber_to FOREIGN KEY (ordernumber_to) REFERENCES aqorders (ordernumber) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table aqorders_claims
--
DROP TABLE IF EXISTS aqorders_claims;
CREATE TABLE aqorders_claims (
id int(11) AUTO_INCREMENT,
ordernumber INT(11) NOT NULL,
claimed_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
CONSTRAINT aqorders_claims_ibfk_1 FOREIGN KEY (ordernumber) REFERENCES aqorders (ordernumber) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
--
-- Table structure for table `transport_cost`