CREATE SCHEMA http;
/*
The purpose of this schema, tables, and associated roles to process HTTP responses.
I may even include a table to keep track of the XML responses
*/

/*
Add a role to manage permissions on the http schema
*/
CREATE ROLE http_requestor;

GRANT CONNECT ON DATABASE aact_db to http_requestor;

GRANT USAGE ON SCHEMA http TO http_requestor;

GRANT INSERT,SELECT ON ALL TABLES IN SCHEMA http TO http_requestor;


/* Create tables related to http requests
As not every request will have an xml doc, split them.
*/

CREATE TABLE IF NOT EXISTS http.responses (
    id SERIAL PRIMARY KEY, 
    nct VARCHAR(15),
    version SMALLINT
    url VARCHAR(255),
    response_code SMALLINT,
    response_date DATE
    );

CREATE TABLE IF NOT EXISTS http.xml_documents (
    id SERIAL PRIMARY KEY,
    xml XML,
    CONSTRAINT http_response 
        FOREIGN KEY (id) 
        REFERENCES http.responses (id)
        ON DELETE CASCADE --remove xml if the request is deleted
);


