Skip to content

Commit

Permalink
Merge pull request #42 from urbanriskmap/dev
Browse files Browse the repository at this point in the history
Merge dev to form v3.0.6
  • Loading branch information
tomasholderness authored Jan 23, 2018
2 parents 15cd8ff + 1b69745 commit 13ce5a2
Show file tree
Hide file tree
Showing 10 changed files with 2,815 additions and 2,705 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ CHANGE LOG
- added Semarang extents to Indonesian data
- added test instance parameters for Semarang
- removed default parameters from database build script

## v3.0.6
- documented release procedure in README.md
- added RDS permissions script
- added table reports_points_log
- added district_id field to local_areas data in Indonesia
- added district_id field to tags property of reports
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,17 @@ $ shp2pgsql -I -d -s 4326 <FILENAME.SHP> <SCHEMA>.<TABLE> | psql -U postgres -d
### Contribution Guidelines
* Issues are tracked on [GitHub](https://github.com/urbanriskmap/cognicity-schema/issues)

### Release
The release procedure is as follows:
- Update the CHANGELOG.md file with the newly released version and high-level overview of changes.
- Check that package.json contains the correct release version number.
- Check that package-lock.json contains the correct release version number.
- Check that schema/cognicity/cognicity.schema.functions.sql `cognicity.version()` function returns the correct release version number.
- Commit any changes and tag in git from the current head of master. The tag should be the same as the version specified in the package.json file and elsewhere - this is the release version.
- Pull changes into dev branch.
- Increment the version number in package.json, package-lock.json, and `cognicity.version()`.
- Commit these changes with the message 'Opened new version for development'.
- Further development is now on the updated version number until the release process begins again.

### License
The schema is released under the GPLv3 License. See LICENSE.txt for details.
10 changes: 10 additions & 0 deletions build/append_district_id_to_reports.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Appends new district ID to report properties of existing reports (Indonesia only)

-- Update the local areas table with the new key (internally generated)
UPDATE cognicity.local_areas SET district_id = (substring(geom_id::varchar, 1,4))::int;

-- Set district_id null across all reports
UPDATE cognicity.all_reports SET tags = b.tags FROM (SELECT tags::jsonb || '{"district_id":null}'::jsonb as tags, pkey from cognicity.all_reports) AS b WHERE cognicity.all_reports.pkey = b.pkey;

-- Set district_id based on local_area
UPDATE cognicity.all_reports SET tags = b.tags FROM (SELECT tags::jsonb || ('{"district_id":"' || j.district_id::varchar || '"}')::jsonb as tags, i.pkey from cognicity.all_reports i, cognicity.local_areas j WHERE ST_WITHIN(i.the_geom, j.the_geom) ) AS b WHERE cognicity.all_reports.pkey = b.pkey;
8 changes: 8 additions & 0 deletions build/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env bash

# Exit 1 on any error
set -e

# Config
PGHOST=${PGHOST:-'localhost'}
PGUSER=${PGUSER:-'postgres'}
Expand All @@ -24,6 +28,10 @@ if [ $SCHEMA == true ]; then
POSTGIS="CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology; CREATE EXTENSION fuzzystrmatch; CREATE EXTENSION address_standardizer; CREATE EXTENSION postgis_tiger_geocoder;"
psql -h $PGHOST -p $PGPORT -U $PGUSER -d $PGDATABASE -c """$POSTGIS"""

# Fix AWS RDS permissions if need
echo "Check if RDS user present and fix permissions if needed"
psql -h $PGHOST -p $PGPORT -U $PGUSER -d $PGDATABASE -f $(pwd)/build/set_rds_postgis_permissions.sql

echo "Load UUID"
# Load UUID extension
UUID="CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";"
Expand Down
29 changes: 29 additions & 0 deletions build/set_rds_postgis_permissions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/** Detect if AWS RDS user present and fix permissions if required
Reference:
(1) https://gist.github.com/matthewberryman/7689766b5f94a5499d8c
**/
CREATE OR REPLACE FUNCTION set_rds_postgis_permissions()
RETURNS VOID AS $$
DECLARE rds INTEGER;
BEGIN
-- if user rdsadmin exists assume this is an AWS RDS instance
SELECT INTO rds count(*) FROM pg_user WHERE usename = 'rdsadmin';
IF rds > 0 THEN
ALTER SCHEMA tiger owner to rds_superuser;
ALTER SCHEMA topology owner to rds_superuser;

CREATE OR REPLACE FUNCTION exec(text) returns text language plpgsql volatile AS $f$ BEGIN EXECUTE $1; RETURN $1; END; $f$;
PERFORM exec('ALTER TABLE ' || quote_ident(s.nspname) || '.' || quote_ident(s.relname) || ' OWNER TO rds_superuser')
FROM (
SELECT nspname, relname
FROM pg_class c JOIN pg_namespace n ON (c.relnamespace = n.oid)
WHERE nspname in ('tiger','topology') AND
relkind IN ('r','S','v') ORDER BY relkind = 'S')
s;
END IF;
RETURN;
END;
$$ LANGUAGE plpgsql VOLATILE
COST 100;

SELECT * FROM set_rds_postgis_permissions();
5,435 changes: 2,734 additions & 2,701 deletions data/indonesia/cognicity/local_areas.data.sql

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cognicity-schema",
"version": "3.0.5",
"version": "3.0.6",
"description": "Cognicity Database Schema",
"engines": {
"node": ">=8.1.4"
Expand Down
5 changes: 3 additions & 2 deletions schema/cognicity/cognicity.functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CREATE OR REPLACE FUNCTION cognicity.define_report_region()
$BODY$
BEGIN
UPDATE cognicity.all_reports
SET tags = (SELECT '{"instance_region_code":"' || COALESCE(code.code, 'null') || '", '|| '"local_area_id":"' || COALESCE(la.pkey::varchar, 'null') ||'"}' FROM (SELECT (SELECT code FROM cognicity.instance_regions AS i WHERE ST_WITHIN(NEW.the_geom, i.the_geom))) AS code, (SELECT (SELECT pkey FROM cognicity.local_areas as j WHERE ST_WITHIN(NEW.the_geom, j.the_geom))) AS la)::json
SET tags = (SELECT (la.x->0)::jsonb || (code.x->0)::jsonb FROM (SELECT COALESCE(array_to_json(array_agg(row_to_json(a))),'[{"local_area_id":null, "district_id":null}]') as x FROM (SELECT pkey::varchar as local_area_id, district_id::varchar as district_id FROM cognicity.local_areas as j WHERE ST_Within(NEW.the_geom, j.the_geom)) as a) as la, (SELECT COALESCE(array_to_json(array_agg(row_to_json(a))),'[{"instance_region_code":null}]') as x FROM (SELECT code as instance_region_code FROM cognicity.instance_regions as i WHERE ST_Within(NEW.the_geom, i.the_geom)) as a) as code)
WHERE pkey = NEW.pkey;
RETURN NEW;
END;
Expand Down Expand Up @@ -108,11 +108,12 @@ CREATE OR REPLACE FUNCTION cognicity.rem_get_flood(timestamp with time zone)
ALTER FUNCTION cognicity.rem_get_flood(timestamp with time zone)
OWNER TO postgres;

/* Output schema version */
CREATE FUNCTION cognicity.version()
RETURNS varchar
AS $BODY$
BEGIN
RETURN '3.0.5';
RETURN '3.0.6';
END
$BODY$
LANGUAGE plpgsql VOLATILE
Expand Down
10 changes: 10 additions & 0 deletions schema/cognicity/cognicity.schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ CREATE TABLE cognicity.local_areas(
parent_name character varying,
city_name character varying,
instance_region_code character varying NOT NULL,
district_id integer,
CONSTRAINT local_area_pkey PRIMARY KEY (pkey)
);

Expand Down Expand Up @@ -83,3 +84,12 @@ CREATE TABLE cognicity.rem_status_log
username character varying,
CONSTRAINT rem_status_log_id_pkey PRIMARY KEY (id)
);

CREATE TABLE cognicity.reports_points_log
(
id bigserial NOT NULL,
report_id bigint NOT NULL,
changed timestamp with time zone DEFAULT now(),
value integer,
CONSTRAINT report_points_log_pkey PRIMARY KEY (id)
);

0 comments on commit 13ce5a2

Please sign in to comment.