colouring-montreal/migrations
2018-09-30 19:49:41 +01:00
..
001.core.down.sql Add building_properties table, buildings.revision_id 2018-09-30 16:17:11 +01:00
001.core.up.sql Add building_properties table, buildings.revision_id 2018-09-30 16:17: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 Add building_properties table, buildings.revision_id 2018-09-30 16:17:11 +01:00
003.index-buildings.up.sql Add building_properties table, buildings.revision_id 2018-09-30 16:17:11 +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 Index and constrain building_user_likes (one like per building per user) 2018-09-30 19:49:41 +01:00
README.md Update migration-running docs 2018-09-29 18:14:21 +01: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_sessons 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;
-- 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;

Set or update passwords:

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