1 -- PostgreSQL kohastructure script
2 -- Initial port 2007/10/22 fbcit
3 -- This is very 'alpha' at this point since much of the source will have to be mod'd to do data manipulations before it can be fully tested.
4 -- Many tables lack a primary key and probably need one as that is generally a good db practice.
5 -- **This script requires plpgsql be loaded into the pg koha db PRIOR to executing.**
6 -- This could be done in this script. However, the user must have superuser priviledge. I'm not sure how the koha installer handles this.
11 -- Function to generate populate timestamp fields on update
14 CREATE FUNCTION time_stamp() RETURNS trigger AS $time_stamp$
16 -- Update timestamp field on row insert or update
17 NEW.timestamp := current_timestamp;
20 $time_stamp$ LANGUAGE plpgsql;
22 COMMENT ON FUNCTION time_stamp() IS $$ This function updates the timestamp field on an insert or update. It equates to mysql 'on update CURRENT_TIMESTAMP'. $$;
25 -- Table structure for table accountlines
28 --DROP TABLE accountlines; --Left the DROP TABLE statements here if needed for some reason...
30 CREATE TABLE accountlines (
31 borrowernumber int NOT NULL default 0,
32 accountno int NOT NULL default 0,
33 itemnumber int default NULL,
34 date date default NULL,
35 amount decimal(28,6) default NULL,
38 accounttype varchar(5) default NULL,
39 amountoutstanding decimal(28,6) default NULL,
40 "timestamp" timestamp NOT NULL default (now()),
41 notify_id int NOT NULL default 0,
42 notify_level int NOT NULL default 0
44 CREATE INDEX accountlines_itemnumber_idx ON accountlines (itemnumber); -- Indecies replace msyql 'enums' datatype. Pg 8.3 will have 'enums' so this may be changed back later...
45 CREATE INDEX accountlines_acctsborr_idx ON accountlines (borrowernumber);
46 CREATE INDEX accountlines_time_idx ON accountlines (timestamp);
49 -- Create timestamp trigger
52 CREATE TRIGGER time_stamp BEFORE INSERT OR UPDATE ON accountlines
53 FOR EACH ROW EXECUTE PROCEDURE time_stamp();
56 -- Table structure for table accountoffsets
59 --DROP TABLE accountoffsets;
61 CREATE TABLE accountoffsets (
62 borrowernumber int NOT NULL default 0,
63 accountno int NOT NULL default 0,
64 offsetaccount int NOT NULL default 0,
65 offsetamount decimal(28,6) default NULL,
66 "timestamp" timestamp NOT NULL default (now())
71 -- Create timestamp trigger
74 CREATE TRIGGER time_stamp BEFORE INSERT OR UPDATE ON accountoffsets
75 FOR EACH ROW EXECUTE PROCEDURE time_stamp();
78 -- Table structure for table action_logs
81 --DROP TABLE action_logs;
83 CREATE TABLE action_logs (
84 "timestamp" timestamp NOT NULL default (now()),
85 "user" int NOT NULL default 0,
88 "object" int default NULL,
90 PRIMARY KEY (timestamp,"user")
94 -- Create timestamp trigger
97 CREATE TRIGGER time_stamp BEFORE INSERT OR UPDATE ON action_logs
98 FOR EACH ROW EXECUTE PROCEDURE time_stamp();
101 -- Table structure for table alert
108 borrowernumber int NOT NULL default 0,
109 "type" varchar(10) NOT NULL default '',
110 externalid varchar(20) NOT NULL default '',
111 PRIMARY KEY (alertid)
113 CREATE INDEX alert_borrowernumber_idx ON alert (borrowernumber);
114 CREATE INDEX alert_type_idx ON alert (type,externalid);
117 -- Table structure for table aqbasket
120 --DROP TABLE aqbasket;
122 CREATE TABLE aqbasket (
124 creationdate date default NULL,
125 closedate date default NULL,
126 booksellerid int NOT NULL default '1',
127 authorisedby varchar(10) default NULL,
128 booksellerinvoicenumber text,
129 PRIMARY KEY (basketno)
131 CREATE INDEX aqbasket_booksellerid_idx ON aqbasket (booksellerid);
134 -- Table structure for table aqbookfund
137 --DROP TABLE aqbookfund;
139 CREATE TABLE aqbookfund (
140 bookfundid varchar(10) UNIQUE NOT NULL default '',
142 bookfundgroup varchar(5) default NULL,
143 branchcode varchar(10) NOT NULL default '',
144 PRIMARY KEY (bookfundid,branchcode)
148 -- Table structure for table aqbooksellers
151 --DROP TABLE aqbooksellers;
153 CREATE TABLE aqbooksellers (
160 phone varchar(30) default NULL,
163 currency varchar(3) NOT NULL default '',
164 deliverydays int default NULL,
165 followupdays int default NULL,
166 followupscancel int default NULL,
170 bookselleremail text,
172 contact varchar(100) default NULL,
174 url varchar(255) default NULL,
175 contpos varchar(100) default NULL,
176 contphone varchar(100) default NULL,
177 contfax varchar(100) default NULL,
178 contaltphone varchar(100) default NULL,
179 contemail varchar(100) default NULL,
181 active int default NULL,
182 listprice varchar(10) default NULL,
183 invoiceprice varchar(10) default NULL,
184 gstreg int default NULL,
185 listincgst int default NULL,
186 invoiceincgst int default NULL,
187 discount numeric(6,4) default NULL,
188 fax varchar(50) default NULL,
189 nocalc int default NULL,
190 invoicedisc numeric(6,4) default NULL,
193 CREATE INDEX aqbooksellers_invoiceprice_idx ON aqbooksellers (invoiceprice);
194 CREATE INDEX aqbooksellers_listprice_idx ON aqbooksellers (listprice);
197 -- Table structure for table aqbudget
200 --DROP TABLE aqbudget;
202 CREATE TABLE aqbudget (
203 bookfundid varchar(10) NOT NULL default '',
204 startdate date default NULL,
205 enddate date default NULL,
206 budgetamount decimal(13,2) default NULL,
207 aqbudgetid BIGSERIAL,
208 branchcode varchar(10) default NULL,
209 PRIMARY KEY (aqbudgetid)
213 -- Table structure for table aqorderbreakdown
216 --DROP TABLE aqorderbreakdown;
218 CREATE TABLE aqorderbreakdown (
219 ordernumber int default NULL,
220 "linenumber" int default NULL,
221 branchcode varchar(10) default NULL,
222 bookfundid varchar(10) NOT NULL default '',
223 allocation int default NULL
225 CREATE INDEX aqorderbreakdown_bookfundid_idx ON aqorderbreakdown (bookfundid);
226 CREATE INDEX aqorderbreakdown_ordernumber_idx ON aqorderbreakdown (ordernumber);
229 -- Table structure for table aqorderdelivery
232 --DROP TABLE aqorderdelivery;
234 CREATE TABLE aqorderdelivery (
235 ordernumber date default NULL,
236 deliverynumber int NOT NULL default 0,
237 deliverydate varchar(18) default NULL,
238 qtydelivered int default NULL,
239 deliverycomments text
243 -- Table structure for table aqorders
246 --DROP TABLE aqorders;
248 CREATE TABLE aqorders (
249 ordernumber BIGSERIAL,
250 biblionumber int default NULL,
252 entrydate date default NULL,
253 quantity int default NULL,
254 currency varchar(3) default NULL,
255 listprice decimal(28,6) default NULL,
256 totalamount decimal(28,6) default NULL,
257 datereceived date default NULL,
258 booksellerinvoicenumber text,
259 freight decimal(28,6) default NULL,
260 unitprice decimal(28,6) default NULL,
261 quantityreceived int default NULL,
262 cancelledby varchar(10) default NULL,
263 datecancellationprinted date default NULL,
265 supplierreference text,
266 purchaseordernumber text,
267 subscription int default NULL,
268 serialid varchar(30) default NULL,
269 basketno int default NULL,
270 biblioitemnumber int default NULL,
271 "timestamp" timestamp NOT NULL default (now()),
272 rrp decimal(13,2) default NULL,
273 ecost decimal(13,2) default NULL,
274 gst decimal(13,2) default NULL,
275 budgetdate date default NULL,
276 sort1 varchar(80) default NULL,
277 sort2 varchar(80) default NULL,
278 PRIMARY KEY (ordernumber)
280 CREATE INDEX aqorders_biblionumber_idx ON aqorders (biblionumber);
281 CREATE INDEX aqorders_basketno_idx ON aqorders (basketno);
284 -- Table structure for table auth_header
287 --DROP TABLE auth_header;
289 CREATE TABLE auth_header (
290 authid BIGSERIAL NOT NULL,
291 authtypecode varchar(10) NOT NULL default '',
292 datecreated date default NULL,
293 datemodified date default NULL,
294 origincode varchar(20) default NULL,
297 linkid int default NULL,
298 marcxml text NOT NULL,
301 CREATE INDEX auth_header_origincode_idx ON auth_header (origincode);
304 -- Table structure for table auth_subfield_structure
307 --DROP TABLE auth_subfield_structure;
309 CREATE TABLE auth_subfield_structure (
310 authtypecode varchar(10) NOT NULL default '',
311 tagfield varchar(3) NOT NULL default '',
312 tagsubfield varchar(1) NOT NULL default '',
313 liblibrarian varchar(255) NOT NULL default '',
314 libopac varchar(255) NOT NULL default '',
315 "repeatable" int NOT NULL default 0,
316 mandatory int NOT NULL default 0,
317 tab int default NULL,
318 authorised_value varchar(10) default NULL,
319 value_builder varchar(80) default NULL,
320 seealso varchar(255) default NULL,
321 isurl int default NULL,
322 hidden int NOT NULL default 0,
323 linkid int NOT NULL default 0,
324 kohafield varchar(45) NULL default '',
325 frameworkcode varchar(8) NOT NULL default '',
326 PRIMARY KEY (authtypecode,tagfield,tagsubfield)
328 CREATE INDEX auth_subfield_structure_tab_idx ON auth_subfield_structure (authtypecode,tab);
331 -- Table structure for table auth_tag_structure
334 --DROP TABLE auth_tag_structure;
336 CREATE TABLE auth_tag_structure (
337 authtypecode varchar(10) NOT NULL default '',
338 tagfield varchar(3) NOT NULL default '',
339 liblibrarian varchar(255) NOT NULL default '',
340 libopac varchar(255) NOT NULL default '',
341 "repeatable" int NOT NULL default 0,
342 mandatory int NOT NULL default 0,
343 authorised_value varchar(10) default NULL,
344 PRIMARY KEY (authtypecode,tagfield)
348 -- Table structure for table auth_types
351 --DROP TABLE auth_types;
353 CREATE TABLE auth_types (
354 authtypecode varchar(10) NOT NULL default '',
355 authtypetext varchar(255) NOT NULL default '',
356 auth_tag_to_report varchar(3) NOT NULL default '',
357 summary text NOT NULL,
358 PRIMARY KEY (authtypecode)
362 -- Table structure for table authorised_values
365 --DROP TABLE authorised_values;
367 CREATE TABLE authorised_values (
369 category varchar(10) NOT NULL default '',
370 authorised_value varchar(80) NOT NULL default '',
371 lib varchar(80) default NULL,
374 CREATE INDEX authorised_values_name_idx ON authorised_values (category);
377 -- Table structure for table biblio
382 CREATE TABLE biblio (
383 biblionumber int NOT NULL default 0,
384 frameworkcode varchar(4) NOT NULL default '',
389 serial int default NULL,
391 copyrightdate int default NULL,
392 "timestamp" timestamp NOT NULL default (now()),
393 datecreated DATE NOT NULL,
395 PRIMARY KEY (biblionumber)
397 CREATE INDEX biblio_blbnoidx_idx ON biblio (biblionumber);
400 -- Table structure for table biblio_framework
403 --DROP TABLE biblio_framework;
405 CREATE TABLE biblio_framework (
406 frameworkcode varchar(4) NOT NULL default '',
407 frameworktext varchar(255) NOT NULL default '',
408 PRIMARY KEY (frameworkcode)
412 -- Table structure for table biblioitems
415 --DROP TABLE biblioitems;
417 CREATE TABLE biblioitems (
418 biblioitemnumber int NOT NULL default 0,
419 biblionumber int NOT NULL default 0,
422 classification varchar(25) default NULL,
423 itemtype varchar(10) default NULL,
424 isbn varchar(14) default NULL,
425 issn varchar(9) default NULL,
426 dewey varchar(30) default '',
427 subclass varchar(3) default NULL,
428 publicationyear text,
429 publishercode varchar(255) default NULL,
430 volumedate date default NULL,
432 collectiontitle text default NULL,
433 collectionissn text default NULL,
434 collectionvolume text default NULL,
435 editionstatement text default NULL,
436 editionresponsibility text default NULL,
437 "timestamp" timestamp NOT NULL default (now()),
438 illus varchar(255) default NULL,
439 pages varchar(255) default NULL,
441 size varchar(255) default NULL,
442 place varchar(255) default NULL,
443 lccn varchar(25) default NULL,
445 url varchar(255) default NULL,
446 lcsort varchar(25) default NULL,
447 ccode varchar(4) default NULL,
448 marcxml text NOT NULL,
449 PRIMARY KEY (biblioitemnumber)
451 CREATE INDEX biblioitems_publishercode_idx ON biblioitems (publishercode);
452 CREATE INDEX biblioitems_biblioitemnumber_idx ON biblioitems (biblioitemnumber);
453 CREATE INDEX biblioitems_biblionumber_idx ON biblioitems (biblionumber);
454 CREATE INDEX biblioitems_isbn_idx ON biblioitems (isbn);
457 -- Table structure for table borrowers
460 --DROP TABLE borrowers;
462 CREATE TABLE borrowers (
463 borrowernumber BIGSERIAL UNIQUE,
464 cardnumber varchar(16) UNIQUE default NULL,
465 surname text NOT NULL,
470 streetnumber varchar(10) default NULL,
471 streettype varchar(50) default NULL,
472 address text NOT NULL,
475 zipcode varchar(25) default NULL,
479 mobile varchar(50) default NULL,
483 B_streetnumber varchar(10) default NULL,
484 B_streettype varchar(50) default NULL,
485 B_address varchar(100) default NULL,
486 B_address2 text default NULL,
488 B_zipcode varchar(25) default NULL,
492 dateofbirth date default NULL,
493 branchcode varchar(10) NOT NULL default '',
494 categorycode varchar(10) NOT NULL default '',
495 dateenrolled date default NULL,
496 dateexpiry date default NULL,
497 gonenoaddress int default NULL,
498 lost int default NULL,
499 debarred int default NULL,
501 contactfirstname text,
503 guarantorid int default NULL,
505 relationship varchar(100) default NULL,
506 ethnicity varchar(50) default NULL,
507 ethnotes varchar(255) default NULL,
508 sex varchar(1) default NULL,
509 "password" varchar(30) default NULL,
510 flags int default NULL,
511 userid varchar(30) default NULL,
513 contactnote varchar(255) default NULL,
514 sort1 varchar(80) default NULL,
515 sort2 varchar(80) default NULL,
516 altcontactfirstname varchar(255) default NULL,
517 altcontactsurname varchar(255) default NULL,
518 altcontactaddress1 varchar(255) default NULL,
519 altcontactaddress2 varchar(255) default NULL,
520 altcontactaddress3 varchar(255) default NULL,
521 altcontactzipcode varchar(50) default NULL,
522 altcontactcountry text default NULL,
523 altcontactphone varchar(50) default NULL,
524 smsalertnumber varchar(50) default NULL
526 CREATE INDEX borrowers_branchcode_idx ON borrowers (branchcode);
527 CREATE INDEX borrowers_borrowernumber_idx ON borrowers (borrowernumber);
528 CREATE INDEX borrowers_categorycode_idx ON borrowers (categorycode);
531 -- Table structure for table branchcategories
534 --DROP TABLE branchcategories;
536 CREATE TABLE branchcategories (
537 categorycode varchar(4) NOT NULL default '',
539 codedescription text,
540 PRIMARY KEY (categorycode)
544 -- Table structure for table branches
547 --DROP TABLE branches;
549 CREATE TABLE branches (
550 branchcode varchar(10) UNIQUE NOT NULL default '',
551 branchname text NOT NULL,
555 branchzip varchar(25) default NULL,
556 branchcity mediumtext,
561 branchurl mediumtext,
562 issuing int default NULL,
563 branchip varchar(15) default NULL,
564 branchprinter varchar(100) default NULL,
565 branchnotes mediumtext
569 -- Table structure for table branchrelations
572 --DROP TABLE branchrelations;
574 CREATE TABLE branchrelations (
575 branchcode varchar(10) NOT NULL default '',
576 categorycode varchar(4) NOT NULL default '',
577 PRIMARY KEY (branchcode,categorycode)
579 CREATE INDEX branchrelations_categorycode_idx ON branchrelations (categorycode);
580 CREATE INDEX branchrelations_branchcode_idx ON branchrelations (branchcode);
583 -- Table structure for table branchtransfers
586 --DROP TABLE branchtransfers;
588 CREATE TABLE branchtransfers (
589 itemnumber int NOT NULL default 0,
590 datesent timestamp default NULL,
591 frombranch varchar(10) NOT NULL default '',
592 datearrived timestamp default NULL,
593 tobranch varchar(10) NOT NULL default '',
596 CREATE INDEX branchtransfers_frombranch_idx ON branchtransfers (frombranch);
597 CREATE INDEX branchtransfers_tobranch_idx ON branchtransfers (tobranch);
598 CREATE INDEX branchtransfers_itemnumber_idx ON branchtransfers (itemnumber);
601 -- Table structure for table browser
603 --DROP TABLE browser;
605 CREATE TABLE browser (
607 classification varchar(20) NOT NULL,
608 description varchar(255) NOT NULL,
614 -- Table structure for table categories
617 --DROP TABLE categories;
619 CREATE TABLE categories (
620 categorycode varchar(10) UNIQUE NOT NULL default '',
622 enrolmentperiod int default NULL,
623 upperagelimit int default NULL,
624 dateofbirthrequired int default NULL,
625 finetype varchar(30) default NULL,
626 bulk int default NULL,
627 enrolmentfee decimal(28,6) default NULL,
628 overduenoticerequired int default NULL,
629 issuelimit int default NULL,
630 reservefee decimal(28,6) default NULL,
631 category_type varchar(1) NOT NULL default 'A',
632 PRIMARY KEY (categorycode)
636 -- Table structure for table cities
641 CREATE TABLE cities (
643 city_name varchar(100) NOT NULL default '',
644 city_zipcode varchar(20) default NULL,
649 -- Table structure for table class_sort_rules
652 CREATE TABLE class_sort_rules (
653 class_sort_rule varchar(10) UNIQUE NOT NULL default '',
655 sort_routine varchar(30) NOT NULL default '',
656 PRIMARY KEY (class_sort_rule)
658 CREATE INDEX class_sort_rule_idx ON class_sort_rules (class_sort_rule);
661 -- Table structure for table class_sources
664 CREATE TABLE class_sources (
665 cn_source varchar(10) NOT NULL default '',
667 used int NOT NULL default 0,
668 class_sort_rule varchar(10) NOT NULL default '',
669 PRIMARY KEY (cn_source)
670 -- This seems redundant -fbcit
671 -- UNIQUE KEY cn_source_idx (cn_source),
673 CREATE INDEX used_idx ON class_sources (used);
676 -- Table structure for table currency
679 --DROP TABLE currency;
681 CREATE TABLE currency (
682 currency varchar(10) NOT NULL default '',
683 rate numeric(7,5) default NULL,
684 PRIMARY KEY (currency)
688 -- Table structure for table deletedbiblio
691 --DROP TABLE deletedbiblio;
693 CREATE TABLE deletedbiblio (
694 biblionumber int NOT NULL default 0,
695 frameworkcode varchar(4) NOT NULL,
700 serial int default NULL,
702 copyrightdate int default NULL,
703 "timestamp" timestamp NOT NULL default (now()),
706 PRIMARY KEY (biblionumber)
708 CREATE INDEX deletedbiblio_blbnoidx_idx ON deletedbiblio (biblionumber);
711 -- Table structure for table deletedbiblioitems
714 --DROP TABLE deletedbiblioitems;
716 CREATE TABLE deletedbiblioitems (
717 biblioitemnumber int NOT NULL default 0,
718 biblionumber int NOT NULL default 0,
721 classification varchar(25) default NULL,
722 itemtype varchar(10) default NULL,
723 isbn varchar(14) default NULL,
724 issn varchar(9) default NULL,
725 dewey numeric(8,6) default NULL,
726 subclass varchar(3) default NULL,
727 publicationyear int default NULL,
728 publishercode varchar(255) default NULL,
729 volumedate date default NULL,
730 volumeddesc varchar(255) default NULL,
731 "timestamp" timestamp NOT NULL default (now()),
732 illus varchar(255) default NULL,
733 pages varchar(255) default NULL,
735 size varchar(255) default NULL,
736 lccn varchar(25) default NULL,
738 url varchar(255) default NULL,
739 place varchar(255) default NULL,
740 lcsort varchar(25) default NULL,
741 ccode varchar(4) default NULL,
742 marcxml text NOT NULL,
743 collectiontitle text,
745 collectionvolume text,
746 editionstatement text,
747 editionresponsibility text,
748 PRIMARY KEY (biblioitemnumber)
750 CREATE INDEX deletedbiblioitems_biblioitemnumber_idx ON deletedbiblioitems (biblioitemnumber);
751 CREATE INDEX deletedbiblioitems_biblionumber_idx ON deletedbiblioitems (biblionumber);
754 -- Table structure for table deletedborrowers
757 --DROP TABLE deletedborrowers;
759 CREATE TABLE deletedborrowers (
760 borrowernumber int NOT NULL default 0,
761 cardnumber varchar(9) NOT NULL default '',
762 surname text NOT NULL,
767 streetnumber varchar(10) default NULL,
768 streettype varchar(50) default NULL,
769 address text NOT NULL,
772 zipcode varchar(25) default NULL,
775 mobile varchar(50) default NULL,
779 B_streetnumber varchar(10) default NULL,
780 B_streettype varchar(50) default NULL,
781 B_address varchar(100) default NULL,
782 B_address2 text default NULL,
784 B_zipcode varchar(25) default NULL,
787 dateofbirth date default NULL,
788 branchcode varchar(10) NOT NULL default '',
789 categorycode varchar(2) default NULL,
790 dateenrolled date default NULL,
791 dateexpiry date default NULL,
792 gonenoaddress int default NULL,
793 lost int default NULL,
794 debarred int default NULL,
796 contactfirstname text,
798 guarantorid int default NULL,
800 relationship varchar(100) default NULL,
801 ethnicity varchar(50) default NULL,
802 ethnotes varchar(255) default NULL,
803 sex varchar(1) default NULL,
804 "password" varchar(30) default NULL,
805 flags int default NULL,
806 userid varchar(30) default NULL,
808 contactnote varchar(255) default NULL,
809 sort1 varchar(80) default NULL,
810 sort2 varchar(80) default NULL,
811 altcontactfirstname varchar(255) default NULL,
812 altcontactsurname varchar(255) default NULL,
813 altcontactaddress1 varchar(255) default NULL,
814 altcontactaddress2 varchar(255) default NULL,
815 altcontactaddress3 varchar(255) default NULL,
816 altcontactzipcode varchar(50) default NULL,
817 altcontactcountry text default NULL,
818 altcontactphone varchar(50) default NULL,
819 smsalertnumber varchar(50) default NULL
821 CREATE INDEX deletedborrowers_borrowernumber_idx ON deletedborrowers (borrowernumber);
822 CREATE INDEX deletedborrowers_cardnumber_idx ON deletedborrowers (cardnumber);
825 -- Table structure for table deleteditems
828 --DROP TABLE deleteditems;
830 CREATE TABLE deleteditems (
831 itemnumber int NOT NULL default 0,
832 biblionumber int NOT NULL default 0,
833 biblioitemnumber int NOT NULL default 0,
834 barcode varchar(9) UNIQUE NOT NULL default '',
835 dateaccessioned date default NULL,
836 booksellerid varchar(10) default NULL,
837 homebranch varchar(4) default NULL,
838 price decimal(28,6) default NULL,
839 replacementprice decimal(28,6) default NULL,
840 replacementpricedate date default NULL,
841 datelastborrowed date default NULL,
842 datelastseen date default NULL,
843 stack int default NULL,
844 notforloan int default NULL,
845 damaged int default NULL,
846 itemlost int default NULL,
847 withdrawn int default NULL,
848 bulk varchar(30) default NULL,
849 issues int default NULL,
850 renewals int default NULL,
851 reserves int default NULL,
852 restricted int default NULL,
854 holdingbranch varchar(4) default NULL,
855 interim int default NULL,
856 "timestamp" timestamp NOT NULL default (now()),
859 "location" varchar(80) default NULL,
860 itemcallnumber varchar(30) default NULL,
861 onloan date default NULL,
862 cutterextra varchar(45) default NULL,
863 itype varchar(10) default NULL,
864 PRIMARY KEY (itemnumber)
866 CREATE INDEX deleteditems_barcode_idx ON deleteditems (barcode);
867 CREATE INDEX deleteditems_biblioitemnumber_idx ON deleteditems (biblioitemnumber);
868 CREATE INDEX deleteditems_itembibnoidx_idx ON deleteditems (biblionumber);
871 -- Table structure for table ethnicity
874 --DROP TABLE ethnicity;
876 CREATE TABLE ethnicity (
877 code varchar(10) NOT NULL default '',
878 name varchar(255) default NULL,
883 -- Table structure for table issues
888 CREATE TABLE issues (
889 borrowernumber int default NULL,
890 itemnumber int default NULL,
891 date_due date default NULL,
892 branchcode varchar(10) default NULL,
893 issuingbranch varchar(18) default NULL,
894 returndate date default NULL,
895 lastreneweddate date default NULL,
896 return varchar(4) default NULL,
897 renewals int default NULL,
898 "timestamp" timestamp NOT NULL default (now()),
899 issuedate date default NULL
901 CREATE INDEX issues_borrowernumber_idx ON issues (borrowernumber);
902 CREATE INDEX issues_itemnumber_idx ON issues (itemnumber);
903 CREATE INDEX issues_bordate_idx ON issues (borrowernumber,timestamp);
906 -- Table structure for table issuingrules
909 --DROP TABLE issuingrules;
911 CREATE TABLE issuingrules (
912 categorycode varchar(10) NOT NULL default '',
913 itemtype varchar(10) NOT NULL default '',
914 restrictedtype int default NULL,
915 rentaldiscount decimal(28,6) default NULL,
916 reservecharge decimal(28,6) default NULL,
917 fine decimal(28,6) default NULL,
918 firstremind int default NULL,
919 chargeperiod int default NULL,
920 accountsent int default NULL,
921 chargename varchar(100) default NULL,
922 maxissueqty int default NULL,
923 issuelength int default NULL,
924 branchcode varchar(10) NOT NULL default '',
925 PRIMARY KEY (branchcode,categorycode,itemtype)
927 CREATE INDEX issuingrules_categorycode_idx ON issuingrules (categorycode);
928 CREATE INDEX issuingrules_itemtype_idx ON issuingrules (itemtype);
931 -- Table structure for table items
937 itemnumber int NOT NULL default 0,
938 biblionumber int NOT NULL default 0,
939 biblioitemnumber int NOT NULL default 0,
940 barcode varchar(20) default NULL,
941 dateaccessioned date default NULL,
942 booksellerid varchar(10) default NULL,
943 homebranch varchar(4) default NULL,
944 price decimal(8,2) default NULL,
945 replacementprice decimal(8,2) default NULL,
946 replacementpricedate date default NULL,
947 datelastborrowed date default NULL,
948 datelastseen date default NULL,
949 stack int default NULL,
950 notforloan int default NULL,
951 damaged int default NULL,
952 itemlost int default NULL,
953 withdrawn int default NULL,
954 itemcallnumber varchar(30) default NULL,
955 issues int default NULL,
956 renewals int default NULL,
957 reserves int default NULL,
958 restricted int default NULL,
960 holdingbranch varchar(10) default NULL,
962 "timestamp" timestamp NOT NULL default (now()),
963 "location" varchar(80) default NULL,
964 onloan date default NULL,
965 cutterextra varchar(45) default NULL,
966 itype varchar(10) default NULL,
967 PRIMARY KEY (itemnumber)
969 CREATE INDEX items_barcode_idx ON items (barcode);
970 CREATE INDEX items_biblioitemnumber_idx ON items (biblioitemnumber);
971 CREATE INDEX items_biblionumber_idx ON items (biblionumber);
972 CREATE INDEX items_homebranch_idx ON items (homebranch);
973 CREATE INDEX items_holdingbranch_idx ON items (holdingbranch);
976 -- Table structure for table itemtypes
979 --DROP TABLE itemtypes;
981 CREATE TABLE itemtypes (
982 itemtype varchar(10) UNIQUE NOT NULL default '',
984 renewalsallowed int default NULL,
985 rentalcharge numeric(16,4) default NULL,
986 notforloan int default NULL,
987 imageurl varchar(200) default NULL,
989 PRIMARY KEY (itemtype)
993 -- Table structure for table labels
998 CREATE TABLE labels (
999 labelid BIGSERIAL UNIQUE NOT NULL,
1000 batch_id varchar(10) NOT NULL default '1',
1001 itemnumber varchar(100) NOT NULL default '',
1002 "timestamp" timestamp NOT NULL default (now()),
1003 PRIMARY KEY (labelid)
1007 -- Table structure for table labels_conf
1010 --DROP TABLE labels_conf;
1012 CREATE TABLE labels_conf (
1013 id BIGSERIAL UNIQUE NOT NULL,
1014 barcodetype varchar(100) default '',
1015 title int default '0',
1016 itemtype int default '0',
1017 barcode int default '0',
1018 dewey int default '0',
1019 "class" int default '0',
1020 subclass int default '0',
1021 itemcallnumber int default '0',
1022 author int default '0',
1023 issn int default '0',
1024 isbn int default '0',
1025 startlabel int NOT NULL default '1',
1026 printingtype varchar(32) default 'BAR',
1027 layoutname varchar(20) NOT NULL default 'TEST',
1028 guidebox int default '0',
1029 active int default '1',
1030 fonttype varchar(10) default NULL,
1031 subtitle int default NULL,
1036 -- Table structure for table labels_templates
1039 --DROP TABLE labels_templates;
1041 CREATE TABLE labels_templates (
1042 tmpl_id BIGSERIAL UNIQUE NOT NULL,
1043 tmpl_code varchar(100) default '',
1044 tmpl_desc varchar(100) default '',
1045 page_width float default '0',
1046 page_height float default '0',
1047 label_width float default '0',
1048 label_height float default '0',
1049 topmargin float default '0',
1050 leftmargin float default '0',
1051 cols int default '0',
1052 "rows" int default '0',
1053 colgap float default '0',
1054 rowgap float default '0',
1055 active int default NULL,
1056 units varchar(20) default 'PX',
1057 fontsize int NOT NULL default '3',
1058 PRIMARY KEY (tmpl_id)
1062 -- Table structure for table letter
1065 --DROP TABLE letter;
1067 CREATE TABLE letter (
1068 module varchar(20) NOT NULL default '',
1069 code varchar(20) NOT NULL default '',
1070 name varchar(100) NOT NULL default '',
1071 title varchar(200) NOT NULL default '',
1073 PRIMARY KEY (module,code)
1077 -- Table structure for table marc_breeding
1080 --DROP TABLE marc_breeding;
1082 CREATE TABLE marc_breeding (
1084 file varchar(80) NOT NULL default '',
1085 isbn varchar(10) NOT NULL default '',
1086 title varchar(128) default NULL,
1087 author varchar(80) default NULL,
1089 "encoding" varchar(40) NOT NULL default '',
1090 z3950random varchar(40) default NULL,
1093 CREATE INDEX marc_breeding_title_idx ON marc_breeding (title);
1094 CREATE INDEX marc_breeding_isbn_idx ON marc_breeding (isbn);
1097 -- Table structure for table marc_subfield_structure
1100 --DROP TABLE marc_subfield_structure;
1102 CREATE TABLE marc_subfield_structure (
1103 tagfield varchar(3) NOT NULL default '',
1104 tagsubfield varchar(1) NOT NULL default '',
1105 liblibrarian varchar(255) NOT NULL default '',
1106 libopac varchar(255) NOT NULL default '',
1107 "repeatable" int NOT NULL default 0,
1108 mandatory int NOT NULL default 0,
1109 kohafield varchar(40) default NULL,
1110 tab int default NULL,
1111 authorised_value varchar(20) default NULL,
1112 authtypecode varchar(20) default NULL,
1113 value_builder varchar(80) default NULL,
1114 isurl int default NULL,
1115 hidden int default NULL,
1116 frameworkcode varchar(4) NOT NULL default '',
1117 seealso varchar(1100) default NULL,
1118 link varchar(80) default NULL,
1119 defaultvalue text default NULL,
1120 PRIMARY KEY (frameworkcode,tagfield,tagsubfield)
1122 CREATE INDEX marc_subfield_structure_kohafield_2_idx ON marc_subfield_structure (kohafield);
1123 CREATE INDEX marc_subfield_structure_tab_idx ON marc_subfield_structure (frameworkcode,tab);
1124 CREATE INDEX marc_subfield_structure_kohafield_idx ON marc_subfield_structure (frameworkcode,kohafield);
1127 -- Table structure for table marc_tag_structure
1130 --DROP TABLE marc_tag_structure;
1132 CREATE TABLE marc_tag_structure (
1133 tagfield varchar(3) NOT NULL default '',
1134 liblibrarian varchar(255) NOT NULL default '',
1135 libopac varchar(255) NOT NULL default '',
1136 "repeatable" int NOT NULL default 0,
1137 mandatory int NOT NULL default 0,
1138 authorised_value varchar(10) default NULL,
1139 frameworkcode varchar(4) NOT NULL default '',
1140 PRIMARY KEY (frameworkcode,tagfield)
1144 -- Table structure for table notifys
1147 --DROP TABLE notifys;
1149 CREATE TABLE notifys (
1150 notify_id int NOT NULL default 0,
1151 borrowernumber int NOT NULL default 0,
1152 itemnumber int NOT NULL default 0,
1153 notify_date date default NULL,
1154 notify_send_date date default NULL,
1155 notify_level int NOT NULL default 0,
1156 method varchar(20) NOT NULL default ''
1160 -- Table structure for table nozebra
1162 CREATE TABLE nozebra (
1163 server varchar(20) NOT NULL,
1164 indexname varchar(40) NOT NULL,
1165 value varchar(250) NOT NULL,
1166 biblionumbers text NOT NULL
1168 CREATE INDEX nozebra_indexname_idx ON nozebra (server,indexname);
1169 CREATE INDEX nozebra_value_idx ON nozebra (server,value);
1172 -- Table structure for table opac_news
1175 --DROP TABLE opac_news;
1177 CREATE TABLE opac_news (
1178 idnew SERIAL NOT NULL,
1179 title varchar(250) NOT NULL default '',
1180 "new" text NOT NULL,
1181 lang varchar(4) NOT NULL default '',
1182 "timestamp" timestamp NOT NULL default CURRENT_TIMESTAMP,
1183 expirationdate date default NULL,
1184 number int default NULL,
1189 -- Table structure for table overduerules
1192 --DROP TABLE overduerules;
1194 CREATE TABLE overduerules (
1195 branchcode varchar(10) NOT NULL default '',
1196 categorycode varchar(2) NOT NULL default '',
1197 delay1 int default 0,
1198 letter1 varchar(20) default NULL,
1199 debarred1 varchar(1) default 0,
1200 delay2 int default 0,
1201 debarred2 varchar(1) default 0,
1202 letter2 varchar(20) default NULL,
1203 delay3 int default 0,
1204 letter3 varchar(20) default NULL,
1205 debarred3 int default 0,
1206 PRIMARY KEY (branchcode,categorycode)
1210 -- Table structure for table printers
1213 --DROP TABLE printers;
1215 CREATE TABLE printers (
1216 printername varchar(40) NOT NULL default '',
1217 printqueue varchar(20) default NULL,
1218 printtype varchar(20) default NULL,
1219 PRIMARY KEY (printername)
1223 -- Table structure for table repeatable_holidays
1226 --DROP TABLE repeatable_holidays;
1228 CREATE TABLE repeatable_holidays (
1230 branchcode varchar(10) NOT NULL default '',
1231 weekday int default NULL,
1232 "day" int default NULL,
1233 "month" int default NULL,
1234 title varchar(50) NOT NULL default '',
1235 description text NOT NULL,
1240 -- Table structure for table reserveCONSTRAINTs
1243 --DROP TABLE reserveCONSTRAINTs;
1245 CREATE TABLE reserveCONSTRAINTs (
1246 borrowernumber int NOT NULL default 0,
1247 reservedate date default NULL,
1248 biblionumber int NOT NULL default 0,
1249 biblioitemnumber int default NULL,
1250 "timestamp" timestamp NOT NULL default (now())
1254 -- Table structure for table reserves
1257 --DROP TABLE reserves;
1259 CREATE TABLE reserves (
1260 borrowernumber int NOT NULL default 0,
1261 reservedate date default NULL,
1262 biblionumber int NOT NULL default 0,
1263 CONSTRAINTtype varchar(1) default NULL,
1264 branchcode varchar(10) default NULL,
1265 notificationdate date default NULL,
1266 reminderdate date default NULL,
1267 cancellationdate date default NULL,
1269 priority int default NULL,
1270 found varchar(1) default NULL,
1271 "timestamp" timestamp NOT NULL default (now()),
1272 itemnumber int default NULL,
1273 waitingdate date default NULL
1275 CREATE INDEX reserves_borrowernumber_idx ON reserves (borrowernumber);
1276 CREATE INDEX reserves_biblionumber__idx ON reserves (biblionumber);
1277 CREATE INDEX reserves_itemnumber__idx ON reserves (itemnumber);
1278 CREATE INDEX reserves_branchcode_idx ON reserves (branchcode);
1281 -- Table structure for table reviews
1284 --DROP TABLE reviews;
1286 CREATE TABLE reviews (
1288 borrowernumber int default NULL,
1289 biblionumber int default NULL,
1291 approved int default NULL,
1292 datereviewed timestamp default NULL,
1293 PRIMARY KEY (reviewid)
1297 -- Table structure for table roadtype
1300 --DROP TABLE roadtype;
1302 CREATE TABLE roadtype (
1303 roadtypeid BIGSERIAL,
1304 road_type varchar(100) NOT NULL default '',
1305 PRIMARY KEY (roadtypeid)
1309 -- Table structure for table serial
1312 --DROP TABLE serial;
1314 CREATE TABLE serial (
1316 biblionumber varchar(100) NOT NULL default '',
1317 subscriptionid varchar(100) NOT NULL default '',
1318 serialseq varchar(100) NOT NULL default '',
1319 status int NOT NULL default 0,
1320 planneddate date default NULL,
1322 publisheddate date default NULL,
1324 claimdate date default NULL,
1326 PRIMARY KEY (serialid)
1330 -- Table structure for table sessions
1333 --DROP TABLE sessions;
1335 CREATE TABLE sessions (
1336 id varchar(32) UNIQUE NOT NULL,
1337 a_session text NOT NULL
1341 -- Table structure for table special_holidays
1344 --DROP TABLE special_holidays;
1346 CREATE TABLE special_holidays (
1348 branchcode varchar(10) NOT NULL default '',
1349 "day" int NOT NULL default 0,
1350 "month" int NOT NULL default 0,
1351 "year" int NOT NULL default 0,
1352 isexception int NOT NULL default '1',
1353 title varchar(50) NOT NULL default '',
1354 description text NOT NULL,
1359 -- Table structure for table statistics
1362 --DROP TABLE statistics;
1364 CREATE TABLE statistics (
1365 datetime timestamp default NULL,
1366 "timestamp" timestamp default NULL,
1367 branch varchar(10) default NULL,
1368 proccode varchar(4) default NULL,
1369 value numeric(16,4) default NULL,
1370 "type" varchar(16) default NULL,
1372 usercode varchar(10) default NULL,
1373 itemnumber int default NULL,
1374 itemtype varchar(10) default NULL,
1375 borrowernumber int default NULL,
1376 associatedborrower int default NULL
1378 CREATE INDEX statistics_timeidx_idx ON statistics (datetime);
1381 -- Table structure for table stopwords
1384 --DROP TABLE stopwords;
1386 CREATE TABLE stopwords (
1387 word varchar(255) default NULL
1391 -- Table structure for table subscription
1394 --DROP TABLE subscription;
1396 CREATE TABLE subscription (
1397 biblionumber int NOT NULL default 0,
1398 subscriptionid BIGSERIAL,
1399 librarian varchar(100) default '',
1400 startdate date default NULL,
1401 aqbooksellerid int default 0,
1403 aqbudgetid int default 0,
1404 weeklength int default 0,
1405 monthlength int default 0,
1406 numberlength int default 0,
1407 periodicity int default 0,
1408 dow varchar(100) default '',
1409 numberingmethod varchar(100) default '',
1411 status varchar(100) NOT NULL default '',
1413 every1 int default 0,
1414 whenmorethan1 int default 0,
1415 setto1 int default NULL,
1416 lastvalue1 int default NULL,
1418 every2 int default 0,
1419 whenmorethan2 int default 0,
1420 setto2 int default NULL,
1421 lastvalue2 int default NULL,
1423 every3 int default 0,
1424 innerloop1 int default 0,
1425 innerloop2 int default 0,
1426 innerloop3 int default 0,
1427 whenmorethan3 int default 0,
1428 setto3 int default NULL,
1429 lastvalue3 int default NULL,
1430 issuesatonce int NOT NULL default '1',
1431 firstacquidate date default NULL,
1432 manualhistory int NOT NULL default 0,
1434 letter varchar(20) default NULL,
1435 numberpattern int default 0,
1439 branchcode varchar(10) NOT NULL default '',
1440 hemisphere int default 0,
1441 PRIMARY KEY (subscriptionid)
1445 -- Table structure for table subscriptionhistory
1448 --DROP TABLE subscriptionhistory;
1450 CREATE TABLE subscriptionhistory (
1451 biblionumber int NOT NULL default 0,
1452 subscriptionid int NOT NULL default 0,
1453 histstartdate date default NULL,
1454 enddate date default NULL,
1455 missinglist text NOT NULL,
1456 recievedlist text NOT NULL,
1457 opacnote varchar(150) NOT NULL default '',
1458 librariannote varchar(150) NOT NULL default '',
1459 PRIMARY KEY (subscriptionid)
1461 CREATE INDEX subscriptionhistory_biblionumber_idx ON subscriptionhistory (biblionumber);
1464 -- Table structure for table subscriptionroutinglist
1467 --DROP TABLE subscriptionroutinglist;
1469 CREATE TABLE subscriptionroutinglist (
1470 routingid BIGSERIAL,
1471 borrowernumber int default NULL,
1472 ranking int default NULL,
1473 subscriptionid int default NULL,
1474 PRIMARY KEY (routingid)
1478 -- Table structure for table suggestions
1481 --DROP TABLE suggestions;
1483 CREATE TABLE suggestions (
1484 suggestionid BIGSERIAL,
1485 suggestedby int NOT NULL default 0,
1486 managedby int default NULL,
1487 STATUS varchar(10) NOT NULL default '',
1489 author varchar(80) default NULL,
1490 title varchar(80) default NULL,
1491 copyrightdate int default NULL,
1492 publishercode varchar(255) default NULL,
1493 date timestamp NOT NULL default (now()),
1494 volumedesc varchar(255) default NULL,
1495 publicationyear int default 0,
1496 place varchar(255) default NULL,
1497 isbn varchar(10) default NULL,
1498 mailoverseeing int default 0,
1499 biblionumber int default NULL,
1501 PRIMARY KEY (suggestionid)
1503 CREATE INDEX suggestions_suggestedby_idx ON suggestions (suggestedby);
1504 CREATE INDEX suggestions_managedby_idx ON suggestions (managedby);
1507 -- Table structure for table systempreferences
1510 --DROP TABLE systempreferences;
1512 CREATE TABLE systempreferences (
1513 variable varchar(50) NOT NULL default '',
1517 type varchar(20) default NULL,
1518 PRIMARY KEY (variable)
1522 -- Table structure for table tags
1528 entry varchar(255) NOT NULL default '',
1529 weight int NOT NULL default 0,
1534 -- Table structure for table userflags
1537 --DROP TABLE userflags;
1539 CREATE TABLE userflags (
1540 "bit" int NOT NULL default 0,
1541 flag varchar(30) default NULL,
1542 flagdesc varchar(255) default NULL,
1543 defaulton int default NULL,
1548 -- Table structure for table virtualshelves
1551 --DROP TABLE virtualshelves;
1553 CREATE TABLE virtualshelves (
1554 shelfnumber BIGSERIAL,
1555 shelfname varchar(255) default NULL,
1556 "owner" varchar(80) default NULL,
1557 category varchar(1) default NULL,
1558 PRIMARY KEY (shelfnumber)
1562 -- Table structure for table virtualshelfcontents
1565 --DROP TABLE virtualshelfcontents;
1567 CREATE TABLE virtualshelfcontents (
1568 shelfnumber int NOT NULL default 0,
1569 biblionumber int NOT NULL default 0,
1570 flags int default NULL,
1571 dateadded timestamp NULL default NULL
1573 CREATE INDEX virtualshelfcontents_shelfnumber_idx ON virtualshelfcontents (shelfnumber);
1574 CREATE INDEX virtualshelfcontents_biblionumber_idx ON virtualshelfcontents (biblionumber);
1577 -- Table structure for table z3950servers
1580 --DROP TABLE z3950servers;
1582 CREATE TABLE z3950servers (
1583 host varchar(255) default NULL,
1584 port int default NULL,
1585 db varchar(255) default NULL,
1586 userid varchar(255) default NULL,
1587 "password" varchar(255) default NULL,
1590 checked int default NULL,
1591 rank int default NULL,
1592 syntax varchar(80) default NULL,
1594 "position" varchar(10) NOT NULL default 'primary',
1595 "type" varchar(10) NOT NULL default 'zed',
1596 description text NOT NULL,
1597 CHECK ( position IN ('primary', 'secondary', '' )),
1598 CHECK ( type IN ('zed', 'opensearch', '' )),
1603 -- Table structure for table zebraqueue
1606 --DROP TABLE zebraqueue;
1608 CREATE TABLE zebraqueue (
1610 biblio_auth_number int NOT NULL default 0,
1611 operation varchar(20) NOT NULL default '',
1612 server varchar(20) NOT NULL default '',
1617 -- Add FK's last... (just because...)
1620 ALTER TABLE accountlines ADD CONSTRAINT accountlines_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) MATCH SIMPLE ON DELETE CASCADE ON UPDATE CASCADE;
1621 ALTER TABLE accountlines ADD CONSTRAINT accountlines_ibfk_2 FOREIGN KEY (itemnumber) REFERENCES items (itemnumber) ON DELETE SET NULL ON UPDATE SET NULL;
1623 -- Added this FK based on the FK in other tables referencing borrowers.borrowernumber -fbcit
1625 ALTER TABLE accountoffsets ADD CONSTRAINT accountoffsets_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE;
1629 ALTER TABLE aqbasket ADD CONSTRAINT aqbasket_ibfk_1 FOREIGN KEY (booksellerid) REFERENCES aqbooksellers (id) ON UPDATE CASCADE;
1630 ALTER TABLE aqbooksellers ADD CONSTRAINT aqbooksellers_ibfk_1 FOREIGN KEY (listprice) REFERENCES currency (currency) ON DELETE CASCADE ON UPDATE CASCADE;
1631 ALTER TABLE aqbooksellers ADD CONSTRAINT aqbooksellers_ibfk_2 FOREIGN KEY (invoiceprice) REFERENCES currency (currency) ON DELETE CASCADE ON UPDATE CASCADE;
1632 ALTER TABLE aqorderbreakdown ADD CONSTRAINT aqorderbreakdown_ibfk_1 FOREIGN KEY (ordernumber) REFERENCES aqorders (ordernumber) ON DELETE CASCADE ON UPDATE CASCADE;
1633 ALTER TABLE aqorderbreakdown ADD CONSTRAINT aqorderbreakdown_ibfk_2 FOREIGN KEY (bookfundid) REFERENCES aqbookfund (bookfundid) ON DELETE CASCADE ON UPDATE CASCADE;
1634 ALTER TABLE aqorders ADD CONSTRAINT aqorders_ibfk_1 FOREIGN KEY (basketno) REFERENCES aqbasket (basketno) ON DELETE CASCADE ON UPDATE CASCADE;
1635 ALTER TABLE aqorders ADD CONSTRAINT aqorders_ibfk_2 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE SET NULL ON UPDATE SET NULL;
1636 ALTER TABLE auth_tag_structure ADD CONSTRAINT auth_tag_structure_ibfk_1 FOREIGN KEY (authtypecode) REFERENCES auth_types (authtypecode) ON DELETE CASCADE ON UPDATE CASCADE;
1637 ALTER TABLE biblioitems ADD CONSTRAINT biblioitems_ibfk_1 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE;
1638 ALTER TABLE borrowers ADD CONSTRAINT borrowers_ibfk_1 FOREIGN KEY (categorycode) REFERENCES categories (categorycode);
1639 ALTER TABLE borrowers ADD CONSTRAINT borrowers_ibfk_2 FOREIGN KEY (branchcode) REFERENCES branches (branchcode);
1640 ALTER TABLE branchrelations ADD CONSTRAINT branchrelations_ibfk_1 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE;
1641 ALTER TABLE branchrelations ADD CONSTRAINT branchrelations_ibfk_2 FOREIGN KEY (categorycode) REFERENCES branchcategories (categorycode) ON DELETE CASCADE ON UPDATE CASCADE;
1642 ALTER TABLE branchtransfers ADD CONSTRAINT branchtransfers_ibfk_1 FOREIGN KEY (frombranch) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE;
1643 ALTER TABLE branchtransfers ADD CONSTRAINT branchtransfers_ibfk_2 FOREIGN KEY (tobranch) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE;
1644 ALTER TABLE branchtransfers ADD CONSTRAINT branchtransfers_ibfk_3 FOREIGN KEY (itemnumber) REFERENCES items (itemnumber) ON DELETE CASCADE ON UPDATE CASCADE;
1645 ALTER TABLE class_sources ADD CONSTRAINT class_sources_ibfk_1 FOREIGN KEY (class_sort_rule) REFERENCES class_sort_rules (class_sort_rule);
1646 ALTER TABLE issues ADD CONSTRAINT issues_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) MATCH SIMPLE ON DELETE SET NULL ON UPDATE SET NULL;
1647 ALTER TABLE issues ADD CONSTRAINT issues_ibfk_2 FOREIGN KEY (itemnumber) REFERENCES items (itemnumber) ON DELETE SET NULL ON UPDATE SET NULL;
1648 ALTER TABLE items ADD CONSTRAINT items_ibfk_1 FOREIGN KEY (biblioitemnumber) REFERENCES biblioitems (biblioitemnumber) ON DELETE CASCADE ON UPDATE CASCADE;
1649 ALTER TABLE items ADD CONSTRAINT items_ibfk_2 FOREIGN KEY (homebranch) REFERENCES branches (branchcode) ON UPDATE CASCADE;
1650 ALTER TABLE items ADD CONSTRAINT items_ibfk_3 FOREIGN KEY (holdingbranch) REFERENCES branches (branchcode) ON UPDATE CASCADE;
1651 ALTER TABLE reserves ADD CONSTRAINT reserves_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) MATCH SIMPLE ON DELETE CASCADE ON UPDATE CASCADE;
1652 ALTER TABLE reserves ADD CONSTRAINT reserves_ibfk_2 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE;
1653 ALTER TABLE reserves ADD CONSTRAINT reserves_ibfk_3 FOREIGN KEY (itemnumber) REFERENCES items (itemnumber) ON DELETE CASCADE ON UPDATE CASCADE;
1654 ALTER TABLE reserves ADD CONSTRAINT reserves_ibfk_4 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE;
1655 ALTER TABLE virtualshelfcontents ADD CONSTRAINT virtualshelfcontents_ibfk_1 FOREIGN KEY (shelfnumber) REFERENCES virtualshelves (shelfnumber) ON DELETE CASCADE ON UPDATE CASCADE;
1656 ALTER TABLE virtualshelfcontents ADD CONSTRAINT virtualshelfcontents_ibfk_2 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE;
1660 -- Table for branch_transfer_limits
1662 CREATE SEQUENCE branch_transfer_limits_limitId_seq START 1;
1664 CREATE TABLE branch_transfer_limits (
1665 limitId int PRIMARY KEY DEFAULT nextval('branch_transfer_limits_limitId_seq'),
1666 toBranch varchar(4) NOT NULL,
1667 fromBranch varchar(4) NOT NULL,
1668 itemtype varchar(4) NOT NULL,
1669 PRIMARY KEY (limitId)