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

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

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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