colouring-montreal/migrations
2019-02-11 09:30:22 +00:00
..
001.core.down.sql Make sure to drop base tables (and cascade) 2018-10-21 19:46:14 +00:00
001.core.up.sql Allow requesting user API key 2018-10-20 12:21:11 +01:00
002.index-geometries.down.sql Add index-dropping migrations 2018-09-27 21:38:37 +01:00
002.index-geometries.up.sql Create/drop database elements conditionally 2018-09-29 18:13:34 +01:00
003.index-buildings.down.sql Remove unused index from drop list 2018-09-30 20:31:20 +01:00
003.index-buildings.up.sql Update etl to load UPRNs to table 2018-10-02 21:12:46 +01:00
004.location-date-size-like.down.sql Add location, date, size, likes to database 2018-09-29 18:14:06 +01:00
004.location-date-size-like.up.sql Limit likes to one per-user per-building (db constraint) 2018-12-11 17:17:41 +00:00
005.limit-likes.down.sql Limit likes to one per-user per-building (db constraint) 2018-12-11 17:17:41 +00:00
005.limit-likes.up.sql Drop duplicate likes and reset counts 2019-01-20 14:36:15 +00:00
006.controls.down.sql Add planning controls database fields 2019-01-10 09:08:26 +00:00
006.controls.up.sql Fix controls migration create type 2019-01-19 19:44:28 +00:00
007.date-details.down.sql Add date details migrations 2019-01-19 17:46:51 +00:00
007.date-details.up.sql Add date details migrations 2019-01-19 17:46:51 +00:00
008.search.up.sql Update GIN/GIST index note 2019-02-05 21:15:48 +00:00
README.md Grant search table permissions 2019-02-11 09:30:22 +00:00

Database setup

Initial setup, on first connection (replacing hostname, username, port, dbname as required):

$ psql "host={hostname} user={username} port={port} sslmode=require dbname=postgres"
> create database colouringlondon;
> \c colouringlondon
> create extension postgis;
> create extension pgcrypto;
> \q

To run all up migrations:

$ ls ./*.up.sql 2>/dev/null | while read -r migration; do psql < $migration; done;

Or all down migrations in reverse order:

$ ls -r ./*.down.sql 2>/dev/null | while read -r migration; do psql < $migration; done;

Create an app user:

-- role for server-side of front end (HTTP POST)
CREATE ROLE appusername WITH LOGIN;
-- create/update, authenticate and authorise users
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE users, user_sessions TO appusername;
-- join users against categories and access levels
GRANT SELECT ON TABLE user_access_levels, user_categories TO appusername;
-- read/write building data
GRANT SELECT, UPDATE ON TABLE buildings TO appusername;
GRANT SELECT, INSERT, DELETE ON TABLE building_user_likes TO appusername;
GRANT SELECT ON TABLE building_properties TO appusername;
-- read geometry data
GRANT SELECT ON TABLE geometries TO appusername;
-- read/append to logs
GRANT SELECT, INSERT ON TABLE logs to appusername;
-- use id sequences
GRANT USAGE ON ALL SEQUENCES IN SCHEMA public to appusername;
-- use postgis/pgcrypto functions
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO appusername;
-- read map search locations
GRANT SELECT ON TABLE search_locations to appusername;

Set or update passwords:

psql -c "ALTER USER appusername WITH PASSWORD 'longsecurerandompassword';"