Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zurich schema and fns (fns need work) #16

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions schema/reports/zurich/zurich.functions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- Create Trigger Function to update all_reports table
CREATE OR REPLACE FUNCTION zurich.update_all_reports_from_zurich()
RETURNS trigger AS
$BODY$
BEGIN
IF (TG_OP = 'UPDATE') THEN
INSERT INTO cognicity.all_reports (fkey, created_at, text, source, disaster_type, lang, url, image_url, title, the_geom) SELECT NEW.pkey, NEW.created_at, NEW.text, 'zurich', NEW.disaster_type, NEW.lang, NEW.url, NEW.image_url, NEW.title, NEW.the_geom;
RETURN NEW;
ELSIF (TG_OP = 'INSERT') THEN
INSERT INTO cognicity.all_reports (fkey, created_at, text, source, disaster_type, lang, url, image_url, title, the_geom) SELECT NEW.pkey, NEW.created_at, NEW.text, 'zurich', NEW.disaster_type, NEW.lang, NEW.url, NEW.image_url, NEW.title, NEW.the_geom;
RETURN NEW;
END IF;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION zurich.update_all_reports_from_zurich()
OWNER TO postgres;

CREATE TRIGGER trigger_update_all_reports_from_zurich
BEFORE INSERT OR UPDATE
ON zurich.reports
FOR EACH ROW
EXECUTE PROCEDURE zurich.update_all_reports_from_zurich();
34 changes: 34 additions & 0 deletions schema/reports/zurich/zurich.schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- Schema for zurich data
CREATE SCHEMA zurich;

-- Create table for zurich reports
CREATE TABLE zurich.reports
(
pkey bigserial NOT NULL,
post_id bigint NOT NULL UNIQUE,
database_time timestamp with time zone DEFAULT now(),
created_at timestamp with time zone,
disaster_type character varying NOT NULL,
text character varying,
lang character varying,
url character varying,
image_url character varying,
title character varying,
city character varying,
CONSTRAINT pkey_zurich PRIMARY KEY (pkey)
);

-- Add Geometry column to tweet_reports
SELECT AddGeometryColumn ('zurich','reports','the_geom',4326,'POINT',2);

-- Add GIST spatial index
CREATE INDEX gix_zurich_reports ON zurich.reports USING gist (the_geom);

-- Create table for zurich report users
CREATE TABLE zurich.users
(
pkey bigserial,
user_hash character varying UNIQUE,
reports_count integer ,
CONSTRAINT pkey_zurich_users PRIMARY KEY (pkey)
);