UPdating the DBREv for Bug 17216 - Add a new table to store authorized
value categories
This commit is contained in:
parent
493d7c30a1
commit
3fe925ee19
2
Koha.pm
2
Koha.pm
|
|
@ -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 = "16.06.00.032";
|
||||
$VERSION = "16.06.00.033";
|
||||
|
||||
sub version {
|
||||
return $VERSION;
|
||||
|
|
|
|||
|
|
@ -1,49 +0,0 @@
|
|||
CREATE TABLE authorised_value_categories (
|
||||
category_name VARCHAR(32) NOT NULL,
|
||||
primary key (category_name)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;
|
||||
|
||||
-- Add authorised value categories
|
||||
INSERT INTO authorised_value_categories (category_name )
|
||||
SELECT DISTINCT category FROM authorised_values;
|
||||
|
||||
-- Add special categories
|
||||
INSERT IGNORE INTO authorised_value_categories( category_name )
|
||||
VALUES
|
||||
('Asort1'),
|
||||
('Asort2'),
|
||||
('Bsort1'),
|
||||
('Bsort2'),
|
||||
('SUGGEST'),
|
||||
('DAMAGED'),
|
||||
('LOST'),
|
||||
('REPORT_GROUP'),
|
||||
('REPORT_SUBGROUP'),
|
||||
('DEPARTMENT'),
|
||||
('TERM'),
|
||||
('SUGGEST_STATUS'),
|
||||
('ITEMTYPECAT');
|
||||
|
||||
-- Add very special categories
|
||||
INSERT IGNORE INTO authorised_value_categories( category_name )
|
||||
VALUES
|
||||
('branches'),
|
||||
('itemtypes'),
|
||||
('cn_source');
|
||||
|
||||
INSERT IGNORE INTO authorised_value_categories( category_name )
|
||||
VALUES
|
||||
('WITHDRAWN'),
|
||||
('RESTRICTED'),
|
||||
('NOT_LOAN'),
|
||||
('CCODE'),
|
||||
('LOC'),
|
||||
('STACK');
|
||||
|
||||
-- Update the FK
|
||||
ALTER TABLE items_search_fields
|
||||
DROP FOREIGN KEY items_search_fields_authorised_values_category;
|
||||
ALTER TABLE items_search_fields
|
||||
ADD CONSTRAINT `items_search_fields_authorised_values_category` FOREIGN KEY (`authorised_values_category`) REFERENCES `authorised_value_categories` (`category_name`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
ALTER TABLE authorised_values
|
||||
ADD CONSTRAINT `authorised_values_authorised_values_category` FOREIGN KEY (`category`) REFERENCES `authorised_value_categories` (`category_name`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
INSERT IGNORE INTO authorised_value_categories( category_name ) SELECT DISTINCT(authorised_value) FROM marc_subfield_structure;
|
||||
|
||||
UPDATE marc_subfield_structure SET authorised_value = NULL WHERE authorised_value = ';';
|
||||
|
||||
ALTER TABLE marc_subfield_structure
|
||||
MODIFY COLUMN authorised_value VARCHAR(32) DEFAULT NULL,
|
||||
ADD CONSTRAINT marc_subfield_structure_ibfk_1 FOREIGN KEY (authorised_value) REFERENCES authorised_value_categories (category_name) ON UPDATE CASCADE ON DELETE SET NULL;
|
||||
|
|
@ -13094,6 +13094,94 @@ if ( CheckVersion($DBversion) ) {
|
|||
}
|
||||
|
||||
|
||||
$DBversion = "16.06.00.033";
|
||||
if ( CheckVersion($DBversion) ) {
|
||||
$dbh->do(q{
|
||||
CREATE TABLE authorised_value_categories (
|
||||
category_name VARCHAR(32) NOT NULL,
|
||||
primary key (category_name)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
});
|
||||
## Add authorised value categories
|
||||
$dbh->do(q{
|
||||
INSERT INTO authorised_value_categories (category_name )
|
||||
SELECT DISTINCT category FROM authorised_values;
|
||||
});
|
||||
|
||||
## Add special categories
|
||||
$dbh->do(q{
|
||||
INSERT IGNORE INTO authorised_value_categories( category_name )
|
||||
VALUES
|
||||
('Asort1'),
|
||||
('Asort2'),
|
||||
('Bsort1'),
|
||||
('Bsort2'),
|
||||
('SUGGEST'),
|
||||
('DAMAGED'),
|
||||
('LOST'),
|
||||
('REPORT_GROUP'),
|
||||
('REPORT_SUBGROUP'),
|
||||
('DEPARTMENT'),
|
||||
('TERM'),
|
||||
('SUGGEST_STATUS'),
|
||||
('ITEMTYPECAT');
|
||||
});
|
||||
|
||||
## Add very special categories
|
||||
$dbh->do(q{
|
||||
INSERT IGNORE INTO authorised_value_categories( category_name )
|
||||
VALUES
|
||||
('branches'),
|
||||
('itemtypes'),
|
||||
('cn_source');
|
||||
});
|
||||
|
||||
$dbh->do(q{
|
||||
INSERT IGNORE INTO authorised_value_categories( category_name )
|
||||
VALUES
|
||||
('WITHDRAWN'),
|
||||
('RESTRICTED'),
|
||||
('NOT_LOAN'),
|
||||
('CCODE'),
|
||||
('LOC'),
|
||||
('STACK');
|
||||
});
|
||||
|
||||
## Update the FK
|
||||
$dbh->do(q{
|
||||
ALTER TABLE items_search_fields
|
||||
DROP FOREIGN KEY items_search_fields_authorised_values_category;
|
||||
});
|
||||
|
||||
$dbh->do(q{
|
||||
ALTER TABLE items_search_fields
|
||||
ADD CONSTRAINT `items_search_fields_authorised_values_category` FOREIGN KEY (`authorised_values_category`) REFERENCES `authorised_value_categories` (`category_name`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
});
|
||||
|
||||
$dbh->do(q{
|
||||
ALTER TABLE authorised_values
|
||||
ADD CONSTRAINT `authorised_values_authorised_values_category` FOREIGN KEY (`category`) REFERENCES `authorised_value_categories` (`category_name`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
});
|
||||
|
||||
$dbh->do(q{
|
||||
INSERT IGNORE INTO authorised_value_categories( category_name ) SELECT DISTINCT(authorised_value) FROM marc_subfield_structure;
|
||||
});
|
||||
|
||||
$dbh->do(q{
|
||||
UPDATE marc_subfield_structure SET authorised_value = NULL WHERE authorised_value = ';';
|
||||
});
|
||||
|
||||
$dbh->do(q{
|
||||
ALTER TABLE marc_subfield_structure
|
||||
MODIFY COLUMN authorised_value VARCHAR(32) DEFAULT NULL,
|
||||
ADD CONSTRAINT marc_subfield_structure_ibfk_1 FOREIGN KEY (authorised_value) REFERENCES authorised_value_categories (category_name) ON UPDATE CASCADE ON DELETE SET NULL;
|
||||
});
|
||||
|
||||
print "Upgrade to $DBversion done (Bug 17216 - Add a new table to store authorized value categories)\n";
|
||||
SetVersion($DBversion);
|
||||
}
|
||||
|
||||
|
||||
# DEVELOPER PROCESS, search for anything to execute in the db_update directory
|
||||
# SEE bug 13068
|
||||
# if there is anything in the atomicupdate, read and execute it.
|
||||
|
|
|
|||
Loading…
Reference in New Issue