Changeset 9542

Show
Ignore:
Timestamp:
05/09/08 12:31:09 (1 week ago)
Author:
dbs
Message:

Make all foreign keys deferrable, so we can DELETE and INSERT inside a transaction without constraints hobbling us

Location:
trunk/Open-ILS/src/sql/Pg
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • trunk/Open-ILS/src/sql/Pg/005.schema.actors.sql

    r9243 r9542  
    3333        email                   TEXT, 
    3434        passwd                  TEXT                            NOT NULL, 
    35         standing                INT                             NOT NULL DEFAULT 1 REFERENCES config.standing (id), 
    36         ident_type              INT                             NOT NULL REFERENCES config.identification_type (id), 
     35        standing                INT                             NOT NULL DEFAULT 1 REFERENCES config.standing (id) DEFERRABLE INITIALLY DEFERRED, 
     36        ident_type              INT                             NOT NULL REFERENCES config.identification_type (id) DEFERRABLE INITIALLY DEFERRED, 
    3737        ident_value             TEXT, 
    38         ident_type2             INT                             REFERENCES config.identification_type (id), 
     38        ident_type2             INT                             REFERENCES config.identification_type (id) DEFERRABLE INITIALLY DEFERRED, 
    3939        ident_value2            TEXT, 
    40         net_access_level        INT                             NOT NULL DEFAULT 1 REFERENCES config.net_access_level (id), 
     40        net_access_level        INT                             NOT NULL DEFAULT 1 REFERENCES config.net_access_level (id) DEFERRABLE INITIALLY DEFERRED, 
    4141        photo_url               TEXT, 
    4242        prefix                  TEXT, 
     
    135135CREATE TABLE actor.usr_note ( 
    136136        id              BIGSERIAL                       PRIMARY KEY, 
    137         usr             BIGINT                          NOT NULL REFERENCES actor.usr ON DELETE CASCADE, 
    138         creator         BIGINT                          NOT NULL REFERENCES actor.usr ON DELETE CASCADE, 
     137        usr             BIGINT                          NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
     138        creator         BIGINT                          NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
    139139        create_date     TIMESTAMP WITH TIME ZONE        DEFAULT NOW(), 
    140140        pub             BOOL                            NOT NULL DEFAULT FALSE, 
     
    146146CREATE TABLE actor.usr_standing_penalty ( 
    147147        id              SERIAL  PRIMARY KEY, 
    148         usr             INT     NOT NULL REFERENCES actor.usr ON DELETE CASCADE, 
     148        usr             INT     NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
    149149        penalty_type    TEXT    NOT NULL 
    150150); 
     
    174174CREATE TABLE actor.usr_setting ( 
    175175        id      BIGSERIAL       PRIMARY KEY, 
    176         usr     INT             NOT NULL REFERENCES actor.usr ON DELETE CASCADE, 
     176        usr     INT             NOT NULL REFERENCES actor.usr ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
    177177        name    TEXT            NOT NULL, 
    178178        value   TEXT            NOT NULL, 
     
    307307CREATE TABLE actor.card ( 
    308308        id      SERIAL  PRIMARY KEY, 
    309         usr     INT     NOT NULL REFERENCES actor.usr (id), 
     309        usr     INT     NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED, 
    310310        barcode TEXT    NOT NULL UNIQUE, 
    311311        active  BOOL    NOT NULL DEFAULT TRUE 
     
    345345        opac_label      TEXT    NOT NULL, 
    346346        depth           INT     NOT NULL, 
    347         parent          INT     REFERENCES actor.org_unit_type (id), 
     347        parent          INT     REFERENCES actor.org_unit_type (id) DEFERRABLE INITIALLY DEFERRED, 
    348348        can_have_vols   BOOL    NOT NULL DEFAULT TRUE, 
    349349        can_have_users  BOOL    NOT NULL DEFAULT TRUE 
     
    353353CREATE TABLE actor.org_unit ( 
    354354        id              SERIAL  PRIMARY KEY, 
    355         parent_ou       INT     REFERENCES actor.org_unit (id), 
    356         ou_type         INT     NOT NULL REFERENCES actor.org_unit_type (id), 
     355        parent_ou       INT     REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, 
     356        ou_type         INT     NOT NULL REFERENCES actor.org_unit_type (id) DEFERRABLE INITIALLY DEFERRED, 
    357357        ill_address     INT, 
    358358        holds_address   INT, 
     
    379379CREATE TABLE actor.org_lasso_map ( 
    380380    id          SERIAL  PRIMARY KEY, 
    381     lasso       INT     NOT NULL REFERENCES actor.org_lasso (id) ON DELETE CASCADE, 
    382     org_unit    INT     NOT NULL REFERENCES actor.org_unit (id) ON DELETE CASCADE 
     381    lasso       INT     NOT NULL REFERENCES actor.org_lasso (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
     382    org_unit    INT     NOT NULL REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED 
    383383); 
    384384CREATE UNIQUE INDEX ou_lasso_lasso_ou_idx ON actor.org_lasso_map (lasso, org_unit); 
     
    394394 
    395395CREATE TABLE actor.hours_of_operation ( 
    396         id              INT     PRIMARY KEY REFERENCES actor.org_unit (id) ON DELETE CASCADE, 
     396        id              INT     PRIMARY KEY REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
    397397        dow_0_open      TIME    NOT NULL DEFAULT '09:00', 
    398398        dow_0_close     TIME    NOT NULL DEFAULT '17:00', 
     
    413413CREATE TABLE actor.org_unit_closed ( 
    414414        id              SERIAL                          PRIMARY KEY, 
    415         org_unit        INT                             NOT NULL REFERENCES actor.org_unit (id), 
     415        org_unit        INT                             NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, 
    416416        close_start     TIMESTAMP WITH TIME ZONE        NOT NULL, 
    417417        close_end       TIMESTAMP WITH TIME ZONE        NOT NULL, 
     
    423423        id              SERIAL  PRIMARY KEY, 
    424424        name            TEXT    NOT NULL UNIQUE, 
    425         owning_lib      INT     NOT NULL REFERENCES actor.org_unit (id) 
     425        owning_lib      INT     NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED 
    426426); 
    427427 
    428428CREATE TABLE actor.usr_org_unit_opt_in ( 
    429429        id              SERIAL                          PRIMARY KEY, 
    430         org_unit        INT                             NOT NULL REFERENCES actor.org_unit (id), 
    431         usr             INT                             NOT NULL REFERENCES actor.usr (id), 
    432         staff           INT                             NOT NULL REFERENCES actor.usr (id), 
     430        org_unit        INT                             NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, 
     431        usr             INT                             NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED, 
     432        staff           INT                             NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED, 
    433433        opt_in_ts       TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW(), 
    434         opt_in_ws       INT                             NOT NULL REFERENCES actor.workstation (id), 
     434        opt_in_ws       INT                             NOT NULL REFERENCES actor.workstation (id) DEFERRABLE INITIALLY DEFERRED, 
    435435        CONSTRAINT usr_opt_in_once_per_org_unit UNIQUE (usr,org_unit) 
    436436); 
     
    438438CREATE TABLE actor.org_unit_setting ( 
    439439        id              BIGSERIAL       PRIMARY KEY, 
    440         org_unit        INT             NOT NULL REFERENCES actor.org_unit ON DELETE CASCADE, 
     440        org_unit        INT             NOT NULL REFERENCES actor.org_unit ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
    441441        name            TEXT            NOT NULL, 
    442442        value           TEXT            NOT NULL, 
     
    475475        within_city_limits      BOOL    NOT NULL DEFAULT TRUE, 
    476476        address_type            TEXT    NOT NULL DEFAULT 'MAILING', 
    477         usr                     INT     NOT NULL REFERENCES actor.usr (id), 
     477        usr                     INT     NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED, 
    478478        street1                 TEXT    NOT NULL, 
    479479        street2                 TEXT, 
     
    499499        valid           BOOL    NOT NULL DEFAULT TRUE, 
    500500        address_type    TEXT    NOT NULL DEFAULT 'MAILING', 
    501         org_unit        INT     NOT NULL REFERENCES actor.org_unit (id), 
     501        org_unit        INT     NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, 
    502502        street1         TEXT    NOT NULL, 
    503503        street2         TEXT, 
  • trunk/Open-ILS/src/sql/Pg/006.schema.permissions.sql

    r8690 r9542  
    1414        id                      SERIAL  PRIMARY KEY, 
    1515        name                    TEXT    NOT NULL UNIQUE, 
    16         parent                  INT     REFERENCES permission.grp_tree (id) ON DELETE RESTRICT, 
     16        parent                  INT     REFERENCES permission.grp_tree (id) ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED, 
    1717        usergroup               BOOL    NOT NULL DEFAULT TRUE, 
    1818        perm_interval           INTERVAL DEFAULT '3 years'::interval NOT NULL, 
     
    2424CREATE TABLE permission.grp_perm_map ( 
    2525        id              SERIAL  PRIMARY KEY, 
    26         grp             INT     NOT NULL REFERENCES permission.grp_tree (id) ON DELETE CASCADE, 
    27         perm            INT     NOT NULL REFERENCES permission.perm_list (id) ON DELETE CASCADE, 
     26        grp             INT     NOT NULL REFERENCES permission.grp_tree (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
     27        perm            INT     NOT NULL REFERENCES permission.perm_list (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
    2828        depth           INT     NOT NULL, 
    2929        grantable       BOOL    NOT NULL DEFAULT FALSE, 
     
    3333CREATE TABLE permission.usr_perm_map ( 
    3434        id              SERIAL  PRIMARY KEY, 
    35         usr             INT     NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE, 
    36         perm            INT     NOT NULL REFERENCES permission.perm_list (id) ON DELETE CASCADE, 
     35        usr             INT     NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
     36        perm            INT     NOT NULL REFERENCES permission.perm_list (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
    3737        depth           INT     NOT NULL, 
    3838        grantable       BOOL    NOT NULL DEFAULT FALSE, 
     
    4242CREATE TABLE permission.usr_object_perm_map ( 
    4343        id              SERIAL  PRIMARY KEY, 
    44         usr             INT     NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE, 
    45         perm            INT     NOT NULL REFERENCES permission.perm_list (id) ON DELETE CASCADE, 
     44        usr             INT     NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
     45        perm            INT     NOT NULL REFERENCES permission.perm_list (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
    4646    object_type TEXT NOT NULL, 
    4747    object_id   TEXT NOT NULL, 
     
    5454CREATE TABLE permission.usr_grp_map ( 
    5555        id      SERIAL  PRIMARY KEY, 
    56         usr     INT     NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE, 
    57         grp     INT     NOT NULL REFERENCES permission.grp_tree (id) ON DELETE CASCADE, 
     56        usr     INT     NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
     57        grp     INT     NOT NULL REFERENCES permission.grp_tree (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
    5858                CONSTRAINT usr_grp_once UNIQUE (usr,grp) 
    5959); 
     
    9494CREATE TABLE permission.usr_work_ou_map ( 
    9595        id      SERIAL  PRIMARY KEY, 
    96         usr     INT     NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE, 
    97         work_ou INT     NOT NULL REFERENCES actor.org_unit (id) ON DELETE CASCADE, 
     96        usr     INT     NOT NULL REFERENCES actor.usr (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
     97        work_ou INT     NOT NULL REFERENCES actor.org_unit (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
    9898                CONSTRAINT usr_work_ou_once UNIQUE (usr,work_ou) 
    9999); 
  • trunk/Open-ILS/src/sql/Pg/011.schema.authority.sql

    r4794 r9542  
    2424CREATE TABLE authority.record_note ( 
    2525        id              BIGSERIAL       PRIMARY KEY, 
    26         record          BIGINT          NOT NULL REFERENCES authority.record_entry (id), 
     26        record          BIGINT          NOT NULL REFERENCES authority.record_entry (id) DEFERRABLE INITIALLY DEFERRED, 
    2727        value           TEXT            NOT NULL, 
    2828        creator         INT             NOT NULL DEFAULT 1, 
  • trunk/Open-ILS/src/sql/Pg/012.schema.vandelay.sql

    r9445 r9542  
    77CREATE TABLE vandelay.queue ( 
    88        id                              BIGSERIAL       PRIMARY KEY, 
    9         owner                   INT                     NOT NULL REFERENCES actor.usr (id), 
     9        owner                   INT                     NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED, 
    1010        name                    TEXT            NOT NULL, 
    1111        complete                BOOL            NOT NULL DEFAULT FALSE, 
     
    5858 
    5959CREATE TABLE vandelay.queued_bib_record ( 
    60         queue           INT     NOT NULL REFERENCES vandelay.bib_queue (id) ON DELETE CASCADE, 
    61         bib_source      INT     REFERENCES config.bib_source (id), 
    62         imported_as     INT     REFERENCES biblio.record_entry (id) 
     60        queue           INT     NOT NULL REFERENCES vandelay.bib_queue (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
     61        bib_source      INT     REFERENCES config.bib_source (id) DEFERRABLE INITIALLY DEFERRED, 
     62        imported_as     INT     REFERENCES biblio.record_entry (id) DEFERRABLE INITIALLY DEFERRED 
    6363) INHERITS (vandelay.queued_record); 
    6464ALTER TABLE vandelay.queued_bib_record ADD PRIMARY KEY (id); 
     
    6666CREATE TABLE vandelay.queued_bib_record_attr ( 
    6767        id                      BIGSERIAL       PRIMARY KEY, 
    68         record          BIGINT          NOT NULL REFERENCES vandelay.queued_bib_record (id), 
    69         field           INT                     NOT NULL REFERENCES vandelay.bib_attr_definition (id), 
     68        record          BIGINT          NOT NULL REFERENCES vandelay.queued_bib_record (id) DEFERRABLE INITIALLY DEFERRED, 
     69        field           INT                     NOT NULL REFERENCES vandelay.bib_attr_definition (id) DEFERRABLE INITIALLY DEFERRED, 
    7070        attr_value      TEXT            NOT NULL 
    7171); 
     
    7474        id                              BIGSERIAL       PRIMARY KEY, 
    7575        field_type              TEXT            NOT NULL CHECK (field_type in ('isbn','tcn_value','id')), 
    76         matched_attr    INT                     REFERENCES vandelay.queued_bib_record_attr (id) ON DELETE CASCADE, 
    77         queued_record   BIGINT          REFERENCES vandelay.queued_bib_record (id) ON DELETE CASCADE, 
    78         eg_record               BIGINT          REFERENCES biblio.record_entry (id) 
     76        matched_attr    INT                     REFERENCES vandelay.queued_bib_record_attr (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
     77        queued_record   BIGINT          REFERENCES vandelay.queued_bib_record (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
     78        eg_record               BIGINT          REFERENCES biblio.record_entry (id) DEFERRABLE INITIALLY DEFERRED 
    7979); 
    8080 
     
    187187 
    188188CREATE TABLE vandelay.queued_authority_record ( 
    189         queue           INT     NOT NULL REFERENCES vandelay.authority_queue (id) ON DELETE CASCADE, 
    190         imported_as     INT     REFERENCES authority.record_entry (id) 
     189        queue           INT     NOT NULL REFERENCES vandelay.authority_queue (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
     190        imported_as     INT     REFERENCES authority.record_entry (id) DEFERRABLE INITIALLY DEFERRED 
    191191) INHERITS (vandelay.queued_record); 
    192192ALTER TABLE vandelay.queued_authority_record ADD PRIMARY KEY (id); 
     
    194194CREATE TABLE vandelay.queued_authority_record_attr ( 
    195195        id                      BIGSERIAL       PRIMARY KEY, 
    196         record          BIGINT          NOT NULL REFERENCES vandelay.queued_authority_record (id), 
    197         field           INT                     NOT NULL REFERENCES vandelay.authority_attr_definition (id), 
     196        record          BIGINT          NOT NULL REFERENCES vandelay.queued_authority_record (id) DEFERRABLE INITIALLY DEFERRED, 
     197        field           INT                     NOT NULL REFERENCES vandelay.authority_attr_definition (id) DEFERRABLE INITIALLY DEFERRED, 
    198198        attr_value      TEXT            NOT NULL 
    199199); 
     
    201201CREATE TABLE vandelay.authority_match ( 
    202202        id                              BIGSERIAL       PRIMARY KEY, 
    203         matched_attr    INT                     REFERENCES vandelay.queued_authority_record_attr (id) ON DELETE CASCADE, 
    204         queued_record   BIGINT          REFERENCES vandelay.queued_authority_record (id) ON DELETE CASCADE, 
    205         eg_record               BIGINT          REFERENCES authority.record_entry (id) 
     203        matched_attr    INT                     REFERENCES vandelay.queued_authority_record_attr (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
     204        queued_record   BIGINT          REFERENCES vandelay.queued_authority_record (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
     205        eg_record               BIGINT          REFERENCES authority.record_entry (id) DEFERRABLE INITIALLY DEFERRED 
    206206); 
    207207 
  • trunk/Open-ILS/src/sql/Pg/080.schema.money.sql

    r7945 r9542  
    77CREATE TABLE money.collections_tracker ( 
    88        id              BIGSERIAL                       PRIMARY KEY, 
    9         usr             INT                             NOT NULL REFERENCES actor.usr (id), -- actor.usr.id 
    10         collector       INT                             NOT NULL REFERENCES actor.usr (id), 
    11         location        INT                             NOT NULL REFERENCES actor.org_unit (id), 
     9        usr             INT                             NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED, -- actor.usr.id 
     10        collector       INT                             NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED, 
     11        location        INT                             NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, 
    1212        enter_time      TIMESTAMP WITH TIME ZONE 
    1313); 
     
    325325 
    326326CREATE TABLE money.bnm_desk_payment ( 
    327         cash_drawer     INT     REFERENCES actor.workstation (id) 
     327        cash_drawer     INT     REFERENCES actor.workstation (id) DEFERRABLE INITIALLY DEFERRED 
    328328) INHERITS (money.bnm_payment); 
    329329ALTER TABLE money.bnm_desk_payment ADD PRIMARY KEY (id); 
  • trunk/Open-ILS/src/sql/Pg/090.schema.action.sql

    r8506 r9542  
    77CREATE TABLE action.in_house_use ( 
    88        id              SERIAL                          PRIMARY KEY, 
    9         item            BIGINT                          NOT NULL REFERENCES asset.copy (id), 
    10         staff           INT                             NOT NULL REFERENCES actor.usr (id), 
    11         org_unit        INT                             NOT NULL REFERENCES actor.org_unit (id), 
     9        item            BIGINT                          NOT NULL REFERENCES asset.copy (id) DEFERRABLE INITIALLY DEFERRED, 
     10        staff           INT                             NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED, 
     11        org_unit        INT                             NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, 
    1212        use_time        TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW() 
    1313); 
     
    1515CREATE TABLE action.non_cataloged_circulation ( 
    1616        id              SERIAL                          PRIMARY KEY, 
    17         patron          INT                             NOT NULL REFERENCES actor.usr (id), 
    18         staff           INT                             NOT NULL REFERENCES actor.usr (id), 
    19         circ_lib        INT                             NOT NULL REFERENCES actor.org_unit (id), 
    20         item_type       INT                             NOT NULL REFERENCES config.non_cataloged_type (id), 
     17        patron          INT                             NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED, 
     18        staff           INT                             NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED, 
     19        circ_lib        INT                             NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, 
     20        item_type       INT                             NOT NULL REFERENCES config.non_cataloged_type (id) DEFERRABLE INITIALLY DEFERRED, 
    2121        circ_time       TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW() 
    2222); 
     
    2424CREATE TABLE action.non_cat_in_house_use ( 
    2525        id              SERIAL                          PRIMARY KEY, 
    26         item_type       BIGINT                          NOT NULL REFERENCES config.non_cataloged_type(id), 
    27         staff           INT                             NOT NULL REFERENCES actor.usr (id), 
    28         org_unit        INT                             NOT NULL REFERENCES actor.org_unit (id), 
     26        item_type       BIGINT                          NOT NULL REFERENCES config.non_cataloged_type(id) DEFERRABLE INITIALLY DEFERRED, 
     27        staff           INT                             NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED, 
     28        org_unit        INT                             NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, 
    2929        use_time        TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW() 
    3030); 
     
    3232CREATE TABLE action.survey ( 
    3333        id              SERIAL                          PRIMARY KEY, 
    34         owner           INT                             NOT NULL REFERENCES actor.org_unit (id), 
     34        owner           INT                             NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, 
    3535        start_date      TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW(), 
    3636        end_date        TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW() + '10 years'::INTERVAL, 
     
    4646CREATE TABLE action.survey_question ( 
    4747        id              SERIAL  PRIMARY KEY, 
    48         survey          INT     NOT NULL REFERENCES action.survey, 
     48        survey          INT     NOT NULL REFERENCES action.survey DEFERRABLE INITIALLY DEFERRED, 
    4949        question        TEXT    NOT NULL 
    5050); 
     
    5252CREATE TABLE action.survey_answer ( 
    5353        id              SERIAL  PRIMARY KEY, 
    54         question        INT     NOT NULL REFERENCES action.survey_question, 
     54        question        INT     NOT NULL REFERENCES action.survey_question DEFERRABLE INITIALLY DEFERRED, 
    5555        answer          TEXT    NOT NULL 
    5656); 
     
    6262        response_group_id       INT, 
    6363        usr                     INT, -- REFERENCES actor.usr 
    64         survey                  INT                             NOT NULL REFERENCES action.survey, 
    65         question                INT                             NOT NULL REFERENCES action.survey_question, 
    66         answer                  INT                             NOT NULL REFERENCES action.survey_answer, 
     64        survey                  INT                             NOT NULL REFERENCES action.survey DEFERRABLE INITIALLY DEFERRED, 
     65        question                INT                             NOT NULL REFERENCES action.survey_question DEFERRABLE INITIALLY DEFERRED, 
     66        answer                  INT                             NOT NULL REFERENCES action.survey_answer DEFERRABLE INITIALLY DEFERRED, 
    6767        answer_date             TIMESTAMP WITH TIME ZONE, 
    6868        effective_date          TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW() 
     
    168168        cancel_time             TIMESTAMP WITH TIME ZONE, 
    169169        target                  BIGINT                          NOT NULL, -- see hold_type 
    170         current_copy            BIGINT                          REFERENCES asset.copy (id) ON DELETE SET NULL, 
    171         fulfillment_staff       INT                             REFERENCES actor.usr (id), 
    172         fulfillment_lib         INT                             REFERENCES actor.org_unit (id), 
    173         request_lib             INT                             NOT NULL REFERENCES actor.org_unit (id), 
    174         requestor               INT                             NOT NULL REFERENCES actor.usr (id), 
    175         usr                     INT                             NOT NULL REFERENCES actor.usr (id), 
     170        current_copy            BIGINT                          REFERENCES asset.copy (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED, 
     171        fulfillment_staff       INT                             REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED, 
     172        fulfillment_lib         INT                             REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, 
     173        request_lib             INT                             NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, 
     174        requestor               INT                             NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED, 
     175        usr                     INT                             NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED, 
    176176        selection_ou            INT                             NOT NULL, 
    177177        selection_depth         INT                             NOT NULL DEFAULT 0, 
    178         pickup_lib              INT                             NOT NULL REFERENCES actor.org_unit, 
     178        pickup_lib              INT                             NOT NULL REFERENCES actor.org_unit DEFERRABLE INITIALLY DEFERRED, 
    179179        hold_type               TEXT                            NOT NULL CHECK (hold_type IN ('M','T','V','C')), 
    180180        holdable_formats        TEXT, 
     
    194194CREATE TABLE action.hold_notification ( 
    195195        id              SERIAL                          PRIMARY KEY, 
    196         hold            INT                             NOT NULL REFERENCES action.hold_request (id), 
    197         notify_staff    INT                             REFERENCES actor.usr (id), 
     196        hold            INT                             NOT NULL REFERENCES action.hold_request (id) DEFERRABLE INITIALLY DEFERRED, 
     197        notify_staff    INT                             REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED, 
    198198        notify_time     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW(), 
    199199        method          TEXT                            NOT NULL, -- email address or phone number 
     
    204204CREATE TABLE action.hold_copy_map ( 
    205205        id              SERIAL  PRIMARY KEY, 
    206         hold            INT     NOT NULL REFERENCES action.hold_request (id) ON DELETE CASCADE, 
    207         target_copy     BIGINT  NOT NULL REFERENCES asset.copy (id) ON DELETE CASCADE, 
     206        hold            INT     NOT NULL REFERENCES action.hold_request (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
     207        target_copy     BIGINT  NOT NULL REFERENCES asset.copy (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
    208208        CONSTRAINT copy_once_per_hold UNIQUE (hold,target_copy) 
    209209); 
     
    215215        source_send_time        TIMESTAMP WITH TIME ZONE, 
    216216        dest_recv_time          TIMESTAMP WITH TIME ZONE, 
    217         target_copy             BIGINT                          NOT NULL REFERENCES asset.copy (id) ON DELETE CASCADE, 
    218         source                  INT                             NOT NULL REFERENCES actor.org_unit (id), 
    219         dest              &nb