[open-ils-commits] r14921 - in trunk/Open-ILS: examples src/sql/Pg src/sql/Pg/upgrade (scottmk)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Nov 16 12:59:13 EST 2009
Author: scottmk
Date: 2009-11-16 12:59:10 -0500 (Mon, 16 Nov 2009)
New Revision: 14921
Added:
trunk/Open-ILS/src/sql/Pg/095.schema.booking.sql
trunk/Open-ILS/src/sql/Pg/upgrade/0086.schema.booking-tables.sql
Modified:
trunk/Open-ILS/examples/fm_IDL.xml
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
Log:
Create booking schema and the tables therein.
A Open-ILS/src/sql/Pg/095.schema.booking.sql
M Open-ILS/src/sql/Pg/002.schema.config.sql
A Open-ILS/src/sql/Pg/upgrade/0086.schema.booking-tables.sql
M Open-ILS/examples/fm_IDL.xml
Modified: trunk/Open-ILS/examples/fm_IDL.xml
===================================================================
--- trunk/Open-ILS/examples/fm_IDL.xml 2009-11-16 14:46:19 UTC (rev 14920)
+++ trunk/Open-ILS/examples/fm_IDL.xml 2009-11-16 17:59:10 UTC (rev 14921)
@@ -1707,6 +1707,7 @@
<field reporter:label="Checkins" name="checkins" oils_persist:virtual="true" reporter:datatype="link"/>
<field reporter:label="Circulations Performed as Staff" name="performed_circulations" oils_persist:virtual="true" reporter:datatype="link"/>
<field reporter:label="Fund Allocation Percentages" name="fund_alloc_pcts" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Reservations" name="reservations" oils_persist:virtual="true" reporter:datatype="link"/>
</fields>
<links>
<link field="demographic" reltype="might_have" key="id" map="" class="rud"/>
@@ -1737,6 +1738,7 @@
<link field="cards" reltype="has_many" key="usr" map="" class="ac"/>
<link reporter:label="Circulations Performed as Staff" field="performed_circulations" reltype="has_many" key="circ_staff" map="" class="circ"/>
<link field="fund_alloc_pcts" reltype="has_many" key="allocator" map="" class="acqfap"/>
+ <link field="reservations" reltype="has_many" key="capture_staff" map="" class="bresv"/>
</links>
</class>
@@ -2330,6 +2332,177 @@
<link field="renewals" reltype="has_many" key="parent_circ" map="" class="circ"/>
</links>
</class>
+
+ <class id="brt" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="booking::resource_type" oils_persist:tablename="booking.resource_type" reporter:label="Resource Type">
+ <fields oils_persist:primary="id" oils_persist:sequence="booking.booking.resource_type_id_seq">
+ <field reporter:label="Resource Type ID" name="id" reporter:datatype="id"/>
+ <field reporter:label="Resource Type Name" name="name" reporter:datatype="text"/>
+ <field reporter:label="Fine Interval" name="fine_interval" reporter:datatype="interval"/>
+ <field reporter:label="Fine Amount" name="fine_amount" reporter:datatype="money"/>
+ <field reporter:label="Owning Library" name="owner" reporter:datatype="org_unit"/>
+ <field reporter:label="Catalog Item" name="catalog_item" reporter:datatype="bool"/>
+ <field reporter:label="Transferable" name="transferable" reporter:datatype="bool"/>
+ <field reporter:label="Resources" name="resources" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Resource Attributes" name="resource_attrs" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Target Resource Types" name="tgt_rsrc_types" oils_persist:virtual="true" reporter:datatype="link"/>
+ </fields>
+ <links>
+ <link field="owner" reltype="has_a" key="id" map="" class="aou"/>
+ <link field="resources" reltype="has_many" key="type" map="" class="brsrc"/>
+ <link field="resource_attrs" reltype="has_many" key="type" map="" class="bra"/>
+ <link field="tgt_rsrc_types" reltype="has_many" key="type" map="" class="bresv"/>
+ </links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ </permacrud>
+ </class>
+
+ <class id="brsrc" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="booking::resource" oils_persist:tablename="booking.resource" reporter:label="Resource">
+ <fields oils_persist:primary="id" oils_persist:sequence="schema.booking.resource_id_seq">
+ <field reporter:label="Resource ID" name="id" reporter:datatype="id"/>
+ <field reporter:label="Owning Library" name="owner" reporter:datatype="org_unit"/>
+ <field reporter:label="Resource Type" name="type" reporter:datatype="link"/>
+ <field reporter:label="Overbook" name="overbook" reporter:datatype="bool"/>
+ <field reporter:label="Barcode" name="barcode" reporter:datatype="text"/>
+ <field reporter:label="Is Deposit Required" name="deposit" reporter:datatype="bool"/>
+ <field reporter:label="Deposit Amount" name="deposit_amount" reporter:datatype="money"/>
+ <field reporter:label="User Fee" name="user_fee" reporter:datatype="money"/>
+ <field reporter:label="Resource Attribute Maps" name="attr_maps" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Reservation Target Resources" name="tgt_rsrcs" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Reservation Current Resources" name="curr_rsrcs" oils_persist:virtual="true" reporter:datatype="link"/>
+ </fields>
+ <links>
+ <link field="owner" reltype="has_a" key="id" map="" class="aou"/>
+ <link field="type" reltype="has_a" key="id" map="" class="brt"/>
+ <link field="attr_maps" reltype="has_many" key="resource" map="" class="bram"/>
+ <link field="tgt_rsrcs" reltype="has_many" key="targeted_resource" map="" class="bresv"/>
+ <link field="curr_rsrcs" reltype="has_many" key="current_resource" map="" class="bresv"/>
+ </links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ </permacrud>
+ </class>
+
+ <class id="bra" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="booking::resource_attr" oils_persist:tablename="booking.resource_attr" reporter:label="Resource Attribute">
+ <fields oils_persist:primary="id" oils_persist:sequence="schema.booking.resource_attr_id_seq">
+ <field reporter:label="Resource Attribute ID" name="id" reporter:datatype="id"/>
+ <field reporter:label="Owning Library" name="owner" reporter:datatype="org_unit"/>
+ <field reporter:label="Resource Attribute Name" name="name" reporter:datatype="text"/>
+ <field reporter:label="Resource Type" name="resource_type" reporter:datatype="link"/>
+ <field reporter:label="Is Required" name="required" reporter:datatype="bool"/>
+ <field reporter:label="Valid Values" name="valid_values" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Resource Attribute Maps" name="attr_maps" oils_persist:virtual="true" reporter:datatype="link"/>
+ </fields>
+ <links>
+ <link field="owner" reltype="has_a" key="id" map="" class="aou"/>
+ <link field="resource_type" reltype="has_a" key="id" map="" class="brt"/>
+ <link field="valid_values" reltype="has_many" key="attr" map="" class="brav"/>
+ <link field="attr_maps" reltype="has_many" key="attr" map="" class="bram"/>
+ </links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ </permacrud>
+ </class>
+
+ <class id="brav" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="booking::resource_attr_value" oils_persist:tablename="booking.resource_attr_value" reporter:label="Resource Attribute Value">
+ <fields oils_persist:primary="id" oils_persist:sequence="schema.booking.resource_attr_value_id_seq">
+ <field reporter:label="Resource Attribute Value ID" name="id" reporter:datatype="id"/>
+ <field reporter:label="Owning Library" name="owner" reporter:datatype="org_unit"/>
+ <field reporter:label="Resource Attribute" name="attr" reporter:datatype="link"/>
+ <field reporter:label="Valid Value" name="valid_value" reporter:datatype="text"/>
+ <field reporter:label="Resource Attribute Maps" name="attr_maps" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Resource Attribute Value Maps" name="attr_val_maps" oils_persist:virtual="true" reporter:datatype="link"/>
+ </fields>
+ <links>
+ <link field="owner" reltype="has_a" key="id" map="" class="aou"/>
+ <link field="attr" reltype="has_a" key="id" map="" class="bra"/>
+ <link field="attr_maps" reltype="has_many" key="id" map="" class="bram"/>
+ <link field="attr_val_maps" reltype="has_many" key="attr_value" map="" class="bravm"/>
+ </links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ </permacrud>
+ </class>
+
+ <class id="bram" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="booking::resource_attr_map" oils_persist:tablename="booking.resource_attr_map" reporter:label="Resource Attribute Map">
+ <fields oils_persist:primary="id" oils_persist:sequence="schema.booking.resource_attr_map_id_seq">
+ <field reporter:label="Resource Attribute Map ID" name="id" reporter:datatype="id"/>
+ <field reporter:label="Resource" name="resource" reporter:datatype="link"/>
+ <field reporter:label="Resource Attribute" name="resource_attr" reporter:datatype="link"/>
+ <field reporter:label="Attribute Value" name="value" reporter:datatype="link"/>
+ </fields>
+ <links>
+ <link field="resource" reltype="has_a" key="id" map="" class="brsrc"/>
+ <link field="resource_attr" reltype="has_a" key="id" map="" class="bra"/>
+ <link field="value" reltype="has_a" key="id" map="" class="brav"/>
+ </links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ </permacrud>
+ </class>
+
+ <class id="bresv" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="booking::reservation" oils_persist:tablename="booking.reservation" reporter:label="Reservation">
+ <fields oils_persist:primary="id" oils_persist:sequence="schema.money.billable_xact_id_seq">
+ <field reporter:label="Transaction ID" name="id" reporter:datatype="id" />
+ <field reporter:label="User" name="usr" reporter:datatype="link"/>
+ <field reporter:label="Transaction Finish Date/Time" name="xact_finish" reporter:datatype="timestamp"/>
+ <field reporter:label="Transaction Start Date/Time" name="xact_start" reporter:datatype="timestamp"/>
+ <field reporter:label="Unrecovered Debt" name="unrecovered" reporter:datatype="bool"/>
+ <field reporter:label="Grocery Billing link" name="grocery" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Circulation Billing link" name="circulation" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Billing Line Items" name="billings" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Payment Line Items" name="payments" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Billing Totals" name="billing_total" oils_persist:virtual="true" reporter:datatype="money"/>
+ <field reporter:label="Payment Totals" name="payment_total" oils_persist:virtual="true" reporter:datatype="money"/>
+ <field reporter:label="Payment Summary" name="summary" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Request Time" name="request_time" reporter:datatype="timestamp"/>
+ <field reporter:label="Start Time" name="start_time" reporter:datatype="timestamp"/>
+ <field reporter:label="End Time" name="end_time" reporter:datatype="timestamp"/>
+ <field reporter:label="Capture Time" name="capture_time" reporter:datatype="timestamp"/>
+ <field reporter:label="Cancel Time" name="cancel_time" reporter:datatype="timestamp"/>
+ <field reporter:label="Pickup Time" name="pickup_time" reporter:datatype="timestamp"/>
+ <field reporter:label="Return Time" name="return_time" reporter:datatype="timestamp"/>
+ <field reporter:label="Booking Interval" name="booking_interval" reporter:datatype="interval"/>
+ <field reporter:label="Fine Interval" name="fine_interval" reporter:datatype="interval"/>
+ <field reporter:label="Fine Amount" name="fine_amount" reporter:datatype="money"/>
+ <field reporter:label="Target Resource Type" name="target_resource_type" reporter:datatype="link"/>
+ <field reporter:label="Target Resource" name="target_resource" reporter:datatype="link"/>
+ <field reporter:label="Current Resource" name="current_resource" reporter:datatype="link"/>
+ <field reporter:label="Request Library" name="request_lib" reporter:datatype="link"/>
+ <field reporter:label="Pickup Library" name="pickup_lib" reporter:datatype="link"/>
+ <field reporter:label="Capture Staff" name="capture_staff" reporter:datatype="link"/>
+ <field reporter:label="Attribute Value Maps" name="attr_val_maps" oils_persist:virtual="true" reporter:datatype="link"/>
+ </fields>
+ <links>
+ <link field="grocery" reltype="might_have" key="id" map="" class="mg"/>
+ <link field="circulation" reltype="might_have" key="id" map="" class="circ"/>
+ <link field="usr" reltype="has_a" key="id" map="" class="au"/>
+ <link field="payments" reltype="has_many" key="xact" map="" class="mp"/>
+ <link field="billings" reltype="has_many" key="xact" map="" class="mb"/>
+ <link field="billing_total" reltype="might_have" key="xact" map="" class="rxbt"/>
+ <link field="payment_total" reltype="might_have" key="xact" map="" class="rxpt"/>
+ <link field="summary" reltype="might_have" key="id" map="" class="mbts"/>
+ <link field="target_resource_type" reltype="has_a" key="id" map="" class="brt"/>
+ <link field="target_resource" reltype="might_have" key="id" map="" class="brsrc"/>
+ <link field="current_resource" reltype="might_have" key="id" map="" class="brsrc"/>
+ <link field="request_lib" reltype="has_a" key="id" map="" class="aou"/>
+ <link field="pickup_lib" reltype="might_have" key="id" map="" class="aou"/>
+ <link field="capture_staff" reltype="might_have" key="id" map="" class="au"/>
+ <link field="attr_val_maps" reltype="has_many" key="reservation" map="" class="bravm"/>
+ </links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ </permacrud>
+ </class>
+
+ <class id="bravm" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="booking::reservation_attr_value_map" oils_persist:tablename="booking.reservation_attr_value_map" reporter:label="Reservation Attribute Value Map">
+ <fields oils_persist:primary="id" oils_persist:sequence="schema.booking.reservation_attr_value_map_id_seq">
+ <field reporter:label="Reservation Attribute Value Map" name="id" reporter:datatype="id"/>
+ <field reporter:label="Reservation" name="reservation" reporter:datatype="link"/>
+ <field reporter:label="Attribute Map" name="attr_value" reporter:datatype="link"/>
+ </fields>
+ <links>
+ <link field="reservation" reltype="has_a" key="id" map="" class="bresv"/>
+ <link field="attr_value" reltype="has_a" key="id" map="" class="brav"/>
+ </links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ </permacrud>
+ </class>
+
<class id="ccnbi" controller="open-ils.cstore" oils_obj:fieldmapper="container::call_number_bucket_item" oils_persist:tablename="container.call_number_bucket_item" reporter:label="Call Number Bucket Item">
<fields oils_persist:primary="id" oils_persist:sequence="container.call_number_bucket_item_id_seq">
<field name="bucket" reporter:datatype="link"/>
@@ -2852,6 +3025,13 @@
<field reporter:label="Fund Allocation Percentages" name="fund_alloc_pcts" oils_persist:virtual="true" reporter:datatype="link"/>
<field reporter:label="Copy Location Orders" name="copy_location_orders" oils_persist:virtual="true" reporter:datatype="link"/>
<field reporter:label="Transit Copy Prev Destinations" name="atc_prev_dests" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Reservation Requests" name="resv_requests" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Reservation Pickups" name="resv_pickups" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Resource Types" name="rsrc_types" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Resources" name="resources" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Resource Attributes" name="rsrc_attrs" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Attribute Values" name="attr_vals" oils_persist:virtual="true" reporter:datatype="link"/>
+
</fields>
<links>
<link field="billing_address" reltype="has_a" key="id" map="" class="aoa"/>
@@ -2873,6 +3053,12 @@
<link field="fund_alloc_pcts" reltype="has_many" key="org" map="" class="acqfap"/>
<link field="copy_location_orders" reltype="has_many" key="org" map="" class="acplo"/>
<link field="atc_prev_dests" reltype="has_many" key="prev_dest" map="" class="atc"/>
+ <link field="resv_requests" reltype="has_many" key="request_lib" map="" class="bresv"/>
+ <link field="resv_pickups" reltype="has_many" key="pickup_lib" map="" class="bresv"/>
+ <link field="rsrc_types" reltype="has_many" key="owner" map="" class="brt"/>
+ <link field="resources" reltype="has_many" key="owner" map="" class="brsrc"/>
+ <link field="rsrc_attrs" reltype="has_many" key="owner" map="" class="bra"/>
+ <link field="attr_vals" reltype="has_many" key="owner" map="" class="brav"/>
</links>
<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
<actions>
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2009-11-16 14:46:19 UTC (rev 14920)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2009-11-16 17:59:10 UTC (rev 14921)
@@ -51,7 +51,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0085'); -- dbs
+INSERT INTO config.upgrade_log (version) VALUES ('0086'); -- Scott McKellar
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Added: trunk/Open-ILS/src/sql/Pg/095.schema.booking.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/095.schema.booking.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/095.schema.booking.sql 2009-11-16 17:59:10 UTC (rev 14921)
@@ -0,0 +1,131 @@
+BEGIN;
+
+CREATE SCHEMA booking;
+
+CREATE TABLE booking.resource_type (
+ id SERIAL PRIMARY KEY,
+ name TEXT NOT NULL,
+ fine_interval INTERVAL,
+ fine_amount DECIMAL(8,2) NOT NULL DEFAULT 0,
+ owner INT NOT NULL
+ REFERENCES actor.org_unit( id )
+ DEFERRABLE INITIALLY DEFERRED,
+ catalog_item BOOLEAN NOT NULL DEFAULT FALSE,
+ transferable BOOLEAN NOT NULL DEFAULT FALSE,
+ CONSTRAINT brt_name_once_per_owner UNIQUE(owner, name)
+);
+
+CREATE TABLE booking.resource (
+ id SERIAL PRIMARY KEY,
+ owner INT NOT NULL
+ REFERENCES actor.org_unit(id)
+ DEFERRABLE INITIALLY DEFERRED,
+ type INT NOT NULL
+ REFERENCES booking.resource_type(id)
+ DEFERRABLE INITIALLY DEFERRED,
+ overbook BOOLEAN NOT NULL DEFAULT FALSE,
+ barcode TEXT NOT NULL,
+ deposit BOOLEAN NOT NULL DEFAULT FALSE,
+ deposit_amount DECIMAL(8,2) NOT NULL DEFAULT 0.00,
+ user_fee DECIMAL(8,2) NOT NULL DEFAULT 0.00,
+ CONSTRAINT br_unique UNIQUE(owner, type, barcode)
+);
+
+-- For non-catalog items: hijack barcode for name/description
+
+CREATE TABLE booking.resource_attr (
+ id SERIAL PRIMARY KEY,
+ owner INT NOT NULL
+ REFERENCES actor.org_unit(id)
+ DEFERRABLE INITIALLY DEFERRED,
+ name TEXT NOT NULL,
+ resource_type INT NOT NULL
+ REFERENCES booking.resource_type(id)
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED,
+ required BOOLEAN NOT NULL DEFAULT FALSE,
+ CONSTRAINT bra_name_once_per_type UNIQUE(resource_type, name)
+);
+
+CREATE TABLE booking.resource_attr_value (
+ id SERIAL PRIMARY KEY,
+ owner INT NOT NULL
+ REFERENCES actor.org_unit(id)
+ DEFERRABLE INITIALLY DEFERRED,
+ attr INT NOT NULL
+ REFERENCES booking.resource_attr(id)
+ DEFERRABLE INITIALLY DEFERRED,
+ valid_value TEXT NOT NULL,
+ CONSTRAINT brav_logical_key UNIQUE(owner, attr, valid_value)
+);
+
+-- Do we still need a name column?
+
+
+CREATE TABLE booking.resource_attr_map (
+ id SERIAL PRIMARY KEY,
+ resource INT NOT NULL
+ REFERENCES booking.resource(id)
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED,
+ resource_attr INT NOT NULL
+ REFERENCES booking.resource_attr(id)
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED,
+ value INT NOT NULL
+ REFERENCES booking.resource_attr_value(id)
+ DEFERRABLE INITIALLY DEFERRED,
+ CONSTRAINT bram_one_value_per_attr UNIQUE(resource, resource_attr)
+);
+
+CREATE TABLE booking.reservation (
+ request_time TIMESTAMPTZ NOT NULL DEFAULT now(),
+ start_time TIMESTAMPTZ,
+ end_time TIMESTAMPTZ,
+ capture_time TIMESTAMPTZ,
+ cancel_time TIMESTAMPTZ,
+ pickup_time TIMESTAMPTZ,
+ return_time TIMESTAMPTZ,
+ booking_interval INTERVAL,
+ fine_interval INTERVAL,
+ fine_amount DECIMAL(8,2),
+ target_resource_type INT NOT NULL
+ REFERENCES booking.resource_type(id)
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED,
+ target_resource INT REFERENCES booking.resource(id)
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED,
+ current_resource INT REFERENCES booking.resource(id)
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED,
+ request_lib INT NOT NULL
+ REFERENCES actor.org_unit(id)
+ DEFERRABLE INITIALLY DEFERRED,
+ pickup_lib INT REFERENCES actor.org_unit(id)
+ DEFERRABLE INITIALLY DEFERRED,
+ capture_staff INT REFERENCES actor.usr(id)
+ DEFERRABLE INITIALLY DEFERRED
+) INHERITS (money.billable_xact);
+
+ALTER TABLE booking.reservation ADD PRIMARY KEY (id);
+
+ALTER TABLE booking.reservation
+ ADD CONSTRAINT booking_reservation_usr_fkey
+ FOREIGN KEY (usr) REFERENCES actor.usr (id)
+ DEFERRABLE INITIALLY DEFERRED;
+
+CREATE TABLE booking.reservation_attr_value_map (
+ id SERIAL PRIMARY KEY,
+ reservation INT NOT NULL
+ REFERENCES booking.reservation(id)
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED,
+ attr_value INT NOT NULL
+ REFERENCES booking.resource_attr_value(id)
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED,
+ CONSTRAINT bravm_logical_key UNIQUE(reservation, attr_value)
+);
+
+COMMIT;
\ No newline at end of file
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0086.schema.booking-tables.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0086.schema.booking-tables.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0086.schema.booking-tables.sql 2009-11-16 17:59:10 UTC (rev 14921)
@@ -0,0 +1,135 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0086');
+
+DROP SCHEMA IF EXISTS booking CASCADE;
+
+CREATE SCHEMA booking;
+
+CREATE TABLE booking.resource_type (
+ id SERIAL PRIMARY KEY,
+ name TEXT NOT NULL,
+ fine_interval INTERVAL,
+ fine_amount DECIMAL(8,2) NOT NULL DEFAULT 0,
+ owner INT NOT NULL
+ REFERENCES actor.org_unit( id )
+ DEFERRABLE INITIALLY DEFERRED,
+ catalog_item BOOLEAN NOT NULL DEFAULT FALSE,
+ transferable BOOLEAN NOT NULL DEFAULT FALSE,
+ CONSTRAINT brt_name_once_per_owner UNIQUE(owner, name)
+);
+
+CREATE TABLE booking.resource (
+ id SERIAL PRIMARY KEY,
+ owner INT NOT NULL
+ REFERENCES actor.org_unit(id)
+ DEFERRABLE INITIALLY DEFERRED,
+ type INT NOT NULL
+ REFERENCES booking.resource_type(id)
+ DEFERRABLE INITIALLY DEFERRED,
+ overbook BOOLEAN NOT NULL DEFAULT FALSE,
+ barcode TEXT NOT NULL,
+ deposit BOOLEAN NOT NULL DEFAULT FALSE,
+ deposit_amount DECIMAL(8,2) NOT NULL DEFAULT 0.00,
+ user_fee DECIMAL(8,2) NOT NULL DEFAULT 0.00,
+ CONSTRAINT br_unique UNIQUE(owner, type, barcode)
+);
+
+-- For non-catalog items: hijack barcode for name/description
+
+CREATE TABLE booking.resource_attr (
+ id SERIAL PRIMARY KEY,
+ owner INT NOT NULL
+ REFERENCES actor.org_unit(id)
+ DEFERRABLE INITIALLY DEFERRED,
+ name TEXT NOT NULL,
+ resource_type INT NOT NULL
+ REFERENCES booking.resource_type(id)
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED,
+ required BOOLEAN NOT NULL DEFAULT FALSE,
+ CONSTRAINT bra_name_once_per_type UNIQUE(resource_type, name)
+);
+
+CREATE TABLE booking.resource_attr_value (
+ id SERIAL PRIMARY KEY,
+ owner INT NOT NULL
+ REFERENCES actor.org_unit(id)
+ DEFERRABLE INITIALLY DEFERRED,
+ attr INT NOT NULL
+ REFERENCES booking.resource_attr(id)
+ DEFERRABLE INITIALLY DEFERRED,
+ valid_value TEXT NOT NULL,
+ CONSTRAINT brav_logical_key UNIQUE(owner, attr, valid_value)
+);
+
+-- Do we still need a name column?
+
+
+CREATE TABLE booking.resource_attr_map (
+ id SERIAL PRIMARY KEY,
+ resource INT NOT NULL
+ REFERENCES booking.resource(id)
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED,
+ resource_attr INT NOT NULL
+ REFERENCES booking.resource_attr(id)
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED,
+ value INT NOT NULL
+ REFERENCES booking.resource_attr_value(id)
+ DEFERRABLE INITIALLY DEFERRED,
+ CONSTRAINT bram_one_value_per_attr UNIQUE(resource, resource_attr)
+);
+
+CREATE TABLE booking.reservation (
+ request_time TIMESTAMPTZ NOT NULL DEFAULT now(),
+ start_time TIMESTAMPTZ,
+ end_time TIMESTAMPTZ,
+ capture_time TIMESTAMPTZ,
+ cancel_time TIMESTAMPTZ,
+ pickup_time TIMESTAMPTZ,
+ return_time TIMESTAMPTZ,
+ booking_interval INTERVAL,
+ fine_interval INTERVAL,
+ fine_amount DECIMAL(8,2),
+ target_resource_type INT NOT NULL
+ REFERENCES booking.resource_type(id)
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED,
+ target_resource INT REFERENCES booking.resource(id)
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED,
+ current_resource INT REFERENCES booking.resource(id)
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED,
+ request_lib INT NOT NULL
+ REFERENCES actor.org_unit(id)
+ DEFERRABLE INITIALLY DEFERRED,
+ pickup_lib INT REFERENCES actor.org_unit(id)
+ DEFERRABLE INITIALLY DEFERRED,
+ capture_staff INT REFERENCES actor.usr(id)
+ DEFERRABLE INITIALLY DEFERRED
+) INHERITS (money.billable_xact);
+
+ALTER TABLE booking.reservation ADD PRIMARY KEY (id);
+
+ALTER TABLE booking.reservation
+ ADD CONSTRAINT booking_reservation_usr_fkey
+ FOREIGN KEY (usr) REFERENCES actor.usr (id)
+ DEFERRABLE INITIALLY DEFERRED;
+
+CREATE TABLE booking.reservation_attr_value_map (
+ id SERIAL PRIMARY KEY,
+ reservation INT NOT NULL
+ REFERENCES booking.reservation(id)
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED,
+ attr_value INT NOT NULL
+ REFERENCES booking.resource_attr_value(id)
+ ON DELETE CASCADE
+ DEFERRABLE INITIALLY DEFERRED,
+ CONSTRAINT bravm_logical_key UNIQUE(reservation, attr_value)
+);
+
+COMMIT;
More information about the open-ils-commits
mailing list