Skip to content
Snippets Groups Projects
Commit 4efc52cb authored by Adriaan Renting's avatar Adriaan Renting
Browse files

Task #8580: updated the Resource Allocation Database scripts to add schemas.

parent c7dc6d82
No related branches found
No related tags found
No related merge requests found
...@@ -7,33 +7,34 @@ ...@@ -7,33 +7,34 @@
-- LC_COLLATE = 'en_US.UTF-8' -- LC_COLLATE = 'en_US.UTF-8'
-- LC_CTYPE = 'en_US.UTF-8' -- LC_CTYPE = 'en_US.UTF-8'
-- CONNECTION LIMIT = -1; -- CONNECTION LIMIT = -1;
--CREATE SCHEMA resourceallocation; CREATE SCHEMA virtual_instrument;
--SET SCHEMA 'resourceallocation'; CREATE SCHEMA resource_monitoring;
CREATE SCHEMA resource_allocation;
-- USE resourceassignment; -- USE resourceassignment;?
BEGIN; BEGIN;
-- This is insanity, but will hopefully work -- This is insanity, but works, order needs to be the reverse of the CREATE TABLE statements
DROP TABLE IF EXISTS resource_group_availability; DROP TABLE IF EXISTS resource_monitoring.resource_group_availability;
DROP TABLE IF EXISTS resource_availability; DROP TABLE IF EXISTS resource_monitoring.resource_availability;
DROP TABLE IF EXISTS resource_capacity; DROP TABLE IF EXISTS resource_monitoring.resource_capacity;
DROP TABLE IF EXISTS resource_claim; DROP TABLE IF EXISTS resource_allocation.resource_claim;
DROP TABLE IF EXISTS resource_claim_status; DROP TABLE IF EXISTS resource_allocation.resource_claim_status;
DROP TABLE IF EXISTS task; DROP TABLE IF EXISTS resource_allocation.task;
DROP TABLE IF EXISTS specification; DROP TABLE IF EXISTS resource_allocation.specification;
DROP TABLE IF EXISTS task_type; DROP TABLE IF EXISTS resource_allocation.task_type;
DROP TABLE IF EXISTS task_status; DROP TABLE IF EXISTS resource_allocation.task_status;
DROP TABLE IF EXISTS resource_group_to_resource_group; DROP TABLE IF EXISTS virtual_instrument.resource_group_to_resource_group;
DROP TABLE IF EXISTS resource_to_resource_group; DROP TABLE IF EXISTS virtual_instrument.resource_to_resource_group;
DROP TABLE IF EXISTS resource_group; DROP TABLE IF EXISTS virtual_instrument.resource_group;
DROP TABLE IF EXISTS resource_group_type; DROP TABLE IF EXISTS virtual_instrument.resource_group_type;
DROP TABLE IF EXISTS resource; DROP TABLE IF EXISTS virtual_instrument.resource;
DROP TABLE IF EXISTS resource_type; DROP TABLE IF EXISTS virtual_instrument.resource_type;
DROP TABLE IF EXISTS unit; DROP TABLE IF EXISTS virtual_instrument.unit;
-- I can not get this to do something useful instead: SET CONSTRAINTS ALL DEFERRED; -- Would like to use this instead, but I can not get it to do something useful: SET CONSTRAINTS ALL DEFERRED;
CREATE TABLE unit ( CREATE TABLE virtual_instrument.unit (
id serial NOT NULL, id serial NOT NULL,
units text NOT NULL, units text NOT NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
...@@ -41,7 +42,7 @@ CREATE TABLE unit ( ...@@ -41,7 +42,7 @@ CREATE TABLE unit (
ALTER TABLE unit ALTER TABLE unit
OWNER TO renting; OWNER TO renting;
CREATE TABLE resource_type ( CREATE TABLE virtual_instrument.resource_type (
id serial NOT NULL, id serial NOT NULL,
name text NOT NULL, name text NOT NULL,
unit_id integer NOT NULL REFERENCES unit DEFERRABLE INITIALLY IMMEDIATE, unit_id integer NOT NULL REFERENCES unit DEFERRABLE INITIALLY IMMEDIATE,
...@@ -50,7 +51,7 @@ CREATE TABLE resource_type ( ...@@ -50,7 +51,7 @@ CREATE TABLE resource_type (
ALTER TABLE resource_type ALTER TABLE resource_type
OWNER TO renting; OWNER TO renting;
CREATE TABLE resource ( CREATE TABLE virtual_instrument.resource (
id serial NOT NULL, id serial NOT NULL,
name text NOT NULL, name text NOT NULL,
type_id integer NOT NULL REFERENCES resource_type DEFERRABLE INITIALLY IMMEDIATE, type_id integer NOT NULL REFERENCES resource_type DEFERRABLE INITIALLY IMMEDIATE,
...@@ -59,7 +60,7 @@ CREATE TABLE resource ( ...@@ -59,7 +60,7 @@ CREATE TABLE resource (
ALTER TABLE resource ALTER TABLE resource
OWNER TO renting; OWNER TO renting;
CREATE TABLE resource_group_type ( CREATE TABLE virtual_instrument.resource_group_type (
id serial NOT NULL, id serial NOT NULL,
name text NOT NULL, name text NOT NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
...@@ -67,7 +68,7 @@ CREATE TABLE resource_group_type ( ...@@ -67,7 +68,7 @@ CREATE TABLE resource_group_type (
ALTER TABLE resource_group_type ALTER TABLE resource_group_type
OWNER TO renting; OWNER TO renting;
CREATE TABLE resource_group ( CREATE TABLE virtual_instrument.resource_group (
id serial NOT NULL, id serial NOT NULL,
name text NOT NULL, name text NOT NULL,
type_id integer NOT NULL REFERENCES resource_group_type DEFERRABLE INITIALLY IMMEDIATE, type_id integer NOT NULL REFERENCES resource_group_type DEFERRABLE INITIALLY IMMEDIATE,
...@@ -76,7 +77,7 @@ CREATE TABLE resource_group ( ...@@ -76,7 +77,7 @@ CREATE TABLE resource_group (
ALTER TABLE resource_group ALTER TABLE resource_group
OWNER TO renting; OWNER TO renting;
CREATE TABLE resource_to_resource_group ( CREATE TABLE virtual_instrument.resource_to_resource_group (
id serial NOT NULL, id serial NOT NULL,
child_id integer NOT NULL REFERENCES resource DEFERRABLE INITIALLY IMMEDIATE, child_id integer NOT NULL REFERENCES resource DEFERRABLE INITIALLY IMMEDIATE,
parent_id integer NOT NULL REFERENCES resource_group DEFERRABLE INITIALLY IMMEDIATE, parent_id integer NOT NULL REFERENCES resource_group DEFERRABLE INITIALLY IMMEDIATE,
...@@ -85,7 +86,7 @@ CREATE TABLE resource_to_resource_group ( ...@@ -85,7 +86,7 @@ CREATE TABLE resource_to_resource_group (
ALTER TABLE resource_to_resource_group ALTER TABLE resource_to_resource_group
OWNER TO renting; OWNER TO renting;
CREATE TABLE resource_group_to_resource_group ( CREATE TABLE virtual_instrument.resource_group_to_resource_group (
id serial NOT NULL, id serial NOT NULL,
child_id integer NOT NULL REFERENCES resource_group DEFERRABLE INITIALLY IMMEDIATE, child_id integer NOT NULL REFERENCES resource_group DEFERRABLE INITIALLY IMMEDIATE,
parent_id integer REFERENCES resource_group DEFERRABLE INITIALLY IMMEDIATE, parent_id integer REFERENCES resource_group DEFERRABLE INITIALLY IMMEDIATE,
...@@ -94,7 +95,7 @@ CREATE TABLE resource_group_to_resource_group ( ...@@ -94,7 +95,7 @@ CREATE TABLE resource_group_to_resource_group (
ALTER TABLE resource_group_to_resource_group ALTER TABLE resource_group_to_resource_group
OWNER TO renting; OWNER TO renting;
CREATE TABLE task_status ( CREATE TABLE resource_allocation.task_status (
id serial NOT NULL, id serial NOT NULL,
name text NOT NULL, name text NOT NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
...@@ -102,7 +103,7 @@ CREATE TABLE task_status ( ...@@ -102,7 +103,7 @@ CREATE TABLE task_status (
ALTER TABLE task_status ALTER TABLE task_status
OWNER TO renting; OWNER TO renting;
CREATE TABLE task_type ( CREATE TABLE resource_allocation.task_type (
id serial NOT NULL, id serial NOT NULL,
name text NOT NULL, name text NOT NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
...@@ -110,7 +111,7 @@ CREATE TABLE task_type ( ...@@ -110,7 +111,7 @@ CREATE TABLE task_type (
ALTER TABLE task_type ALTER TABLE task_type
OWNER TO renting; OWNER TO renting;
CREATE TABLE specification ( CREATE TABLE resource_allocation.specification (
id serial NOT NULL, id serial NOT NULL,
starttime timestamp, starttime timestamp,
endtime timestamp, endtime timestamp,
...@@ -120,7 +121,7 @@ CREATE TABLE specification ( ...@@ -120,7 +121,7 @@ CREATE TABLE specification (
ALTER TABLE specification ALTER TABLE specification
OWNER TO renting; OWNER TO renting;
CREATE TABLE task ( CREATE TABLE resource_allocation.task (
id serial NOT NULL, id serial NOT NULL,
mom_id integer, mom_id integer,
otdb_id integer, otdb_id integer,
...@@ -132,7 +133,7 @@ CREATE TABLE task ( ...@@ -132,7 +133,7 @@ CREATE TABLE task (
ALTER TABLE task ALTER TABLE task
OWNER TO renting; OWNER TO renting;
CREATE TABLE resource_claim_status ( CREATE TABLE resource_allocation.resource_claim_status (
id serial NOT NULL, id serial NOT NULL,
name text NOT NULL, name text NOT NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
...@@ -140,7 +141,7 @@ CREATE TABLE resource_claim_status ( ...@@ -140,7 +141,7 @@ CREATE TABLE resource_claim_status (
ALTER TABLE resource_claim_status ALTER TABLE resource_claim_status
OWNER TO renting; OWNER TO renting;
CREATE TABLE resource_claim ( CREATE TABLE resource_allocation.resource_claim (
id serial NOT NULL, id serial NOT NULL,
resource_id integer NOT NULL REFERENCES resource DEFERRABLE INITIALLY IMMEDIATE, resource_id integer NOT NULL REFERENCES resource DEFERRABLE INITIALLY IMMEDIATE,
task_id integer NOT NULL REFERENCES task DEFERRABLE INITIALLY IMMEDIATE, -- ON DELETE CASCADE, task_id integer NOT NULL REFERENCES task DEFERRABLE INITIALLY IMMEDIATE, -- ON DELETE CASCADE,
...@@ -156,7 +157,7 @@ CREATE TABLE resource_claim ( ...@@ -156,7 +157,7 @@ CREATE TABLE resource_claim (
ALTER TABLE resource_claim ALTER TABLE resource_claim
OWNER TO renting; OWNER TO renting;
CREATE TABLE resource_capacity ( CREATE TABLE resource_monitoring.resource_capacity (
id serial NOT NULL, id serial NOT NULL,
resource_id integer NOT NULL REFERENCES resource DEFERRABLE INITIALLY IMMEDIATE, resource_id integer NOT NULL REFERENCES resource DEFERRABLE INITIALLY IMMEDIATE,
available bigint NOT NULL, available bigint NOT NULL,
...@@ -166,7 +167,7 @@ CREATE TABLE resource_capacity ( ...@@ -166,7 +167,7 @@ CREATE TABLE resource_capacity (
ALTER TABLE resource_capacity ALTER TABLE resource_capacity
OWNER TO renting; OWNER TO renting;
CREATE TABLE resource_availability ( CREATE TABLE resource_monitoring.resource_availability (
id serial NOT NULL, id serial NOT NULL,
resource_id integer NOT NULL REFERENCES resource DEFERRABLE INITIALLY IMMEDIATE, resource_id integer NOT NULL REFERENCES resource DEFERRABLE INITIALLY IMMEDIATE,
available bool NOt NULL, available bool NOt NULL,
...@@ -175,7 +176,7 @@ CREATE TABLE resource_availability ( ...@@ -175,7 +176,7 @@ CREATE TABLE resource_availability (
ALTER TABLE resource_availability ALTER TABLE resource_availability
OWNER TO renting; OWNER TO renting;
CREATE TABLE resource_group_availability ( CREATE TABLE resource_monitoring.resource_group_availability (
id serial NOT NULL, id serial NOT NULL,
resource_group_id integer NOT NULL REFERENCES resource_group DEFERRABLE INITIALLY IMMEDIATE, resource_group_id integer NOT NULL REFERENCES resource_group DEFERRABLE INITIALLY IMMEDIATE,
available bool NOt NULL, available bool NOt NULL,
......
BEGIN; BEGIN;
INSERT INTO unit VALUES (0, 'station'),(1, 'bytes'); INSERT INTO virtual_instrument.unit VALUES (0, 'station'),(1, 'bytes');
INSERT INTO resource_type VALUES (0, 'station', 0),(1, 'storage', 1); INSERT INTO virtual_instrument.resource_type VALUES (0, 'station', 0),(1, 'storage', 1);
INSERT INTO resource VALUES (0, 'CS001', 0), (1,'CS002', 0), (2, 'cep4_storage', 1); INSERT INTO virtual_instrument.resource VALUES (0, 'CS001', 0), (1,'CS002', 0), (2, 'cep4_storage', 1);
INSERT INTO resource_group_type VALUES (0, 'stations'),(1, 'cluster'); INSERT INTO virtual_instrument.resource_group_type VALUES (0, 'stations'),(1, 'cluster');
INSERT INTO resource_group VALUES (0, 'CORE', 0),(1, 'CEP4', 1); INSERT INTO virtual_instrument.resource_group VALUES (0, 'CORE', 0),(1, 'CEP4', 1);
INSERT INTO resource_to_resource_group VALUES (0, 0, 0),(1, 1, 0), (2, 2, 1); INSERT INTO virtual_instrument.resource_to_resource_group VALUES (0, 0, 0),(1, 1, 0), (2, 2, 1);
INSERT INTO resource_group_to_resource_group VALUES (0, 0, NULL),(1, 1, NULL); INSERT INTO virtual_instrument.resource_group_to_resource_group VALUES (0, 0, NULL),(1, 1, NULL);
INSERT INTO task_status VALUES (0, 'SCHEDULED'),(1, 'CONFLICT'); INSERT INTO resource_allocation.task_status VALUES (0, 'SCHEDULED'),(1, 'CONFLICT');
INSERT INTO task_type VALUES (0, 'OBSERVATION'),(1, 'PIPELINE'); INSERT INTO resource_allocation.task_type VALUES (0, 'OBSERVATION'),(1, 'PIPELINE');
INSERT INTO specification VALUES (0, '2015-11-05 12:00:00', '2015-11-05 12:30:00', 'key=value'), INSERT INTO resource_allocation.specification VALUES (0, '2015-11-05 12:00:00', '2015-11-05 12:30:00', 'key=value'),
(1, '2015-11-05 13:00:00', '2015-11-05 14:00:00', 'key=1'); (1, '2015-11-05 13:00:00', '2015-11-05 14:00:00', 'key=1');
INSERT INTO task VALUES (0, 654321, 12345, 0, 0, 0),(1, 765432, 2654321, 1, 1, 1); INSERT INTO resource_allocation.task VALUES (0, 654321, 12345, 0, 0, 0),(1, 765432, 2654321, 1, 1, 1);
INSERT INTO resource_claim_status VALUES (0, 'CLAIMED'),(1, 'ALLOCATED'); INSERT INTO resource_allocation.resource_claim_status VALUES (0, 'CLAIMED'),(1, 'ALLOCATED');
INSERT INTO resource_claim VALUES (0, 0, 0, '2015-11-05 12:00:00', '2015-11-05 12:30:00', 0, '2015-11-06 12:00:00', 1), INSERT INTO resource_allocation.resource_claim VALUES (0, 0, 0, '2015-11-05 12:00:00', '2015-11-05 12:30:00', 0, '2015-11-06 12:00:00', 1),
(1, 2, 1, '2015-11-05 13:00:00', '2015-11-05 14:00:00', 1, '2015-11-06 12:00:00', 1234); (1, 2, 1, '2015-11-05 13:00:00', '2015-11-05 14:00:00', 1, '2015-11-06 12:00:00', 1234);
INSERT INTO resource_capacity VALUES (0, 0, 1, 1), (1, 1, 1,1 ), (2, 2, 15000, 100000); INSERT INTO resource_monitoring.resource_capacity VALUES (0, 0, 1, 1), (1, 1, 1,1 ), (2, 2, 15000, 100000);
INSERT INTO resource_availability VALUES (0, 0, TRUE), (1, 1, TRUE), (2, 2, TRUE); INSERT INTO resource_monitoring.resource_availability VALUES (0, 0, TRUE), (1, 1, TRUE), (2, 2, TRUE);
INSERT INTO resource_group_availability VALUES (0, 0, TRUE), (1, 1, TRUE); INSERT INTO resource_monitoring.resource_group_availability VALUES (0, 0, TRUE), (1, 1, TRUE);
COMMIT; COMMIT;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment