colouring-montreal/migrations
2019-10-01 17:11:35 +01: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 Update 006.controls.up.sql 2019-03-23 09:16:51 +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
009.user-deleted.down.sql Add user delete database migrations 2019-08-16 11:12:18 +01:00
009.user-deleted.up.sql Add user delete database migrations 2019-08-16 11:12:18 +01:00
010.password-reset.down.sql Add password reset token database migrations 2019-08-21 14:20:53 +01:00
010.password-reset.up.sql Add password reset token database migrations 2019-08-21 14:20:53 +01:00
011.sustainability.down.sql Addresses review comments for #360 2019-08-29 16:13:09 +01:00
011.sustainability.up.sql Update 011.sustainability.up.sql 2019-09-27 15:03:20 +01:00
012.type.down.sql File naming consistency 2019-10-01 16:30:15 +01:00
012.type.up.sql File naming consistency 2019-10-01 16:30:15 +01:00
013.bulk-extracts.down.sql Reorder bulk extract migration 012->013 2019-10-01 17:11:35 +01:00
013.bulk-extracts.up.sql Reorder bulk extract migration 012->013 2019-10-01 17:11:35 +01: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';"