diff --git a/Building/ddl/mechanical_turk_generate_schema.sql b/Building/ddl/mechanical_turk_generate_schema.sql index ecb6691ced7d0311b437bd125b7e6176d03db271..d7be21cec4bca8a3cbeb7c4b2af585b428788040 100644 --- a/Building/ddl/mechanical_turk_generate_schema.sql +++ b/Building/ddl/mechanical_turk_generate_schema.sql @@ -12,7 +12,7 @@ ALTER DEFAULT PRIVILEGES IN SCHEMA mechanical_turk TO "RW_users" WITH GRANT OPTION; ALTER DEFAULT PRIVILEGES IN SCHEMA mechanical_turk - GRANT INSERT, SELECT, UPDATE ON TABLES + GRANT INSERT, DELETE, SELECT, UPDATE ON TABLES TO "building_service"; ALTER DEFAULT PRIVILEGES IN SCHEMA mechanical_turk @@ -132,3 +132,163 @@ select 'Rejected'; select count(*) from mechanical_turk.hit_status + + + + +-- table: mechanical_turk.feature + +drop table if exists mechanical_turk.feature cascade; + +create table mechanical_turk.feature +( + id serial not null, + description character varying(15), + constraint feature_pkey primary key (id) +) +with ( + oids=false +); + +--populate feature_table + +insert into mechanical_turk.feature(description) +select 'Door'; + +insert into mechanical_turk.feature(description) +select 'Window'; + +insert into mechanical_turk.feature(description) +select 'Building Point'; + +insert into mechanical_turk.feature(description) +select 'Roof Point'; + +-- Table: mechanical_turk.unapproved_point + +DROP TABLE if exists mechanical_turk.unapproved_point cascade; + +CREATE TABLE mechanical_turk.unapproved_point +( + id serial NOT NULL, + latitude float, + longitude float, + elevation integer, + corresponding_height smallint, + feature smallint, + hit_id integer, + building_id integer, + CONSTRAINT unapproved_point_pkey PRIMARY KEY (id), + CONSTRAINT unapproved_point_feature_fkey FOREIGN KEY (feature) + REFERENCES mechanical_turk.feature (id) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT unapproved_point_hit_id_fkey FOREIGN KEY (hit_id) + REFERENCES mechanical_turk.hit (id) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE NO ACTION +) +WITH ( + OIDS=FALSE +); + +-- table: mechanical_turk.direction + +drop table if exists mechanical_turk.direction cascade; + +create table mechanical_turk.direction +( + id serial not null, + description character varying(15), + constraint direction_pkey primary key (id) +) +with ( + oids=false +); + +--populate direction_table + +insert into mechanical_turk.direction(description) +select 'South/Front'; + +insert into mechanical_turk.direction(description) +select 'East/Right'; + +insert into mechanical_turk.direction(description) +select 'West/Left'; + +insert into mechanical_turk.direction(description) +select 'North/Back'; + +-- Table: mechanical_turk.unapproved_window_door + +DROP TABLE if exists mechanical_turk.unapproved_window_door cascade; + +CREATE TABLE mechanical_turk.unapproved_window_door +( + id serial NOT NULL, + height float, + width float, + quantity smallint, + orientation smallint, + direction smallint, + feature smallint, + hit_id integer, + building_id integer, + CONSTRAINT unapproved_window_door_pkey PRIMARY KEY (id), + CONSTRAINT unapproved_window_door_orientation_fkey FOREIGN KEY (orientation) + REFERENCES mechanical_turk.direction (id) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT unapproved_window_door_direction_fkey FOREIGN KEY (direction) + REFERENCES mechanical_turk.direction (id) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT unapproved_window_door_feature_fkey FOREIGN KEY (feature) + REFERENCES mechanical_turk.feature (id) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT unapproved_window_door_hit_id_fkey FOREIGN KEY (hit_id) + REFERENCES mechanical_turk.hit (id) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE NO ACTION +) +WITH ( + OIDS=FALSE +); + +-- Table: mechanical_turk.unapproved_building_dimensions + +DROP TABLE if exists mechanical_turk.unapproved_building_dimensions cascade; + +CREATE TABLE mechanical_turk.unapproved_building_dimensions +( + id serial NOT NULL, + perimeter float, + area float, + num_floors smallint, + ground_elevation smallint, + hit_id integer, + building_id integer, + north_adjacency float, + south_adjacency float, + west_adjacency float, + east_adjacency float, + CONSTRAINT unapproved_building_dimensions_pkey PRIMARY KEY (id), + CONSTRAINT unapproved_building_dimensions_hit_id_fkey FOREIGN KEY (hit_id) + REFERENCES mechanical_turk.hit (id) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE NO ACTION +) +WITH ( + OIDS=FALSE +); + +-- Function: mechanical_turk.delete_unapproved_dimensions(integer) +DROP FUNCTION IF EXISTS mechanical_turk.delete_unapproved_dimensions(integer); + +CREATE OR REPLACE FUNCTION mechanical_turk.delete_unapproved_dimensions(IN in_hit_id integer) + RETURNS smallint as +$BODY$ + +BEGIN +DELETE FROM mechanical_turk.unapproved_point WHERE mechanical_turk.unapproved_point.hit_id = in_hit_id; +DELETE FROM mechanical_turk.unapproved_window_door WHERE mechanical_turk.unapproved_window_door.hit_id = in_hit_id; +DELETE FROM mechanical_turk.unapproved_building_dimensions WHERE mechanical_turk.unapproved_building_dimensions.hit_id = in_hit_id; +RETURN in_hit_id; +END; +$BODY$ + LANGUAGE plpgsql VOLATILE;